[9221] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2816 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 8 19:07:24 1998

Date: Mon, 8 Jun 98 16:00:26 -0700
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, 8 Jun 1998     Volume: 8 Number: 2816

Today's topics:
    Re: . <Jesus@vkr.k-net.dk>
    Re: Capitalizing acronyms (Re: Is PERL case sensitive?) (Craig Berry)
    Re: Day of Week Display for User-defined date <tchrist@mox.perl.com>
    Re: Day of Week Display for User-defined date (I R A Aggie)
    Re: Day of Week Display for User-defined date <kcl@mindspring.com>
        DBM in Perl (INTMEC)
        How do you include a header file? breyer@breyer.com
    Re: How do you include a header file? <tchrist@mox.perl.com>
    Re: How do you include a header file? <probavm@cat.com>
    Re: How to install PERL with user account? (Bob Trieger)
        localtime() and y2k (Chris)
    Re: localtime() and y2k (Michael J Gebis)
    Re: localtime() and y2k <tchrist@mox.perl.com>
        Newbie Question - Contest Script...? <ythan@hempseed.com>
    Re: problem w/ ^M in Win95 <bowlin@sirius.com>
    Re: Problems with open() <tchrist@mox.perl.com>
    Re: Q: apply func to mutate list; oneliner (Charles DeRykus)
        READING MAIL BY PERL <thijs@esense.nl>
    Re: READING MAIL BY PERL <metcher@spider.herston.uq.edu.au>
    Re: RECOMMEND A PERL BOOK/RESOURCES ?? <joe.odenweller@eds.com>
    Re: Skipping iterations in while <tchrist@mox.perl.com>
        Testing for valid URL before writing HTML code (cgi) genglergarret@my-dejanews.com
        use strict vs. iterative filehandles? (Paul D. Smith)
    Re: use strict vs. iterative filehandles? <tchrist@mox.perl.com>
    Re: Why is there no "in" operator in Perl? (Snowhare)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Mon, 08 Jun 1998 23:32:23 +0200
From: Jesus <Jesus@vkr.k-net.dk>
Subject: Re: .
Message-Id: <357C5867.D503B3EF@vkr.k-net.dk>

> }> > >   "640k ought to be enough for anybody" -Bill Gates, 1981
> }> >
> }> > "If you can't make it good, at least make it look good" - Microsoft
> }> > Marketing
> }>
> }> "It's an undocumented feature" - Microsoft Tech Support
> }
> }"There won't be anything we won't say to people to try and convince them
> }that our way is the way to go." - Microsoft marketing
>
> "These [security loopholes] are not security loopholes - they're
> undocumented features." - Microsoft on Windows NT

"There are people who don't like capitalism, and people who don't like PCs.
But there's no-one who likes the PC who doesn't like Microsoft"  - Bill Gates
in LA Times




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

Date: 8 Jun 1998 21:18:46 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Capitalizing acronyms (Re: Is PERL case sensitive?)
Message-Id: <6lhkfm$lob$1@marina.cinenet.net>

Tom Phoenix (rootbeer@teleport.com) wrote:
: On Sat, 6 Jun 1998, REUBEN LOGSDON wrote:
: 
: > PERL is an acroynm for "Practical Extraction and Report Language".  It's
: > common practice to capitalize acronyms. 
: 
: You're right, but once the acronym becomes a word (such as laser, scuba,
: or zip code) the caps are dropped. Thus the FAQ turns out to be correct
: once again. :-)

At this point, shouldn't that be 'faq'? :)

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 8 Jun 1998 20:43:00 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Day of Week Display for User-defined date
Message-Id: <6lhick$sfi$2@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Scratchie <upsetter@ziplink.net> writes:
:That module is a hog. 

There is that.

:I prefer to use Time::ParseDate and POSIX myself.

I haven't used the former.

--tom
-- 
s = (unsigned char*)(SvPVX(sv));    /* deeper magic */
    --Larry Wall, from util.c in the v5.0 perl distribution


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

Date: Mon, 08 Jun 1998 17:55:50 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Day of Week Display for User-defined date
Message-Id: <fl_aggie-0806981755510001@aggie.coaps.fsu.edu>

In article <357C3050.3EBE6D1C@mindspring.com>, KC Lucchese
<kcl@mindspring.com> wrote:

[to Abigail]
+ What a witch.  Your trailer park cancel bingo again, honey?

