in reply to Modifying value of $1 clobbers $2, $3 etc?

I think you missed the importance of

or to the next successful pattern match, whichever comes first

$author =~ s/\.//g; # Remove full stops (periods)

is that next successful pattern match, clobbering your $3!

Liz

Replies are listed 'Best First'.
Re: Re: Modifying value of $1 clobbers $2, $3 etc?
by Roger (Parson) on Oct 12, 2003 at 11:15 UTC
    Liz was absolutely right. The $1 .. $3 variables are reset after the second regexp.

    To fix the problem, save your $1 .. $3 variables in temporary local variables.

    use strict; use warnings; my $str = "Title: Learning Perl Author: Schwartz, Randal L. ISBN: xxx +x"; if ($str =~ /^Title: (.*)\s+Author: (.*)\s+ISBN: (.*)/) { my ($title, $author, $isbn) = ($1, $2, $3); $author =~ s/\.//g; # Remove full stops (periods) print "<$title><$author><$isbn>"; }
Re: Re: Modifying value of $1 clobbers $2, $3 etc?
by Not_a_Number (Prior) on Oct 12, 2003 at 12:32 UTC

    Thanks. How could I have missed that? :-(

    dave