Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Comparing ARRAY Ref values

by ww (Bishop)
on May 09, 2013 at 13:48 UTC ( #1032775=note: print w/ replies, xml ) Need Help??

in reply to Comparing ARRAY Ref values

You're definitely missing something. InfiniteSilence has addressed your second question one of your questions (yes, I used to get confused about 'left' and 'right' sometimes, too.

As to the first other, the values you're looking at are -- to all intents and purposes -- pointers to the memory locations (addresses) where the arrays begin. They are NOT, IN ANY SENSE reflective of the values in the arrays themselves.

Update: Demo:

#!/usr/bin/perl use 5.016; my @arr1 = qw(a b c d e); my @arr2 = (3, 5, 7, 9); my $ref1 = \@arr1; my $ref1a = \@arr1; my $ref2 = \@arr2; say "\$ref1: $ref1 and \$ref1a: $ref1a"; say "\$ref2: $ref2; \@$ref2: @$ref2;" #Second half DEREFs the referen +ce =head demo C:\> $ref1: ARRAY(0x119ee3c) and $ref1a: ARRAY(0x119ee3c) $ref2: ARRAY(0x119f12c); @ARRAY(0x119f12c): 3 5 7 9;

See the tuts here at References.

If you didn't program your executable by toggling in binary, it wasn't really programming!

Comment on Re: Comparing ARRAY Ref values
Download Code
Re^2: Comparing ARRAY Ref values
by filipebean (Novice) on May 09, 2013 at 14:31 UTC


    this is similar of what I have:

    #!/usr/bin/perl my @arr1=(); push(@arr1,3); push(@arr1,5); push(@arr1,7); push(@arr1,9); my @arr2 = (3, 5, 7, 9); my $ref1 = \@arr1; my $ref2 = \@arr2; print "\$ref1: $ref1 \n"; print "\$ref2: $ref2";


    $ perl $ref1: ARRAY(0x80071d38) $ref2: ARRAY(0x80071e40)

    As you said, it points to the memory locations (addresses) where the arrays begin and it has no relation with the values inside.

    Thank you

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032775]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-08-20 11:25 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (111 votes), past polls