James Edward Gray II wrote:
>
> On Friday, October 10, 2003, at 08:17  AM, angie ahl wrote:
>
> > while ($line = <>) {
> >     if ($line =~ /$pattern/o) {
> >         # do something
> >     }
> > }
> >
> > It's almost exactly what I want to do. I want to see if a line starts
> > with a
> > pattern and if doesn't do something, so I would use unless instead of
> > if.
> >
> > However the file I want to run this on is actually in a variable not a
> > file.
> > Normal line endings of \n.
>
> The answer is in the question.  :)  The first line of your code sample
> reads a line from a file and stores it in the variable $line.  The
> second line in your sample, tests for a pattern in the variable $line.
>
> Or did you mean, how would you go through a variable's content
> line-by-line?  For that, try something like this:
>
> my @lines = split /(\n)/, $data;
> foreach (@lines) { do_something() if /pattern/; }
> $data = join '', @lines;

Hi James.

I'm not sure if the group saw all of the dialogue? Later
postings seem to assume an enclosing loop as you wrote
above.

It seems wasteful to split $data like that and process
each record (including the alternate "\n" separators)
when you could probably just process the entire string
using the /m (multi-record) qualifer on the regex
(which is exactly what it was meant for).

I don't have a clear grasp of the problem and don't
know if this is applicable.

Cheers,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to