With that sort of attitude, you won't be getting any answers to any
of your questions in this newsgroup.

Abigail gave you a short, concise, and most importantly, a *correct*
answer. What you want *is* in the documentation. That you're too lazy
to find it out on your own is not anyone's problem but your own.

But don't abuse people simply because they don't give you the answer
that you want.

James

-- 
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>


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

Date: Mon, 08 Jun 1998 18:23:18 -0400
From: KC Lucchese <kcl@mindspring.com>
Subject: Re: Day of Week Display for User-defined date
Message-Id: <357C6454.ACB9A54C@mindspring.com>

Geez, what is it with you people....   I ask a simple question... I
apologized in advance if it was something that has been answered
before....  I humbled myself by admitting my limited knowledge...  I was
hoping for a helping hand and I get smug, nasty "I'm smarter than you
are" rhetoric.

In the time it takes you to scold me you could have pointed me to an
answer.

For the record, I DID read the FAQ.... I searched through page after page
of complicated programming information written for the advanced user and
was unable to come up with an answer that worked. All I'm trying to do is
maintain this piece of crap system that I inherited until I can rewrite
it in something I'm more experienced in.

Give a guy a break.

I withdraw my plea for help....  you people can go back to your important
discussions of whatever it is that people with no manners and no social
skills prefer to discuss.

I R A Aggie wrote:

> In article <357C3050.3EBE6D1C@mindspring.com>, KC Lucchese
> <kcl@mindspring.com> wrote:
>
> [to Abigail]
> + What a witch.  Your trailer park cancel bingo again, honey?
>
> With that sort of attitude, you won't be getting any answers to any
> of your questions in this newsgroup.
>
> Abigail gave you a short, concise, and most importantly, a *correct*
> answer. What you want *is* in the documentation. That you're too lazy
> to find it out on your own is not anyone's problem but your own.
>
> But don't abuse people simply because they don't give you the answer
> that you want.
>
> James
>
> --
> Consulting Minister for Consultants, DNRC
> The Bill of Rights is paid in Responsibilities - Jean McGuire
> To cure your perl CGI problems, please look at:
> <url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>





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

Date: 08 Jun 1998 17:43:20 EDT
From: Hyeled@cris.com (INTMEC)
Subject: DBM in Perl
Message-Id: <6lhlto$qlp@examiner.concentric.net>

Hi,

Does anyone know how to convert a flat file to DBM format?

Thanks,

-Helgge


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

Date: Mon, 08 Jun 1998 22:20:46 GMT
From: breyer@breyer.com
Subject: How do you include a header file?
Message-Id: <6lho3u$7fh$1@nnrp1.dejanews.com>

I have several Perl scripts utilizing some common data definitions.
I have collected all the common data definitions in a single file
that I would like to "include" in each of the Perl scripts.

I have tried "do '<fully-qualified-path-filename>';"
and "require '<fully-qualified-path-filename>';".
I even tried "eval" but that only works on a single line.

Nothing seems to work short of reading the file in a loop
and performing a line-by-line eval.

How is this supposed to be done?

thanks.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 8 Jun 1998 22:36:27 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How do you include a header file?
Message-Id: <6lhp1b$92m$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, breyer@breyer.com writes:
:I have several Perl scripts utilizing some common data definitions.
:I have collected all the common data definitions in a single file
:that I would like to "include" in each of the Perl scripts.

:How is this supposed to be done?

The way explained in the standard perlfaq7 manpage that's on your system
which you could and should have read for yourself, as elaborated by the
standard perlmod and Exporter manpages that are on your system which you
could and should have read for yourself, whose syntactic particulars
are shown the per-function listings of the perlfunc manpage that's on
your system which you could and should have read for yourself.

--tom, the last reader on earth
-- 
sv_magic(sv, Nullsv, 'B', Nullch, 0);     /* deep magic */
    --Larry Wall, from util.c in the v5.0 perl distribution


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

Date: Mon, 08 Jun 1998 17:50:45 -0500
From: "Vincent M. Probasco" <probavm@cat.com>
Subject: Re: How do you include a header file?
Message-Id: <357C6AC5.D8974818@cat.com>

require "the_file.pl"




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

Date: Mon, 08 Jun 1998 21:42:05 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: How to install PERL with user account?
Message-Id: <6lhlue$put$1@ligarius.ultra.net>

[ posted and mailed ]

Tom Phoenix <rootbeer@teleport.com> wrote:
-> Maybe I've misunderstood what you were saying...
-> 
-> On Sun, 7 Jun 1998, Bob Trieger wrote:
-> 
-> > -> So, is it possible for me to install PERL to my own directory, and start
->  =
-> > -> using the cool scripts?
-> > 
-> > Not unless you have administrator access.
-> 
-> In general, though, you _can_ install perl and modules without being a
-> system administrator. (You shouldn't be able to install them into
-> directories like /usr/bin, of course, but that's another matter.) 

The original poster was talking about an NT ISP. Installing perl would be next 
to impossible and even if he did manage to get it installed via FTP, he'd have 
no chance of configuring IIS to run his CGI scripts.


Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-239-0341
    and hang up when the recording starts. "


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

Date: 8 Jun 98 22:36:39 GMT
From: chris@bcadventure.com (Chris)
Subject: localtime() and y2k
Message-Id: <357c6777.0@news.westel.com>

Hi, I am still learning perl.

The perl script command:
localtime(time)
 
Will give a 2 digit date, several small scripts I have seen in this newsgroup 
simply add 1900 to the year and say it is y2k compliant.
Am I missing something here?
Is there a better way to get the local year in a 4 digit format?
I could use the epoch format but that is added script lines and I am trying to 
keep my script small.
Thanks,
 
Do you know of a fix for this?



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

Date: 8 Jun 1998 22:48:33 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: localtime() and y2k
Message-Id: <6lhpo1$m6e@mozo.cc.purdue.edu>

chris@bcadventure.com (Chris) writes:

}Hi, I am still learning perl.
}The perl script command:
}localtime(time)
} 
}Will give a 2 digit date, several small scripts I have seen in this newsgroup 
}simply add 1900 to the year and say it is y2k compliant.
}Am I missing something here?

Read the docs.  Short answer: It will work, it's not limited to 2
digits of date, it just works out that way 'cause it's 1984 right now,
and 1984-1900=84, thus two digits.  In 16 years, 2000-1900=100,
you'll get three digits and you'll be happy.

This answer tends to surprise people because they are so jaded by the
way other programs work, they are amazed that perl gets it right.
This also means that this question is asked again and again and again,
and you'll probably get a few flames saying "This question again?"
Enjoy!

If you are using perl4, there is a bug fix patch out that makes this
all true.  Look for "perl5".

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: 8 Jun 1998 22:38:59 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: localtime() and y2k
Message-Id: <6lhp63$92m$2@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, chris@bcadventure.com (Chris) writes:
:Will give a 2 digit date, several small scripts I have seen in this newsgroup 
:simply add 1900 to the year and say it is y2k compliant.
:Am I missing something here?

You may have missed having read the FAQ.
Or my document at www.perl.com.

:Is there a better way to get the local year in a 4 digit format?

Better then adding 1900 to it?  What would you like to do, 
a Fast Fourier Transform?  Shall we consider its complex roots?
Whiat do you mean "better"?  What's wrong with adding 1900 
the way you've been told to?

:Do you know of a fix for this?

There's nothing broken to fix.  

--tom
-- 
I just hate to be pushed around by some fucking machine. - Ken Thompson, on the i960


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

Date: Mon, 08 Jun 1998 22:39:37 GMT
From: Ythan Burstein <ythan@hempseed.com>
Subject: Newbie Question - Contest Script...?
Message-Id: <357C681E.81F38A3A@hempseed.com>

I'm trying to write a CGI script for my webpage which allows my visitors
to submit their address to be entered in a random drawing to win a
prize. I want them to be able to enter once every 24 hours with the same
IP address (so if they have a dynamic IP address they *can* enter more
than once a day, as long as their IP address is different every time). 
Once they enter their postal address and click "submit", the script will
check a file which contains the IP addresses of everyone who has entered
the contest in the last 24 hours. If their IP address is not in the
file, then their address is added to a different file and the IP list is
updated so they can't enter again for 24 hours.

I am totally lost as to how I would even begin going about writing this
script, but if someone could point me in the right direction or supply
me with some sample code, I'd be incredibly grateful.

Thanks so much!

-Ythan
(ythan@hempseed.com)


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

Date: Mon, 08 Jun 1998 14:35:35 -0700
From: Jim Bowlin <bowlin@sirius.com>
To: "Mark E. Perkins" <meperkins@att.com>
Subject: Re: problem w/ ^M in Win95
Message-Id: <357C5927.A6799DA3@sirius.com>

Mark E. Perkins wrote:
> 
> I have some Mac text files that need conversion to DOS text files
> (Mac uses ^M as end of line char). The following simple script works
> fine on a Unix Perl (5.003_01), but not on my installation of
> Gurusamy Sarathy's Windows Perl (5.004_02).
> 
> while (<>) {
>     s/\015/\015\012/g;
>     print ;
> }
> 
> All instances of ^M get stripped out, but are not replaced. If the s///
> is replaced with
> 
>     s/a/a/g
> 
> the ^M are all stripped, even though they shouldn't get touched.
> 
> What am I missing?

The binmode() function.  Here is an example:

{
    open(MAC, 'mac.txt') or die "could not open mac.txt\n$!";
    binmode(MAC);
    local($/) = "\r";   # input record separator
    while(<MAC>) {
	chomp;
	print "$.: $_\n";
    }
}

-- Jim Bowlin


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

Date: 8 Jun 1998 20:57:15 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Problems with open()
Message-Id: <6lhj7b$sfi$3@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    mfrost@my-dejanews.com writes:
:Of course, there is no program called "wackawacka" to run, but this still
:seems to work.	According the the blue camel book, open() is supposed to
:return a non-zero value upon success and "undefined" otherwise.  No matter
:what program I tell open() to run, I still get a non-zero return value.  

That's because your forks keep succeeding.  You need to read more.

Here's the relevant Camel passage, found in Chapter 6:

    Be careful to check the return values of both \fBopen\fP and
    \fBclose\fP.  (If you're \fIwriting\fP to a pipe, you should also
    be prepared to handle the PIPE signal, which is sent to you if the
    process on the other end dies before you're done sending to it.)
    The reason you need to check both the \fBopen\fP and the \fBclose\fP
    have to do with an idiosyncrasy of UNIX in how piped commands are
    started up.  When you do the \fBopen\fP, your process forks a child
    process that is in charge of executing the command you gave it.
    The \fIfork\fP(2) system call, if successful, returns immediately
    within the parent process, and the parent script leaves the \fBopen\fP
    function successfully, even though the child process may not have
    even run yet.  By the time the child process actually tries to run
    the command, it's already a separately scheduled process.  So if
    it fails to execute the command, it has no easy way to communicate
    the fact back to the \fBopen\fP statement, which may have already
    exited successfully in the parent.  The way the disaster is finally
    communicated back to the parent is the same way that any other
    disaster in the child process is communicated back: namely, the exit
    status of the child process is harvested by the parent process when it
    eventually does a \fIwait\fP(2) system call.  But this happens in the
    \fBclose\fP function, not the \fBopen\fP function.  And that's why you
    have to check the return value of your \fBclose\fP function.  Whew.

And here is the relevant passage from perlipc:

    Be careful to check both the open() and the close() return values. If
    you're *writing* to a pipe, you should also trap SIGPIPE. Otherwise,
    think of what happens when you start up a pipe to a command that
    doesn't exist: the open() will in all likelihood succeed (it
    only reflects the fork()'s success), but then your output will
    fail--spectacularly. Perl can't know whether the command worked
    because your command is actually running in a separate process
    whose exec() might have failed. Therefore, while readers of bogus
    commands return just a quick end of file, writers to bogus command
    will trigger a signal they'd better be prepared to handle. Consider:

        open(FH, "|bogus")  or die "can't fork: $!";
        print FH "bang\n"   or die "can't write: $!";
        close FH            or die "can't close: $!";

    That won't blow up until the close, and it will blow up with a
    SIGPIPE. To catch it, you could use this:

        $SIG{PIPE} = 'IGNORE';
        open(FH, "|bogus")  or die "can't fork: $!";
        print FH "bang\n"   or die "can't write: $!";
        close FH            or die "can't close: status=$?";

And here's the part from perlfaq8:

       It does, but probably not how you expect it to.  It works like
       this: open() causes a fork().  In the parent, open() returns
       with the process ID of the child.  The child exec()s the command
       to be piped to/from.  The parent can't know whether the exec()
       was successful or not - all it can return is whether the fork()
       succeeded or not.  To find out if the command succeeded, you have
       to catch SIGCHLD and wait() to get the exit status.  You should
       also catch SIGPIPE if you're writing to the child -- you may
       not have found out the exec() failed by the time you write.
       This is documented in the perlipc manpage.

I swear I am the last living man who knows what's in the perldocs.

--tom
-- 
:The only reason [not to use] perl is that some sysadmins don't allow software that they didn't pay for.
By all means, let them send me money if it makes them feel better.  :-)
	--Larry Wall in <1993Dec13.213032.26623@netlabs.com>


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

