um... why not:
#!perl
use strict;
my $str = "aaa 111 222 aaa 333 444 fgd asd 324 agd dd sadf fde aaa 333
sfsd<END>";
my $search = "aaa";
output($str);
sub output{
my $text = $_[0];
$text =~ s/.*?($search)/ $1/g;
$text =~ s/(.* $search).*/$1/;
$text =~ s/ ($search)/$1\n/g;
chomp $text;
print $text;
}
Play with the $search, there are some oddities (you will notice the spaces
added and taken away through the regexes...
Shawn
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Jenda
> Krynicky
> Sent: Wednesday, June 13, 2001 11:45 AM
> To: [EMAIL PROTECTED];
> [EMAIL PROTECTED]
> Subject: Re: 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
> >
>
> Is two regexps solution good enought?
>
> $str =~ s/.*?(aaa)/$1\n/g;
> $str =~ s/(aaa)?.*?$/$1/;
>
>
> Jenda
>
>
> == [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
> Always code as if the guy who ends up maintaining your code will be a
> violent psychopath who knows where you live.
> -- Rick Osborne, <[EMAIL PROTECTED]>
> _______________________________________________
> ActivePerl mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/activeperl
>
>
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl