Perhaps a hash, or an array is would suit your purpose better. Here is an example using an array, also showing a way to put the vals in $i, $j, $k and a way to use a hash.
Update: Added hash demo to code too, and better behaviour when it runs out of values
use strict;
use warnings;
my @names;
while (my $name = <DATA>) {
chomp $name; # remove newline
push @names, $name;
}
print "The third name is $names[2]\n";
my @copy = @names; # take a copy for the hash demo
my ($i, $j, $k);
while (@names) {
for (\$i, \$j, \$k) {
if (@names) {
$$_ = shift @names;
}
else {
$$_ = 'ran out of records'; # could use undef too
}
}
print "i: $i j:$j k: $k \n";
}
# and with a hash
my %hash;
while (@copy) {
%hash = (i=>'', j=>'', k=>''); # clear the hash
for my $key (qw(i j k)) {
$hash{$key} = shift @copy if @copy;
}
print "the hash contains $hash{$_} under $_\n" for ('i'..'k');
}
__DATA__
a
b
c
d
e
f
g
h
Cheers,
R.
Pereant, qui ante nos nostra dixerunt!