Date: Mon, 8 Jun 1998 22:14:25 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Q: apply func to mutate list; oneliner
Message-Id: <Eu9741.5p1@news.boeing.com>

In article <6lgrha$p7h$1@pegasus.csx.cam.ac.uk>,
M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
>In article <yo33edkyyur.fsf@shell13.ba.best.com>,
>Xah Lee  <xah@shell13.ba.best.com> wrote:
>>
>>
>>Suppose I have a list from split(...), then I want to apply a function to the second element, then return the list. How to do it in one line?
>
>A simple substitute will do it:
>
> $line =~ s!/(\w+)/!'/'.monthNameToNumber($1).'/'!e
>

Here's a variant:

  $line =~ s!/(\w+)/!/@{[monthNametoNumber($1)]}/!; 



HTH,
--
Charles DeRykus


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

Date: 8 Jun 1998 21:54:54 GMT
From: "Mathijs Oosterom" <thijs@esense.nl>
Subject: READING MAIL BY PERL
Message-Id: <01bd9328$107c5300$a44a6dc2@earl.esense.nl>

Hi all,

I want a Perl script on my Linux-server to read incoming mail on a certain
account, especially for the script. The Perl-script should read the mail
and execute commands in that mail.

What is the best way to let a Perl-script read mail? Now I let the script
read the /var/spool/mail/xxxxx file, but I don't klow if that's the best
way to do it. My server software is RedHat.

Can anybody help me? Thanx in advance!

Thijs.




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

Date: Tue, 09 Jun 1998 08:35:13 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: READING MAIL BY PERL
Message-Id: <357C6721.D0AA803F@spider.herston.uq.edu.au>

A more general way might be to use the Net::POP3 module to read the mail
like any other mail client.

-- 
Jaime Metcher

Mathijs Oosterom wrote:
> 
> Hi all,
> 
> I want a Perl script on my Linux-server to read incoming mail on a certain
> account, especially for the script. The Perl-script should read the mail
> and execute commands in that mail.
> 
> What is the best way to let a Perl-script read mail? Now I let the script
> read the /var/spool/mail/xxxxx file, but I don't klow if that's the best
> way to do it. My server software is RedHat.
> 
> Can anybody help me? Thanx in advance!
> 
> Thijs.


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

Date: Mon, 8 Jun 1998 15:47:59 -0500
From: "Joe Odenweller" <joe.odenweller@eds.com>
Subject: Re: RECOMMEND A PERL BOOK/RESOURCES ??
Message-Id: <6lhint$s1v$1@news.ses.cio.eds.com>


