Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How to save first two columns of an array into another array

by Athanasius (Monsignor)
on Oct 01, 2012 at 16:44 UTC ( #996692=note: print w/ replies, xml ) Need Help??


in reply to How to save first two columns of an array into another array

On a side note, I just want to point out that the code:

# Find the number of vertices my @L; for my $i (0 .. $#S) { for my $j (0 .. $#{$S[$i]}) { push(@L, $S[$i][$j]); } }

can be simplified down to:

my @L = map { @$_ } @S;

since it’s just flattening a 2-dimensional list into a 1-dimensional list.

I know only too well how hard it is to switch from thinking in C to thinking in Perl. But persevere, it’s worth the effort!

Hope that helps,

Athanasius <°(((><contra mundum


Comment on Re: How to save first two columns of an array into another array
Select or Download Code
Re^2: How to save first two columns of an array into another array
by GrandFather (Cardinal) on Oct 02, 2012 at 20:11 UTC

    Or to explore the language just a little more:

    my @l; push @l, @$_ for @S;

    to show statement modifiers and that push can push multiple elements at a time.

    Update: Fix array name inconsistency.

    True laziness is hard work

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2014-07-28 11:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (196 votes), past polls