in reply to I don't understand string versus numeric context
Think about it like this:
A Perl-scalar is not something has only holds a single value, bit rather it consists of a number of "slots" that contain values for the different contexts in which the scalar can be used.
Normally these values are "the same" and are computed by Perl as needed (e.g. a scalar containing a 4 in it's integer-slot will get the value "4" (a string!) in it's string-slot when used in a string-context), but not always.
A good example for this are references. Observe:
As you can see in numeric context the value becomes the memory-address whereas in string-context it also shows the type of the reference "ARRAY(0x.....)".my $ref = []; # reference to an array my $a = $ref + 0; # force numeric context my $b = "$ref"; # force string-contect print "$a $b\n";
|
|---|