in reply to How to replace spaces with different chars?
my @special_chars = qw( : ; , = - ); my $special_chars_glob_alt = "{".( join ",", map quotemeta, @special_chars )."}"; my $corrupt_qfn = ...; my $glob = $corrupt_qfn =~ s{ ( [ ] ) | ( [^\w ] ) }{ defined( $1 ) ? $special_chars_glob_alt : "\\$2" }xegr; my @possible_qfns = glob( $glob ); say for @possible_qfns;
or
use Algorithm::Loops qw( NestedLoops ); my @special_chars = qw( : ; , = - ); my $corrupt_qfn = ...; my $iter = NestedLoops([ map { $_ eq " " ? \@special_chars : [ $_ ] } split( /( )/, $corrupt_qfn, -1 ) ]); while ( my @parts = $iter->() ) { my $possible_qfn = join( "", @parts ); say for $possible_qfn; }
Four spaces results in 54 = 625 possible paths.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to replace spaces with different chars?
by AnomalousMonk (Archbishop) on Jul 07, 2022 at 02:43 UTC | |
by ikegami (Patriarch) on Jul 07, 2022 at 19:13 UTC | |
|
Re^2: How to replace spaces with different chars?
by ikegami (Patriarch) on Jul 06, 2022 at 21:00 UTC | |
by 5mi11er (Deacon) on Jul 11, 2022 at 14:14 UTC | |
by ikegami (Patriarch) on Jul 11, 2022 at 18:59 UTC |