Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: $_ and list flattening with map()

by pg (Canon)
on Dec 14, 2003 at 22:05 UTC ( #314690=note: print w/ replies, xml ) Need Help??


in reply to $_ and list flattening with map()

This tells why:

use strict; use warnings; use Data::Dumper; my $a = [[0,1,2], [10,11,12]]; print \$a->[0][0], "\n"; print \$a->[0][1], "\n"; print \$a->[0][2], "\n"; print \$a->[1][0], "\n"; print \$a->[1][1], "\n"; print \$a->[1][2], "\n"; print "=======\n"; print \$_, "\n" for map @$_, @{$a};#one of your way print "=======\n"; foreach (@$a) { print \$_, "\n" foreach @$_ }#your other way

Result, see how the 3rd set is the same as the 1st one, but the 2nd set stands alone:

SCALAR(0x15551a4) SCALAR(0x15551b0) SCALAR(0x15551c8) SCALAR(0x155abd4) SCALAR(0x155500c) SCALAR(0x1571284) ======= SCALAR(0x15712c0) SCALAR(0x1571290) SCALAR(0x15551d4) SCALAR(0x15712e4) SCALAR(0x15712d8) SCALAR(0x15712cc) ======= SCALAR(0x15551a4) SCALAR(0x15551b0) SCALAR(0x15551c8) SCALAR(0x155abd4) SCALAR(0x155500c) SCALAR(0x1571284)


Comment on Re: $_ and list flattening with map()
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2015-07-29 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls