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;

Hope that helps.

James


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



Reply via email to