Only one snag - it falls into the trap of finding more a's - altho this
might not be a real world prob with actual text.

I was going for a loop construct too when yours came in. A slight mod to
yours (which is much cleaner and elegant than mine!) to test word boundaries
instead of spaces and I think we have this one nailed.

foreach ($text =~ /(\baaa\b)/g);

Andy

----- Original Message -----
From: "Snyder, Christopher" <[EMAIL PROTECTED]>
To: "ActivePerl" <[EMAIL PROTECTED]>
Sent: Wednesday, June 13, 2001 7:48 AM
Subject: RE: simple global substitution


> I sent this to Allan earlier, but I tweaked it a bit and thought I'd show
it
> to everyone for review.  What do you folks think about this solution?
>
> $str = "aaa 111 222 aaa 333 444<END>";
> output($str);
>
> sub output
> {
>     $text = $_[0];
>
>     foreach ($text =~ /\s*(aaa)\s/g)
>     {print "$1\n";}
> }
>
> Chris
> -----Original Message-----
> From: Andy Jennings [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, June 13, 2001 8:13 AM
> To: Allan Juul; ActivePerl
> Subject: Re: simple global substitution
>
>
> Allan
>
> How about:-
>
> $text =~ s/.*?(aaa)[^aaa]+/$1\n/ig;
>
> The only messy thing about this, is that it produces one blank line at the
> end of the output - not perfect but probably tolerable, as you can always
> chomp it afterward.
>
> hth
>
> Andy
>
> ----- Original Message -----
> From: "Allan Juul" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, June 13, 2001 6:03 AM
> Subject: simple global substitution
>
>
> > hi
> > am i going totally blind or?
> > from the snip below i want to output just:
> > aaa
> > aaa
> >
> > what i get is :
> > aaa
> > aaa
> >  333 444<END>
> >
> >
> > why is that?
> > thanks
> > allan
> >
> >
> > #!perl
> > $str = "aaa 111 222 aaa 333 444<END>";
> > output($str);
> > sub output{
> > $text = $_[0];
> > $text =~ s/.*?(aaa).*?/$1\n/ig;
> > print $text;
> > }
> > _______________________________________________
> > ActivePerl mailing list
> > [EMAIL PROTECTED]
> > http://listserv.ActiveState.com/mailman/listinfo/activeperl
> >
> >
>
> _______________________________________________
> ActivePerl mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/activeperl
> _______________________________________________
> ActivePerl mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/activeperl
>
>

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl

Reply via email to