[25332] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7577 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 27 14:05:34 2004

Date: Mon, 27 Dec 2004 11:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 27 Dec 2004     Volume: 10 Number: 7577

Today's topics:
        [OT - Google Groups] WAS: copying values from a hash in <mritty@gmail.com>
    Re: copying values from a hash into CGI.pm via tied has <mritty@gmail.com>
    Re: copying values from a hash into CGI.pm via tied has <mritty@gmail.com>
    Re: copying values from a hash into CGI.pm via tied has ioneabu@yahoo.com
    Re: copying values from a hash into CGI.pm via tied has <matthew.garrish@sympatico.ca>
    Re: copying values from a hash into CGI.pm via tied has ioneabu@yahoo.com
    Re: copying values from a hash into CGI.pm via tied has <mritty@gmail.com>
    Re: copying values from a hash into CGI.pm via tied has <mritty@gmail.com>
    Re: copying values from a hash into CGI.pm via tied has ioneabu@yahoo.com
    Re: how to delete files that create date <=20041210 <mritty@gmail.com>
    Re: how to delete files that create date <=20041210 <jgibson@mail.arc.nasa.gov>
    Re: Is zero even or odd? <jmw@jmwa.demon.contraspam.yuk>
    Re: Is zero even or odd? <jfields@austininstruments.com>
    Re: Is zero even or odd? <george@briar.demon.co.uk>
        Loading Modules with "require" amerar@iwc.net
    Re: Loading Modules with "require" <noreply@gunnar.cc>
    Re: Loading Modules with "require" <mritty@gmail.com>
        Perl Developer neded. <ccolumbu@hotmail.com>
    Re: Perl Developer neded. <mritty@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 27 Dec 2004 18:18:59 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: [OT - Google Groups] WAS: copying values from a hash into CGI.pm via tied hash reference
Message-Id: <nmYzd.15040$vF5.12346@trndny07>

<ioneabu@yahoo.com> wrote in message
news:1104170863.164575.54560@z14g2000cwz.googlegroups.com...
> Regarding my poor posting practices recently, specifically improper
> quoting, this is due to Google's new beta version of
groups.google.com.
> I prefer it over the old format because posts go up immediately rather
> than 6-8 hours.
>
> Unfortunately, replies to a message are done in such a way to make
them
> non-compliant with comp.lang.perl.misc posting practices.
>
> Try it and see, a little reply box appears at the bottom of the
message
> you are replying to and that's all you get.

Instead of clicking Reply, click the "Show Options" link, and then click
the Reply link that appears near the top of the message text.

Paul Lalli



------------------------------

Date: Mon, 27 Dec 2004 16:13:27 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: copying values from a hash into CGI.pm via tied hash reference
Message-Id: <HwWzd.2607$PY6.2590@trndny02>

