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

Welcome to IWETHEY!

New Wouldn't it be better to build it as you read?
Instead of reading in the whole file and splitting it, wouldn't it make more sense as you read each chunk to look for the newline, take whatever is in your sting up to that and push it into the hash, delete it from the front of your string and keep reading?

If the file is truly "large" I wouldn't want to read then whole thing in then split it.
===

Implicitly condoning stupidity since 2001.
New Its not large - its small
and the only api I see is "read n bytes" or "read n bytes starting at m". No line oriented interface that I can see.

Which is annoying as hell, so I'll just read it all. Anyhow, if the file exceeds 20k I will be amazed.




That was lovely cheese.

     --Wallace, The Wrong Trousers
Expand Edited by tuberculosis Aug. 21, 2007, 06:31:41 AM EDT
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
Expand Edited by broomberg Sept. 14, 2004, 12:10:08 AM EDT
     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)

Mother Hubbard got me covered, like Sarah Lee on her cherry pie.
172 ms