in reply to Re^3: parsing CSV
in thread parsing CSV

Hey there, thanks a lot for the the code. I've been playing around with it trying to get it to work. I added the CSV webpages and dates. As well as changed the print to an output at the bottom. But no luck on this at all. Keep getting "Can't find string terminator "http" anywhere before EOF" and stuff like that.
use strict; use warnings; use Text::CSV; START_DATE=$(date '+%Y-%m-%d' -d "-1 month"); END_DATE=$(date '+%Y-%m-%d'); my $page1 = <<http://url/website.com/thing?end_date=$END_DATE&start_da +te=$START_DATE&type=csv; 512.45,c100 6734, c200 5653.2, c300 PG1CSV my $csv = Text::CSV->new(); my %idData; open my $pg1In, '<', \$page1; while (my $row = $csv->getline($pg1In)) { s/^\s+|\s+$//g for @$row; $idData{$row->[1]}{size} = $row->[0]; $idData{$row->[1]}{name} = '-- missing --'; } close $pg1In; my $page2 = <<https:/url/website.com/thing?end_date=$END_DATE&start_da +te=$START_DATE&type=csv; c100, Joe Shmo c200, Jack Black c300, Cinderella c400, Barack Obama c5 +00, Cruella Deville PG2CSV $page2 =~ s/\b(?=\w+,)/\n/g; # Insert newlines in front of id codes open my $pg2In, '<', \$page2; while (my $row = $csv->getline($pg2In)) { next if !$row->[0]; # Skip blank lines s/^\s+|\s+$//g for @$row; $idData{$row->[0]}{name} = $row->[1]; $idData{$row->[0]}{size} //= '-- missing --'; } close $pg2In; for my $id (sort keys %idData) { $output .= "$id: $idData{$id}{name} size $idData{$id}{size}\n"; } curl -s -G "$output" | mail -s "send the thing for $END_DATE" name@nam +e.com

Replies are listed 'Best First'.
Re^5: parsing CSV
by AnomalousMonk (Archbishop) on Oct 08, 2016 at 03:13 UTC
    my $page1 = <<http://url/website.com/thing?end_date=$END_DATE&start_da +te=$START_DATE&type=csv; 512.45,c100 6734, c200 5653.2, c300 PG1CSV

    What you are (incorrectly) attempting is a here document. The proper form (I'm making some assumptions about just exactly what you want) is:

    my $page1 = <<PG1CSV; http://url/website.com/thing?end_date=$END_DATE&start_date=$START_DATE +&type=csv; 512.45,c100 6734, c200 5653.2, c300 PG1CSV
    See also the discussion of here-docs in Quote and Quote-like Operators and Quote-Like Operators, both in perlop.

    Update: Do you want semicolon at the end of the
        http://url/website.com/thing?end_date...=csv;
    string | sub-string?

    Update 2: The here-doc with the label  PG2CSV is also incorrect, and in the same way.


    Give a man a fish:  <%-{-{-{-<

      This is still not working. I'm not sure what the problem is. Essentially Each webpage shows me a page of data represented in csv format. Just a single blank white page with data. Currently in our office we we run a curl command on each webpage to send that data in an email. One webpage has customer id and storage size the other webpage has those same customer id but with the customer names associated with the customer id.
      What I'm trying to do is take both of those web pages data and match their the customer id and storage size to the corresponding customer id and client name on the other put that into a new csv format and email that information to whoever needs it in the body of the email.
      In short. I need to take two web pages, match and concatenate the data and email it.

        Can you post an example of each of these pages (with fake customer data, obviously) and what the output you require is? With access to the right data and an example of what you want the output to be it'll be easier for people to help.