Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Re-inventing the wheel, same hash, three scripts

Reply
Thread Tools

Re-inventing the wheel, same hash, three scripts

 
 
Justin C
Guest
Posts: n/a
 
      04-24-2007

I've been re-inventing the wheel, and it's costing me time. I have a
hash that is used in three scripts, and it's in all three scripts. Each
time there is a change to it I have to update all three scripts. I know
I'm wasting my time.

I'd like to store this hash in an external file and reference the
contents from each script. The scripts are only going to need to look up
one or two elements (out of about 100) each time they are run.

It has been suggested to me that I use one of the Config:: modules, I'd
rather, if possible, do this without modules (these may end up running
somewhere I can't request modules be installed).

I'm happy to read the documentation, I just don't know which
documentation I should read. Opening a file, reading all the contents
into a hash seems, though easy, a waste of time.

Thank you for your suggestions for help with this matter.

Justin.

--
Justin C, by the sea.
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      04-24-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I've been re-inventing the wheel, and it's costing me time. I have a
> hash that is used in three scripts, and it's in all three scripts. Each
> time there is a change to it I have to update all three scripts. I know
> I'm wasting my time.
>
> I'd like to store this hash in an external file and reference the
> contents from each script. The scripts are only going to need to look up
> one or two elements (out of about 100) each time they are run.


If the scripts are only going to look up 1 or 2, then why are there 100
in the first place?

> It has been suggested to me that I use one of the Config:: modules, I'd
> rather, if possible, do this without modules (these may end up running
> somewhere I can't request modules be installed).


A module is nothing more than an external file containing a certain kind
of valid perl code. If you can't install modules, you can't install an
external file to contain the hash's info, either.

> I'm happy to read the documentation, I just don't know which
> documentation I should read. Opening a file, reading all the contents
> into a hash seems, though easy, a waste of time.


How precious is your computer's time relative to your own? If it is very
precious, perhaps you should choose a different language to code in in the
first place.


Personally, I'd just make the config file be a custom-made module.

=== my_config.pm ===
package my_config;
%my_config::config = (
foo => 'bar',
baz => 'boo',
};

1;

=== script.pl ===
use my_config;
warn $my_config{foo};


Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
Andreas Pürzer
Guest
Posts: n/a
 
      04-24-2007
(E-Mail Removed) schrieb:
> Personally, I'd just make the config file be a custom-made module.
>
> === my_config.pm ===
> package my_config;
> %my_config::config = (
> foo => 'bar',
> baz => 'boo',
> };


Unmatched right curly bracket at my_config.pm...

>
> 1;
>
> === script.pl ===
> use my_config;
> warn $my_config{foo};


Warning: something's wrong at script.pl...
warn $my_config::config{foo};

> Xho
>


Sorry for the nitpicking, no offense intended :->

Andreas Pürzer

--
Have Fun,
and if you can't have fun,
have someone else's fun.
The Beautiful South
 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      04-24-2007
Justin C wrote:
> I've been re-inventing the wheel, and it's costing me time. I have a
> hash that is used in three scripts, and it's in all three scripts. Each
> time there is a change to it I have to update all three scripts. I know
> I'm wasting my time.
>
> I'd like to store this hash in an external file and reference the
> contents from each script. The scripts are only going to need to look up
> one or two elements (out of about 100) each time they are run.
>
> It has been suggested to me that I use one of the Config:: modules, I'd
> rather, if possible, do this without modules (these may end up running
> somewhere I can't request modules be installed).
>
> I'm happy to read the documentation, I just don't know which
> documentation I should read. Opening a file, reading all the contents
> into a hash seems, though easy, a waste of time.


perldoc -f dbmopen
perldoc -f dbmclose



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
 
Reply With Quote
 
Justin C
Guest
Posts: n/a
 
      04-24-2007
In article <20070424110709.877$(E-Mail Removed)>, (E-Mail Removed) wrote:
> (E-Mail Removed) wrote:
>> I've been re-inventing the wheel, and it's costing me time. I have a
>> hash that is used in three scripts, and it's in all three scripts. Each
>> time there is a change to it I have to update all three scripts. I know
>> I'm wasting my time.
>>
>> I'd like to store this hash in an external file and reference the
>> contents from each script. The scripts are only going to need to look up
>> one or two elements (out of about 100) each time they are run.

>
> If the scripts are only going to look up 1 or 2, then why are there 100
> in the first place?


What I meant was that though they'll only look up 1 or 2 values each
time, they're likely to be different keys/values each time.


>> It has been suggested to me that I use one of the Config:: modules, I'd
>> rather, if possible, do this without modules (these may end up running
>> somewhere I can't request modules be installed).

>
> A module is nothing more than an external file containing a certain kind
> of valid perl code. If you can't install modules, you can't install an
> external file to contain the hash's info, either.


I understand. What I mean, then, is that I'd rather manage this task
with a standard Perl install.


>> I'm happy to read the documentation, I just don't know which
>> documentation I should read. Opening a file, reading all the contents
>> into a hash seems, though easy, a waste of time.

>
> How precious is your computer's time relative to your own? If it is very
> precious, perhaps you should choose a different language to code in in the
> first place.


Yes, but I'm not starting from "in the first place" am I? I already have
these scripts written, and my time is valuable enough that I don't want
to write them again in something else.

Thank you for your comments.

Justin.

--
Justin C, by the sea.
 
Reply With Quote
 
Justin C
Guest
Posts: n/a
 
      04-24-2007
In article <240420071017079484%(E-Mail Removed)>, Jim Gibson wrote:
> In article <(E-Mail Removed) m>, Justin
> C <(E-Mail Removed)> wrote:
>
>> I've been re-inventing the wheel, and it's costing me time. I have a
>> hash that is used in three scripts, and it's in all three scripts. Each
>> time there is a change to it I have to update all three scripts. I know
>> I'm wasting my time.
>>
>> I'd like to store this hash in an external file and reference the
>> contents from each script. The scripts are only going to need to look up
>> one or two elements (out of about 100) each time they are run.
>>
>> It has been suggested to me that I use one of the Config:: modules, I'd
>> rather, if possible, do this without modules (these may end up running
>> somewhere I can't request modules be installed).
>>
>> I'm happy to read the documentation, I just don't know which
>> documentation I should read. Opening a file, reading all the contents
>> into a hash seems, though easy, a waste of time.

>
> Here is one way:
>
> main.pl:
>
> require 'hash.pl';
> if( $hash{$key} ) {
> ...
>
>
> hash.pl:
>
> %hash = ( ... );


OK, that looks fairly straight forward. I'll have a read up on 'require'
and see where that leads me. I'm not sure, at this stage how we get from
"require 'fname' ;" to "$hash{$key}" ... does it just 'import' those?
I'd have to be careful not to re-use those variable names.


> You can improve this scheme by using 'package', 'my', or 'our' in
> various combinations (left as an exercise or another poster).


Thanks, that's more to read up on, I know 'my' (learnt that very early!)
not come across 'package', or 'our' before, so that's going to confuse
the grey matter... still, I need something to keep me occupied at work.

Thanks again for the help.

Justin.

--
Justin C, by the sea.
 
Reply With Quote
 
Justin C
Guest
Posts: n/a
 
      04-24-2007
In article <qqvXh.7$_G.4@edtnps89>, John W. Krahn wrote:
> Justin C wrote:
>> I've been re-inventing the wheel, and it's costing me time. I have a
>> hash that is used in three scripts, and it's in all three scripts. Each
>> time there is a change to it I have to update all three scripts. I know
>> I'm wasting my time.
>>
>> I'd like to store this hash in an external file and reference the
>> contents from each script. The scripts are only going to need to look up
>> one or two elements (out of about 100) each time they are run.
>>
>> It has been suggested to me that I use one of the Config:: modules, I'd
>> rather, if possible, do this without modules (these may end up running
>> somewhere I can't request modules be installed).
>>
>> I'm happy to read the documentation, I just don't know which
>> documentation I should read. Opening a file, reading all the contents
>> into a hash seems, though easy, a waste of time.

>
> perldoc -f dbmopen
> perldoc -f dbmclose


Thank you, I shall read those.

Justin.

--
Justin C, by the sea.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Three Mobile --> Skype on three (Non-three [Symbian - Nokia] handsets) Harry Stottle UK VOIP 0 01-05-2010 08:59 AM
Using Python Scripts with IIS - ASP or Python-based CGI scripts withIIS - which makes more sense? davidj411 Python 0 06-27-2008 04:38 PM
What is required for perl scripts to run correct when launched from rc scripts on HPUX 11? deanjones7@gmail.com Perl Misc 13 09-10-2007 11:58 AM
Stupid question: Making scripts python-scripts Jan Danielsson Python 8 07-22-2005 12:20 AM
Re: Stupid question: Making scripts python-scripts Jp Calderone Python 0 07-21-2005 02:38 PM



Advertisments