Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^3: Parse file, split

by AnomalousMonk (Abbot)
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'

Comment on Re^3: Parse file, split
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2015-03-01 23:46 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (21 votes), past polls