Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: Re: Re: reading certain lines

by harry34 (Sexton)
on Jun 26, 2003 at 13:42 UTC ( [id://269224]=note: print w/replies, xml ) Need Help??


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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://269224]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-25 05:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found