in reply to whats the best way to query/extract fields from a tab delimited file

The following is admittedly ugly as sin but it allows you to choose columns and set their order -- just substitute tabs for spaces:

use strict; my @cols_to_print = qw(LAST_NAME FIRST_NAME); my @col_nbrs; while (<DATA>) { my $line = $_; if ($. == 1) { #1st line of input? my @col_names = split(/\s+/, $line); for my $x (0..$#cols_to_print) { for my $y (0..$#col_names) { if ($cols_to_print[$x] eq $col_names[$y]) { push @col_nbrs, $y; last; } } } } else { my @cols = split /\s+/, $line; @cols = @cols[@col_nbrs]; #slice into wanted column nbrs print "@cols\n"; } } __DATA__ CUST_ID FIRST_NAME LAST_NAME FAV_LANG 1 Larry Wall Perl 2 Bill Joy Java 3 Richard Stallman emacslisp 4 Bill Gates tinyBasic
Would render:
Wall Larry Joy Bill Stallman Richard Gates Bill

This helps if the column selections truly need to be dynamic. @cols_to_print could come from ARGV or other external vars.

There might be a more idomatic way of handling the sequence for the first line, but darned if I figure out what it is.

Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"