zyzzogeton has asked for the wisdom of the Perl Monks concerning the following question:

I have the following code: open(my $data, '<', $file) or die "Could not open '$file'\n"; <$data> for 1 .. 1; while (my $line = <$data>) { chomp $line; ...etc I am curious what what does the "for 1 .. 1;" construct do?

Replies are listed 'Best First'.
Re: What does "<$data> for 1 .. 1;" do?
by almut (Canon) on Mar 18, 2010 at 12:17 UTC
    <$data> for 1 .. 1;

    It reads one line from the file.  I suppose it may have originally been something like

    <$data> for 1 .. 3;

    with the intention to skip a few lines at the beginning of the file, before starting to process the rest.  But then later it turned out that only one line was to be skipped, and the author left in the (in this case superfluous) for loop — possibly anticipating it might become useful again in the future...

Re: What does "<$data> for 1 .. 1;" do?
by Anonymous Monk on Mar 18, 2010 at 12:20 UTC
    perlintro
    .. range operator (creates a list of numbers)
    $ perl -le " print for 1 .. 1; " 1 $ perl -le " print for 1 .. 4; " 1 2 3 4 $ perl -le " print 1 .. 4; " 1234 $ perl -le " print 1 .. 1; " 1 $ perl -le " print 1 .. 0; "