Re: RegEx Substitution + Arrays

2007-05-10 Thread Jenda Krynicky
From: Seanie <[EMAIL PROTECTED]> > Rob Dixon wrote: > > > map(s/$find/$replace/, @arr); > > Haha yes you can, but if you want to write nasty code go for > > grep s/$find/$replace/, @arr; > > which also works. > > True, but grep implies "find stuff", while map implies "do stuff", so your > nasty

Re: RegEx Substitution + Arrays

2007-04-26 Thread Dr.Ruud
yitzle schreef: > What's the best way to apply a RegEx to an array? For loop? > @arr = qw/dc2ds reew12dsfa df2fdw/; > s/$find/$replace/ for(@arr); Consider: s/\Q$find/$replace/ for(@arr); -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional c

Re: RegEx Substitution + Arrays

2007-04-25 Thread Chas Owens
On 4/25/07, John W. Krahn <[EMAIL PROTECTED]> wrote: Seanie wrote: > Rob Dixon wrote: >>> map(s/$find/$replace/, @arr); >> Haha yes you can, but if you want to write nasty code go for >> grep s/$find/$replace/, @arr; >> which also works. > > True, but grep implies "find stuff", while map implie

Re: RegEx Substitution + Arrays

2007-04-25 Thread John W. Krahn
Seanie wrote: > Rob Dixon wrote: >>> map(s/$find/$replace/, @arr); >> Haha yes you can, but if you want to write nasty code go for >> grep s/$find/$replace/, @arr; >> which also works. > > True, but grep implies "find stuff", while map implies "do stuff", so your > nasty code is way, way, nasti

Re: RegEx Substitution + Arrays

2007-04-25 Thread Seanie
Rob Dixon wrote: > > map(s/$find/$replace/, @arr); > Haha yes you can, but if you want to write nasty code go for > grep s/$find/$replace/, @arr; > which also works. True, but grep implies "find stuff", while map implies "do stuff", so your nasty code is way, way, nastier than mine - it masks t

Re: RegEx Substitution + Arrays

2007-04-25 Thread Rob Dixon
Sean King wrote: Chas Owens wrote: map(s/$find/$replace/, @arr); You should not use map in a void context, it is bad form. Care to explain? Neither 'strict' nor 'warnings' complains, and it does what it says on the tin, but if I've missed something fundamental here I'd be grateful to know a

Re: RegEx Substitution + Arrays

2007-04-25 Thread Rob Dixon
Seanie wrote: yitzle wrote: What's the best way to apply a RegEx to an array? For loop? @arr = qw/dc2ds reew12dsfa df2fdw/; s/$find/$replace/ for(@arr); Yep, you can do that. Or use map() map(s/$find/$replace/, @arr); Haha yes you can, but if you want to write nasty code go for grep s/$fi

Re: RegEx Substitution + Arrays

2007-04-25 Thread Seanie
Chas Owens wrote: > > map(s/$find/$replace/, @arr); > You should not use map in a void context, it is bad form. Care to explain? Neither 'strict' nor 'warnings' complains, and it does what it says on the tin, but if I've missed something fundamental here I'd be grateful to know about it. -- [E

Re: RegEx Substitution + Arrays

2007-04-25 Thread Chas Owens
On 4/25/07, Seanie <[EMAIL PROTECTED]> wrote: yitzle wrote: > What's the best way to apply a RegEx to an array? For loop? > @arr = qw/dc2ds reew12dsfa df2fdw/; > s/$find/$replace/ for(@arr); Yep, you can do that. Or use map() map(s/$find/$replace/, @arr); You should not use map in a void cont

Re: RegEx Substitution + Arrays

2007-04-25 Thread Seanie
yitzle wrote: > What's the best way to apply a RegEx to an array? For loop? > @arr = qw/dc2ds reew12dsfa df2fdw/; > s/$find/$replace/ for(@arr); Yep, you can do that. Or use map() map(s/$find/$replace/, @arr); -- [EMAIL PROTECTED] [pgp: 8A8FA6DE] -- To unsubscribe, e-mail: [EMAIL PROTECTED]

Re: RegEx Substitution + Arrays

2007-04-25 Thread John W. Krahn
yitzle wrote: > What's the best way to apply a RegEx to an array? For loop? > @arr = qw/dc2ds reew12dsfa df2fdw/; > s/$find/$replace/ for(@arr); Yes, although the parentheses are redundant. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools

Re: RegEx Substitution + Arrays

2007-04-25 Thread Rob Dixon
yitzle wrote: What's the best way to apply a RegEx to an array? For loop? @arr = qw/dc2ds reew12dsfa df2fdw/; s/$find/$replace/ for(@arr); Yes. Exactly that. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: regex substitution question

2006-12-31 Thread Mathew Snyder
John W. Krahn wrote: > Mathew Snyder wrote: >> A script I've been working on will provide time spent on a work ticket in >> H:MM >> format. However, if the MM section is less than 10 it only shows as H:M so I >> need to append a 0 to it. So, for instance, if the output looks like this >> 9:7 I

Re: regex substitution question

2006-12-31 Thread John W. Krahn
Mathew Snyder wrote: > A script I've been working on will provide time spent on a work ticket in H:MM > format. However, if the MM section is less than 10 it only shows as H:M so I > need to append a 0 to it. So, for instance, if the output looks like this > 9:7 I > need to append the 0 to the 7

Re: regex substitution

2005-04-27 Thread John W. Krahn
Ramprasad A Padmanabhan wrote: Hi all, Hello, I want a regex to replace all continuous occurrences of '-' with something else say 'x' except the first one These are some examples "- Ram" ===> "- Ram" "-- bla"===> "-x blah" "bla ---" ===> "bla -

Re: regex substitution

2005-04-27 Thread Offer Kaye
On 4/27/05, Ramprasad A Padmanabhan wrote: > Hi all, > > I want a regex to replace all continuous occurrences of '-' with > something else say 'x' except the first one > Here's one way: s/-(-+)/"-".("x"x length$1)/ge; Explanation: Flags: "g" means global, i.e. replace all occurences, and "

Re: regex substitution

2005-04-27 Thread Ing. Branislav Gerzo
Ramprasad A Padmanabhan [RAP], on Wednesday, April 27, 2005 at 15:55 (+0530) thinks about: RAP> I want a regex to replace all continuous occurrences of '-' with RAP> something else say 'x' except the first one this is nearly what you want, it should be a bit improved: my @input = ("- Ram", "--

Re: regex substitution using $1

2001-07-20 Thread Abdulaziz Ghuloum
Hello, You have: my $rcs = '$Revision: 1.47 $'; # $version was a typo I believe $rcs =~ s/[^\d.]+//; The substitution matches the first sequence of non-digits and non-dots and replaces it with "" (nothing). So, it matches 'Revision: ' and you have $rcs = '1.47 $'. You need to use the 'g' mo

Re: regex substitution using $1

2001-07-20 Thread Michael Fowler
On Fri, Jul 20, 2001 at 05:19:23PM -0500, [EMAIL PROTECTED] wrote: > i have: > > my $version = '$Revision: 1.47 $'; > $rcs =~ s/[^\d.]+//; > > looking at the regex match, i would think this should match all > non-numeric and \. characters. however, the value of $rcs ends up as: > > 1.47 $ > >