in reply to How to replace spaces with different chars?
G'day ovedpo15,
"How can I use the system instead?"
With these paths:
ken@titan ~/tmp/pm_11145308_test_dir $ ls -1 a/b/c/d/e 'f:i-:l;e' 'fi:l;e' 'f-i:l;e' 'f-i-:l;e' fi:le
And this code (find_file_match.pl):
#!/usr/bin/env perl use strict; use warnings; my @data = ( 'a/b/c/d/e/fi le', 'a/b/c/d/e/fi l e', 'a/b/c/d/e/f i l e', 'a/b/c/d/e/f i l e', ); for my $datum (@data) { print "\n*** Files matching '$datum':\n"; # $datum =~ y/ /?/; -- see update below $datum =~ s/ /[\\;:,-]/g; system("ls -1 $datum"); }
You get this output:
ken@titan ~/tmp/pm_11145308_test_dir $ ./find_file_match.pl *** Files matching 'a/b/c/d/e/fi le': a/b/c/d/e/fi:le *** Files matching 'a/b/c/d/e/fi l e': 'a/b/c/d/e/fi:l;e' *** Files matching 'a/b/c/d/e/f i l e': 'a/b/c/d/e/f-i:l;e' *** Files matching 'a/b/c/d/e/f i l e': 'a/b/c/d/e/f:i-:l;e' 'a/b/c/d/e/f-i-:l;e'
Update: See ++LanX' valid comment regarding the inherent bug in the code I posted above. Changing y/ /?/ to s/ /[\\;:,-]/g fixes this.
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to replace spaces with different chars?
by LanX (Saint) on Jul 07, 2022 at 10:45 UTC | |
by kcott (Archbishop) on Jul 07, 2022 at 13:12 UTC | |
by LanX (Saint) on Jul 07, 2022 at 13:44 UTC | |
by hippo (Archbishop) on Jul 07, 2022 at 13:48 UTC | |
by LanX (Saint) on Jul 07, 2022 at 14:03 UTC | |
by kcott (Archbishop) on Jul 07, 2022 at 14:19 UTC |