in reply to replace number by args<number>

Not tested, but it should give you the idea:

join('',(map { /\d/ ? "args$_" : $_ } split(/(\d+)/,$yourInputGoesHere +)))
Maybe someone could suggest how to write the map block in a nicer way? It looks a bit clumsy.

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^2: replace number by args<number>
by JavaFan (Canon) on Mar 20, 2009 at 12:09 UTC
    Maybe someone could suggest how to write the map block in a nicer way? It looks a bit clumsy.
    I agree it looks clumsy. But, IMO, the clumsy part is using split, map and join. Why?
    $yourInputGoesHere =~ s/([0-9])/args$1/g;
    No split. No map. No join. Nothing clumsy here.

      Oh my god! I didn't see the obvious :-O

      -- 
      Ronald Fischer <ynnor@mm.st>
Re^2: replace number by args<number>
by AnomalousMonk (Archbishop) on Mar 20, 2009 at 12:35 UTC
    >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'
    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.)