roho has asked for the wisdom of the Perl Monks concerning the following question:
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."
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Strange Occurrence in Substitution Statement
by Corion (Patriarch) on May 06, 2025 at 18:54 UTC | |
by choroba (Cardinal) on May 06, 2025 at 18:59 UTC | |
by roho (Bishop) on May 06, 2025 at 19:16 UTC | |
by LanX (Saint) on May 06, 2025 at 21:08 UTC | |
by choroba (Cardinal) on May 07, 2025 at 06:38 UTC | |
| |
by roho (Bishop) on May 07, 2025 at 04:36 UTC | |
by roho (Bishop) on May 06, 2025 at 19:15 UTC |