Which of these is the better solution, or does someone (I hope) have another solution that would be best?#!/usr/bin/perl -w use strict; # Use undef hash values for unneeded fields my @fields = ( 'FIRSTNAME', 'LASTNAME', 'PHONE', undef, # Useless data undef, # Useless data undef, # Useless data 'FAX', undef, # Useless data 'CITY', 'STATE', ); # Use dummy key for unneeded fields my @fields2 = ( 'FIRSTNAME', 'LASTNAME', 'PHONE', 'DUMMY', # Useless data 'DUMMY', # Useless data 'DUMMY', # Useless data 'FAX', 'DUMMY', # Useless data 'CITY', 'STATE', ); while (<DATA>) { chomp; my (%record, %record2); # Using undef keys; requires disabling warnings # about uninitialized values in hash slice no warnings; @record{@fields} = split(/\t/, $_); print "1) First Name: $record{FIRSTNAME}, State: $record{STATE}\n" +; # Using dummy key, then deleting it use warnings; @record2{@fields2} = split(/\t/, $_); delete $record2{'DUMMY'}; print "2) First Name: $record2{FIRSTNAME}, State: $record2{STATE}\ +n"; } print "\n---------------\nDone.\n"; exit; __DATA__ Bill Davis 999-888-7777 KH101 1 1 999-888-7770 19 +65 Chantilly VA Bob Rogers 999-777-8888 KH101 1 1 999-777-8880 19 +53 Dallas TX Jim Dawson 999-787-8787 KH101 1 1 999-787-8787 19 +72 San Diego CA Harry Jones 999-878-7878 KH101 1 1 999-878-7870 1 +963 Chicago IL John Black 999-778-7788 KH101 1 1 999-778-7788 19 +36 Topeka KS
In reply to Ignoring values in a hash slice assignment by impossiblerobot
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |