in reply to Sort by specific column
You have a table. Treat it as such.
At this point, you can do whatever you want with $r. But modifying the original file becomes unnecessary since you can always re-order the rows you're interested in by whatever field you want.#! /usr/bin/perl -l use strict; use warnings; use DBI; my $file = 'f1'; my $dbh = DBI->connect("dbi:CSV:csv_eol=\n;csv_sep_char=|"); $dbh->{csv_tables}->{FOO}{file} = $file; $dbh->{csv_tables}->{FOO}{col_names} = [ qw/date id unk1 price unk2 qu +antity/ ]; my $r = $dbh->selectall_arrayref('SELECT * FROM FOO ORDER BY ID'); use Data::Dumper; print Dumper $r;
I emphasise the tabular nature of your data because you're probably doing other things that SQL makes easy. And, you probably should also put it in a real db anyway, even if that real db is SQLite.
|
|---|