samizdat has asked for the wisdom of the Perl Monks concerning the following question:
My problem was that if $dorient doesn't have SOMETHING_, $rs2 was set to the previous value of $1. In this particular case, I could sometimes get away with using /^(^_+)/ as the pattern, but I'm looking for the more general solution here.if (1) # extra if resets $1 backreference { $filename =~ /^([^_]+)_([^_]+)/; $rs[0] = $1; $rs[1] = $2; } # end of extra if (1) open (TESTF, "<./$filename") or die "open\n"; # now process lines which may or may not have matches while (my $line = <TESTF>) { chomp $line; if ($line =~ /^\x7CTARGET/) { my ( $kw, $dtarget, $kw2, $dorient ) = split( /\x7C/, $line ); $dorient =~ /^([^_]+)_/; $rs[2] = $1; if (!defined($rs[2])) { $rs[2] = 'nocount'; } } elsif (...) { ... } } # test @rs values
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: resetting Perl RegEx backreferences
by davido (Cardinal) on Mar 08, 2006 at 19:58 UTC | |
by samizdat (Vicar) on Mar 08, 2006 at 20:10 UTC | |
|
Re: resetting Perl RegEx backreferences
by pKai (Priest) on Mar 08, 2006 at 21:07 UTC | |
|
Re: resetting Perl RegEx backreferences
by hv (Prior) on Mar 08, 2006 at 20:11 UTC |