Using DBD::CSV
#!/usr/bin/env perl use Data::Dumper; use DBI; use Try::Tiny; use strict; use warnings; try { my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_dir => "./", f_ext => ".csv/r", f_lock => 2, csv_eol => "\r\n", csv_sep_char => "|", RaiseError => 1, PrintError => 1, FetchHashKeyName => "NAME_lc", }) or die $DBI::errstr; # Sorting by author my $sth=$dbh->prepare(<<"__SQL__"); select * from books order by author __SQL__ $sth->execute(); my $field_aref=$sth->{NAME_lc}; warn Data::Dumper->Dump([\$field_aref],[qw(*field_aref)]),' '; while (my $value_aref=$sth->fetchrow_arrayref()) { warn Data::Dumper->Dump([\$value_aref],[qw(*value_aref)]),' '; }; } catch { Carp::confess $!; };
on ./books.csv which contains
title1|title2|pages|author Perl Best Practices|hound|a few|Damian Conway Learning Perl|llama|thin|Randal Schwartz Programming Perl|camel|many|Larry Wall
results in
$field_aref = \[ # fields 'title1', 'title2', 'pages', 'author' ]; at data.plx line 28. $value_aref = \[ # first when sorted by aut +hor 'Perl Best Practices', 'hound dog', 'a few', 'Damian Conway' ]; at data.plx line 30. $value_aref = \[ 'Programming Perl', 'camel', 'many', 'Larry Wall' ]; at data.plx line 30. $value_aref = \[ 'Learning Perl', 'llama', 'thin', 'Randal Schwartz' ]; at data.plx line 30.

In reply to Re: Sorting Text File for HTML Output by clueless newbie
in thread Sorting Text File for HTML Output by michael.kitchen

Title:
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, details, 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, summary, 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.