Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: newbie attempting to extract

by Prior Nacre V (Hermit)
on Oct 04, 2004 at 01:15 UTC ( #396088=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://396088]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2022-05-23 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?