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
    Agreed.

    Digression: One place where you may see explicit stringification is when using Class::DBI, where stringification produces a (numerical) primary key.

    # untested my $object = Foo->retrieve(1234); # an object &function_needing_int_not_object('' . $object);

      That's odd. It should overload numerification and numerical ops instead of (or in additon to) stringification.

      There is only one case where stringification is needed that comes to mind: When the function behaves differently whether a parameter is a string* or an object, and the parameter is an object with an overloaded stringification operator. For example,

      sub output { my ($fh, ...) = @_ if (!ref($fh) && ref($fh) ne 'GLOB') { open($fh, '>>', $fh); } ... }

      * or number vs object, or boolean vs object