Expanding a string
The problem:
We have a string like this:my $str = 'perl-{file-{which,basedir,copy-recursive},pathtools,path-class}';
... and we need to expand it into:
( 'perl-file-which', 'perl-file-basedir', 'perl-file-copy-recursive', 'perl-pathtools', 'perl-path-class', )
Solutions:
One-line solution: split q{ }, qx(echo $string);
- Go: https://github.com/trizen/go-learning/blob/master/abs_string.go
- Perl: https://github.com/trizen/perl-scripts/blob/master/Text/abs_string.pl
- Sidef: https://github.com/trizen/sidef/blob/master/scripts/absolute_string.sf
- Sidef: https://github.com/trizen/sidef-scripts/blob/master/Text/shell_string_expand.sf
Comments
Post a Comment