scaryfast has asked for the wisdom of the Perl Monks concerning the following question:
UPDATE::: I found that if I include a '\n' character to the print line, the matches are printed to screen. For some strange reason it will not print to screen without it.( or without the extra print line as pointed out in the original post below. ___________ P.S. I only have one of the blocks active in the code at a time, not both.
Why? Hello, I,m using perl 5.1 This first one finds the matches of ABC######## this one fails to print ####### if($templine =~ /(ABC)/) {print " xxx xx";} ######## when this one works ###### if($templine =~ /(ABC)/) {print " xxx \n xx";}
?????????????????????????????????????????????????????? # This first one finds the matches of ABC ?????????????????????????????????????????????????????? foreach my $line (@_lines) { my $templine= $line; print "$templine"; # or print "$line"; if($templine =~ /(ABC)/){print "$1 = the line";} } #?????????????????????????????????????????????????????? # This next one doesn't find the matches of ABC #?????????????????????????????????????????????????????? foreach my $line (@_lines) { my $templine= $line; ############ print "$templine"; ############ # or print "$line"; if($templine =~ /(ABC)/){print "$1 = the line";} }
If printed to LOG, (e.g. print LOG $templine;), it fails as if I didn't print it at all. Why is the printing of the variable, or the variable it was just set equal to, making a difference. Thank You! Brian
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Printing the variable makes the next match code work. Why?
by GrandFather (Saint) on Jan 11, 2012 at 04:43 UTC | |
by scaryfast (Initiate) on Jan 11, 2012 at 04:58 UTC | |
by GrandFather (Saint) on Jan 11, 2012 at 05:11 UTC | |
by scaryfast (Initiate) on Jan 11, 2012 at 05:41 UTC | |
|
Re: Printing the variable makes the next match code work. Why?
by Ratazong (Monsignor) on Jan 11, 2012 at 07:37 UTC | |
by AnomalousMonk (Archbishop) on Jan 11, 2012 at 09:07 UTC | |
|
Re: Printing the variable makes the next match code work. Why?
by 3dbc (Monk) on Jan 11, 2012 at 04:53 UTC | |
|
Re: Printing the variable makes the next match code work. Why?
by Jenda (Abbot) on Jan 11, 2012 at 23:16 UTC |