in reply to Putting weird things into $#array

There was a thread not too long ago, which I can't find, in which a poster used some module or feature to dump the internal representation of a scalar, showing its numeric value and string values separately. It wasn't Data::Dumper.

The thread was about the difference between

print $i, "\n"; # and print "$i\n";
It seems like dumping out $#a in a few of these situations would be interesting.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Putting weird things into $#array
by bmann (Priest) on Mar 08, 2005 at 00:13 UTC
    I remember that thread.

    If I'm not mistaken, print "$var\n" or print $var, "\n" looks like the thread, and Re: print "$var\n" or print $var, "\n" would be the post that uses Devel::Peek's Dump function to show the variable's internal state.

    Here are results of perl -MDevel::Peek -le "$b=[1,2,3]; $#a=$b;Dump $b;Dump $#a"

    The SV slot for both variables hold a reference to the anonymous array (PVAV(0x15d674c) at 0x15d50e0), and "SV = PVMG" means either "magic is attached or the value is blessed"1 The first SV is $b, the second SV is $#a.

    Maybe someone with a little more knowledge of perl internals can help interpret this...

    1 From PerlGuts Illustrated

Re^2: Putting weird things into $#array
by Limbic~Region (Chancellor) on Mar 07, 2005 at 23:31 UTC
      That isn't the thread. I don't know for sure whether it's the utility that was being used. In the thread I'm thinking of, one poster noted (using some utility) the memory consumed by a program that interpolates numbers into a string to print vs. the memory consumed by a program that passes the numbers as separate arguments to print. The respondant dumped the value of an interpolated number and a non-interpolated one, showing that the memory overhead was due to having stored a stringified value.

      Does that sound familiar at all? I know it wasn't very many weeks ago.


      Caution: Contents may have been coded under pressure.