in reply to picking x numbers of lines from a file

You could try this piece of code, in order to pick up a selection of the file. But, in this way, you actually read the entire file. What about using an array containing (index, image, url) tuples?
(I think in this case you don't need a hash).
#!/usr/bin/perl $from = 3; $to = 5; # There's the nice operator .., which has a useful # behaviour in scalar context while (<DATA>) { if (($from == $.) .. ($to == $.)) { print "$.: $_"; } } __DATA__ 1|/images/banners/internal/image1.gif|http://www.blah.com 2|/images/banners/internal/dumb.gif|http://www.dumb.com 3|/images/banners/internal/perl.gif|http://www.perl.com 4|/images/banners/internal/slashdot.gif|http://www.slashdot.org 5|/images/banners/internal/linux.gif|http://www.linux.org 5|/images/banners/internal/apache.gif|http://www.apache.org 6|/images/banners/internal/bsd.gif|http://www.bsd.org 7|/images/banners/internal/penguin.gif|http://www.penguin.com

I hope this could be useful
larsen

Replies are listed 'Best First'.
RE: Re: picking x numbers of lines from a file
by dchetlin (Friar) on Sep 19, 2000 at 15:52 UTC
    Actually, the scalar range operator defaults to testing against equality with C<$.> So, more simply, the above code becomes:  ($from .. $to) && print while <DATA>
      From Perl 5.004 docs:
      If either operand of scalar ".." is a numeric literal, that operand is implicitly compared to the $. variable, the current line number.
      This is an excerpt from MacPerl documentation (I'm used to program on Macintosh). On my Linux box (with Perl 5.004 installed) the phrase is (I think):
      If eitrher operand ... is a constant
      Am I missing something?
      -- "Fatti non foste a viver come bruti"