[11515] in Perl-Users-Digest
Perl-Users Digest, Issue: 5115 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 11 23:08:28 1999
Date: Thu, 11 Mar 99 20:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 11 Mar 1999 Volume: 8 Number: 5115
Today's topics:
Re:
Re:
Re: 1000 thread limit? <sugalskd@netserve.ous.edu>
Re: =?iso-8859-1?Q?=80help--newbie_script_won't_work=80 (Sam Holden)
Re: An Image's Dimension in CGI? <jbc@shell2.la.best.com>
Appending to the Beginning of an Empty File <thelma@alpha2.csd.uwm.edu>
Re: Can't Increment Counter in FILE Using http:// (George Crissman)
Re: Can't Increment Counter in FILE Using http:// (George Crissman)
Re: Can't Increment Counter in FILE Using http:// (George Crissman)
Re: cobol line seq. file - one very long line - <uri@besmarter.com>
Re: Complex Structure Question <mpersico@bestweb.net>
Re: debugger mystery... <mpersico@bestweb.net>
Re: does perl discourage obfuscated code? (was Re: Perl <mpersico@bestweb.net>
Re: Executing SSI from CGI Output (Martien Verbruggen)
Re: Help with Modules <mpersico@bestweb.net>
Re: Help with Modules <prlawrence@lehigh.edu>
Re: Help with Modules <prlawrence@lehigh.edu>
How to get an image or text by an URL (Tom Tingdale)
Re: How to get an image or text by an URL (brian d foy)
Re: How to you pass parameters into subroutines in Perl <jamesht@idt.net>
Re: How to you pass parameters into subroutines in Perl (Alastair)
I have a question about page counters <rollo@enter.net>
Re: I want to know where I can get a sendmail program t <cphamney@dts.com>
interpolating package name into require statement <prlawrence@lehigh.edu>
Re: Oracle/perl warning (was: Re: DBD::Oracle question) mille01@my-dejanews.com
Printing with object references matthew_keene@my-dejanews.com
Re: Problems with File::Find and links (Martien Verbruggen)
Serial Connection <styroNO@SPAMdial.eunet.ch>
Shopping Cart with Email Encryption? (Brantley Smith)
Re: Shopping Cart with Email Encryption? (Sam Holden)
wish list <ekkis@arix.com>
Working with CLOBs, DBI::Oracle problems <nospam_earnold@requisite.com>
Re: Writing to a file (Larry Rosler)
Re: Writing to a file (Larry Rosler)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 11 Mar 1999 12:56:10 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re:
Message-Id: <MPG.1151cdc41a82b7d989722@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <bingdo19-ya02408000R1103991044570001@news.alt.net> on Thu,
11 Mar 1999 10:44:57 -0400, Bob Langdon <bingdo19@earthlink.net> says...
> I'm new to perl, so I wrote a short script I thought I couldn't screw up,
> but it won't work.
That's because it doesn't do anything!
> I want to remove the ".html" from all of the files in a directory called "bbs"
>
> the script I tried is:
>
> #!/usr/bin/perl
Add the '-w' flag to this line, and 'use strict;' as the next line. Get
into this habit now and you'll never regret it.
> opendir(BBS, '/home/gigs/public_html/bbs');
How do you know that this succeeded? Always check the results of a
system call, especially 'open' or 'opendir'.
my $dir = '/home/gigs/public_html/bbs';
opendir BBS, $dir or die "Couldn't open $dir. $!\n";
> @allfiles = readdir(BBS);
> foreach $file(@allfiles){
You could simply put the list directly into the foreach loop:
foreach my $file (readdir BBS) {
> $file =~ 's/(.*)\.html/$1/g';
The real problem is here (and this is the only 'stupid mistake' you
made). You tried to change the value of the temporary variable $file
(and wouldn't succeed, because the right-hand side is a string, not a
substitution operator), but that wouldn't change the name of the file in
the file system, would it? You need to ask the OS to do that.
Something like the following:
if ($file =~ /(.*)\.html$/) {
rename $dir/$file, $dir/$1
or die "Couldn't rename $dir/$file. $!\n";
}
> }
> exit
>
> Okay, what stupid mistake(s) did I make?
Now you know. :-)
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 11 Mar 1999 15:34:56 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re:
Message-Id: <gd99c7.379.ln@magna.metronet.com>
Bob Langdon (bingdo19@earthlink.net) wrote:
: I want to remove the ".html" from all of the files in a directory called "bbs"
: the script I tried is:
: #!/usr/bin/perl
: opendir(BBS, '/home/gigs/public_html/bbs');
: @allfiles = readdir(BBS);
: foreach $file(@allfiles){
: $file =~ 's/(.*)\.html/$1/g';
: }
: exit
: Okay, what stupid mistake(s) did I make?
I see only 7 things :-)
1) you have not enabled warnings
2) you have not invoked the 'use strict' pragma (compiler directive)
3) you have not checked the return value from your opendir() call
4) you have changed your pattern match into a string by enclosing
it in quotes (this is the "biggie")
5) you haven't anchored your pattern match to the end of the string
6) you never actually move the file to the new filename
7) you should closedir() when you are done with it
The first two lines of every single perl program should be:
#!/usr/bin/perl -w
use strict;
You should check the return value from functions that might fail:
opendir(BBS, '/home/gigs/public_html/bbs') ||
die "could not open '/home/gigs/public_html/bbs' $!";
Lose the single quotes around your pattern match:
$file =~ s/(.*)\.html/$1/g;
Your regex (after fixing the other things) would change
'my.html.file' to 'my.file'. You probably don't want
that:
$file =~ s/(.*)\.html$/$1/g;
^
^ force the .html to be at the end of the string
You need to call rename() to rename your file.
But you no longer have a copy of the original name.
Probably should have saved that off somewhere.
$newname = $file;
$newname =~ s/(.*)\.html$/$1/g;
rename( $file, $newname) || die "could not move '$file' $!";
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 12 Mar 1999 01:28:30 GMT
From: Dan Sugalski <sugalskd@netserve.ous.edu>
Subject: Re: 1000 thread limit?
Message-Id: <7c9qju$l3c$1@news.NERO.NET>
archon16@my-dejanews.com wrote:
: I'm playing with the Thread module... and I was dismayed to discover a limit
: of about 1000 threads allowed at a time (on my machine, at least.) After
: hitting this limit, the program simply dumps core. Does anyone know of a way
: to get around this limitation? (Without recompiling the Linux kernel, that
: is.) I really, really need to have about 30,000 simultaneous threads.
: (Don't ask. I just do. ;-)
IIRC, Linux creates a new process (more or less) for each thread, so you
need to up the total # of processes allowed on the system. (I think
there's a text file someplace you can twiddle with to do this)
However.... Are you really sure you want to do this? You may find that
Linux gets a bit cranky with that many threads. (Heck, it wouldn't
surprise me if most OSes got cranky with a single process that had 30k+
threads in it) It might be better to consider using a thread pool or
something like that.
Dan
------------------------------
Date: 12 Mar 1999 03:30:17 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: =?iso-8859-1?Q?=80help--newbie_script_won't_work=80?=
Message-Id: <slrn7eh2i9.k2q.sholden@pgrad.cs.usyd.edu.au>
On Thu, 11 Mar 1999 15:34:56 -0500, Tad McClellan <tadmc@metronet.com> wrote:
>
>
> The first two lines of every single perl program should be:
>
>#!/usr/bin/perl -w
>use strict;
Except for CGI scripts of course which really should have a T in there
somewhere...
--
Sam
There's no such thing as a simple cache bug.
--Rob Pike
------------------------------
Date: 12 Mar 1999 01:36:55 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Re: An Image's Dimension in CGI?
Message-Id: <36e86fb7$0$220@nntp1.ba.best.com>
James Tolley <jamesht@idt.net> wrote:
> Here's something that should work for gifs.
> There are modules at CPAN that will help as well (of course).
In particular, Image::Size, which I believe was just updated to a new
version.
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
Date: 12 Mar 1999 03:54:15 GMT
From: Thelma Lubkin <thelma@alpha2.csd.uwm.edu>
Subject: Appending to the Beginning of an Empty File
Message-Id: <7ca357$8nu$1@uwm.edu>
This code was adapted from something that Allen Due kindly sent me in
response to an earlier post to the newsgroup; Allen adapted it from
code in Christiansen and Torkington's work.
My files will sometimes need to be created during a run: the code
below just hangs when confronted with the new, empty, files--how
can I modify it to get around that?
(Someone else posted this very question a few days ago and I've
been eagerly waiting a response, but since none came I'm trying
too).
--thelma
#####################
#STORE_DATA
#####################
sub store_data
{
my %records = %{$_[0]};
my $linefmt = "%-10s %-15s %-4s %-4s %-4s %-6s %-6s\n";
local $^I = '.old'; # emulate -i.old
local @ARGV = (keys %records); # initialize list of files
while (<>)
{ if ($. == 1 ) {
foreach (@{$records{$ARGV}}) { printf $linefmt, @{$_}; }
}
print;
} continue {close ARGV if eof}
}
------------------------------
Date: Fri, 12 Mar 1999 03:34:02 GMT
From: strads@tmisnet.com (George Crissman)
Subject: Re: Can't Increment Counter in FILE Using http://
Message-Id: <36e889a0.11744425@news2.tmisnet.com>
On Thu, 11 Mar 1999 03:19:14 -0500, (Tad McClellan) wrote:
>George Crissman (strads@tmisnet.com) wrote:
>: The good news: it WORKS in telnet mode based in the
>: cgi-bin directory.
>: The bad news: it DOESN'T work in http:// mode from my browser.
> ^^^^^^^^^^^^
> We cannot help much if you don't decribe what that means.
You're right. I'm embarrassed that I asked the question the way I
did. What I meant to say was "the counter doesn't increment
when the cgi program is called from a browser."
> What happens?
The counter increments properly when operated from the command
line (i.e., perl price.cgi) but does not increment when the cgi
program is called by http method.
> Get any messages?
No.
> Get any output?
Output is flawless ... except the counter hasn't incremented.
> Dumps core?
No.
> You have a race condition here.
Now, THAT I understand. It would seem that I'm attempting to
re-open the file for write access before it has had a chance to
close for read access (maybe due to system latency). Is that
a correct explanation?
> syscount.txt may be created by another instance of your program
> right here, before this instance of your program opens the file.
>
> Better to just open it, then check to see if it has any content.
Nice idea ... but I need to use the number as part of program
output, and I'd like to save the incremented number back to
the file so it's ready for use next time.
> If you are going to use this code in a multitasking environment
> (CGI is one of those), then you need to do file locking to
> avoid corrupting the data.
>
> See the Perl FAQ, part 5:
>
> "How can I lock a file?"
>
> "What can't I just open(FH, ">file.lock")?"
>
> "I still don't get locking. I just want to increment the
> number in the file. How can I do this?"
thank you, thank you, thank you, thank you, thank you.
-- George Crissman
-- strads@tmisnet.com
> Tad McClellan SGML Consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
-----------------------------------------------------------------------
"There is no need to criminalize millions of legitimate and responsible
businesses and individuals in order to stop a very small group of
irresponsible people, particularly when there are other ways already
working ." says Mr. Dan Hufnal of the 10,000 member DEAA
<http://www.deaa.com>. What does he mean by "already working"?
Maybe: <http://www.tmisnet.com/~strads/spamhunt/index.html>
-----------------------------------------------------------------------
------------------------------
Date: Fri, 12 Mar 1999 03:35:54 GMT
From: strads@tmisnet.com (George Crissman)
Subject: Re: Can't Increment Counter in FILE Using http://
Message-Id: <36e88b42.12161847@news2.tmisnet.com>
On 11 Mar 1999 18:42:59 GMT, Judith Patrice wrote:
>George Crissman explains it all:
>( much to the amusement of all....)
>: <9> % perl if (-e "syscount.txt") then { print "yahoo!\n\n" ; }
> ^ ^^^^
>1) try perl -e 'commands'
Thanks -- I'll try that!
>2) There's no "then" in an "if" statement
<ID4>oops</ID4>. Thank you. (Hangs head sheepishly).
>:Badly placed ()'s.
>
>That may be your shell talking to you.
Good point. Thank you for your help!
-- George Crissman
-- strads@tmisnet.com
>
>--
>perl -e 'while(<>){$f.= $_}@l=split(/\s+/, $f);for($i=0;$i<@l-1;$i++){$W{$l[$i]
>}.=" ".$l[$i+1];}sub a{$w=$l[1]}&a;sub b{print "\n"}while($w){if(!($W{$w})){&b;
>&b;&a;last if ($q++>3);}print"$w ";@p=split(/ /,$W{$w});$c=@p;until($s=int(rand
>($c))){1}$w=$p[$s]}&b' big_text_file
>
-----------------------------------------------------------------------
"There is no need to criminalize millions of legitimate and responsible
businesses and individuals in order to stop a very small group of
irresponsible people, particularly when there are other ways already
working ." says Mr. Dan Hufnal of the 10,000 member DEAA
<http://www.deaa.com>. What does he mean by "already working"?
Maybe: <http://www.tmisnet.com/~strads/spamhunt/index.html>
-----------------------------------------------------------------------
------------------------------
Date: Fri, 12 Mar 1999 03:39:01 GMT
From: strads@tmisnet.com (George Crissman)
Subject: Re: Can't Increment Counter in FILE Using http://
Message-Id: <36e88bb1.12273154@news2.tmisnet.com>
On 11 Mar 1999 18:16:24 GMT, (Abigail) wrote:
>George Crissman (strads@tmisnet.com) wrote on MMXVIII September MCMXCIII
>in <URL:news:36205783.7562027@news2.tmisnet.com>:
>|| The good news: it WORKS in telnet mode based in the
>|| cgi-bin directory.
>|| The bad news: it DOESN'T work in http:// mode from my browser.
>|| More bad news: it's supposed to work using http:// access.
>
>Then it isn't a Perl problem, is it?
I thought maybe Perl worked differently when called by a
browser as compared to the command line. Based on that
presumption, it could reasonably be considered a Perl problem.
However, as noticed elsewhere, it's more likely a cockpit problem.
:-(
>Of course, your program is hopelessly wrong, unless you can garantee
>you never have 2 people visiting your site at nearly the same time.
At this point in time, it's only being used by one person at the
same time (me). It has been suggested that I investigate file
locking -- so that's where I'm headed next.
Thanks, everyone, for the help!
-- George Crissman
-- strads@tmisnet.com
>Abigail
>--
>perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
> "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
> "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
-----------------------------------------------------------------------
"There is no need to criminalize millions of legitimate and responsible
businesses and individuals in order to stop a very small group of
irresponsible people, particularly when there are other ways already
working ." says Mr. Dan Hufnal of the 10,000 member DEAA
<http://www.deaa.com>. What does he mean by "already working"?
Maybe: <http://www.tmisnet.com/~strads/spamhunt/index.html>
-----------------------------------------------------------------------
------------------------------
Date: 12 Mar 1999 03:42:21 +0000
From: Uri Guttman <uri@besmarter.com>
To: lr@hpl.hp.com (Larry Rosler)
Subject: Re: cobol line seq. file - one very long line -
Message-Id: <7moglz74rm.fsf@glory.besmarter.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> You mean "%010d". Tough night at the keyboard, Ronald?
LR> Remember, though, that that's a 0 flag followed by a decimal
LR> number, 10; in other contexts, '010' represents an octal number
LR> that has the decimal value 8.
but it is in a string so it is not being interpreted as octal. field
sizes for printf are in decimal. the leading zero just causes the field
to be left filled with zeros. i think it is fine and never would confuse
it with octal. only an unquoted 010 would be 8 octal. larry, you know
context is everything in perl. :-)
uri
--
Uri Guttman Hacking Perl for USite
uri@sysarch.com uri@besmarter.com
------------------------------
Date: Fri, 12 Mar 1999 02:30:45 GMT
From: "Matthew O. Persico" <mpersico@bestweb.net>
Subject: Re: Complex Structure Question
Message-Id: <36E87C88.A9E11746@bestweb.net>
Bruce Hodo wrote:
>
> Let me see if I understand what you said:
>
> I can save a reference to the array as long as I redeclare the array inside my loop,
> and Perl will keep track of each instance until the program terminates? If my
> understanding is correct, then that solves my problem!
>
Your understanding is correct. When you declare a variable in a loop in
a langage like 'C', you are simply allocating a place in the stack.
Taking the address of it is bound to core-dump because the stack keeps
getting torn down at loop end and rebuild at loop top.
However, in Perl, the declared 'my' variable is not just a piece of a
stack: it is a brand new data structure in the Perl guts that is
reference counted. The creation of it sets count==1. Stuffing a
reference to it someplace sets count==2. The end of the loop sets
count==1. Bingo. It still lives. This is a common perl idiom, but it is
one that took an EXTREEEEMLY long time to get into my K&R-biased head:
while (some condition) {
my %foo = ();
## fill %foo;
push @someArrary, \%foo;
}
Now, if I'm going to go through the trouble of taking the reference
anyway, I usually declare foo as a scalar and use reference notation to
vivify into existance anything I need and push the scalar, now
containing a reference:
while (some condition) {
my $foo = undef;
## This is a hash of hashes of arrays, for the record
$foo->{'bar'}->{3}->[7] = junk;
push @someArray, $foo;
}
--
Matthew O. Persico
http://www.bestweb.net/~mpersico
------------------------------
Date: Fri, 12 Mar 1999 02:34:22 GMT
From: "Matthew O. Persico" <mpersico@bestweb.net>
Subject: Re: debugger mystery...
Message-Id: <36E87D71.E01252A8@bestweb.net>
John Chambers wrote:
>
> James Tolley wrote:
> >
> > Hello all,
> >
> > The debugger displays some of my code out of order. It also seems to
> > skip over some while loops.
> >
> > Has anyone sen anything like this? What's causing it?
>
> Yeah; I noticed that after I first picked up 5.004 many moons
> ago. It doesn't happen all that often, but when it does, it
> pretty much makes the debugger unusable. I've since seen it
> on any number of different machines, including SunOS, Digital
> Unix (OSF1), and linux, so it's definitely a new feature. I
> asked a few questions and got no replies at all.
This mostly happens with loops. You hit the loop top and the next step
takes you to the first executable line past the loop bottom. It's
annoying, but it is not harmful. If you really have a problem with it,
report it as a bug. The docs that come with perl tell you how. Try
perldoc perlbug.
--
Matthew O. Persico
http://www.bestweb.net/~mpersico
------------------------------
Date: Fri, 12 Mar 1999 02:00:31 GMT
From: "Matthew O. Persico" <mpersico@bestweb.net>
Subject: Re: does perl discourage obfuscated code? (was Re: Perl evangelism)
Message-Id: <36E87580.B0B623C9@bestweb.net>
Perl (the language definition) and perl (the executable) do not
discourage or encourage anything. They merely provide the MEANS by which
you or I can write whatever we damn well please. The results depend
entirely on the skill of the operator. You can write crap or gold just
as easily in ANY language you please.
That being said, it may be useful to compare how to express concepts in
Perl vs another language. For this argument, let's use 'C'. Let's pick a
Perl strength:
If I want to search a directory for all entries that are not dot files
that match some arbitrary list that I have been passed and store those
files in a structure conducive to doing something with the files later,
then in Perl, I write the following UNTESTED code, of the top of my
balding pate, with possible typos and error checking removed for
succinctity:
openddir(DIR,"/home/persico");
my @void = map {
push @goodOnes, {
name => $_,
printed_yet => 'N'
}
sort
grep {exists $listOfFiles{$_}
grep {$_ !~ /^./ && -r $_} readdir(DIR);
If you feel that's obfuscated, then you aren't using Perl for its
strengths. Obfuscated would be if:
1) I did not explicitly use $_.
2) I put that all in one line.
3) I did not include the paragraph that explained what the #@@&^%$%#$$ I
was doing (and in my PRODUCTION code, there IS such a paragraph!). And
don't give me the argument that because the comment is included, it
proves the code is obfuscated. Hell, one of the reasons that 'C' is not
very well commented is because it takes so long (in code length terms)
to do what you want that you end up with a big paragraph that's two
pages away from where the action is and lots of little nothing comments
in bewteen. Here, the comment and the action fit in a page. Perl's
succinctness in comparison to 'C' is an encouragement to write comments!
Now, do you really want to try that in 'C'? Or, rather, do you want to
try writing the equivilent 'C' code in the short time that I wrote the
Perl, with as few errors? Not!
One of Perl's strengths is compactness when applying actions to sets.
It's almost as if 'C' is to Perl as a btrieve is to an RDBMS.
On the other hand, I am certain 'C' has strengths. Device drivers.
Speedy interaction with hardware. I am no longer sure since I don't
write much 'C' anymore.
My point is that arguing the obfuscatedness of Perl in relationshp to
itself is arguing in a vacuum. It is what it is and, more importantly,
it is what we make of it.
--
Matthew O. Persico
http://www.bestweb.net/~mpersico
------------------------------
Date: Fri, 12 Mar 1999 01:16:32 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Executing SSI from CGI Output
Message-Id: <QVZF2.114$Ss1.1061@nswpull.telstra.net>
In article <36E841E9.C09299ED@idt.net>,
James Tolley <jamesht@idt.net> writes:
> open(F, "file.file");
Check the return value of that open. Always check the return value of
system calls.
Bad. Bad. Bad.
> while(<F>) {
> if($_ =~ /<!--([^>]+)-->/) {
obsolete use of $_. If you are going to use the binding, you might as
well use a named variable:
while (defined(my $line = <F>))
> print $` . &do_ssi($1) . $';
the & is not necessary when using brackets (parentheses).
the use of $' and $` is slow. It slows down everything else in your
program that has to do with RE's. consider capturing those parts
explicitly.
> next;
> }
> print $_;
Obsolete use of $_.
$_ is there as a 'default' variable for many operations. If you choose
to use it, you should make use of that. It is just not consistent to
use it in one spot and not in another.
Martien
--
Martien Verbruggen |
Interactive Media Division | That's not a lie, it's a terminological
Commercial Dynamics Pty. Ltd. | inexactitude.
NSW, Australia |
------------------------------
Date: Fri, 12 Mar 1999 02:35:23 GMT
From: "Matthew O. Persico" <mpersico@bestweb.net>
Subject: Re: Help with Modules
Message-Id: <36E87DAD.B8FF7E71@bestweb.net>
Paul Falbe wrote:
>
> Hi,
>
> I'm trying to create a module that will set Globals variables. I have
> a lot of Perl scripts and each one of them has to set these static variables.
> What I want to do is create a module and use it to set these variables.
> I have two questions 1) how do I set up the module. And 2) how do
> I use them in my script. e.g. I want to set $MYVAR="/opt" in the module.
>
> Thanks!
>
> -Paul
>
> --
> Internet: | Paul J. Falbe |
> falbe@cassens.com | Cassens Transport | Std disclaimers apply.
> Voice: | 145 N. Kansas Str. | (But you knew that!)
> 618-656-3006 | Edwardsville, IL 62025 |
perldoc perlmod
--
Matthew O. Persico
http://www.bestweb.net/~mpersico
------------------------------
Date: Thu, 11 Mar 1999 17:10:09 -0500
From: "Phil R Lawrence" <prlawrence@lehigh.edu>
Subject: Re: Help with Modules
Message-Id: <7c9f0g$261o@fidoii.cc.Lehigh.EDU>
Paul,
>I have
>a lot of Perl scripts and each one of them has to set these static variables.
>What I want to do is create a module and use it to set these variables.
Set.pm:
____________________________________
package Set;
use strict;
sub set1{
my $self = shift;
my $param = shift or die "horribly!";
if ($param eq 'this') {
return 'that';
} else {
return 'the other';
}
}
sub set2 {
my $self = shift;
my $scalar_ref = shift or die "horribly!";
${ $scalar_ref } = 'whatever';
}
___________________________
needs_setting.pl:
____________________________
#!/usr/local/bin/perl -w
use diagnostics;
use strict;
use lib '/u/path/perl/modules';
use Set;
my $var1;
my $param = 'this';
$var1 = Set->set($param);
my $var2;
Set->set(\$var2);
___________________________
HTH,
Phil R Lawrence
Lehigh University
Enterprise Systems Implementation
Programmer / Analyst
prlawrence@lehigh.edu - work
prlawrence@planetall.com - personal
------------------------------
Date: Thu, 11 Mar 1999 17:10:09 -0500
From: "Phil R Lawrence" <prlawrence@lehigh.edu>
Subject: Re: Help with Modules
Message-Id: <7c9f2u$1fpu@fidoii.cc.Lehigh.EDU>
Paul,
>I have
>a lot of Perl scripts and each one of them has to set these static variables.
>What I want to do is create a module and use it to set these variables.
Set.pm:
____________________________________
package Set;
use strict;
sub set1{
my $self = shift;
my $param = shift or die "horribly!";
if ($param eq 'this') {
return 'that';
} else {
return 'the other';
}
}
sub set2 {
my $self = shift;
my $scalar_ref = shift or die "horribly!";
${ $scalar_ref } = 'whatever';
}
___________________________
needs_setting.pl:
____________________________
#!/usr/local/bin/perl -w
use diagnostics;
use strict;
use lib '/u/path/perl/modules';
use Set;
my $var1;
my $param = 'this';
$var1 = Set->set($param);
my $var2;
Set->set(\$var2);
___________________________
HTH,
Phil R Lawrence
Lehigh University
Enterprise Systems Implementation
Programmer / Analyst
prlawrence@lehigh.edu - work
prlawrence@planetall.com - personal
------------------------------
Date: Fri, 12 Mar 1999 01:52:09 GMT
From: tingdale@flash.net (Tom Tingdale)
Subject: How to get an image or text by an URL
Message-Id: <36eb6ee4.4170065@news.flash.net>
What is the best way to get and save a text and binary file from an
URL? What I need to do is something like this:
$string = (get_url.pl "http://www.domain.com/xyz.html");
print (FILE $string) if ($string);
$image = (get_url.pl "http://www.domain.com/xyx.gif");
print (FILE $image) if ($image);
Of course what I need to find is the get_url.pl function, program, or
module. Any ideas where I might find such an animal. I've seen this
posted before but am pulling a blank on any details.
tingdale@flash.net
------------------------------
Date: Thu, 11 Mar 1999 22:39:40 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: How to get an image or text by an URL
Message-Id: <comdog-ya02408000R1103992239400001@news.panix.com>
In article <36eb6ee4.4170065@news.flash.net>, tingdale@flash.net (Tom Tingdale) posted:
> What is the best way to get and save a text and binary file from an
> URL? What I need to do is something like this:
use LWP::Simple qw(getstore);
see the docs for examples :)
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
------------------------------
Date: Thu, 11 Mar 1999 20:00:13 -0500
From: James Tolley <jamesht@idt.net>
To: William Yeung <wwyeung@undergrad.math.uwaterloo.ca>
Subject: Re: How to you pass parameters into subroutines in Perl?
Message-Id: <36E8671D.250A41A7@idt.net>
$one = "one";
$two = "two";
$return = &routine($one, $two);
sub routine {
my ($one, $two) = @_;
# ...
"something"; # same as 'return "something";'
}
### OR
sub routine {
my $one = shift;
my $two = shift;
# ...
return "something";
}
hth,
James
William Yeung wrote:
> How to you pass parameters into subroutines in Perl?
> Thanks.
------------------------------
Date: Fri, 12 Mar 1999 01:28:08 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: How to you pass parameters into subroutines in Perl?
Message-Id: <slrn7egrgq.5p.alastair@calliope.demon.co.uk>
William Yeung <wwyeung@undergrad.math.uwaterloo.ca> wrote:
>How to you pass parameters into subroutines in Perl?
Lazy ones like that deserve an RTFM.
--
Alastair
work : alastair@psoft.co.uk
home : alastair@calliope.demon.co.uk
------------------------------
Date: Thu, 11 Mar 1999 20:43:03 -0500
From: "Rollo Lawson" <rollo@enter.net>
Subject: I have a question about page counters
Message-Id: <36e87077.0@news3.enter.net>
Iam trying to implement a counter on a webpage at work. But their web
server doesn't support server side includes.
EX. !<--exec cgi"count.pl" -->
Now I read on the internet the way to call a perl script from an html
program without server side includes is using the image tag
EX. <img src="count.pl">
There is one problem here since its not an image it leaves a picture of a
dead image on the page.
What can I do is there a way to hide the image with attributes.. Or how can
I call the script and return a value or maybe some numbers that represent
the count. Please help
rollo lawson
rollo@enter.net
------------------------------
Date: Fri, 12 Mar 1999 02:43:29 GMT
From: "Chill Phamney" <cphamney@dts.com>
Subject: Re: I want to know where I can get a sendmail program that will work with NT.
Message-Id: <lb%F2.1527$Y31.15379@news1.rdc1.on.wave.home.com>
http://curiosityshoppe.tierranet.com/framecal/
Try this one.
PC
------------------------------
Date: Thu, 11 Mar 1999 17:17:38 -0500
From: "Phil R Lawrence" <prlawrence@lehigh.edu>
Subject: interpolating package name into require statement
Message-Id: <7c9feb$1nga@fidoii.cc.Lehigh.EDU>
I want to do this:
my $package_name = 'ding';
require $package_name;
It chokes, presumably because it is looking for a text file named 'ding',
instead of a module named ding.pm. Any ideas on how I can do this sort of
thing? I'd hate to use a huge if/else construct.
Actual code:
______________________________
#!/usr/local/bin/perl -w
use diagnostics;
use strict;
use lib '/u/path/perl/modules';
# Get report_name
my $rn = shift;
my $rn_validation = {
AIStats => {
mod_name => 'AIRIStats',
auto_parms => ['AI'],
},
RIStats => {
<SNIP!>
};
my $rn_regexp = join '|', (keys %{ $rn_validation });
die "Invalid report name specified!\n" unless ($rn =~ /^($rn_regexp)$/);
my $mod_name = $rn_validation->{$rn}{mod_name};
require $mod_name;
my @auto_parms = @{ $rn_validation->{$rn}{auto_parms} };
$mod_name->report(@_, @auto_parms);
______________________________
------------------------------
Date: Fri, 12 Mar 1999 02:41:56 GMT
From: mille01@my-dejanews.com
To: ajs@ajs.com
Subject: Re: Oracle/perl warning (was: Re: DBD::Oracle question)
Message-Id: <7c9utj$90p$1@nnrp1.dejanews.com>
In article <7annuc$ql6$1@nnrp1.dejanews.com>,
ajs@ajs.com wrote:
> In article <7aidrs$dv2$1@nnrp1.dejanews.com>,
> ajs@ajs.com wrote:
> > Is the following DBD::Oracle (for inserting a row with a null value)
supposed
> > to work?
> >
> > # Assume a $db which is a valid, connected DBD::Oracle handle
> > $field = undef;
> > $prep = $db->prepare('insert into table_foo values (:1)');
> > $prep->bind_param(1, $field, {TYPE => SQL_VARCHAR, NULLABLE => 1});
> > $prep->execute;
>
> I've since solved some of this problem, and here's a warning to anyone who
> wants to do more with Oracle from perl than run a static query: use the "-8"
> option when you compile. Thus, go into DBD-Oracle-xx.xx and type "perl
> Makefile.PL -8". This is assuming version 0.59. The bug that I've found
> results in an incorrect handling of undefined values in bound variables. I've
> tracked it down to a spot in the "documentation" that comes with Oracle8-eval
> which says that OCIBindByNmae will ignore the field that specifies that the
> value is null. This is not code that I know well, so I will have to look at
> it more, but be warned, the above code, if you need to do such, may not work
> unless you use -8 (thus shutting off Oracle version 8 support).
>
> The "NULLABLE" attribute also seems to be ignored by DBD::Oracle, which I
> consider a bit of a bug. It's stored into a field of the placeholder structure
> called "nullok", but then never used.
>
> -AJS
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
>
FYI --
This particular problem appears to have been fixed [ at least in my case it
was <grin> ] in the 0.60 release of DBD::Oracle, which was put up on CPAN
yesterday. The same code that failed under 0.59 works without change under
0.60.
Thanks for the original post, AJS; it resulted in me keeping the remaining
hair on my head ... <grin> And thanks to Tim for the fix!
Brgds,
Mike.
mille01@my-dejanews.com
==========
Sorry for the dejanews address. The spam
has finally gotten to me....
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 12 Mar 1999 00:49:07 GMT
From: matthew_keene@my-dejanews.com
Subject: Printing with object references
Message-Id: <7c9oa0$3c3$1@nnrp1.dejanews.com>
I'm confused about using object data methods in a print statement. If I use:
print "Error received: $res->code\n"
then Perl prints out:
Error received: HTTP::Response=HASH(0x1117a28)->code
If I use
print "Error received: ", $res->code, "\n" ;
then everything prints as expected, ie:
Error received: 407
In my limited understanding I think that the first example evaluates the
variable $res in a scalar context rather than as an object, but I'm not
entirely sure why. Is there any way I could have coded the first type of
statement and had Perl resolve the reference to the object method correctly ?
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 12 Mar 1999 01:18:56 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Problems with File::Find and links
Message-Id: <4YZF2.115$Ss1.1061@nswpull.telstra.net>
In article <36E7BB9A.A58CC453@math.uio.no>,
Peter John Acklam <jacklam@math.uio.no> writes:
> Well, yes, but there should be ways around that? Unfortunately I'm
> not working on a UNIX machine now, so I'n not able to try this out,
> but I would expect that something like this should work (at least
> with some modifications):
Very serious modifications. There are good reasons why File::Find does
not follow symlinks. There are some sources out there for find that do
allow you to follow symlinks. Check those sources to find out why it
is non-trivial, and why it is not possible to write something general
that will always do the 'right thing'.
Martien
--
Martien Verbruggen |
Interactive Media Division | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd. | selective about its friends.
NSW, Australia |
------------------------------
Date: Fri, 12 Mar 1999 01:59:00 +0100
From: Marcel Ackerknecht <styroNO@SPAMdial.eunet.ch>
Subject: Serial Connection
Message-Id: <36E866D4.F0082A3B@SPAMdial.eunet.ch>
Hello,
how can i manage a serial connection via ttyS0 in perl
(setting baudrate etc) and getting unbufferd, pollable input
without the need to wait for a CR.
marcel ackerknecht
styroNO@SPAMdial.eunet.ch
remove NO SPAM for reply
------------------------------
Date: Fri, 12 Mar 1999 03:51:21 GMT
From: mtbdude1999@yahoo.com (Brantley Smith)
Subject: Shopping Cart with Email Encryption?
Message-Id: <36e88e48.12933846@news.vnet.net>
Does anyone know of a PERL Shopping Cart program that encrypts order
data before sending to the merchant? I'm thinking of something that
processes orders, encrypts them with PGP or something similar, and
emails the encrypted data to the merchant. I'm trying to get something
more secure than normal email, but without the expense and hassle of a
secure server. Any help would be appreciated.
Brantley Smith
bas@binaryweb.com
http://binaryweb.com
------------------------------
Date: 12 Mar 1999 03:59:01 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Shopping Cart with Email Encryption?
Message-Id: <slrn7eh485.l7g.sholden@pgrad.cs.usyd.edu.au>
On Fri, 12 Mar 1999 03:51:21 GMT, Brantley Smith <mtbdude1999@yahoo.com> wrote:
>Does anyone know of a PERL Shopping Cart program that encrypts order
>data before sending to the merchant? I'm thinking of something that
>processes orders, encrypts them with PGP or something similar, and
>emails the encrypted data to the merchant. I'm trying to get something
>more secure than normal email, but without the expense and hassle of a
>secure server. Any help would be appreciated.
But the data is still being sent from the broweser to the CGI over an
insecure channel.
--
Sam
If your language is flexible and forgiving enough, you can prototype
your belief system without too many core dumps.
--Larry Wall
------------------------------
Date: Thu, 11 Mar 1999 18:25:15 -0800
From: "Ekkis" <ekkis@arix.com>
Subject: wish list
Message-Id: <RV_F2.4911$TD3.54064@typhoon-sf.pbi.net>
Is there a wish list for Perl? I couldn't find reference to one in the docs
and FAQs.
------------------------------
Date: Thu, 11 Mar 1999 19:37:03 -0700
From: "Eric Arnold" <nospam_earnold@requisite.com>
Subject: Working with CLOBs, DBI::Oracle problems
Message-Id: <7c9ukq$rjd$1@news1.rmi.net>
Does anybody have examples of using CLOBs with Perl? In particular, I'm
trying to append strings to CLOBs, and having no luck. I've just started
using the DBI::Oracle module, so I might be doing some simple thing wrong.
I can't get a CLOB locator reference into a Perl variable, to pass into
later "DBMS_LOB...()" calls, at
$item_ctx_get_clob->bind_param_inout(":clob_locator ...........
Thanks,
-Eric
P.S. Please Cc: earnold@requisite.com
#!D:/perl/bin/perl
$^W = 1; use strict vars;
$|=1;
use DBI;
use DBD::Oracle qw(:ora_types);
my $dbh = DBI->connect( "dbi:Oracle:----", "---", "---" );
my( $clob_locator, $clob_offset, $catid );
my $item_query = $dbh->prepare( qq{
select catid, itemid, ctx_desc
from category_item, item_tl
where itemid = item_itemid
and catid is not NULL -- I got a NULL catid once, how?
and rownum < 5
} );
my $item_ctx_get_clob = $dbh->prepare( qq{
select item_ctx_desc_all into :clob_locator from category_item_desc
where category_item_desc.catid = :catid1 for update
});
# The following causes: "Error: Runtime exception", and exits Perl:
#
#my $item_ctx_get_clob = $dbh->prepare( qq{
# declare
# locator_var CLOB;
# begin
# select item_ctx_desc_all into locator_var from category_item_desc
# where category_item_desc.catid = :catid1 for update
# :clob_locator := locator_var;
# end;
# });
my $category_item_desc_insert = $dbh->prepare( qq{
insert into category_item_desc values ( ?, EMPTY_CLOB() )
});
my $dbms_lob_getlength = $dbh->prepare( qq{
:offset_var := DBMS_LOB.GETLENGTH( :clob_locator ) + 1;
});
my $dbms_lob_write = $dbh->prepare( qq{ DBMS_LOB.WRITE( ?, ?, ?, ? ) });
my( $row, $len, $itemid, $ctx_desc );
$item_query->execute;
while( $row = $item_query->fetch )
{
( $catid, $itemid, $ctx_desc ) = @$row;
print " ( $catid, $itemid, $ctx_desc ) \n";
# The following gives:
# DBD::Oracle::st bind_param_inout failed: ORA-01036: illegal variable
name/number
# (DBD ERROR: OCIBindByName) at cid_populate.pl line 54.
$item_ctx_get_clob->bind_param_inout(":clob_locator", \$clob_locator, 100
,
{ ora_type => ORA_CLOB } );
$item_ctx_get_clob->bind_param(":catid1", $catid,
{ TYPE => DBI::SQL_INTEGER } );
if ( not $item_ctx_get_clob->execute )
{
$category_item_desc_insert->execute( $catid ); # no commit if
Autocommit
$item_ctx_get_clob->bind_param(":catid1", $catid,
{ TYPE => DBI::SQL_INTEGER } ) ;
$item_ctx_get_clob->execute;
}
$len = length( $ctx_desc );
if ( $len > 0 )
{
$dbms_lob_getlength->bind_param_inout(":offset_var", \$clob_offset, 20,
DBI::SQL_INTEGER );
$dbms_lob_getlength->bind_param(":clob_locator", $clob_locator );
$dbms_lob_getlength->execute; # returns $clob_offset
$dbms_lob_write->execute( $clob_locator, $len, $clob_offset,
$ctx_desc );
}
}
$item_query->finish;
$dbh->disconnect;
exit;
------------------------------
Date: Thu, 11 Mar 1999 13:08:12 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Writing to a file
Message-Id: <MPG.1151d096760a4966989723@nntp.hpl.hp.com>
In article <36E72FBB.B28394CF@bigfoot.com> on Wed, 10 Mar 1999 21:51:39
-0500, Mark D. Sholund <msholund@bigfoot.com> says...
> I just tried this and it prints error everytime (I am setting $bookLocation to
> an existing file). The way he tried to open the file (+>) is the correct way
> for reading and writing to the file.
NO, unless you want to truncate the file to zero length when you open
it. That's what '>' means! Read `peldoc -f open` more carefully.
> Reading and writing to a file at the same
> time can get a bit tricky however as this example seems to prove.
I'll say, but not for the reasons you imply! You take the risk of a
catastrophe during the rewriting of the file, corrupting the only copy
of the data. The FAQ that I referred to in a different response tells
how to use a temporary file to avoid this risk.
> Zenin wrote:
...
> > You probably wanted to use <+ (instead of +>)
Zenin was being unduly diffident. The 'probably' means "use '<+' if you
are willing to take the risk detailed above". Otherwise do it as the
FAQ says. In any case, don't use '>+'!
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 11 Mar 1999 13:09:03 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Writing to a file
Message-Id: <MPG.1151d0c9d9e6e19d989725@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7c76b8$r9k$1@nnrp1.dejanews.com> on Thu, 11 Mar 1999
01:30:15 GMT, olmert@netvision.net.il <olmert@netvision.net.il> says...
> ... what i am trying to do is to insert the line
> "This line contains the blues!<P>\n" every time the file contains the string
> "begin".
...
Read perlfaq5: "How do I change one line in a file/delete a line in a
file/insert a line in the middle of a file/append to the beginning of a
file?"
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5115
**************************************