Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^5: filtering an array

by philiprbrenan (Monk)
on Sep 01, 2012 at 23:03 UTC ( #991211=note: print w/replies, xml ) Need Help??

in reply to Re^4: filtering an array
in thread filtering an array

Likewise, the for is unnecessary in this code too:

for (@positions) {@positions = map $_->[0], @positions;}

It should just be:

@positions = map $_->[0], @positions;

because map iterates over the array you give it. Even better, you could write:

$_ = $_->[0] for @positions;

here we are making the for implicit in map explicit.

Replies are listed 'Best First'.
Re^6: filtering an array
by prbndr (Acolyte) on Sep 01, 2012 at 23:15 UTC

    perl still has a problem with this:

    @positions = grep $_->[1] =~ /ac/i, @positions;

    with the same error Use of uninitialized value in pattern match (m//)

      One or more of the elements of the array @positions is undefined. The easiest way to check this is like this:

      use Data::Dump qw(pp); pp([@positions]);

      This will give you a printout of the value of each element in array @positions. I expect we will see that some are "undef" meaning undefined. It will be these elements that are causing the problem.

        i don't see any that are "undef. that's a little strange. the data dumper output prints:



        etc. etc. this is a little strange...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991211]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-12-18 09:21 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (475 votes). Check out past polls.