Stephan Carydakis wrote in message <357BDEBF.4779@hotkey.net.au>...
snip..snip
>My wife bought me "Programming Perl" for Christmas, and I've been trying
>to learn Perl from this book. I realise its a tad beyond me(the "Grade
>Example" is still awesome in my books!) and am wondering if anyone could
>point me in the direction of a good Intermediate book that teaches Perl.


I am currently teaching myself Perl.  I've stepped straight from Learning
Perl (the llama book) to Programming Perl (the camel book).  I've tripped
across nothing in Programming Perl that I couldn't understand quickly.  I do
have over 22 years in IT, and while I do know COBOL, I also know many
others.







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

Date: 8 Jun 1998 20:40:44 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Skipping iterations in while
Message-Id: <6lhi8c$sfi$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, ptimmins@netserv.unmc.edu writes:
:while (<>) {
:    unless ($. == 1) {
:        $your_code = "here";
:        # etc.
:    }
:}

That's backwards logic, generally.  You want to reduce
complexity and indentation.

    while (<>) {
	next if $. == 1;
	$your_code = "here";
	# etc.
    } continue {
	close ARGV if eof;
    } 

The continue block is needed to reset $. on each file.

--tom
-- 
    "You can't have filenames longer than 14 chars.  
     You can't even think about them!"
        --Larry Wall in Configure from the perl distribution


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

Date: Mon, 08 Jun 1998 20:52:27 GMT
From: genglergarret@my-dejanews.com
Subject: Testing for valid URL before writing HTML code (cgi)
Message-Id: <6lhiub$uit$1@nnrp1.dejanews.com>

I wonder if the following is possible:

I have a very simple cgi-script that dynamically writes out HTML code, that
includes some images.  The images change each day, so the perl code figures
out what the latest image filename should be and writes that into the html
code on the fly.

If the images aren't actually available, of course, the result is a broken
graphic... This doesn't happen very often, but since the graphic production is
inconsistent and out of my hands, it does happen occasionally.

The images reside on a different web server than the cgi-script.

What I'd like my cgi script to be able to do is to check that the file exists,
somehow, and if it doesn't, try back another day, or two, until it finds a
valid file.

If my script was on the same server as the images, it would be much easier
(just file open error code stuff).  But since the files are on another web
server, I have no idea how to proceed.

Can a perl script establish http connections and get back error codes?  How?

-Garret Gengler
 RoundTable Media

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 08 Jun 1998 17:04:06 -0400
From: psmith@baynetworks.com (Paul D. Smith)
Subject: use strict vs. iterative filehandles?
Message-Id: <p5solfa9mh.fsf@baynetworks.com>

(perl 5.004, SunOS 4.1.4)

I have code, taken from the perl docs, which generates unique
filehandles on iterative calls quite nicely.  Now when I "use strict;"
this code chokes on me :(.

    $ cat strict-test

    use strict;
    use vars qw($fh $rdr $wtr);

    $fh = 'FH0001';

    $rdr = $fh++;
    $wtr = $fh++;

    pipe($rdr, $wtr) or die "Can't create pipe: $!\n";

Obviously in the "real world" the increment of $fh and creation of the
pipe would be in a sub, in order to get unique filehandles.

Without use strict this works great; with it I get:

  $ perl -w ./strict-tst
  Can't use string ("FH0001") as a symbol ref while "strict refs" in use at ./strict-tst line 11.

I understand from the docs why this is (more or less), but I'm unsure
what to do about it.

Can this method be salvaged?  Is there some way to convince strict that
this is in fact a hard reference and should be treated as OK?  I'm
afraid I'm not quite familiar enough with references in perl to know if
this makes sense, or how to do it.

Or is there some other method of doing this that doesn't run afoul of
use strict?

I realize I could use no strict 'refs', but is that the only or "best"
way (given TMTOWTDI)?

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <psmith@baynetworks.com>         Network Management Development
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
     These are my opinions--Bay Networks takes no responsibility for them.


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

Date: 8 Jun 1998 21:32:57 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: use strict vs. iterative filehandles?
Message-Id: <6lhla9$375$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    psmith@baynetworks.com writes:
:
:Without use strict this works great; with it I get:
:
:  $ perl -w ./strict-tst
:  Can't use string ("FH0001") as a symbol ref while "strict refs" in use at ./strict-tst line 11.

:
:I understand from the docs why this is (more or less), but I'm unsure
:what to do about it.
:
:Can this method be salvaged?  Is there some way to convince strict that
:this is in fact a hard reference and should be treated as OK?  

You'd have to use *{$fh} but that's still a symbolic reference.
Filehandles are just that way.

:I'm
:afraid I'm not quite familiar enough with references in perl to know if
:this makes sense, or how to do it.
:
:Or is there some other method of doing this that doesn't run afoul of
:use strict?

Here's a silly little program that generates its own handles
quite a lot.  See the queue() function.  Look, Graham, no modules! :-)

--tom

#!/usr/bin/perl
# prime-fork - tchrist@perl.com

sub forksub(&);

use strict;
main();
exit;

sub main { 
    my($head,$tail) = queue();
    my $kid = forksub { 
	close($tail); 
	check_num($head, 2) 
    };
    close $head;
    for (my $i = 3; $i <= 1000; $i++) {
	enqueue($tail, $i);
    } 
    close $tail;
    waitpid($kid,0);
}


sub check_num {
    my ($stream, $cur_prime) = @_;
    my ($spawned, $num);

    my($head, $tail) = queue();

    while ($num = dequeue($stream) ) {
	next unless $num % $cur_prime;
	if ($spawned) { 
	    enqueue($tail, $num);
	    next;
	}
	print "Found prime $num\n";
	$spawned = forksub { 
	    close($tail); 
	    check_num($head, $num) 
	};
	close $head;
    } 
    close($head)  		unless $spawned;
    close($tail);
    waitpid($spawned,0) 	if     $spawned;
    exit;
}

sub forksub(&) {
    my $coderef = $_[0];
    my $pid = fork();
    die "cannot fork: $!" 	unless defined $pid;
    return $pid if $pid;
    goto &$coderef;		# don't need no stinkin' stack frames
} 

sub queue {
    local(*READER, *WRITER);
    pipe(READER, WRITER) || die "can't pipe: $!";
    return (*READER, *WRITER);
} 

sub enqueue(*$) {
    my ($stream, $n) = @_;
    syswrite($stream, pack("L", $n), 4);  # XXX: errno
} 

sub dequeue(*) {
    my ($stream) = @_;
    my $n;
    sysread($stream, $n, 4) == 4 || return;
    unpack("L", $n);
} 
-- 
    Dimensions will always be expressed in the least usable term.
    Velocity, for example, will be expressed in furlongs per fortnight.


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

Date: 8 Jun 1998 15:02:46 -0600
From: snowhare@xmission.xmission.com (Snowhare)
Subject: Re: Why is there no "in" operator in Perl?
Message-Id: <6lhjhm$44h$1@xmission.xmission.com>



Nothing above this line is part of the signed message.

Apologies if this shows up twice. The server I was posting it on has
'hiccuped'. The post I made there didn't _appear_ to have gone out,
so here it is from a slightly more reliable server.

In article <6lh89c$9ga$1@client3.news.psi.net>,
Abigail <abigail@fnx.com> wrote:
>Snowhare (snowhare@xmission.xmission.com) wrote on MDCCXLII September
>MCMXCIII in <URL: news:6lh3sd$6d4$1@xmission.xmission.com>:
>++ In article <6lgsuk$5k7$1@client3.news.psi.net>,
>++ Abigail <abigail@fnx.com> wrote:
>++ >
>++ >Building? What's the build when the array is given?
>++ 
>++ Naughty naughty. If you get to assume that your array is 'given' then I
>++ get to assume my hash is 'given' as well. Then the comparision becomes 
>++ S O(N) vs T and the hash wins _all_ the time for large enough N. Data
>++ structures do not come from nowhere. 
>
>This thread started with the question:
>
>    Am I missing something or does Perl lack the ability to check if
>    something is part of a list,
>    <3576f315.106536561@news.mindspring.com>
>
>That looks to me the list is already there, but the hash isn't.

That doesn't mean you get to neglect the construction time.
The 'list' (and there is a certain amount of semantic ambiguity
in this context as to whether the author strictly meant a
array) had to be built. If you were going to assemble a
set of elements - you would put them into the most efficient
structure available for what you intend to use it for. Since
we _don't know_ the entire intended usage, there is no reason
to assume that it _must_ be an array vice a hash initially.

I could just as validly claim that his 'list' is originally
a hash and you now have to copy its keys into an array.

But that isn't a fair test because then I would be factoring
out the creation time for the hash while forcing you to include
it for the array.

[...]

>As for array lookups, yes they require in general a multiplication.
>But how do you think hash keys and values are stored?

Point.

>++ My _instinct_ says that _most_ of the time, for a single search, with
>++ perfectly optimized array search and hash functions and short variable
>++ strings, the array search will win for a single search.
>
>Which is what I was claiming.

Note the qualification: 'My _instinct_'. That says that I suspect
its truth but haven't proved it. This is a red flag for something 
that should be investigated further.

[...]

>++ swallowed by it) or degenerate cases like lists of identically sized
>++ 200000 character strings differing only in their final 10 positions.
>
>
>And don't forget the phases of the moon!
>
>
>#!/usr/local/bin/perl -w
>
>use strict;
>use Benchmark;
>
>my @array = map {my $str = '';
>                 foreach (1 .. 2 + int rand (5) + int rand (5)) {
>                    $str .= chr (int rand 256);
>                 }
>                 $str} 1 .. 5000;
>
>my $q = '';
>foreach (1 .. 2 + int rand (5) + int rand (5)) {$q .= chr (int rand 256);}
>
>
>timethese 1000, {
>    'in'   =>  sub {foreach (@array) {return 1 if $_ eq $q}},
>    'hash' =>  sub {my %hash; @hash {@array} = (); exists $hash {$q} ? 1 : 0}
>};
>
>__END__
>Benchmark: timing 1000 iterations of hash, in...
>      hash: 103 secs (84.21 usr  0.18 sys = 84.39 cpu)
>        in: 49 secs (38.49 usr  0.07 sys = 38.56 cpu)

