On Mon, 24 Sep 2001, Chris Devers wrote:

> On Mon, 24 Sep 2001, [EMAIL PROTECTED] wrote:
> 
> > i would like to keep all of them. for example
> > 
> > $s = "regex tesT";
> > $s =~ /(.)*/;
> > print $1;           #prints "T"
> > 
> > i wish $1 could be an array containing ("r", "e", "g", "e", "x", ... ,
> > "T") or better yet, a two dementional array @mem = (["r" ... "T"]).
> 
> Aren't there usually better ways to get what you're looking for?
> 
>     $s = "regex test";
>     while ($s =~ /(.)*/ ) {
>         print $_;
>         push @mem, $_;  # i forget push syntax, this looks right...
>     }

that matches more than once which is inefficient and it matters in my case
as the input is commonly a file around 200 lines. 2000 lines is also
popular. this example also requires the iteration to be wrapped around the
entire regex eg: (hello)*  as opposed to (hel*o). i think this same
limitation exists for the g flag to the regex engine.
 
> Or something like that. There are more idiomatic ways to do it, but
> suffice to say that if you need to get the positions that's possible. 

yeah i don't really want the positions but for storing it is more memory
efficient and i'm willing to deal with the substr CPU inefficiency as a
trade off as that only occurs once at print out time

> > does anyone know a way to store either the string or the positions of
> > all text matching a memory slot as upposed to just the last piece?
>  
> Would the while-loop above, or something to that effect, do it?
> 
> 
> 
> -- 
> Chris Devers                     [EMAIL PROTECTED]
> 

Reply via email to