I have paired the problem down as much as possible. In the SSCCE below I am removing placeholder backticks between date and time (the reason for this lies in complete program). I am also removing extra spaces in the text (again, the reason for this lies in the complete program). When there is no extra space to remove the
"$extra" variable contains the empty string, which I explicitly set to the empty string to recreate the error condition in the SSCCE.
The problem is the second and subsequent lines have the backtick removed (i.e., replaced with nothing), while the first line is processed as expected where the backtick is replaced by a single space.
It appears the substitution of "$extra" is taking out the backticks (for data lines 2 and following) before the following substitution replaces backticks with a single space. It's a mystery why only the first data line is processed correctly.
#!/usr/bin/perl
use strict;
use warnings;
while ( <DATA> ) {
chomp;
my $fname = $_;
print qq(\nBefore: $fname\n);
my $extra = '';
$fname =~ s/$extra//;
$fname =~ s/`/ /;
print qq( After: $fname\n);
}
exit;
__DATA__
2025-05-05`09:22:00 7,674 -rw-rw-rw- C:\~Zipfile\H\Helpin
+gHand\Software\DevTools\.edit.current
2025-05-05`09:22:00 7,674 -rw-rw-rw- C:\PerlApps\H\Helpin
+gHand\Software\DevTools\.edit.current
2025-05-05`09:22:00 5,448 -rw-rw-rw- C:\~Zipfile\B\Bat\pi
+cs\.edit.current
"It's not how hard you work, it's how much you get done."
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.