# data_read
use strict;
use warnings;
while (<DATA>)
{
chomp;
my @data = split;
for (my $i = 0; $i <= $#data; ++$i)
{
print "$._$i = $data[$i]\n";
}
}
__DATA__
qwerty qwerty qwerty asdf zxcv 1234
qwerty qwerty qwerty asdf zxcv
Here's the output:
[ ~/tmp ] $ perl data_read
1_0 = qwerty
1_1 = qwerty
1_2 = qwerty
1_3 = asdf
1_4 = zxcv
1_5 = 1234
2_0 = qwerty
2_1 = qwerty
2_2 = qwerty
2_3 = asdf
2_4 = zxcv
[ ~/tmp ] $
Here's a perl.com article which describes $. and other special variables.
|