in reply to Re: replace number by args<number>
in thread replace number by args<number>
Note that split /(\d+)/ does not give the OPer's specified 'arg1arg2' from '12', for which split /(\d)/ vice split /(\d+)/. (However, I still prefer the s///g approach.)>perl -wMstrict -le "printf qq{'%s' yields '%s' \n}, $_, join '', map /\d/ ? qq{arg$_} : $_, split /(\d+)/ for @ARGV ; " "1:2" "-p 1 -t 2 3" "1 2" "12" "no digits" '1:2' yields 'arg1:arg2' '-p 1 -t 2 3' yields '-p arg1 -t arg2 arg3' '1 2' yields 'arg1 arg2' '12' yields 'arg12' 'no digits' yields 'no digits'
|
|---|