Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Sorting Text File for HTML Output

by clueless newbie (Deacon)
on Sep 14, 2017 at 14:04 UTC ( #1199393=note: print w/replies, xml ) Need Help??


in reply to Sorting Text File for HTML Output

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1199393]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2019-12-09 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?