ozman has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: CSV File Parsing
by GrandFather (Saint) on Aug 21, 2012 at 02:41 UTC

    A good place to start is with Text::CSV. Beyond that, we will halp more when you show some code you are having trouble with.

    Note that PerlMonks focuses on helping you to fish (use Perl) rather than giving you a fish (writing the code for you).

    True laziness is hard work
      Note that PerlMonks focuses on helping you to fish (use Perl) rather than giving you a fish (writing the code for you).

      If the fisherman is weak from starvation, giving him a fish up-front is a good starting point;

      Ditto, if he's standing there staring at the stick, ball of string and pin with glazed-over eyes and no clue what to do with them, a brief demonstration may work wonders.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

Re: CSV File Parsing
by Anonymous Monk on Aug 21, 2012 at 06:56 UTC

    I would provide code but I have know idea where to begin.

    Start by writing down a list steps  <ul><li> first <li> second <li> then another <li> other </ul> of how you would accomplish this task using only paper and pencil , using the human computer that is you -- read a line, pick first part, etc etc

    Something clearer than what you've posted

    • first
    • second
    • then another
    • other
Re: CSV File Parsing
by aitap (Curate) on Aug 21, 2012 at 07:53 UTC
    Try something like this:
    use warnings; use strict; # should be used almost always my %new_strings; # create the hash containing new values while (<>) { # read STDIN and/or files specified on the command line chomp; # cut the newline symbol my ($first,$id) = (split ",",$_,3); # read first two columns and disc +ard all others my $numeric = /(,[\d,]+)$/; # use regexp to match numeric values at t +he end of the line unless (exists $new_strings{$id}) { # if this data was found the firs +t time, initialise the value in the hash $new_strings{$id}="$first,$id"; } $new_strings{$id}.=$numeric; # append the numeric data found } foreach (sort keys %new_strings) { # for each datum found in the secon +d column, in alphabet order print "$new_strings{$_}\n"; # print the full string with all numeric +data found }
    I hope that was understandable enough. See perlintro warnings strict perlop chomp split perlretut exists print for more.
    Sorry if my advice was wrong.