Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Hash references and efficiency

by jlongino (Parson)
on Aug 08, 2002 at 16:43 UTC ( [id://188638]=note: print w/replies, xml ) Need Help??


in reply to Hash references and efficiency

Although your original question was answered, no one seemed to address the fact that if you code with a little planning, you can preserve efficiency and use %hash for all of your non-module code.

Generally people write modules for whatever purpose and then only occasionally (if ever) go back and modify them. So use the references in the module and once it's finished, you can write as many programs as you like using %hash and still have efficient code. Here is an example module:

package mylib; use strict; use warnings; use Exporter; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @EXPORT = qw( load_hash ); sub mylib::load_hash { my $href = shift; for (1..1000) { $$href{$_} = $_; } }
And an example program that uses it:
#!/usr/local/bin/perl use strict; use warnings; use mylib; my %hash; mylib::load_hash(\%hash); for (keys %hash) { print "key: $_ value: $hash{$_}\n"; }

--Jim

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-20 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found