in reply to Re: Re: reading certain lines
in thread reading certain lines
To read file into a string you can do:use strict; use warnings; my $str = qq/ 1 2 3 4 ---------- C 2, 2(13) R 2, 2( 8) C 2, 2(13) ---------- C 2, 2(11) C 2, 2(13) R 2, 2(18) ---------- C 2, 2(18) C 1, 2(11) C 2, 2(13) ---------- C 1, 2(11) C 2, 2(18) C 2, 2(11) /; my @match = ($str =~ /([A-Z]\s\d+,\s\d+\(\s*\d+\))/g); print "$_\n" for @match; __END__ C 2, 2(13) R 2, 2( 8) C 2, 2(13) C 2, 2(11) C 2, 2(13) R 2, 2(18) C 2, 2(18) C 1, 2(11) C 2, 2(13) C 1, 2(11) C 2, 2(18) C 2, 2(11)
my $str = slurp('file.txt'); sub slurp { open(F, shift); local $/ = undef; # undef record seperator my $txt = <F>; close(F); return $txt; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: reading certain lines
by harry34 (Sexton) on Jun 26, 2003 at 13:42 UTC | |
by chunlou (Curate) on Jun 26, 2003 at 13:54 UTC | |
by harry34 (Sexton) on Jun 26, 2003 at 14:05 UTC | |
by chunlou (Curate) on Jun 26, 2003 at 14:23 UTC |