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

Re: Comma Delimitted Fields..

by scain (Curate)
on Oct 19, 2001 at 00:01 UTC ( [id://119786]=note: print w/replies, xml ) Need Help??


in reply to Comma Delimitted Fields..

I imiagine there is more that one way, but assuming PER is a record delimiter, you need to check if you have hit a delimiter and then start grabbing data. I would wonder though if all of your records look like this (ie, all on one line) why do you need a delimiter?

Anyway, assuming you do need the delimiter:

/usr/bin/perl-Tw use strict; use Text::ParseWords; open(DATA,"basicdez.dat") || die "Cannot open datfile: $!\n"; my @data; my $i = 0; my $new_record=0; while (<DATA>) { chomp; last if /^"EOS"$/; if (/^PER\s*$/) { $new_record=1; } elsif ($new_record) { @data = &quotewords('\s+', 0, $_); print "Name = $data[0]\n"; print "Color = $data[1]\n"; print "Date = $data[2]\n"; $new_record = 0; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found