"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:yVVzd.12015$Tn1.363027@news20.bellglobal.com...
>
> <ioneabu@yahoo.com> wrote in message
> news:1104156167.901423.152830@f14g2000cwb.googlegroups.com...
> >I am trying to restore values from a saved session to fill in my
CGI.pm
> > fields in the simplest and most generic way possible (such that if I
> > change my form, I don't have to rewrite this code).  This statement
did
> > not work:
> >
> > $params->{keys %session} = values %session;
> >
>
> If you don't use some kind of loop, you're never going to get what you
want:
>
> foreach (keys %session) { $params->{$_} = $session{$_} }

Untrue.  A hash slice will do just fine.  See my previous response in
this thread.  (And no, I haven't benchmarked to see which is faster...)

Paul Lalli



------------------------------

Date: Mon, 27 Dec 2004 16:16:02 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: copying values from a hash into CGI.pm via tied hash reference
Message-Id: <6zWzd.5602$sh5.4400@trndny08>

<ioneabu@yahoo.com> wrote in message
news:1104163295.020784.314140@f14g2000cwb.googlegroups.com...
> Sorry for saying 'did not work.'
>
> Here is what I tried:
>
> $params->{keys %session} = values %session;
>
> Here is the example I based it on:
>
 <<<SNIPPED PIRATTED BOOK URL>>>

Ah, so you used a piratted copy of material and didn't understand what
it actually did.  I'd say that satisfies Karma.

> <quote>
> Hash slices can also be used to merge a smaller hash into a larger
one.
> In this example, the smaller hash takes precedence in the sense that
if
> there are duplicate keys, the value from the smaller hash is used:
>
> %league{keys %score} = values %score;
> </quote>
>
> Maybe this was the source of my confusion.  I thought I understood the
> example but now I am not sure.

Do you understand how the above line of code differs from what you did?
If not, you need to read up on references.  Fortunately, Perl comes with
free documentation that you don't have to steal.

At your command line, type
perldoc perlreftut
perldoc perllol
perldoc perldsc
perldoc perlref
(generally in that order)


Paul Lalli



------------------------------

Date: 27 Dec 2004 08:43:49 -0800
From: ioneabu@yahoo.com
Subject: Re: copying values from a hash into CGI.pm via tied hash reference
Message-Id: <1104165829.896175.165990@f14g2000cwb.googlegroups.com>

I didn't realize that was not an official site.  I did buy all of the
O'Reilly Perl books plus a few others, so I'm not totally a terrible
person.  I did not mean to put a disreputable link into this group.
Sorry again.

$params->{keys %session} = values %session;

hmm...This would be like saying...

${$params}{keys %session} = values %session;

which is accessing an individual hash element which requires a scalar
for the key which puts keys %session into scalar context and is not the
same as:

%hash1{keys %hash2} = values %hash2;

which I assume is special notation for dealing with hash slices.  Would
this be the same?

@hash1{keys %hash2} = values %hash2;

Now I am wondering about how to interprete the hash slice notation and
why to use the @ in one case and the % in the other.

Thanks,

wana



------------------------------

Date: Mon, 27 Dec 2004 11:53:53 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: copying values from a hash into CGI.pm via tied hash reference
Message-Id: <v6Xzd.12800$Tn1.389068@news20.bellglobal.com>


"Paul Lalli" <mritty@gmail.com> wrote in message 
news:HwWzd.2607$PY6.2590@trndny02...
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
> news:yVVzd.12015$Tn1.363027@news20.bellglobal.com...
>>
>> <ioneabu@yahoo.com> wrote in message
>> news:1104156167.901423.152830@f14g2000cwb.googlegroups.com...
>> >I am trying to restore values from a saved session to fill in my
> CGI.pm
>> > fields in the simplest and most generic way possible (such that if I
>> > change my form, I don't have to rewrite this code).  This statement
> did
>> > not work:
>> >
>> > $params->{keys %session} = values %session;
>> >
>>
>> If you don't use some kind of loop, you're never going to get what you
> want:
>>
>> foreach (keys %session) { $params->{$_} = $session{$_} }
>
> Untrue.  A hash slice will do just fine.  See my previous response in
> this thread.  (And no, I haven't benchmarked to see which is faster...)
>

Fair enough. I was thinking that keys and values wouldn't necessarily return 
in the same order when I wrote that, but learned something new today (I'd 
still take a loop over a hash slice for clarity, though). And fyi, the time 
disparity between the two is minimal, but foreach is slightly faster.

Matt 




------------------------------

Date: 27 Dec 2004 09:24:04 -0800
From: ioneabu@yahoo.com
Subject: Re: copying values from a hash into CGI.pm via tied hash reference
Message-Id: <1104168243.981052.15180@f14g2000cwb.googlegroups.com>

I agree with the loop.  That is what I finally used in my program since
I realized that I don't necessarily want to share all of the values of
one hash with the other.  I needed to do a little filtering along the
way.  It is still good for me for learning purposes.  Thanks for help.
wana



------------------------------

Date: Mon, 27 Dec 2004 17:33:43 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: copying values from a hash into CGI.pm via tied hash reference
Message-Id: <XHXzd.10238$113.9733@trndny03>

"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:v6Xzd.12800$Tn1.389068@news20.bellglobal.com...
>
> Fair enough. I was thinking that keys and values wouldn't necessarily
return
> in the same order when I wrote that, but learned something new today
(I'd
> still take a loop over a hash slice for clarity, though). And fyi, the
time
> disparity between the two is minimal, but foreach is slightly faster.

Just to be clear, keys, values, and each all return the hash's elements
in the same order.  That's a guarantee.  What that order *is* however,
is unknowable (without digging into the internals of perl itself, I
imagine).

Paul Lalli



------------------------------

Date: Mon, 27 Dec 2004 17:43:09 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: copying values from a hash into CGI.pm via tied hash reference
Message-Id: <NQXzd.15038$vF5.12149@trndny07>

<ioneabu@yahoo.com> wrote in message
news:1104165829.896175.165990@f14g2000cwb.googlegroups.com...

Please read the posting guidlines for this group.  Specifically, please
quote the message you are responding to.  Thank you.

> I didn't realize that was not an official site.

If it's not on oreilly.com or perl.com, it's not official.

> $params->{keys %session} = values %session;
>
> hmm...This would be like saying...
>
> ${$params}{keys %session} = values %session;
>
> which is accessing an individual hash element which requires a scalar
> for the key which puts keys %session into scalar context

All correct.

> and is not the same as:
>
> %hash1{keys %hash2} = values %hash2;

This is a classic example of "What happened when you tried it?"  I
gather that you did not try it, because when I try it, I get:

syntax error at - line 4, near "%hash1{"

> which I assume is special notation for dealing with hash slices.
Would
> this be the same?
>
> @hash1{keys %hash2} = values %hash2;

No.  This is the correct way of creating hash slices.  The example with
% above is not valid code.

> Now I am wondering about how to interprete the hash slice notation and
> why to use the @ in one case and the % in the other.

You use % to assign a list of key/value pairs to a hash.  You use @ to
create a hash slice - that is, to read or set a list of values based on
a list of keys.  (There are no restrictions on the size of that list -
it could be empty, it could contain all of the currently existing hash
keys, it could contain hash keys that do not currently exist).

my %hash = (foo=>1, bar=>2);
is equivalent to:
my %hash;
@hash{foo,bar}=(1,2);

I hope that clears things up,
Paul Lalli



------------------------------

Date: 27 Dec 2004 10:07:43 -0800
From: ioneabu@yahoo.com
Subject: Re: copying values from a hash into CGI.pm via tied hash reference
Message-Id: <1104170863.164575.54560@z14g2000cwz.googlegroups.com>

Thank you very much for taking the time to explain.  Through Google,
all answers to my questions have provided an incredibly invaluable
reference in my studies and practice.

Regarding my poor posting practices recently, specifically improper
quoting, this is due to Google's new beta version of groups.google.com.
I prefer it over the old format because posts go up immediately rather
than 6-8 hours.

Unfortunately, replies to a message are done in such a way to make them
non-compliant with comp.lang.perl.misc posting practices.

Try it and see, a little reply box appears at the bottom of the message
you are replying to and that's all you get.  I was paying $10 monthly
for a newsgroup service, but I did not need nearly the bandwidth I was
paying for and I had no interest in any kind of large encoded binary
files.

I hope that Google fixes this, I don't know exactly who to complain to.
You would think that such a powerful search engine must use a little
Perl somewhere and that their programmers who spend time here would
have noticed the problem.

wana



------------------------------

Date: Mon, 27 Dec 2004 16:16:53 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: how to delete files that create date <=20041210
Message-Id: <VzWzd.13223$152.1908@trndny01>

"sonet" <sonet.all@msa.hinet.net> wrote in message
news:cqpbk9$f00$1@netnews.hinet.net...
> I can scan the dir and get all file create date.
> if create date<=20041210 to delete this file.
>
> EX:
> #!/usr/bin/perl
use strict;
use warnings;
> $a='file';
>     ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
>        $atime,$mtime,$ctime,$blksize,$blocks)
>            = stat("$a");
                    ^^^^
Please read:
perldoc -q quoting

No reason to make assignments to all those variables if you're not going
to use them:
my $ctime = (stat($a))[10];

> print $ctime;
>
> But have any other good method to do this job??

What do you mean by 'other'?  You haven't shown what code you're
currently using to delete all files with a certain creation date.

What part of this do you need help with?  What have you done so far?
  Reading a list of all files in a directory:
   perldoc -f opendir
   perldoc -f readdir
  Deleting a certain file:
   perldoc -f unlink

Paul Lalli
>
>



------------------------------

Date: Mon, 27 Dec 2004 10:32:45 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: how to delete files that create date <=20041210
Message-Id: <271220041032450330%jgibson@mail.arc.nasa.gov>

In article <cqpbk9$f00$1@netnews.hinet.net>, sonet
<sonet.all@msa.hinet.net> wrote:

> I can scan the dir and get all file create date.
> if create date<=20041210 to delete this file.
> 
> EX:
> #!/usr/bin/perl
> $a='file';
>     ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
>        $atime,$mtime,$ctime,$blksize,$blocks)
>            = stat("$a");
> print $ctime;

Please note that if you are using unix the ctime entry is NOT the file
creation time. It is the file _CHANGE_ time, the last time at which the
file status changed. See 'man stat' for those operations that modify
the file status.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


------------------------------

Date: Mon, 27 Dec 2004 16:21:47 +0000
From: John Woodgate <jmw@jmwa.demon.contraspam.yuk>
Subject: Re: Is zero even or odd?
Message-Id: <LhHHOeBbaD0BFwtK@jmwa.demon.co.uk>

I read in sci.electronics.design that George Dishman
<george@briar.demon.co.uk> wrote (in <cqpaom$7rf$1@news.freedom2surf.net
>) about 'Is zero even or odd?', on Mon, 27 Dec 2004:

>Hence 0/0 can have any value and it is therefore undefined.

You just *defined* it. 0/0 = any value. For specific instances, a value
exists, and several examples have been given, but *in general*, it can
take any value.
-- 
Regards, John Woodgate, OOO - Own Opinions Only. 
The good news is that nothing is compulsory.
The bad news is that everything is prohibited.
http://www.jmwa.demon.co.uk Also see http://www.isce.org.uk 


------------------------------

Date: Mon, 27 Dec 2004 10:30:56 -0600
From: John Fields <jfields@austininstruments.com>
Subject: Re: Is zero even or odd?
Message-Id: <h8c0t0dvf5fq2ig0uqgaihf89ovrikmsn2@4ax.com>

On Mon, 27 Dec 2004 15:47:32 -0000, "George Dishman"
<george@briar.demon.co.uk> wrote:

>
>"John Fields" <jfields@austininstruments.com> wrote in message 
>news:2dvvs0ppsmtl1tgcpv4rp4fd8a5cko8bak@4ax.com...
>> On Mon, 27 Dec 2004 02:23:11 +0100, Michael Mendelsohn
>> <invalid@msgid.michael.mendelsohn.de> wrote:
>>
><snip>
>> When using Ohm's law:
>>
>>               E
>>          R = ---
>>               I
>>
>> The assumption is made that in order for resistance to be measured, a
>> voltage and a current must exist.  Implicit in that assumption is that
>> the voltage must be applied across, and the current forced to flow
>> through, the resistance.
>
>Correct so far.
>
>> Your circuit:
>>
>>
>>        +---------------------(V)----+
>>        |                            |
>> (-)-----o-------[__R__]---o---(A)----o--------(+)
>>        |____________________________|
>>               the short
>>
>> contrives to hide the resistance while purporting to use Ohms law to
>> determine the resistance so, quite clearly, the results obtained will
>> be nonsensical.
>
>In the above circuit, the current measurement
>is accurate but the voltage is the sum of that
>across R and that across the ammeter. You must
>subtract I times the resistance of the ammeter
>from the voltage measurement to find the voltage
>across the resistor.

---
The short, according to the OP, is perfect, so the voltage drop across
it is zero.  With no voltage difference across the ammeter, no current
will flow through it _or_ through the resistor.
---

>> The proper circuit:
>>
>>      +---(V)---+
>>      |         |
>> (-)---o---[R]---o---(A)---o---(+)
>>
>> Will yield the proper results if examined using Ohm's law.
>
>In the above circuit, the voltage measurement
>is accurate but the current is the sum of that
>through R and that through the voltmeter. You
>must subtract V divided by the resistance of
>the voltmeter from the current measurement to
>find the current through the resistor.

---
In the above circuit, as in the previous, the instrumentation is
assumed to be perfect, so there will be no current required to read
the voltage.  If that's not satisfactory then a wheatstone bridge can
be used to measure the voltage with no regard given to the impedance
of the voltmeter.
---
>Neither circuit gives both readings accurately.

---
Knowing the meter resistance, the second circuit does.
--- 
>
><snip proof that 1=1>
>
>If you want to use an Ohms Law example to
>understand this, realise that when you try to
>calculate 0/0, you are asking "what resistance
>will allow zero current to flow when zero voltage
>is applied. The answer is any resistance. 

---
Yes, and that's why I wouldn't ordinarily use Ohm's law to try to
prove that 0/0 = 1.  In this case, however, to indicate to the OP that
when the current through the resistor and the voltage across it are
both numerically equal, the value of the resistance will be one ohm
and will remain one ohm as the voltage across the resistance goes to
zero.
---   

>Equally, you could ask what current flowing through a
>superconductor produces zero volts and again the
>answer is any current. Hence 0/0 can have any
>value and it is therefore undefined.

---
The very notion of a superconductor renders Ohm's law unfit to
characterized it, so saying that 0/0 can have any value because Ohm's
law doesn't work for superconductors is nonsensical.

-- 
John Fields


------------------------------

Date: Mon, 27 Dec 2004 16:51:57 -0000
From: "George Dishman" <george@briar.demon.co.uk>
Subject: Re: Is zero even or odd?
Message-Id: <cqpehg$8sq$1@news.freedom2surf.net>


"John Fields" <jfields@austininstruments.com> wrote in message 
news:h8c0t0dvf5fq2ig0uqgaihf89ovrikmsn2@4ax.com...
> On Mon, 27 Dec 2004 15:47:32 -0000, "George Dishman"
> <george@briar.demon.co.uk> wrote:
>
>>
>>"John Fields" <jfields@austininstruments.com> wrote in message
>>news:2dvvs0ppsmtl1tgcpv4rp4fd8a5cko8bak@4ax.com...
>>> On Mon, 27 Dec 2004 02:23:11 +0100, Michael Mendelsohn
>>> <invalid@msgid.michael.mendelsohn.de> wrote:
>>>
<snip>
>>> Your circuit:
>>>
>>>
>>>         +---------------------(V)----+
>>>         |                            |
>>> (-)-----o-------[__R__]---o---(A)----o--------(+)
>>>         |____________________________|
>>>                the short
>>>
>>> contrives to hide the resistance while purporting to use Ohms law to
>>> determine the resistance so, quite clearly, the results obtained will
>>> be nonsensical.
<snip second circuit>

> In the above circuit, as in the previous, the instrumentation is
> assumed to be perfect, so there will be no current required to read
> the voltage.

If the instrumentation is assumed to be perfect, there
will be no voltage dropped across the ammeter and hence
the first circuit (above) is equally valid.

> If that's not satisfactory then a wheatstone bridge can
> be used to measure the voltage with no regard given to the impedance
> of the voltmeter.

Agreed, it is easier to achieve it in reality that
way, but for the purposes of considering 0/0 that
is academic.

>>Neither circuit gives both readings accurately.
>
> ---
> Knowing the meter resistance, the second circuit does.

The point was, knowing the meter resistance,
both circuits do.

> --- 
>>
>><snip proof that 1=1>
>>
>>If you want to use an Ohms Law example to
>>understand this, realise that when you try to
>>calculate 0/0, you are asking "what resistance
>>will allow zero current to flow when zero voltage
>>is applied. The answer is any resistance.
>
> ---
> Yes, and that's why I wouldn't ordinarily use Ohm's law to try to
> prove that 0/0 = 1.

Neither would I, but I'm not the OP.

> In this case, however, to indicate to the OP that
> when the current through the resistor and the voltage across it are
> both numerically equal, the value of the resistance will be one ohm
> and will remain one ohm as the voltage across the resistance goes to
> zero.

Sure, but as has been pointed out, if you start
by assuming any other value of resistance, the
numerical value of the ratio also remains constant
at that other value. You have simply illustrated a
particular example, not proven any general rule.

>>Equally, you could ask what current flowing through a
>>superconductor produces zero volts and again the
>>answer is any current. Hence 0/0 can have any
>>value and it is therefore undefined.
>
> ---
> The very notion of a superconductor renders Ohm's law unfit to
> characterized it,

Not at all, R is defined as V/I and for any current
(below the level that destroys the superconduction
obviously), V=0 hence R=0.

> so saying that 0/0 can have any value because Ohm's
> law doesn't work for superconductors is nonsensical.

I wouldn't have chosen Ohms Law myself but since that
is the topic, you should at least get the arguments
right.

George




------------------------------

Date: 27 Dec 2004 09:41:09 -0800
From: amerar@iwc.net
Subject: Loading Modules with "require"
Message-Id: <1104169269.484973.88750@f14g2000cwb.googlegroups.com>


Hi All,

I'm trying to figure out how Perl operates regarding the 'require'
function.

Say I have the following code in an included library because several
modules use the code:

$sel = $dbh->prepare("SELECT acronym, table_name, proper_name
FROM table_data WHERE acronym = '$x_table' AND email_ind = 'Y'");
$sel->execute() || die "Select of table $x_table failed: ",
$dbh->errstr, "\n";
($acronym,$table,$name) = $sel->fetchrow_array();
$sel->finish;


Notice that there are some variables there, '$x_table', etc.  What I am
noticing is that Perl will load it once, and then reuse that exact
code.

So, the very first time Perl will fill in the variable values, and then
that code remains static.  So, even if the variables change, they do
not change for the included code.
Is there a way around this?  

Arthur



------------------------------

Date: Mon, 27 Dec 2004 18:20:31 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Loading Modules with "require"
Message-Id: <33b095F3v3s15U1@individual.net>

amerar@iwc.net wrote:
> I'm trying to figure out how Perl operates regarding the 'require'
> function.
> 
> Say I have the following code in an included library because several
> modules use the code:
> 
> $sel = $dbh->prepare("SELECT acronym, table_name, proper_name
> FROM table_data WHERE acronym = '$x_table' AND email_ind = 'Y'");
> $sel->execute() || die "Select of table $x_table failed: ",
> $dbh->errstr, "\n";
> ($acronym,$table,$name) = $sel->fetchrow_array();
> $sel->finish;
> 
> Notice that there are some variables there, '$x_table', etc.  What I am
> noticing is that Perl will load it once, and then reuse that exact
> code.
> 
> So, the very first time Perl will fill in the variable values, and then
> that code remains static.  So, even if the variables change, they do
> not change for the included code.
> Is there a way around this?

Put the code in a subroutine and call that routine rather than requiring 
the library repeatedly.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Mon, 27 Dec 2004 17:53:27 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Loading Modules with "require"
Message-Id: <r_Xzd.22105$Ff3.4746@trndny04>

<amerar@iwc.net> wrote in message
news:1104169269.484973.88750@f14g2000cwb.googlegroups.com...
>
> I'm trying to figure out how Perl operates regarding the 'require'
> function.
>
> Say I have the following code in an included library because several
> modules use the code:
>
> $sel = $dbh->prepare("SELECT acronym, table_name, proper_name
> FROM table_data WHERE acronym = '$x_table' AND email_ind = 'Y'");
> $sel->execute() || die "Select of table $x_table failed: ",
> $dbh->errstr, "\n";
> ($acronym,$table,$name) = $sel->fetchrow_array();
> $sel->finish;
>
>
> Notice that there are some variables there, '$x_table', etc.  What I
am
> noticing is that Perl will load it once, and then reuse that exact
> code.
>
> So, the very first time Perl will fill in the variable values, and
then
> that code remains static.  So, even if the variables change, they do
> not change for the included code.
> Is there a way around this?

The correct way of doing what I believe you are trying to do is to wrap
that code in a subroutine, and pass the relevant variables in to the
subroutine as parameters.

sub do_sql {
  my ($x_table) = @_;
  my ($acronym, $table, $name);
  #... your code here
  return ($acronym, $table, $name);
}

my ($acr, $tbl, $nme) = do_sql('SCUBA');


Hope this helps,
Paul Lalli



------------------------------

Date: Mon, 27 Dec 2004 08:56:41 -0800
From: "Chad Columbus" <ccolumbu@hotmail.com>
Subject: Perl Developer neded.
Message-Id: <_8Xzd.17621$Cl3.2457@fed1read03>

Hi all,
I am pretty sure I should not be posting this here, but I am in need of a 
perl developer to work for me part time via telecommute.
Please don't blast me.
If there is another free way to touch as large a group as this please let me 
know.
I am starting up a company and need some perl, mysql, Linux, and system 
admin help.
I am a perl application developer and entrepreneur.
Please contact me if you are interested, I am starting the company with my 
own money so I need to control costs.
I will require any developers to sign a non-disclosure and a non-compete, 
you will work as a 1099 independent contractor.
Thank you all for your time/attention.

-- 

Chad 




------------------------------

Date: Mon, 27 Dec 2004 18:57:53 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Perl Developer neded.
Message-Id: <RWYzd.2642$PY6.408@trndny02>

"Chad Columbus" <ccolumbu@hotmail.com> wrote in message
news:_8Xzd.17621$Cl3.2457@fed1read03...
> Hi all,
> I am pretty sure I should not be posting this here

Correct.

> Please don't blast me.

Please don't say "I shouldn't do this" and then do it anyway.

> If there is another free way to touch as large a group as this please
let me
> know.

web: http://jobs.perl.org
usenet: perl.jobs




------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 7577
***************************************


home help back first fref pref prev next nref lref last post