Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by Athanasius (Abbot)
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 (Sage) 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 chilling in the Monastery: (8)
As of 2015-07-04 16:21 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 (60 votes), past polls