in reply to Re: Loosing variable content after regular expression
in thread Loosing variable content after regular expression

Excellent explanation! You can see the buggy code causing my problem in an answer above. Your example explains this phenomena short and precise. Thank you.

  • Comment on Re^2: Loosing variable content after regular expression

Replies are listed 'Best First'.
Re^3: Loosing variable content after regular expression
by AnomalousMonk (Archbishop) on Dec 19, 2014 at 18:29 UTC

    In general, it's a Good Idea to "capture the capture variables" immediately after a match in order to avoid these kinds of strange problems:

    if ($string =~ m{ (foo|bar) (\d+) (w[ia]g) }xms) { my ($one, $two, $three) = ($1, $2, $3); do_something_with($one); ... }
    or:
    if (my ($one, $two, $three) = $string =~ m{ (foo|bar) (\d+) (w[ia]g) } +xms) { do_something_with($one); ... }