Home > Archive > PERL Miscellaneous > March 2004 > how get next 5 lines?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how get next 5 lines?
|
|
| Geoff Cox 2004-03-27, 12:01 am |
| Hello
I am opening a file to look for a piece of data and having found that
data I want to read the next 5 lines...as there is another bit of data
on one of those lines...
appreciate a little help here!
Thanks
Geoff
| |
| Walter Roberson 2004-03-27, 12:01 am |
| In article <8vc860l0c6ifrepujr8pm89upcgua6pp59@4ax.com>,
Geoff Cox <geoffacox@dontspamblueyonder.co.uk> wrote:
:I am opening a file to look for a piece of data and having found that
:data I want to read the next 5 lines...as there is another bit of data
:on one of those lines...
my (undef, undef, undef, undef, $interestingline) =
map { <FILEHANDLE> } (1..5);
--
vi -- think of it as practice for the ROGUE Olympics!
| |
| John Bokma 2004-03-27, 12:01 am |
|
Walter Roberson wrote:
> In article <8vc860l0c6ifrepujr8pm89upcgua6pp59@4ax.com>,
> Geoff Cox <geoffacox@dontspamblueyonder.co.uk> wrote:
> :I am opening a file to look for a piece of data and having found that
> :data I want to read the next 5 lines...as there is another bit of data
> :on one of those lines...
>
> my (undef, undef, undef, undef, $interestingline) =
> map { <FILEHANDLE> } (1..5);
uhm, on "one of those lines" :D
my @oneofthoselines = map { <FILEHANDLE> } (1..5);
--
John personal page: http://johnbokma.com/
Freelance Perl / Java developer available - http://castleamber.com/
| |
| Geoff Cox 2004-03-27, 12:01 am |
| On 26 Mar 2004 14:32:03 GMT, roberson@ibd.nrc-cnrc.gc.ca (Walter
Roberson) wrote:
>In article <8vc860l0c6ifrepujr8pm89upcgua6pp59@4ax.com>,
>Geoff Cox <geoffacox@dontspamblueyonder.co.uk> wrote:
>:I am opening a file to look for a piece of data and having found that
>:data I want to read the next 5 lines...as there is another bit of data
>:on one of those lines...
>
>my (undef, undef, undef, undef, $interestingline) =
> map { <FILEHANDLE> } (1..5);
Walter
Thanks for the above- will get read up on this one! I found following
which works but does not look too elegant I suppose!
my $pattern = $1;
open (IN, "d:/file.htm");
while (<IN> ){
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <IN>;
close (IN);
etc etc
Cheers
Geoff
| |
| Brian McCauley 2004-03-27, 12:01 am |
| John Bokma <postmaster@castleamber.com> writes:
> Walter Roberson wrote:
>
>
> uhm, on "one of those lines" :D
>
> my @oneofthoselines = map { <FILEHANDLE> } (1..5);
That is equivalent to
my @oneofthoselines = <FILEHANDLE>;
You meant
my @oneofthoselines = map { scalar <FILEHANDLE> } (1..5);
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
| |
| Brian McCauley 2004-03-27, 12:01 am |
| Geoff Cox <geoffacox@dontspamblueyonder.co.uk> writes:
> my ($curr, $next1, $next2, $next3) = <IN>;
That slurps the whole remainder of the file into memory then throws
away all but the first 4 lines. See other branches of this thread.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
| |
| David H. Adler 2004-03-27, 12:01 am |
| In article <8vc860l0c6ifrepujr8pm89upcgua6pp59@4ax.com>, Geoff Cox wrote:
> Hello
>
> I am opening a file to look for a piece of data and having found that
> data I want to read the next 5 lines...as there is another bit of data
> on one of those lines...
I wouldn't recommend it for real work, but just for fun....
$l=$. + 4;<> until $. == $l;print scalar <>;
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Your question doesn't make any sense. You might as well ask whether
it is possible to grow vegetables from a painting, without becoming
Wednesday first. - Abigail, c.l.p.misc
|
|
|
|
|