in reply to Re^2: newbie attempting to extract
in thread newbie attempting to extract
This provides a unique value for each data item. It combines a row ID ($.) and a field ID ($i).
# 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.
Regards,
PN5
|
|---|