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
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
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
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
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
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
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
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
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
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]
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
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/
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
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
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 -
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 "
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", "--
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
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 $
>
>
19 matches
Mail list logo