Bad benchmark. Its performance will vary _a lot_ from run to 
run because $q is not reassigned during each test. So you could pick
a value that during one run would finish on $array[0] (*REALLY*
fast) and the next run could pick a value that would finish on 
$array[$#array] (*REALLY* slow) for all 1000 iterations.
You should have chosen the value at the mid-point of the array to 
get the average case.  And you compared apples and oranges by making 
the hash get rebuilt everytime while factoring the array build out of 
the loop. 

Here is an improved one that demonstrates just how much difference
factoring out the builds makes (as well as demonstrates the
importance of picking the right implementation and benchmark
methodology to prevent comparing apples and oranges):

#!/usr/local/bin/perl -w

use strict;
use Benchmark;

my @array = map {my $str = '';
                 foreach (1 .. 2 + int rand (5) + int rand (5)) {
                    $str .= chr (int rand 256);
                 }
                 $str} 1 .. 5000;

my ($q) = $array[2500];
my (%hash);
@hash{@array} = ();

timethese 1000, {
    'in2'   =>  sub {grep($q eq $_,@array) ? 1 : 0},
    'hash2' =>  sub {exists $hash {$q} ? 1 : 0},
    'in1'   =>  sub {my @newarray; @newarray = @array; grep($q eq $_,@newarray) ? 1 : 0 },
    'hash1' =>  sub {my %newhash; @newhash {@array} = (); exists ($newhash {$q}) ? 1 : 0},
    'in0'   =>  sub {my @newarray; @newarray = @array; foreach (@newarray) {return 1 if $_ eq $q}},
    'hash0' =>  sub {my %newhash; @newhash {@array} = (); exists $newhash {$q} ? 1 : 0},
    'in'   =>  sub {foreach (@array) {return 1 if $_ eq $q}},
    'hash' =>  sub {my %newhash; @newhash {@array} = (); exists $newhash {$q} ? 1 : 0}
 };

__END__

Benchmark: timing 1000 iterations of hash, hash0, hash1, hash2, in, in0, in1, in2...
      hash: 42 secs (40.78 usr  0.01 sys = 40.79 cpu)
     hash0: 42 secs (40.77 usr  0.04 sys = 40.81 cpu)
     hash1: 41 secs (40.56 usr  0.01 sys = 40.57 cpu)
     hash2:  0 secs ( 0.02 usr  0.00 sys =  0.02 cpu)
            (warning: too few iterations for a reliable count)
        in:  7 secs ( 7.08 usr  0.00 sys =  7.08 cpu)
       in0: 42 secs (40.88 usr  0.04 sys = 40.92 cpu)
       in1: 45 secs (44.73 usr  0.02 sys = 44.75 cpu)
       in2: 11 secs (11.29 usr  0.00 sys = 11.29 cpu)

The build times actually *favor* the hash over the array
 - slightly - and the build time appears to take MORE time
than the search itself does by a large factor: Thus my original
concern about neglecting the build time when considering the 
performance of a single search was justified. It appears that, 
on average, it *IS* faster (just barely), even for just one search, 
to build the hash and lookup the result than to build the array and 
search it.

It seems the phase of the moon doesn't favor arrays today.

Benjamin Franz
"Damn it. Do you realize I had to upgrade my Perl from 5.003 to run 
these benchmarks? ;-)"


Version: 2.6.2

iQCVAwUBNXxRV+jpikN3V52xAQGAqgQArYgCq8SJZ8jTJJTpTIAShG8W/6gFPiCQ
/G8YJh5zcFJP63xJgQcqFZ3O9xUERRhWHjY8Es6UYQdOAPI/flRTxOBNHmv2b9Pk
bcq1E7KBWdtCALNuTU+bsUirHVOZlZgPL4x8ht/EE3PdFAaV7iTGPE6eQ266peNS
1OFgaveehbY=
=gP62
-----END PGP SIGNATURE-----


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.  

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 2816
**************************************

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