Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Making a hash of making a hash of an array

by kabel (Chaplain)
on Jun 04, 2003 at 04:58 UTC ( #262884=note: print w/ replies, xml ) Need Help??


in reply to Making a hash of making a hash of an array

open (FILE, "$record") or die "can't open $record: $!"; my @record = reverse <FILE>; close FILE;

this is considered bad due to the fact that the file could eventually get large and fill up your memory. have a look at File::ReadBackwards.

%member = ( $timestamp => [$current_time, $funds, $action, $current_funds]);
this is 100% wrong, because %member contains afterwards exactly one element, the ten that got into before are lost. you want:

$member{$timestamp} = [$current_time, $funds, $action, $current_funds];
then, you really want to use strict; #damn ;) and to use CGI; or an equivalent module. see the tutorials for why.

update: i just realized that you don't chomp; your input lines. so, the last elem will have a line separator character at its end.

HTH

btw i hope formatting is correct ...


Comment on Re: Making a hash of making a hash of an array
Select or Download Code
Replies are listed 'Best First'.
Re: Re: Making a hash of making a hash of an array
by jonnyfolk (Vicar) on Jun 04, 2003 at 05:24 UTC
    Thanks very much for your input, kabel, the File::ReadBackwards is especially interesting. I am actually using CGI.pm and strict but simply put in a snippet of my script which I thought the most relevant.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2015-07-28 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls