in reply to Re: Improve foreach with help of map?
in thread Improve foreach with help of map?

Hey that solved it, thx! Knew there was a shorter way of saying that :)

The final code is as...

my ($dummy, $dummy, $result) = map /(\d\d \w\w\w \d\d\d\d)/, split /\n +/, $content;

Instead of.

my $match = 0; my $result = undef; foreach(split /\n/, $content) { if(/End Date/) { $match = 1 } elsif($match && /(\d\d \w\w\w \d\d\d\d)/) { $result = $1; last; } }

Thx again!

Replies are listed 'Best First'.
Re^3: Improve foreach with help of map?
by ikegami (Patriarch) on Oct 09, 2009 at 15:18 UTC
    my ($dummy, $dummy, $result) = ...;

    should be

    my (undef, undef, $result) = ...;

    There's also

    my $result = ( map /(\d\d \w\w\w \d\d\d\d)/, split /\n+/, $content )[2];

    But really, you want the faster and more accurate

    my ($result) = $content =~ /End Date.*?(\d\d \w\w\w \d\d\d\d)/s;

      Thx, that even makes it simpler. Perl Nirvana is in reach I tell you.

      Your last one worked like a charm.