Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^3: Parse file, split

by AnomalousMonk (Chancellor)
on May 28, 2013 at 01:29 UTC ( #1035496=note: print w/replies, xml ) Need Help??

in reply to Re^2: Parse file, split
in thread Parse file, split

If the dataset is assumed valid and you avoid multi-word 'make' fields, LanX's approach would certainly seem to do the trick with this dataset. Note that  $extended_model has to be 'fixed' if the field does not exist, otherwise it's undefined.

>perl -wMstrict -le "my @records = ( '2011 Chevy Camaro', '2011 Dodge Ram Crew Cab Short Bed', '2011 Ford F150 Platinum', '2011 GMC Cargo Van Extended', ); ;; for my $record (@records) { my ($year, $make, $model, $extended_model) = split ' ', $record, 4; $extended_model //= ''; print qq{'$year' '$make' '$model' '$extended_model'}; } " '2011' 'Chevy' 'Camaro' '' '2011' 'Dodge' 'Ram' 'Crew Cab Short Bed' '2011' 'Ford' 'F150' 'Platinum' '2011' 'GMC' 'Cargo' 'Van Extended'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1035496]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2017-07-26 21:26 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (402 votes). Check out past polls.