SavannahLion has asked for the wisdom of the Perl Monks concerning the following question:
So I found myself updating an old script (parses oodles of HTML files). and unknowingly introduced a subtle bug.
Here is a condensed version of the original code. The match is irrelevant.
my $k = ''; # A bunch of junk happens to this scalar before this point my $t = "\ttest \n \n"; ($k) = $t =~ /^\s*(.*?)\s*$/g; print $k ."\n";
my $k = ''; # A bunch of junk happens to this scalar before this point my $t = "\ttest \n \n"; ($k) .= $t =~ /^\s*(.*?)\s*$/g; print $k ."\n";
my $k = ''; # A bunch of junk happens to this scalar before this point my $t = "\ttest \n \n"; $t =~ /^\s*(.*?)\s*$/g; ($k) .= $1; print $k ."\n";
my $k = ''; # A bunch of junk happens to this scalar before this point my $t = "\ttest \n \n"; ($k) .= $($t =~ /^\s*(.*?)\s*$/g)[0]; print $k ."\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Appending a single Scalar after a match
by Athanasius (Archbishop) on May 25, 2015 at 09:07 UTC | |
by SavannahLion (Pilgrim) on May 25, 2015 at 14:51 UTC | |
|
Re: Appending a single Scalar after a match
by BrowserUk (Patriarch) on May 25, 2015 at 09:05 UTC | |
by SavannahLion (Pilgrim) on May 25, 2015 at 15:16 UTC |