Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: File Reading

by Limbic~Region (Chancellor)
on Oct 01, 2007 at 14:36 UTC ( [id://641902]=note: print w/replies, xml ) Need Help??


in reply to File Reading

mantra2006,
I agree with others, this looks like homework. After reading a few of the 70+ other posts you have made over the last year, I am willing to give you the benefit of a doubt.
#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] or die "Usage: $0 <input_file>"; open(my $fh, '<', $file) or die "Unable to open '$file' for reading: $ +!"; my $header = <$file>; chomp $header; my @field = split /:/, $header; print "What field would you like to look for?\n"; my $choice = <STDIN>; chomp $choice; while (<$fh>) { chomp; my %record; @record{@field} = split /:/; print "$record{$choice}\n"; }
It is untested and intentionally does not do a lot of the error checking that it should. These are tasks that you will need to do yourself.

Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://641902]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-29 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found