in reply to Getting the value of a pointer
Your terminlogy is confusing. $a->{apple} has a value; it doesn't point to one.
my $b = $a->{apple};
would be equivalent to you snippet, except it won't convert the value to a string.
If $a->{apple} is a string, it will copy the string.
If $a->{apple} is a number, it will copy the number.
If $a->{apple} is a reference, it will copy the reference.
If $a->{apple} is undefined, $b will be undefined.
Similarly, I've seen many people do
my_func("$var1", "$var2", "$var3");
instead of
my_func($var1, $var2, $var3);
for no reason.
Concatenating with empty strings ("".$var) or quoting variables ("$var") is only needed to force stringification, and stringifying a variable is practically never needed. Functions that require a string (such as print, eval EXPR and the LHS of the regexp match operator) will stringify variables as needed, automatically.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting the value of a pointer
by water (Deacon) on Jul 18, 2005 at 19:05 UTC | |
by ikegami (Patriarch) on Jul 18, 2005 at 19:49 UTC |