http://www.perlmonks.org?node_id=617388


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

ooops, In our production server I am not allowed to load any modules. I need to use this parsing scripts, in our production server. thanks for the Idea. I will look into Text::CSV_XS module, and try my best.
  • Comment on Re: I would like to find a good logic to parse the data

Replies are listed 'Best First'.
Re^2: I would like to find a good logic to parse the data
by GrandFather (Saint) on May 25, 2007 at 03:14 UTC

    You may be able to get around the letter of the law by copying the important parts of Text::CSV into your code rather than installing the whole thing.


    DWIM is Perl's answer to Gödel
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
    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%
Re^2: I would like to find a good logic to parse the data
by Tux (Canon) on Jun 01, 2007 at 09:44 UTC

    You don't need to have write-access to the main perl installation tree at all:

    # perl Makefile.PL PREFIX=/home/greatshots/perl5 # make test # make install UNINST=1

    Do so with all modules you need, and add the PATH's to your env $PERL5LIB


    Enjoy, Have FUN! H.Merijn