Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: list references

by Enlil (Parson)
on Jun 15, 2004 at 22:07 UTC ( [id://367066]=note: print w/replies, xml ) Need Help??


in reply to list references

They both seem to produce the same thing: $ref=\(1..3); will return a reference to the last thing in the list of references namely a scalar reference to 3 (as usually happens with lists on the right and scalars on the left). But then again so does $enum_list_ref. That is
use Data::Dumper; use strict; use warnings; my $ref=\(1..3); my $oth_ref = \(1,2,3); print Dumper $ref,$oth_ref __OUTPUT__ $VAR1 = \3; $VAR2 = \3;
On the other hand @a=(\(1..3),\(5..9)); will flatten the lists out before assigning to the array so you get the same thing as if you had written:
@a = (\1,\2,\3,\5,\6,\7,\8,\9);
the same thing would happen with @a=(\(1,2,3),\(5,6,7,8,9)) That is:
use Data::Dumper; use strict; use warnings; my @array = \(1 .. 3, 5 ..9); my @array2 = \(1,2,3,5,6,7,8,9); my @array3 = (\(1 ..3),\(5,6,7,8,9)); print Dumper \@array,\@array2,\@array3 __OUTPUT__ $VAR1 = [ \1, \2, \3, \5, \6, \7, \8, \9 ]; $VAR2 = [ \1, \2, \3, \5, \6, \7, \8, \9 ]; $VAR3 = [ \1, \2, \3, \5, \6, \7, \8, \9 ];

-enlil

Replies are listed 'Best First'.
Re^2: list references
by sleepingsquirrel (Chaplain) on Jun 15, 2004 at 23:41 UTC
    Maybe I've got a funky version of perl. When I run both your snippets I get answers different from yours. For the first program I get...
    greg@sparky:~/test$ cat enlil1 #!/usr/bin/perl use Data::Dumper; use strict; use warnings; my $ref=\(1..3); my $oth_ref = \(1,2,3); print Dumper $ref,$oth_ref greg@sparky:~/test$ ./enlil1 $VAR1 = [ 1, 2, 3 ]; $VAR2 = \3;
    ...and for the second...
    greg@sparky:~/test$ cat enlil2 #!/usr/bin/perl use Data::Dumper; use strict; use warnings; my @array = \(1 .. 3, 5 ..9); my @array2 = \(1,2,3,5,6,7,8,9); my @array3 = (\(1 ..3),\(5,6,7,8,9)); print Dumper \@array,\@array2,\@array3; greg@sparky:~/test$ ./enlil2 $VAR1 = [ [ 1, 2, 3 ], [ 5, 6, 7, 8, 9 ] ]; $VAR2 = [ \1, \2, \3, \5, \6, \7, \8, \9 ]; $VAR3 = [ [ 1, 2, 3 ], \5, \6, \7, \8, \9 ];
    Here's what my 'perl -V' looks like...


    -- All code is 100% tested and functional unless otherwise noted.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-19 19:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found