Re: Using =~ with a list

2002-02-07 Thread Randal L. Schwartz
> "Lysander" == Lysander <[EMAIL PROTECTED]> writes: Lysander> This doesn't seem to work... My webhost is running PERL 5.004_04 That's your problem. For older Perls, you can use for (@body) { s/foo/bar/ } >> This works: >> >> s/foo/bar/ for @body; >> >> presuming you have a re

Re: Using =~ with a list

2002-02-07 Thread Jenda Krynicky
From: "Lysander" <[EMAIL PROTECTED]> > This doesn't seem to work... My webhost is running PERL 5.004_04 > > s/foo/bar/ for @body; Too old perl for this. Use for (@body) { s/foo/bar/; } instead. Jenda === [EMAIL PROTECTED] == http://

Re: Using =~ with a list

2002-02-07 Thread Lysander
MAIL PROTECTED]>; "Robert Hanson" <[EMAIL PROTECTED]>; "Lysander" <[EMAIL PROTECTED]> Sent: Monday, February 04, 2002 12:28 PM Subject: Re: Using =~ with a list [snip] > This works: > > s/foo/bar/ for @body; > > presuming you have a reasonably modern Perl. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Using =~ with a list

2002-02-04 Thread sachin balsekar
hi, use a for loop to traverse the list... for ($i=0;$i<$#body;$i++){ $body=$body[$i]; $body =~ s/foo/bar/; $body[$i]=$body;# 2 } this will also change the contents of the listif u dont want it...comment statement marked 2. hope this solves u r query regs, sa

RE: Using =~ with a list

2002-02-04 Thread Jonathan E. Paton
> > Eeek. A map in void context! Please don't do that. > > If I do not sound inane, could you please clarify the > following: > > a) Why do perl gurus exhort, not to use 'grep' or 'map' > functions under void context? > Do you work 80 hours a week for no pay (void context)? Grep, map and oth

Re: Using =~ with a list

2002-02-04 Thread Randal L. Schwartz
> "RArul" == RArul <[EMAIL PROTECTED]> writes: RArul> a) Why do perl gurus exhort, not to use 'grep' or 'map' RArul> functions under void context? It is only an artifact of implementation that altering $_ can alter the input list. The purpose of map or grep is to process a list to produce

RE: Using =~ with a list

2002-02-04 Thread RArul
> > Eeek. A map in void context! Please don't do that. > If I do not sound inane, could you please clarify the following: a) Why do perl gurus exhort, not to use 'grep' or 'map' functions under void context? b) What other functions, are to be avoided in 'void' context? Thanks, Rex

Re: Using =~ with a list

2002-02-04 Thread Randal L. Schwartz
> "Hanson," == Hanson, Robert <[EMAIL PROTECTED]> writes: Hanson,> Ahhh, I see. So this would work as well. Hanson,> map {s/foo/bar/} @data; Eeek. A map in void context! Please don't do that. Hanson,> ...But the "for" seems to be a little bit faster which makes sense. Hanson,> Benchmark

RE: Using =~ with a list

2002-02-04 Thread Hanson, Robert
wallclock secs (18.87 usr + 0.00 sys = 18.87 CPU) @ 52982.94/s (n=100) Thanks. Rob -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Monday, February 04, 2002 1:34 PM To: [EMAIL PROTECTED] Subject: Re: Using =~ with a list >>>>> "Randal

Re: Using =~ with a list

2002-02-04 Thread Randal L. Schwartz
> "Randal" == Randal L Schwartz <[EMAIL PROTECTED]> writes: > "Robert" == Robert Hanson <[EMAIL PROTECTED]> writes: Robert> You probably want to use "map". Robert> This should work. Robert> @body = map { s/foo/bar/; $_ } (@body); Randal> No. Please don't answer without testing. Randal

Re: Using =~ with a list

2002-02-04 Thread Jonathan E. Paton
--- Lysander <[EMAIL PROTECTED]> wrote: > I need to replace all the occurances of one thing > with another. This is simple enough, except that > I am working with a list variable, rather than a > scalar. > > @body =~ s/foo/bar/; Do I sense someone trying to do what HTML::Template was designed

Re: Using =~ with a list

2002-02-04 Thread Jonathan E. Paton
--- Lysander <[EMAIL PROTECTED]> wrote: > I need to replace all the occurances of one thing > with another. This is simple enough, except that > I am working with a list variable, rather than a > scalar... list != array (and you mean an array) > > for my $body (@body) > { > $body =~

Re: Using =~ with a list

2002-02-04 Thread Randal L. Schwartz
> "Robert" == Robert Hanson <[EMAIL PROTECTED]> writes: Robert> You probably want to use "map". Robert> This should work. Robert> @body = map { s/foo/bar/; $_ } (@body); No. Please don't answer without testing. That messes up @body as well, since $_ is an alias back into the original list

RE: Using =~ with a list

2002-02-04 Thread Hanson, Robert
You probably want to use "map". This should work. @body = map { s/foo/bar/; $_ } (@body); Rob -Original Message- From: Lysander [mailto:[EMAIL PROTECTED]] Sent: Monday, February 04, 2002 1:17 PM To: [EMAIL PROTECTED] Subject: Using =~ with a list I need to replace all the

Using =~ with a list

2002-02-04 Thread Lysander
I need to replace all the occurances of one thing with another. This is simple enough, except that I am working with a list variable, rather than a scalar. @body =~ s/foo/bar/; give an error and for my $body (@body) { $body =~ s/foo/bar/; } appears to leave @body empty. How does