Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: I would like to find a good logic to parse the data

by varian (Chaplain)
on May 25, 2007 at 08:38 UTC ( #617430=note: print w/ replies, xml ) Need Help??


in reply to Re: I would like to find a good logic to parse the data
in thread I would like to find a good logic to parse the data

I am not allowed to load any modules
Core modules do not have to be installed so you may benefit from Text::Balanced.
Below code is not bullit proof but should be sufficient to process your data:
#!/usr/bin/perl use strict; use warnings; use Text::Balanced qw(extract_quotelike); sub getfields { my ($str) = @_; my @fields; my $field = ''; while ($str) { $field .= $str =~ s/^(\s*)// ? $1 :''; my $extracted; if ($str=~/^["']/) { ($extracted,$str) = extract_quotelike($str); $field.=$extracted; } else { ($extracted,$str) = split(',',$str,2); push @fields,$field.$extracted; $field=''; } } return @fields; } while (my $line = <DATA>) { chomp($line); print "$_\t" foreach ( getfields($line) ); print "\n"; } __DATA__ Submitted,"696,028","50,946","15,127,534","14,458,899" Expired,245,275,273,248 Less in,90.12%,90.49%,90.04%,89.55%
Output is:
Submitted "696,028" "50,946" "15,127,534" Expired 245 275 273 248 Less in 90.12% 90.49% 90.04% 89.55%


Comment on Re^2: I would like to find a good logic to parse the data
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2015-07-28 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls