Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

ok here's a full program that produces the same result. It pulls in a $resultsFile called "results.txt."

#! /strawberry/Perl/bin/perl use CGI; use CGI::Carp qw( fatalsToBrowser ); use Text::CSV; use Excel::Writer::XLSX; use utf8; use strict; ### read the output my(@urls); my($header); my($resultsFile) = "results.txt"; open my $fh, "<:encoding(utf8)", "$resultsFile" || die("cannot open re +sults file $resultsFile for reading."); my($c)=0; # just here for counting my($d)=0; # just here for counting while(<$fh>){ $c++; if ($_ =~ /\/search\//){ push(@urls, $_); } else{ $d++; } } close($fh); # sort @urls based on the search string my @sorted_urls = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { m|/search/\s*([^\?]+)\?|; [$_, $1] } @urls; my($count) = -1; my $csv = Text::CSV->new ({ binary => 1, sep_char => "|" }); my $q = new CGI; # parse and print print $q->header(-charset => 'utf-8'); print $q->start_html( -title => 'SearchME'); print $q->start_table(); foreach my $row (@sorted_urls){ # print TEMP $row; $csv->parse($row); print "<tr>"; $count++; my @els = $csv->fields; my(@splits) = split('\|',$row); $els[0] =~ /\/search\/(.+)\?scope=/i; my($term) = $1; my($link) = $els[0]; print "<td>"; # print $link; print $q->a({-href=>$link,-target=>'_blank'},$term); print "</td>"; for(my $i=1; $i <= 4; $i++){ print "<td>"; print $els[$i]; print "</td>"; } print "</tr>\n"; } print $q->end_table, $q->end_html;

And here's a short results file (not sure how to keep it from wrapping, so it's not code):

PAGE_COMPL_URL|PAGE_REFRL_COMPL_URL|IBMER|VIEWS|VISITORS|ENGAGED_VISITS¿Cuales son las partes de una cadena de conexión??scope=SSGU8G_12.1.0||0|1|1|0||1|1|1|1

Thank you.

In reply to Re^14: Text::CSV encoding parse() by slugger415
in thread Text::CSV encoding parse() by slugger415

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (8)
    As of 2019-10-14 19:17 GMT
    Find Nodes?
      Voting Booth?