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

I am wanting to read the strings of interest from a file e.g.
$in_filename = "test.out"; open (IN,"$in_filename") or die "Can't open $in_filename:$!\n";
They are not already stored in an array so I cannot use
@array = qw (stuff);
as you have displayed in the start of your solution.
but yes, the output that you've shown is exactly what I want.
cheers

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: reading certain lines
by chunlou (Curate) on Jun 26, 2003 at 13:54 UTC
    It was $str = qq/ stuff /; a string in double quote.
      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
        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;