Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Help to assign a 2D-Array to another while excluding specific rows.

by SuicideJunkie (Vicar)
on Sep 13, 2011 at 21:09 UTC ( [id://925772]=note: print w/replies, xml ) Need Help??


in reply to Help to assign a 2D-Array to another while excluding specific rows.

It sounds like you might want to use grep:

my @array = (0,1,2,3,4,5); @array = grep {$_ % 3} @array; #replace $_%3 with whatever condition +applies. print @array;
which returns "1245"

You can chop one element out with a splice:

my @array = (0,1,2,3,4,5); my $cutme = <>; @array = @array[0..$cutme-1, $cutme+1..$#array]; print @array;

Entering "2" gives "01345", "0" gives "12345", and so on. Of course, doing so changes the indices of some of the remaining elements, so be careful with this one.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-25 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found