Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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.


btw i hope formatting is correct ...

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 and strict but simply put in a snippet of my script which I thought the most relevant.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://262884]
[Discipulus]: who's Disci+?

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2017-12-18 09:07 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (475 votes). Check out past polls.