in reply to Re: Newbie Trying to Read and Reformat File
in thread Newbie Trying to Read and Reformat File

Drat! Chromatic already showed you the hashslice!

That's my favorite... anyway here is my belated version of the same thing--

#!/usr/bin/perl -w use strict; my @fields = qw[Company Contact Title Phone]; for my $file (@ARGV) { open TEXT, "< $file" or die "Couldn't open $file: $!\n"; my %contact; while(<TEXT>) { chomp; my ($k, $v) = split ": " or next; $contact{$k} = $v; } # hashslice print join("|", @contact{ @fields }), "\n"; }
Just watch out for people with pipes in their names... :)