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

Nice, although second /g should be omitted
  • Comment on Re^6: Improve foreach with help of map?

Replies are listed 'Best First'.
Re^7: Improve foreach with help of map?
by JavaFan (Canon) on Oct 09, 2009 at 16:00 UTC
    Perhaps you should actually try your suggestions first. It will not work correctly if you omit the second /g.
    my $content = <<EOT; Blah blah 12 Feb 1992 # Wrong date! Mah Mah Mah End Date: 14 Jul 2007 # Correct date! EOT $content =~ /End Date/g and $content =~ /(\d\d \w\w\w \d\d\d\d)/ and my $result1 = $1; say "Ikegami's end date: $result1"; pos($content) = 0; $content =~ /End Date/g and $content =~ /(\d\d \w\w\w \d\d\d\d)/g and my $result2 = $1; say "JavaFan's end date: $result2"; __END__ Ikegami's end date: 12 Feb 1992 JavaFan's end date: 14 Jul 2007
      Right. My fix was wrong. You need to reset pos some other way on success. Unfortunately, it appears to be simpler to use a single match.