Retrieving Values
To use the value stored in a variable, use it anywhere where a value is required, such as the argument to a function or in an expression. For example, if you wish to print the value to the browser, you can type print($s) to print the value of a variable named s. You can even set a variable with the value of another, such as $s = $t.
If a variable contains a string, you may refer to each character using square brackets. Each character is numbered starting with zero. To refer to the seventh character in the s variable, you would type $s[6]. This notation works both ways, in fact. You can set a single character of a string with an expression like $s[6] ="x". Only the first character of the value on the right-hand side will be used ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access