Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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%

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2017-12-15 01:45 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (415 votes). Check out past polls.