IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Perl is line oriented by default
Use the <FILE_HANDLE> construct.

While Ben will do this in one line, here is
how I would handle it.

If you NEED to open the file (rather than STDIN):
\nuse strict;\nopen (IN,"file.dat") or die "Can't open file - $!";\nmy %hash;\nwhile (<IN>){\n  chomp;\n  my ($key,$data) = split(' ',$_,2);\n  $hash{$key} = $data;\n}\nclose (IN);\n
Collapse Edited by broomberg Sept. 14, 2004, 12:10:08 AM EDT
Perl is line oriented by default
Use the <FILE_HANDLE> construct.

While Ben will do this in one line, here is
how I would handle it.

If you NEED to open the file (rather than STDIN):
use strict;
open (IN,"file.dat") or die "Can't open file - $!";
my $hash;
while (<IN>){
	chomp;
	my ($key,$data) = split(' ',$_,2);
	$hash{$key} = $data;
}
close (IN);


     Perl - storing a hash in a file to re-read later - (tuberculosis) - (26)
         Wouldn't it be better to build it as you read? - (drewk) - (2)
             Its not large - its small - (tuberculosis) - (1)
                 Perl is line oriented by default - (broomberg)
         This wheel has been invented already :-) - (ben_tilly) - (22)
             <fawn>Wonderful post</fawn> - (pwhysall) - (1)
                 <preen /> -NT - (ben_tilly)
             I am so glad I gave up on tying my programming skills... - (inthane-chan) - (7)
                 Why? -NT - (deSitter) - (6)
                     Because there's no way I could match that answer. -NT - (inthane-chan) - (5)
                         But that isn't programming - (ben_tilly) - (4)
                             Nice to see a teacher/craftsman in action. - (ChrisR) - (3)
                                 A good thing for my spare time you mean? - (ben_tilly)
                                 Why? -NT - (deSitter) - (1)
                                     Jack of all languages... - (ChrisR)
             I figured it had - one more quickie question - (tuberculosis) - (11)
                 Error checking remains a best practice - (ben_tilly) - (10)
                     Agree - (tuberculosis) - (9)
                         You lucky duck. - (FuManChu)
                         What do you mean by plists? - (ben_tilly) - (6)
                             I meant NextStep style plists - (tuberculosis) - (5)
                                 Do you mean kind of like this? - (ben_tilly) - (3)
                                     Pretty close - (tuberculosis) - (2)
                                         Ah - (ben_tilly) - (1)
                                             One True Data Format - (tuberculosis)
                                 Big River Books - rofl - (deSitter)
                         ICLRPD (new thread) - (Meerkat)

One of them was this cute little yellowtail, and she's giving me the eye. So I figured, this is my chance for a little fun. You know, piece o' Pisces.
82 ms