in reply to Re: Using regex in Map function
in thread Using regex in Map function
************* Output ******my @in = qw(a b c d e f g h); print "Start: ",@in,"\n","***RUNNING MAP***\n\n"; my @out = map { s/.$/x/} @in; print "in : ",@in,"\n"; print "out: ",@out,"\n"
*********************Start: abcdefgh ***RUNNING MAP*** in : xxxxxxxx out: 11111111
************* Output ******my @in = qw(a b c d e f g h); print "Start: ",@in,"\n","***RUNNING MAP***\n\n"; my @out = map { s/.$/x/r} @in; print "in : ",@in,"\n"; print "out: ",@out,"\n"
****************Start: abcdefgh ***RUNNING MAP*** in : abcdefgh out: xxxxxxxx
But what if you REALLY wanted the return value of the regex - and not modify the original output? (why? I don't know)
Localize the input...
************* Output ******my @in = qw(a b c d e f g h); print "Start: ",@in,"\n","***RUNNING MAP***\n\n"; my @out = map { s/.$/x/} my @temp = @in; print "in : ",@in,"\n"; print "out: ",@out,"\n"
Start: abcdefgh ***RUNNING MAP*** in : abcdefgh out: 11111111
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Using regex in Map function
by merlyn (Sage) on Feb 08, 2013 at 18:40 UTC | |
by Anonymous Monk on Jan 29, 2016 at 21:12 UTC |