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

Re^2: filtering an array

by prbndr (Acolyte)
on Sep 01, 2012 at 22:30 UTC ( #991204=note: print w/replies, xml ) Need Help??

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

this code gives the warning: Use of uninitialized value in pattern match (m//). what exactly does this mean?

Replies are listed 'Best First'.
Re^3: filtering an array
by philiprbrenan (Monk) on Sep 01, 2012 at 22:41 UTC

    You are using a variable in a pattern matching regular expression and said variable currently has no value. Please try assigning a value to the variable and see what happens. Thanks.

      i see. so if my array @positions is already defined and created, do i need to loop over all the values in @positions and then execute the code you posted?

      something like:

       for (@positions) {@positions = grep $_->[1] =~ /ac/i, @positions;}

      and then:

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

        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.

        You do not need the for becuase grep loops over the array you give it. Please change:

        for (@positions) {@positions = grep $_->[1] =~ /ac/i, @positions;}


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991204]
[Discipulus]: my son was used to say being left-handed on both hands..
[erix]: ambysinistral ;)
[Discipulus]: the fun is the mother used to say ' two left hand' to describe people unabel to manual work..

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2018-02-19 12:19 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (264 votes). Check out past polls.