in reply to Re: Re: Re: Re: Re: reading certain lines
in thread reading certain lines

sorry I read it wrong
but can I automatically open the file (using code below) and read in the strings using the pattern you have provided ?
e.g using
$in_filename = "test.out"; open (IN,"$in_filename") or die "Can't open $in_filename:$!\n";
I need code which will be general, I do not wish to write the stings in my program.
thanks harry

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: reading certain lines
by chunlou (Curate) on Jun 26, 2003 at 14:23 UTC
    Try this:
    use strict; use warnings; # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - my $in_filename = "test.out"; open (IN,"$in_filename") or die "Can't open $in_filename:$!\n"; local $/ = undef; # undef record seperator my $str = <IN>; # read file into string close(IN); # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - my @match = ($str =~ /([A-Z]\s\d+,\s\d+\(\s*\d+\))/g); print "$_\n" for @match;