in reply to Re: Using map
in thread Using map

Possibly a bit more 'intuitive'...
my @sub_locs = grep { $_ } map { /taxman\.add\.subloc\.(.*)/ } @sessio +n_keys;
...though YMMV depending on comfort with the language.

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
It's not what you know, but knowing how to find it if you don't know that's important

Replies are listed 'Best First'.
Re: Re: Re: Using map
by merlyn (Sage) on Oct 05, 2001 at 00:56 UTC
    my @sub_locs = grep { $_ } map { /taxman\.add\.subloc\.(.*)/ } @sessio +n_keys;
    Maybe a "bit more intuitive", but "wrong" if the value after taxman string might be empty or the value "0". Did you mean instead:
    my @sub_locs = grep { defined $_ } map { /taxman\.add\.subloc\.(.*)/ } + @session_keys;
    perhaps?

    And of course, as I'm seeing this, the grep isn't even necessary, since on a failed match, the match returns an empty list!

    my @sub_locs = map { /taxman\.add\.subloc\.(.+)/ } @session_keys;
    is enough!

    -- Randal L. Schwartz, Perl hacker