[11419] in Perl-Users-Digest
Perl-Users Digest, Issue: 5019 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 1 13:07:35 1999
Date: Mon, 1 Mar 99 10:00:50 -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 Mon, 1 Mar 1999 Volume: 8 Number: 5019
Today's topics:
Re: 'x' operator to pre-extend a string <gellyfish@btinternet.com>
Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Pos (Andrew M. Langmead)
Accessing a module written as a COM component layer on <dontspam.bob@textor.com>
Re: alpha numeric limiter <gellyfish@btinternet.com>
Re: Array Initialization and directory list searching (Abigail)
assignment operators <gbc1@axe.humboldt.edu>
Re: assignment operators <jdf@pobox.com>
Re: assignment operators (Bart Lateur)
Re: assignment operators <uri@home.sysarch.com>
Re: assignment operators <gbc1@axe.humboldt.edu>
Re: assignment operators <gbc1@axe.humboldt.edu>
baffled by MacPerl <23_skidoo@geocities.com>
Basic Authentication (Carl)
c2perl, awk2perl, sed2perl <coyote38@pacbell.net>
Re: Can I do this w/ Perl? <bjm@a2b01118.paralynx.bconnected.net>
Re: Can I do this w/ Perl? (Abigail)
Re: Can I do this w/ Perl? (Larry Rosler)
Re: Can I do this w/ Perl? (Larry Rosler)
Re: Can I do this w/ Perl? <memymy@earthlink.com>
Re: Compile Perl <ajonsson@csi.com>
Re: Do you really need to do 'open(whatever, ..) or die <jdf@pobox.com>
Re: Do you really need to do 'open(whatever, ..) or die (Greg Bacon)
Re: FAQ 4.13: How can I find the Julian Day? (ICG)
FAQ 7.18: What's the difference between deep and shallo <perlfaq-suggestions@perl.com>
FAQ 7.23: How can I catch accesses to undefined variabl <perlfaq-suggestions@perl.com>
file confirmation <cplee@bigfoot.com>
finishing a DBI's $sth in module before returning <li@smart.net>
Re: finishing a DBI's $sth in module before returning (Honza Pazdziora)
Re: forum program wanted (Mark P.)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Feb 1999 16:22:53 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: 'x' operator to pre-extend a string
Message-Id: <7bbqgt$63k$1@gellyfish.btinternet.com>
On Tue, 23 Feb 1999 00:59:54 +0000 Michael Ryan wrote:
> camel book, 2d ed., page 541:
> "Pre-extending a string with the x operator ..."
> which got me thinking because i couldn't find an example except the $^M
> allocation.
>
> is the proper syntax pre-extending something like:
>
> $s = 'a' x ( 1 << 16 )
> $s = "" # $s is still large
> $s = "first element" . "second element"
> print $s # which should print "first elementsecond element"
>
> is it better to tr/a//d the string to clear it?
>
Both of course achieve same reult however there is of course some
performance difference:
#!/usr/bin/perl
use Benchmark;
sub Assign
{
$s = 'a' x ( 1 << 16 );
$s = ""; # $s is still large
}
sub Translate
{
$s = 'a' x ( 1 << 16 );
$s =~ tr/a//d;
}
timethese (1000, {
Translate => \&Translate,
Assign => \&Assign
});
gellyfish@gellyfish:/home/gellyfish/clpmtest > extend.pl
Benchmark: timing 1000 iterations of Assign, Translate...
Assign: 2 wallclock secs ( 2.41 usr + 0.01 sys = 2.42 CPU)
Translate: 8 wallclock secs ( 7.75 usr + 0.02 sys = 7.77 CPU)
So I would suggest you would want to go with the assignment. It makes
sense really because 'tr' has to visit each 65536 of the characters in
the string.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Mon, 1 Mar 1999 16:58:46 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Posted Twice Weekly ***
Message-Id: <F7xDty.EG4@world.std.com>
Andrew Fry <andrewf@beausys.demon.co.uk> writes:
>Not so. It is just that to suggest that newbies should read...
>* the FAQs
>* the man pages
>* on-line articles at the main Perl sites
>* the main Perl books
>...before posting a question is both patronising and unhelpful
>(when done too frequently).
But the don't have to read the entire FAQ before posting a question,
they just have to search through the titles of the questions to see if
any of the pre-written answers apply top them.
The same with the man pages, they just need to find the one that deals
with the major topic that would cover their question (operators,
function, syntax, regular expressions, data structures, etc.) and see
if they can figure it out from the documentation. The books have
tables of contents and indexes for easy access. (and I've never seen
an RTFM repsonse about some web page that a novice would be unlikely
to know about.)
A large part of any engineering occupation consists of research. For
the novices that don't realize that yet, its about time they
learn.
Earlier today, a co-worker who is just learning Perl walked into my
office and asked a fairly basic question about a perl operator. (he
knew what the corresponding C operator would be, but wanted to know if
Perl's was the same or a different one.) I politely told him the
answer, and then showed him where the man pages on his machine were so
he could find the answer for himself next time.
Thats what I try to do on Usenet.
--
Andrew Langmead
------------------------------
Date: Mon, 1 Mar 1999 17:32:16 -0000
From: "Bob" <dontspam.bob@textor.com>
Subject: Accessing a module written as a COM component layer on NT
Message-Id: <7beis0$kan$1@taliesin.netcom.net.uk>
I am talking to a windows NT system guy who has a database which I need to
access. He says that the best way to do this is for him to write a COM
component in C++. Apparently the database is rather un-normalised and he is
nervous about us accessing it directly.
Does anyone know if it is possible to communicate with a COM component in
Perl on Win 32?
Bob
bob@textor.com
------------------------------
Date: 28 Feb 1999 16:06:21 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: alpha numeric limiter
Message-Id: <7bbpht$61g$1@gellyfish.btinternet.com>
On Mon, 22 Feb 1999 21:57:31 -0500 evil Japh wrote:
>> I have a form with multiple text inputs and I would like to restrict
>> non-alpha-numeric characters by means of an error response.
>
> You can either implement a simple regular expression, shown presently, or
> use the function quotemeta(), which will escape all possibly hazardous
> characters.
>
> Keeping in mind local characters, this will work nicely:
>
> for (@values){
> die "Illegal character ($1) in $_!" if /([\W_])/;
> }
>
Bear in mind thought if this is to be used in a CGI program then it is
probably not appropriate to 'die' like this unless one has set up a die
handler to do something appropriate.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 28 Feb 1999 04:55:08 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Array Initialization and directory list searching
Message-Id: <7bai7c$rn5$4@client2.news.psi.net>
Randal L. Schwartz (merlyn@stonehenge.com) wrote on MMVI September
MCMXCIII in <URL:news:m1zp5ztqv3.fsf@halfdome.holdit.com>:
== >>>>> "Ronald" == Ronald J Kimball <rjk@linguist.dartmouth.edu> writes:
==
== Ronald> There is, however, a more Perlish way to do it:
==
== Ronald> while (defined($name = readdir(CUR_DIR)) {
== Ronald> if ( $name =~ /xyz$/ ) {
== Ronald> push @xyz_array, $name;
== Ronald> }
== Ronald> }
==
== Of course, an even more Perlish way looks like:
==
== @xyz_array = grep /xyz$/, readdir CUR_DIR;
==
My, my, my, are you the same Randal that's always complaining about
needless lists being created when a map in void context shows up?
grep /xyz$/, readdir CUR_DIR;
would read in content of the directory in a (possible long) list,
while
while (defined($name = readdir(CUR_DIR)) {
push @xyz_array, $name if $name =~ /xyz$/;
}
uses much less overhead.
Now, I would use
grep {/xyz$/} readdir CUR_DIR;
myself, but then, I don't object agains a map {} in void context.
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
------------------------------
Date: Mon, 01 Mar 1999 09:02:13 -0800
From: Greg Coit <gbc1@axe.humboldt.edu>
Subject: assignment operators
Message-Id: <36DAC815.DCB67172@axe.humboldt.edu>
I've seen many references to all the assignment operators that Perl
supports, but I cant find explanations in the Perl Docs or in the Camel
Book (or the nutshell book).
Here is a list of the ones I don't understand:
**=
&=
&&=
<<=
>>=
|=
||=
%=
^= (Raise to the power of and add? Kinda like += and *= ?)
x=
If this is listed somewhere, I'd appreciate a pointer to that info. If
it's not listed, would anybody be willing to tell me what these mean?
Thanks!
Greg Coit
gbc1@axe.humboldt.edu
------------------------------
Date: 01 Mar 1999 12:19:29 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: Greg Coit <gbc1@axe.humboldt.edu>
Subject: Re: assignment operators
Message-Id: <m3iucljffi.fsf@joshua.panix.com>
Greg Coit <gbc1@axe.humboldt.edu> writes:
> I've seen many references to all the assignment operators that Perl
> supports, but I cant find explanations in the Perl Docs or in the
> Camel Book (or the nutshell book).
For any operator FOO, the construct
$a FOO= $b
is exactly equivalent to
$a = $a FOO $b
So to determine the meaning of, say
$a ^= $b;
You must look up the ^ operator in perlop. HTH.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Mon, 01 Mar 1999 17:26:41 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: assignment operators
Message-Id: <36dbcc3f.446155@news.skynet.be>
Greg Coit wrote:
>Here is a list of the ones I don't understand:
>**=
>&=
...
All are similar to "C". Yeah, I know, the Perl documentation relies a
bit too much on intimate knowlegde of "that" language. It's getting
bettter, I assure you.
The rule is: If you see:
$lhs op= $rhs;
where "op" is "any operator", this means something like:
$lhs = $lhs op $rhs;
For example:
> ^= (Raise to the power of and add? Kinda like += and *= ?)
No: "^" means "XOR" in Perl.
$lhs = $lhs ^ $rhs;
Flip the bits in $lhs where those bits are set in $rhs.
Rasie to the poser is "**".
Gain: you only have to write $lhs (which can be an elaborate chain that
eventually gets into a scalar left hand side value, i.e. modifiable)
ONCE. Perl will have to follow that chain only once, too.
Bart.
------------------------------
Date: 01 Mar 1999 12:30:40 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: assignment operators
Message-Id: <x7ww11dsn3.fsf@home.sysarch.com>
>>>>> "GC" == Greg Coit <gbc1@axe.humboldt.edu> writes:
GC> I've seen many references to all the assignment operators that Perl
GC> supports, but I cant find explanations in the Perl Docs or in the Camel
GC> Book (or the nutshell book).
they say they are the same as the traditional way of writing the same
expression. so:
$foo op= $bar ;
is always defined to be
$foo = $foo op $bar ;
so just take eachof these and perform that transformation on each to get
their meaning. many of these below have common uses which make them very
idiomatic and useful.
GC> Here is a list of the ones I don't understand:
GC> $a **= $b # raise $a to $b power
GC> $a &= $b # bitwise masking of $a with $b
# ($a &= ~b is pdp-11 BITCLR)
GC> $a &&= $b #
GC> $a <<= $b # shift $a left by $b bits
GC> $a >>= $b # shift $a right by $b bits
GC> $a |= $b # bitwise setting $b's bits in $a (pdp-11 BITSET!)
GC> ||=
GC> $a %= $b # keep the remainder in $a. used in math algorithms
GC> $a ^= $b # bitwise toggle $b's bint in $a
GC> (Raise to the power of and add? Kinda like += and *= ?)
^ is XOR, not power. ** is power
GC> $a x= $b # duplicate the string $a, $b times
the answers you wanted are in those docs you read but aren't spelled out
in great (or any) detail.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Mon, 01 Mar 1999 09:53:16 -0800
From: Greg Coit <gbc1@axe.humboldt.edu>
Subject: Re: assignment operators
Message-Id: <36DAD40C.8C2E95B5@axe.humboldt.edu>
Jonathon, Bart, and Uri,
Thanks for the info. It makes sense now!
Greg Coit
gbc1@axe.humboldt.edu
------------------------------
Date: Mon, 01 Mar 1999 09:53:28 -0800
From: Greg Coit <gbc1@axe.humboldt.edu>
Subject: Re: assignment operators
Message-Id: <36DAD418.2E3A7ED4@axe.humboldt.edu>
Jonathan, Bart, and Uri,
Thanks for the info. It makes sense now!
Greg Coit
gbc1@axe.humboldt.edu
------------------------------
Date: Mon, 01 Mar 1999 17:57:04 +0000
From: 23_skidoo <23_skidoo@geocities.com>
Subject: baffled by MacPerl
Message-Id: <36DAD4EF.628A@geocities.com>
can anyone explain why this works:
open (LIST, "kyle:emails.dat") || print "CO emails.dat\n";
@list=<LIST>;
close (LIST);
foreach $line (@list) {
$line =~ s/^.*?\|//;
# print "$line";
push(@newlist, "$line");
}
open (NEWLIST, ">kyle:emails2.dat") || print "CO emails2.dat\n";
foreach $line (@newlist) {
# print "$line";
print NEWLIST "$line" || print "CP emails2.dat\n";
}
close(NEWLIST);
print "done!\n";
#end
and this dies with the message "CP emails3.dat":
open (LIST, "kyle:emails2.dat") || print "CO emails2.dat\n";
@list=<LIST>;
close (LIST);
@newlist = '';
foreach $line (@list) {
foreach $newline (@newlist) {
if ($line eq $newline) {
$matched = 1;
last;
}
}
unless ($matched == 1) {push(@newlist, "$line");}
$matched = 0;
}
open (NEWLIST, ">kyle:emails3.dat") || print "CO emails3.dat\n";
foreach $line (@newlist) {
# print "$line";
print NEWLIST "$line" || print "CP emails3.dat\n";
}
close(NEWLIST);
print "done!\n";
#end
the second prog was modified from the first, i've cut and pasted the
section that opens, prints and closes NEWLIST then ammended it to open
emails3.dat rather than emails2.dat. i'm stumped. i'm running macperl
5.2.0r4 and the only difference i can see is that the first prog opens a
file created by BBEdit, the second prog opens a file created by the
first prog. *shrugs* any suggestions?
thanks
-23
------------------------------
Date: Mon, 01 Mar 1999 17:47:51 GMT
From: crd@eclipse.net (Carl)
Subject: Basic Authentication
Message-Id: <36dace75.83220054@news.rcn.com>
I'm working on a Netscape Interprise Web Server and I'm trying to set
up a basic authentication scheme where users may log in to a
restricted area using a single login and a software serial number as
their password.
The login would be the same for everyone but the password (serial
number) would be different for each user. The user would submit the
user name and their serial number to a perl script running on the
server (via an HTML form). The perl script would run the serial
number through an algorithm that would translate it back to a uniform
number to check its validity. If the serial number is valid, the
script would then pass the login and a translated password to the
server. The web server would then authenticate the user and pass back
the requested page.
Using the UserAgent library I can pass the login and translated
password to the server, receive authentation and get the page for the
user.
What I would like to do is have the server handle all the subsequent
requests (rather than the script having to mediate each request). I
believe that this requires setting the Authorization header in the
browser to something like the following:
Authorization: Basic B4s7K8GB4V2F
Unfortunately I can't figure out how (or if it is even possible) to
set this header in the browser either from the server side or from a
client side JavaScript.
Does anyone have any ideas or is this a lost cause?
------------------------------
Date: Sat, 27 Feb 1999 19:47:15 -0800
From: "coyote38" <coyote38@pacbell.net>
Subject: c2perl, awk2perl, sed2perl
Message-Id: <G%2C2.4712$8N5.42117@typhoon-sf.pbi.net>
I remember reading about awk2perl and sed2perl once. I cannot find
any information about these anywhere on the internet or within CPAN.
I think they were mentioned in the camel book.
What I am really looking for is c2perl. Does anyone know where I can
find such a thing so I don't have to write it myself?
coyote38@pacbell.net
------------------------------
Date: 27 Feb 1999 19:37:26 -0800
From: Brad Murray <bjm@a2b01118.paralynx.bconnected.net>
Subject: Re: Can I do this w/ Perl?
Message-Id: <87pv6vfbbd.fsf@a2b01118.paralynx.bconnected.net>
>>>>> "Ken" == Ken <cant_take@thespam.com> writes:
Ken> but my local system in WinTel and my ISP is UNIX. Won't that
Ken> be a problem?
This makes Perl an even better choice. Grab a win32 version from
www.activestate.com.
--
BMurray
Perl Guy
------------------------------
Date: 28 Feb 1999 04:46:31 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Can I do this w/ Perl?
Message-Id: <7bahn7$rn5$1@client2.news.psi.net>
Ken (cant_take@thespam.com) wrote on MMVII September MCMXCIII in
<URL:news:36d8b8e3.15460181@news.tiac.net>:
.. bart.lateur@skynet.be (Bart Lateur) wrote:
..
.. >Ken Loomis wrote:
.. >
.. >>Is Perl a good language for these application and how hard would it be
.. >>to do them?
.. >
.. >Yes, Perl is a good choice. I would advice you to get the structure of
.. >your programs right on your local system, not online; debugging would be
.. >soooo much easier. So download Perl, from CPAN (www.cpan.org or
.. >www.perl.com/CPAN).
.. >
..
.. but my local system in WinTel and my ISP is UNIX. Won't that be a
.. problem?
What's the difference in systems to do with anything?
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";`$@`'
------------------------------
Date: Sun, 28 Feb 1999 07:44:46 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Can I do this w/ Perl?
Message-Id: <MPG.11430445bf8cd2749896ac@nntp.hpl.hp.com>
In article <36d9313a.806159@news.tiac.net>, on Sun, 28 Feb 1999 12:12:11
GMT cant_take@thespam.com says...
...
> >.. but my local system in WinTel and my ISP is UNIX. Won't that be a
> >.. problem?
> >
> Abigail cryptically replies:
>
> >What's the difference in systems to do with anything?
>
> Brad suggests that I test my routines on my system before uploading
> them to my ISP. I thought that Perl was written for UNIX systems and
> wouldn't run on WinTel. If I do as Brad suggests and download the
> WINTel version then those routines won't run on the UNIX box.
What a strange idea! Perl runs in dozens of environments; why not
WinTel? Get thee to <URL:http://www.activestate.com/> and download
ActivePerl. The price is right.
Then read the document 'perlport', which will help you address many
portability issues. But the issues will be in your code, not in Perl.
> Abigail, if you would like to be helpful I'd sure appreciate it. You
> remind me a little bit of the guy at my local hardware store. The guy
> will only answer questions. He will answer any question, but only the
> exact question and nothing more. So you have to keep on asking a
> series of questions.
Don't count on it! :-)
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sun, 28 Feb 1999 07:49:35 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Can I do this w/ Perl?
Message-Id: <MPG.1143056c40d4614d9896ad@nntp.hpl.hp.com>
In article <36dc3505.1985648@news.skynet.be>, on Sun, 28 Feb 1999
12:25:58 GMT bart.lateur@skynet.be says...
> Ken wrote:
> >but my local system in WinTel and my ISP is UNIX. Won't that be a
> >problem?
>
> No. There are some tiny differences between Perl ports (e.g. flock()),
> but I do my primary debugging (shaking out the really big oomphs) on
> DOS, and one ISP is on BSD, and the other one on Linux.
>
> I have noticed some largish differences between CGI related environment
> variables, though.
Those are set by the HTTP servers -- which are likely to be different --
not by Perl. But there is a large common 'standard' subset.
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sun, 28 Feb 1999 01:25:00 -0500
From: "Frank White" <memymy@earthlink.com>
Subject: Re: Can I do this w/ Perl?
Message-Id: <7bangt$avc$1@birch.prod.itd.earthlink.net>
Ken,
You're right! Ultimately you will need a script to handle the results. I'm
new to this group, just learning to program Perl and should have keep my
mouth shut. Anyway, I just downloaded a perl script that tabulates results
entered in a survey. So I don't see why Perl wouldn't handle your quest.
Many pardons,
Frank
Ken wrote in message <36d8b7c7.15176124@news.tiac.net>...
>"Frank White" <memymy@earthlink.com> wrote:
>
>>Why not use HTML and a form handler?
>>
>
>And a "form handler" is........?
>
>Ken
------------------------------
Date: Sun, 28 Feb 1999 22:04:21 -0600
From: "AJ" <ajonsson@csi.com>
Subject: Re: Compile Perl
Message-Id: <#HdQZh5Y#GA.356@nih2naad.prod2.compuserve.com>
Check out this Website:
http://www.demobuilder.com/perl2exe.htm
They have a utility that creates executables. Warning: the demo version
inserts a demo stamp so when the exe runs you get the stamp as part of the
output. If you
try it and it suits your needs, you'll have to buy it.
AJ
Kenneth Rose wrote in message <36D5D7C1.16EC4306@home.com>...
>Hi all,
>
>OK, here's the scoop. I have a programming contest on March 2. I would
>like to use Perl for this, but one of the requirements of the program is
>you submit an executable. That is, an EXE file. Does anyone know of
>anyway to compile Perl source code into an EXE? I'd be using Perl for
>Win32.
>
>Thanks to anyone who can help.
>
>/<enneth Rose
------------------------------
Date: 01 Mar 1999 12:08:25 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: Baillie <baillie@my-dejanews.com>
Subject: Re: Do you really need to do 'open(whatever, ..) or die..'
Message-Id: <m3lnhhjfxy.fsf@joshua.panix.com>
Baillie <baillie@my-dejanews.com> writes:
> It seems as if a program will never die at the open line, but rather
> at the close line. Why is that?
> close(FH) || die "can't close $file: $!";
Who knows? What does the error message say? You've printed out the
contents of $!, so you've got the answer right in front of you.
> I don't get this. What's the point in setting up to die from the
> open if it doesn't work?
Different errors can take place for different reasons at different
times. If a file doesn't exist, for example, then you will get an
error when you try to open the file.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 1 Mar 1999 17:01:27 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Do you really need to do 'open(whatever, ..) or die..'
Message-Id: <7beh57$3gv$2@info.uah.edu>
In article <7bee9t$m4l$1@nnrp1.dejanews.com>,
Baillie <baillie@my-dejanews.com> writes:
: It seems as if a program will never die at the open line, but rather
: at the close line. Why is that?
I don't see this behavior:
[10:58] ettsn% cat try
#! /usr/bin/perl -w
open FILE, "fooquux" or die "$0: failed open fooquux: $!\n";
close FILE or die "$0: failed close fooquux: $!\n";
[10:58] ettsn% ./try
./try: failed open fooquux: No such file or directory
What does your `perl -V' say?
Greg
--
There are no facts, only interpretations.
-- Nietzsche
------------------------------
Date: Mon, 01 Mar 99 03:35:15 GMT
From: postmaster@UU.NET (ICG)
Subject: Re: FAQ 4.13: How can I find the Julian Day?
Message-Id: <7bd5lt$bdu@world6.bellatlantic.net>
In article <MPG.113b4deb892be441989a6a@nntp.hpl.hp.com>, lr@hpl.hp.com (Larry Rosler) wrote:
>In article <36d17cde@csnews> on 22 Feb 1999 08:50:54 -0700, Tom
>Christiansen <tchrist@mox.perl.com> says...
>> In comp.lang.perl.misc,
>> smithj@statenislandonline.com writes:
>> :Can someone please tell me how to do this without the mod.
>>
>> Sure -- read the source.
>
>Or pick up this function directly from the Perl Function Repository:
Why a function? If you are in a Linux environ try this:
# Get Julian date variable NO PARTICULAR REASON, JUST GET IT
$date = `/bin/date '+%y%j'`;
(for those of you who are wondering, yes, I do yell at myself in my program
comments.)
-------------------------------------------------------------
No, not the postmaster, I just hate SPAM
------------------------------
Date: 28 Feb 1999 09:02:57 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 7.18: What's the difference between deep and shallow binding?
Message-Id: <36d968b1@csnews>
(This excerpt from perlfaq7 - Perl Language Issues
($Revision: 1.24 $, $Date: 1999/01/08 05:32:11 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)
What's the difference between deep and shallow binding?
In deep binding, lexical variables mentioned in anonymous subroutines
are the same ones that were in scope when the subroutine was created. In
shallow binding, they are whichever variables with the same names happen
to be in scope when the subroutine is called. Perl always uses deep
binding of lexical variables (i.e., those created with my()). However,
dynamic variables (aka global, local, or package variables) are
effectively shallowly bound. Consider this just one more reason not to
use them. See the answer to the section on "What's a closure?".
--
OK, enough hype.
--Larry Wall in the perl man page
------------------------------
Date: 28 Feb 1999 21:33:10 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 7.23: How can I catch accesses to undefined variables/functions/methods?
Message-Id: <36da1886@csnews>
(This excerpt from perlfaq7 - Perl Language Issues
($Revision: 1.24 $, $Date: 1999/01/08 05:32:11 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)
How can I catch accesses to undefined variables/functions/methods?
The AUTOLOAD method, discussed in the section on "Autoloading" in the
perlsub manpage and the section on "AUTOLOAD: Proxy Methods" in the
perltoot manpage, lets you capture calls to undefined functions and
methods.
When it comes to undefined variables that would trigger a warning under
`-w', you can use a handler to trap the pseudo-signal `__WARN__' like
this:
$SIG{__WARN__} = sub {
for ( $_[0] ) { # voici un switch statement
/Use of uninitialized value/ && do {
# promote warning to a fatal
die $_;
};
# other warning cases to catch could go here;
warn $_;
}
};
--
"I woudn't recommend sex, drugs, or Unix for everyone, but they work for me."
Jim Thompson (jthomp@tadpole.com), paraphrasing Hunter S. Thompson
------------------------------
Date: Sun, 28 Feb 1999 13:50:51 +0800
From: Cplee <cplee@bigfoot.com>
Subject: file confirmation
Message-Id: <36D8D93B.AFB2FF45@bigfoot.com>
Dear Friends
I try to read a file which located at another http server
I wish to know how to access it
also wish to confirm the file exist or not
Any command can do that please replay asap
Andrea
------------------------------
Date: 28 Feb 1999 15:55:12 GMT
From: "Vlad Podgurschi" <li@smart.net>
Subject: finishing a DBI's $sth in module before returning
Message-Id: <01be6332$af5bdba0$9cf31bce@default>
Hi:
I'm trying to find a way to `finish' a DBI's statement handler $sth before
I return from a module, so that I don't get that 6-7lines warning in
Apache's logs.
I have a module:
======
package MyModule;
< blahblah >
my $dbh=DBI->connect...........;
sub first_method {
my $sth=$dbh->blahblah.......;
< do some other things here and get some vars form db $this, $that >
($this ne $that) || return _ret("error message here");
< some other code here using $sth..... >
$sth->finish;
< return something here >
}
< some other methods...... >
sub _ret {
$MyModule::global_errormsg=shift;
$dbh->disconnect;
return;
}
1;
=============
As you can see I want to `return' false on error from module, not to `die',
and, before returning, to put a global error mesage that can be used by the
calling script (something like $DBI::errstr).
The question is: how do I finish the $sth (which is scoped in
first_method, and not available to `_ret')?
I wouldn't like to do $sth package scoped (ie declaring something like `my
$sth' outside methods).
On the other hand, making everytime a block like: { $sth->finish; return
_ret("blahblah"); } is not nice.
I couls solve the problem if I could pass the $sth object as argument to
`_ret'. How should I do that ? (I'm not sure if I didn't ask a stupid
thing here ie passing objects as arguments....)
Should I use closures ? (I remember there is a recipe in Perl CookBook
about that)
If I use DESTROY, will it be called AFTER the `_ret' subroutine? (I think
the answer is 'yes') Can I `return' false from DESTROY or only `die'?
Another question would be: "Can I do something else than that `return
_ret("mm")' stuff?" Meaning: could I return (not die) from the module
directly from `_ret', without passing the return value of `_ret' to the
calling method and then outside?
Thanks a lot for your help,
Vlad
------------------------------
Date: Sun, 28 Feb 1999 16:39:07 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: finishing a DBI's $sth in module before returning
Message-Id: <F7vI97.2uM@news.muni.cz>
On 28 Feb 1999 15:55:12 GMT, Vlad Podgurschi <li@smart.net> wrote:
> sub first_method {
> my $sth=$dbh->blahblah.......;
> < do some other things here and get some vars form db $this, $that >
> ($this ne $that) || return _ret("error message here");
> < some other code here using $sth..... >
> $sth->finish;
> < return something here >
> }
>
> < some other methods...... >
>
> sub _ret {
> $MyModule::global_errormsg=shift;
> $dbh->disconnect;
> return;
> }
[...]
> calling script (something like $DBI::errstr).
> The question is: how do I finish the $sth (which is scoped in
> first_method, and not available to `_ret')?
Why don't you just pass the $sth as second parameter to _ret and make
it available that way?
> I wouldn't like to do $sth package scoped (ie declaring something like `my
> $sth' outside methods).
> On the other hand, making everytime a block like: { $sth->finish; return
> _ret("blahblah"); } is not nice.
>
> I couls solve the problem if I could pass the $sth object as argument to
> `_ret'. How should I do that ? (I'm not sure if I didn't ask a stupid
> thing here ie passing objects as arguments....)
You pass a reference. Doing something like
|| return _ret("Error", $sth);
and
sub _ret {
my ($msg, $sth) = @_;
$sth->finish;
}
is completely legal.
> Should I use closures ? (I remember there is a recipe in Perl CookBook
> about that)
No, just pass it as a parameter.
> Another question would be: "Can I do something else than that `return
> _ret("mm")' stuff?" Meaning: could I return (not die) from the module
> directly from `_ret', without passing the return value of `_ret' to the
Note, that you are not returning from amodule, but from a method
call.
> calling method and then outside?
No, I do not think you can do that. If you are in some function, to
get back you have to go through all of them (basically).
Hope this helps,
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
make vmlinux.exe -- SGI Visual Workstation Howto
------------------------------------------------------------------------
------------------------------
Date: Sun, 28 Feb 1999 22:32:10 GMT
From: mag@imchat.com (Mark P.)
Subject: Re: forum program wanted
Message-Id: <36d9c330.615884214@news.ionet.net>
You should try UBB (Ultimate Bulletin Board) from
http://www.UltimateBB.com . Its the best cgi forum I've seen and its
free for private use. It only costs like $30 for commercial use so it
won't drain your wallet.
On Sun, 28 Feb 1999 21:01:43 +0100, Ulrike <ulrikestar@hotmail.com>
wrote:
>Hi perl experts!
>
>I'm looking for a perl program which allows a threaded discussion
>forum on a web page. It would also need to have administration features.
>If
>anyone out there has seen anything that could help me, shareware or
>even freeware programs, I would really appreciate it. Even any advice
>on where I could search further would be great, or which programs are
>the best as there are so many out there it gets a bit confusing. Well
>thanks very much for listening and I hope to hear from you soon.
>
>Ulrike.
>
>
>
------------------------------
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 5019
**************************************