in reply to Reading from a file
If you're going to look for multiple lines in the file, perhaps you should read the file as one huge string, then use regular expressions to find the lines of interest. For example:
should print:#!/usr/bin/perl -w use strict; use warnings; # Slurp entire file into $file my $file; open FH, $0 or die $!; { # localize scope as described in perlvar local $/; $file = <FH>; } my $line = '---not found---'; $line=$1 if $file=~/\n(ope[^\n]*)/; print "Line='", $line, "'";
--roboticusLine='open FH, $0 or die $!;'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reading from a file
by just dave (Acolyte) on May 23, 2006 at 12:24 UTC | |
by dsheroh (Monsignor) on May 23, 2006 at 14:31 UTC | |
by roboticus (Chancellor) on May 23, 2006 at 23:24 UTC |