use strict; use warnings; my @foo = (); while (<DATA>){ chomp; if ($. < 4){push @foo, $_}} print "my first variable is $foo[0]"; print "my second variable is $foo[1]"; print "my third variable is $foo[2]"; __DATA__ one two a beautiful tree, maybe an oak?
no need to read after "n lines"
And you can add also a fifth line to rename your variables and that's all:
my ($ball,$dog,$bird) = ($fo[1],$fo[2],$fo[0]);In reply to Re: Save first n values from a file
by pvaldes
in thread Save first n values from a file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |