i was slicing up a csv line (actually tabbed) and i wanted a hash of the
desired columns since there were many and i couldn't deal with column
numbers in the code. the first row has column names which is
needed. there is a slice to initialize the name2col hash and later 3
slices in one statement :).
actually i could factor out the list of column numbers and move it
outside the loop as it is static. i just realized that now but i doubt i
will change this short script just for that. and @wanted_cols should be
renamed to @wanted_names (or fields).
my @col_names = split( /\t/, <> ) ;
my %name2col ;
@name2col{ @col_names } = 0 .. $#col_names ;
my @wanted_cols = qw(
NAME BADDR1 BADDR2 BADDR3 BADDR4 BADDR5 PHONE1 CUSTFLD3 CUSTFLD4 NOTEPAD ) ;
while( <> ) {
my %fields ;
@[EMAIL PROTECTED] =
(split( /\t/, $_ ))[ @name2col{ @wanted_cols } ] ;
yes, i like slicing!
thanx,
uri
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm