[11331] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4931 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 18 13:07:20 1999

Date: Thu, 18 Feb 99 10:00:25 -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, 18 Feb 1999     Volume: 8 Number: 4931

Today's topics:
    Re: Anybody get .pl scripts to run on Win32 Perl and Ap <vamp71@freemail.gr>
    Re: Anybody get .pl scripts to run on Win32 Perl and Ap <joec@impacttech.com>
    Re: Anybody get .pl scripts to run on Win32 Perl and Ap <Allan@due.net>
    Re: Anybody get .pl scripts to run on Win32 Perl and Ap <camerond@mail.uca.edu>
        DEMO: new qr// operator <tchrist@mox.perl.com>
    Re: DOC: perlopentut.pod for 5.005_55 (Bart Lateur)
        FAQ 5.18: Why can't I just open(FH, ">file.lock")?   <perlfaq-suggestions@perl.com>
        FAQ 5.20: How do I randomly update a binary file?   <perlfaq-suggestions@perl.com>
    Re: FAQ 5.6: How can I make a filehandle local to a sub <tchrist@mox.perl.com>
    Re: Help a new Perl student Please <hcranc@hcranches.com>
    Re: Help with a simple problem <ophir@saifun.com>
        help! navigating URLs in Perl (Gord Barentsen)
        Help: Install ActivePerl on NT 4.0 <Tong.Liu@MCI.COM>
    Re: Matching for a null string (Larry Rosler)
    Re: Matching for a null string <dboorstein@ixl.com>
    Re: MYSQL, PERL AND PWS <vamp71@freemail.gr>
    Re: print: location not working? <vrwaciuk@sprint.ca>
    Re: Problem passing arrays and hashes to subroutines. <tchrist@mox.perl.com>
        Problem sending e-mails <ughridk@bbbhotmail.com>
        RECIPE: Unpublished Tales from the PCB, 2 of 2 <tchrist@mox.perl.com>
        running through proxy? <arudnick@inet.net>
        SRC: lockarea -- use fcntl for region locking <tchrist@mox.perl.com>
        SSI question? <GuoY@battelle.org>
    Re: String Manipulation (yet another newbie question) (Bart Lateur)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 19 Feb 1999 08:28:06 +0200
From: "John Chronakis" <vamp71@freemail.gr>
Subject: Re: Anybody get .pl scripts to run on Win32 Perl and Apache 1.3.3. &#$%*Damn MS Windoze file associations.
Message-Id: <7ahhjg$7ci$1@ns1.otenet.gr>

If the shebang you are using is #!C:\pelr\bin\
then it does not working for sure and it shouldn't be.
You must provide the executable name too (aka perl.exe)
Use    #!C:\pelr\bin\perl.exe
or       #!C:/pelr/bin/perl.exe
Whichever you want.

The file associations are not usufull to apache at all.

John


Rod MacBain wrote in message <36cb7eff.4040385@allnews.nbnet.nb.ca>...
>Here's the thing - I've had the Win32 apache 1.3.3 server running for
>a while and it serves standard HTML no problem. All my perl scripts
>run fine if I run them from the command line like (perl.exe hello.pl)
>but I can't get seem to get  the files to associate properly. Am I
>missing something? I've got the shebang setup properly to
>#!C:\pelr\bin\ and I've done the standard windoze file association
>thing and setup the .pl extension to run with C:\perl\bin\perl.exe %1
>%* as per the activestate documentation but I can't run a perl file
>directly from the explorer. So obviously I can't get anything to run
>by POSTing it input from the server since I can't even get it to
>"hello world" properly by running it from the command line. Has
>anybody got the file associations to work properly it a Win95 and
>Perl 5 environment? How do you do it?
>
>Much more of this and I'm loading RedHat.
>
>
>Thanks
>Rod




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

Date: Thu, 18 Feb 1999 10:39:20 -0600
From: "Joseph Henry Chambers" <joec@impacttech.com>
Subject: Re: Anybody get .pl scripts to run on Win32 Perl and Apache 1.3.3. &#$%*Damn MS Windoze file associations.
Message-Id: <7ahfo5$un$1@ash.prod.itd.earthlink.net>

> ...
>Better yet, search DejaNews because this comes up all the time.  Apache
does
>not come ready to run CGI out of the box, you must change the
configuration.

>...

This is not currently true.

I installed apache and with its default settings was running cgi-scripts
with perl inside of 45 minutes (that included the Perl and the Apache
downloads and installations.  I did not have to do any apache associations.
My Windows NT associations sufficed for the Perl side.


Thanks,

Joe Chambers






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

Date: Thu, 18 Feb 1999 12:56:30 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Anybody get .pl scripts to run on Win32 Perl and Apache 1.3.3. &#$%*Damn MS Windoze file associations.
Message-Id: <7ahjti$j8h$1@camel0.mindspring.com>

Joseph Henry Chambers wrote in message
<7ahfo5$un$1@ash.prod.itd.earthlink.net>...
:> ...
:>Better yet, search DejaNews because this comes up all the time.  Apache
:does
:>not come ready to run CGI out of the box, you must change the
:configuration.
:
:>...
:
:This is not currently true.
:
:I installed apache and with its default settings was running cgi-scripts
:with perl inside of 45 minutes (that included the Perl and the Apache
:downloads and installations.  I did not have to do any apache associations.
:My Windows NT associations sufficed for the Perl side.
:


1.3.3?  Really?  You didn't have to modify the .conf files?  Fascinating,
that is going to make my life easier.

AmD






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

Date: Thu, 18 Feb 1999 11:37:10 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
To: Rod MacBain <darcys@.nbnet.nb.ca>
Subject: Re: Anybody get .pl scripts to run on Win32 Perl and Apache 1.3.3.  &#$%*Damn MS Windoze file associations.
Message-Id: <36CC4FC6.27262A8A@mail.uca.edu>

[cc'd to rmb]

Rod MacBain wrote:
> 
> [snip]
>  Thanks everyone. I was trying to run it from the windows explorer,
> you know click the file name and have it run - to test if Win95 knew
> what to do with a .pl file. Turns out it didn't, even with my path set
> properly. I've since learned that out the proper association
> perameters are OPEN perl.exe "%1". I guess I left out the quotes and
> the %* that active state tells you to use just don't work! There is
> nothing about the " " syntax in their doc's either. DOH! I've got
> apache running and script aliased and all of that stuff now; no small
> thanks to your help.

Close, but no see-gar. If I read your original post correctly, then the
script did run, and correctly. If the file association is done correctly
(and what ActiveState told you to do *IS* correct), then double-clicking
on the script name will make it run, but immediately upon finishing, the
DOS box closes. Due to the slow retinal pigments we were supplied with
as original equipment, the result disappeared before you "saw" it. In
order to have a DOS box with sufficient persistence to be useful, you
either have to run the DOS box from the taskbar or have a last line in
your script which waits for some input (which you don't really care
about, since as soon as you supply it, it will disappear). Take out the
quotes and put the %* back in, or you might have trouble down the road
with more complicated scripts.

> 
> As I re-read my message now I'm surprised that anyone bothered to
> help, It certainly sounds like a clueless newbie who needs to RTFM. To
> you guys who did, thanks a lot.

You're welcome.

> 
> Now if I could only get flock() working properly.

Not on Win95, never:

perlwin32faq5.html (from ActiveState, on your system)

Cameron
camerond@mail.uca.edu


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

Date: 18 Feb 1999 07:35:00 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: DEMO: new qr// operator
Message-Id: <36cc2514@csnews>

This shows how to use spiffy new qr// operator, with /i flag even.

    use 5.005;
    @popstates = qw(CO ON MI WI MN);
    @poppats   = map { qr/\b$_\b/i } @popstates;
    while ($line = <>) {
        for $patobj (@poppats) {
            print $line if $line =~ /$patobj/;
        }
    }

--tom
-- 
I might be able to shoehorn a reference count in on top of the numeric
value by disallowing multiple references on scalars with a numeric value,
 but it wouldn't be as clean.  I do occasionally worry about that. --lwall


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

Date: Thu, 18 Feb 1999 17:04:14 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: DOC: perlopentut.pod for 5.005_55
Message-Id: <36d2472c.8982489@news.skynet.be>

Tom Christiansen wrote:

>Subject: DOC: perlopentut.pod for 5.005_55

>perlopentut - the basics on opening things in Perl

POD files' filenames always used to be "8.3" compatible, e.g.
"perltoot.pod". I wonder why this has been dropped. In fact, I'm quite
unhappy about that. Even DOS boxes have seriously modern Perl ports now!

	Bart.


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

Date: 18 Feb 1999 07:45:56 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 5.18: Why can't I just open(FH, ">file.lock")?  
Message-Id: <36cc27a4@csnews>

(This excerpt from perlfaq5 - Files and Formats 
    ($Revision: 1.34 $, $Date: 1999/01/08 05:46:13 $)
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/perlfaq5.html
if your negligent system adminstrator has been remiss in his duties.)

  Why can't I just open(FH, ">file.lock")?

    A common bit of code NOT TO USE is this:

        sleep(3) while -e "file.lock";      # PLEASE DO NOT USE
        open(LCK, "> file.lock");           # THIS BROKEN CODE

    This is a classic race condition: you take two steps to do something
    which must be done in one. That's why computer hardware provides an
    atomic test-and-set instruction. In theory, this "ought" to work:

        sysopen(FH, "file.lock", O_WRONLY|O_EXCL|O_CREAT)
                    or die "can't open  file.lock: $!":

    except that lamentably, file creation (and deletion) is not atomic over
    NFS, so this won't work (at least, not every time) over the net. Various
    schemes involving link() have been suggested, but these tend to involve
    busy-wait, which is also subdesirable.

-- 
	QVIDQVID LATINE DICTVM SIT PROFVNDVM VIDITVR


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

Date: 18 Feb 1999 08:03:38 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 5.20: How do I randomly update a binary file?  
Message-Id: <36cc2bca@csnews>

(This excerpt from perlfaq5 - Files and Formats 
    ($Revision: 1.34 $, $Date: 1999/01/08 05:46:13 $)
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/perlfaq5.html
if your negligent system adminstrator has been remiss in his duties.)

  How do I randomly update a binary file?

    If you're just trying to patch a binary, in many cases something as
    simple as this works:

        perl -i -pe 's{window manager}{window mangler}g' /usr/bin/emacs

    However, if you have fixed sized records, then you might do something
    more like this:

        $RECSIZE = 220; # size of record, in bytes
        $recno   = 37;  # which record to update
        open(FH, "+<somewhere") || die "can't update somewhere: $!";
        seek(FH, $recno * $RECSIZE, 0);
        read(FH, $record, $RECSIZE) == $RECSIZE || die "can't read record $recno: $!";
        # munge the record
        seek(FH, -$RECSIZE, 1);
        print FH $record;
        close FH;

    Locking and error checking are left as an exercise for the reader. Don't
    forget them, or you'll be quite sorry.

-- 
    if (instr(buf,sys_errlist[errno]))  /* you don't see this */
        --Larry Wall in eval.c from the 4.0 perl source code


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

Date: 18 Feb 1999 07:45:57 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: FAQ 5.6: How can I make a filehandle local to a subroutine?  How do I pass filehandles between subroutines?  How do I make an array of filehandles?
Message-Id: <36cc27a5@csnews>

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

In comp.lang.perl.misc, bernie@fantasyfarm.com (Bernie Cosell) writes:
:}         sub findme {
:}             local *HostFile;
:}             open(HostFile, "</etc/hosts") or die "no /etc/hosts: $!";
:}             local $_;               # <- VERY IMPORTANT
:}             while (<HostFile>) {
:}                 print if /\b127\.(0\.0\.)?1\b/;
:}             }
:}             # *HostFile automatically closes/disappears here
:}         }
:
:Why do you have to localize $_?

Because I crunched it!  See that while loop?  While loops
do *NOT* localize $_, contrary to popular misbelief.
Only foreach loops, map, and grep do.  Not while.

--tom
-- 
"When you type to Unix, a gnome deep in the system is gathering your
characters and saving them in a secret place."  - Unix 6th edition manual


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

Date: Thu, 18 Feb 1999 10:33:34 -0700
From: Mickey Todd <hcranc@hcranches.com>
Subject: Re: Help a new Perl student Please
Message-Id: <36CC4EED.70282FC6@hcranches.com>

Sounds like you have a similar problem as I did.  Mine deals with using Win95
and associated applications.  The Win95 registry "understands" certain file
types and associates file extensions to those file types and saves a "new" file
with a particular file extension.  I use WordPad to create my text files.  After
I save it the first time I have to go out to a DOS window and rename the file
correctly and then re-load it into WordPad.  Then everytime I save the file as a
Text Document it is saved with the correct file name.  I know this isn't the
"right" solution, but I haven't found out how to correct the initial problem.

"William M. Toohey" wrote:

> I am teaching myself to write CGI's in Perl from an otherwise great book.  I
> know this is an elementary question, but without this piece of information,
> I can do nothing.
>
> Simply, I know Perl is a free language, but where do I type in the perl code
> and how do I save it?
>
> I code HTML in MS Word and save as text only with a .htm extension.
> I code C++ in a compiler and compile and link the code.
> What is the equivelant in Perl?
>
> I tried writing the Perl Code in Word (named "first"), saving as text only
> with a .cgi extention.
> When I uploaded this to my server, it ended up being labeled "first.cgi.txt"
> If I can only get over this bump, the rest of the book seems well written,
> and the language itself seems rather easy for me to learn.  It just seems
> that everyone forgot to include this basic instruction.
>
> Thanking you all ahead of time for responses.
>
> I am at ceo@mptenterprises.com
>
> William M. Toohey



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

Date: Thu, 18 Feb 1999 10:49:10 +0200
From: Ophir Marko <ophir@saifun.com>
Subject: Re: Help with a simple problem
Message-Id: <36CBD406.E262F792@saifun.com>

# /local/perl/bin/perl -w
$file = <ARGV>;
open(MYFILE, ">$file");
split;
@lines = @_;

# And this is were I'm stuck. Like I said,
# It has to search for a word in a line(MOS)
# and then transfer the line with the word to
# a new file and copy the file to /home/ophir/backup/



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

Date: Thu, 18 Feb 1999 17:51:11 GMT
From: gpb@ppaolucci.com (Gord Barentsen)
Subject: help! navigating URLs in Perl
Message-Id: <36cc514a.11708929@news.the-wire.com>



	Hello,
	I am currently having a problem with a Perl script that asks
for userID and password and then, upon receiving correct validation,
goes directly to an order form.
	I need to push the client directly to the form page, but I
need to carry over a string of values in the Location line to be
harvested for populating text fields.  I have tried the CGI Location
header, i.e.

print "Location:
http://somewhere.com/perlscript.pl?name1=value1&name2=value2 etc.
etc., but it doesn't seem to want to work - it just displays the
string to the screen.

	Is there a Perl function that can be used to push to another
webpage/perl script that will carry name-value pairs over with it?  If
you reply, please reply to the list and to my email
(gpb@ppaolucci.com).  Thanks a lot!

Gord Barentsen




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

Date: Thu, 18 Feb 1999 17:11:17 GMT
From: "Tong Liu" <Tong.Liu@MCI.COM>
Subject: Help: Install ActivePerl on NT 4.0
Message-Id: <VQXy2.162$DG2.72144@PM01NEWS>

Hi:

I an trying to install ActivePerl (build 508/509) on NT server 4.0 with
service pack 3, I got the following error message during the installation:

"Failed to create PerlEz object in ConfigureComponents()"


Then  the NT (Dr. Watson for Windows NT) will generate another
error message:

"An application error has occurred and an application error log is being
generated
_INS0432_MP.exe
Exception: access violation (0xc0000005), address: 0x01131c29"


Then the installation will just abort

BTW, I installed Perl on the another machine with  NT server 4.0/service
pack before, it was OK.

Any help will be appreciated.


Thanks in advance,
Tong Liu
Sr. Consultant
MCI WorldCom










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

Date: Thu, 18 Feb 1999 09:01:30 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Matching for a null string
Message-Id: <MPG.1135e73b395e0d4f989a56@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <36CC320A.1429@eds.exsc01.exch.com> on Thu, 18 Feb 1999 
09:30:18 -0600, David W. Hundley <dave.hundley@eds.exsc01.exch.com> 
says...
> This seems like it ought to be a no-brainer (and maybe that's what I'm
> dealing with :^) ) but I'm unable to figure this out.  Anyone know how
> to either match for a null string or determine that a string is
> definitely not null?  I have tried the /.+?/ pattern (as well as several
> other variations) which would seem to perform the latter determiniation
> but it does not work.

You can do it with a regex, but you run into the problem of '$' matching 
before a new-line, so it gets slightly more complex.  But why bother 
with a regex?  Here are two other ways, which are cheaper and cleaner, 
IMO:

   length($string) == 0

   $string eq ""

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 18 Feb 1999 12:13:41 -0500
From: Dan Boorstein <dboorstein@ixl.com>
Subject: Re: Matching for a null string
Message-Id: <36CC4A45.6D300295@ixl.com>

if by null you mean either undefined or of zero-length then the
following might be of use:

$_ = '0';
unless (defined && length) {
  print 'null';
}
else {
  print 'not null';
}

you can do with out the 'defined' test since undefined strings have no
length, but i include it in case you (like i) run under '-w'.

cheers!

dan

"David W. Hundley" wrote:
> 
> This seems like it ought to be a no-brainer (and maybe that's what I'm
> dealing with :^) ) but I'm unable to figure this out.  Anyone know how
> to either match for a null string or determine that a string is
> definitely not null?  I have tried the /.+?/ pattern (as well as several
> other variations) which would seem to perform the latter determiniation
> but it does not work.
[SNIP]


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

Date: Fri, 19 Feb 1999 19:47:27 +0200
From: "John Chronakis" <vamp71@freemail.gr>
Subject: Re: MYSQL, PERL AND PWS
Message-Id: <7ahk9k$80n$1@ns1.otenet.gr>

Hi,
You 've come accross the same problem I had a few days ago
"
>But how to make them 'talk to each other' on PWS?
(mySQL and PERL)
>I know that this problem can be solved by installing
>Perl DBI...But how to install the DBI module on Windows?
"
MySQL DBI is not available as a binary for Win32 and my first attempt to
compile it with nmake (from Visual C++ 5) failed. I found two solutions for
the problem.

First. tcx has a binary zip file with perl 5.something with the DBI and
mySQL DBD already installed.
I haven't tried this because I have an already good installation of Avtive
State's perl and didn't want to mess it.

Second. You can take advandage of DBI's portability. (That's what I am doing
and it is great). If you have any other windows ODBC compliant database
(like MS Access) you can make an identical table of the one on the Unix
machine, populate it with some rows, and use it for testing your DBI perl
scripls. You will need for this the DBD:ODBC module. If you write strict
ANSI SQL statments, your scripts will work on the Unix enviroment and mySQL
by just changing three lines; The datasource, username and password
variables.

There is also a third solution but I haven't tried it. Find the compiler
that perl was built with and use the same to built the DBD mySQL module.

John

PS. If you have perl from Active State, the easiest way to install a module
is ppm. Read more in the documentation.





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

Date: Thu, 18 Feb 1999 12:48:57 -0500
From: "Vince Waciuk" <vrwaciuk@sprint.ca>
Subject: Re: print: location not working?
Message-Id: <xrYy2.41743$b8.17387427@hme2.newscontent-01.sprint.ca>

Try this:
#!/usr/bin/perl

$next_url = 'http://your.next_url.com';

print "Location: $next_url\nURI: $next_url\n\n";

1;

Curtiss Hammock wrote in message <36cb0192.14958390@nntp4.mindspring.com>...
>I'm trying to do a redirect, randomly sending one of four web pages. I
>think I've got the random part right, but the print: location thing
>isn't working right (unless I'm just misunderstanding it). I've
>searched high and low, and found lots of examples of why this should
>work. I must be missing something.
>
>Here's the page (index.shtml)  from which I call the script:





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

Date: 18 Feb 1999 08:10:22 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Problem passing arrays and hashes to subroutines.
Message-Id: <36cc2d5e@csnews>

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

In comp.lang.perl.misc, "James Oliver" <oliver.james.jh@bhp.com.au> writes:
:I have a question regarding passing both an array and a hash as the argument
:of a subroutine.
:
:Specifically I want to be able to perform something like this:
:
:sub
:my_sub
:{
:    my(%hash,@array) = @_;
:
:    # Function operations.
:}
:
:my_sub(%hash, @array);

You seem to have neglected to read the perlsub manpage, included standard
on your system.  I enclose the relevant sections.

Enjoy.

--tom

=head1 NAME

perlsub - Perl subroutines

=head1 DESCRIPTION

Like many languages, Perl provides for user-defined subroutines.  These
may be located anywhere in the main program, loaded in from other files
via the C<do>, C<require>, or C<use> keywords, or even generated on the
fly using C<eval> or anonymous subroutines (closures).  You can even call
a function indirectly using a variable containing its name or a CODE reference
to it.

The Perl model for function call and return values is simple: all
functions are passed as parameters one single flat list of scalars, and
all functions likewise return to their caller one single flat list of
scalars.  Any arrays or hashes in these call and return lists will
collapse, losing their identities--but you may always use
pass-by-reference instead to avoid this.  Both call and return lists may
contain as many or as few scalar elements as you'd like.  (Often a
function without an explicit return statement is called a subroutine, but
there's really no difference from the language's perspective.)

 ...

=head2 Pass by Reference

If you want to pass more than one array or hash into a function--or
return them from it--and have them maintain their integrity, then
you're going to have to use an explicit pass-by-reference.  Before you
do that, you need to understand references as detailed in L<perlref>.
This section may not make much sense to you otherwise.

Here are a few simple examples.  First, let's pass in several
arrays to a function and have it C<pop> all of then, return a new
list of all their former last elements:

    @tailings = popmany ( \@a, \@b, \@c, \@d );

    sub popmany {
	my $aref;
	my @retlist = ();
	foreach $aref ( @_ ) {
	    push @retlist, pop @$aref;
	}
	return @retlist;
    }

Here's how you might write a function that returns a
list of keys occurring in all the hashes passed to it:

    @common = inter( \%foo, \%bar, \%joe );
    sub inter {
	my ($k, $href, %seen); # locals
	foreach $href (@_) {
	    while ( $k = each %$href ) {
		$seen{$k}++;
	    }
	}
	return grep { $seen{$_} == @_ } keys %seen;
    }

So far, we're using just the normal list return mechanism.
What happens if you want to pass or return a hash?  Well,
if you're using only one of them, or you don't mind them
concatenating, then the normal calling convention is ok, although
a little expensive.

Where people get into trouble is here:

    (@a, @b) = func(@c, @d);
or
    (%a, %b) = func(%c, %d);

That syntax simply won't work.  It sets just C<@a> or C<%a> and clears
the C<@b> or C<%b>.  Plus the function didn't get passed into two separate
arrays or hashes: it got one long list in C<@_>, as always.

If you can arrange for everyone to deal with this through references,
it's cleaner code, although not so nice to look at.  Here's a function
that takes two array references as arguments, returning the two array
elements in order of how many elements they have in them:

    ($aref, $bref) = func(\@c, \@d);
    print "@$aref has more than @$bref\n";
    sub func {
	my ($cref, $dref) = @_;
	if (@$cref > @$dref) {
	    return ($cref, $dref);
	} else {
	    return ($dref, $cref);
	}
    }

It turns out that you can actually do this also:

    (*a, *b) = func(\@c, \@d);
    print "@a has more than @b\n";
    sub func {
	local (*c, *d) = @_;
	if (@c > @d) {
	    return (\@c, \@d);
	} else {
	    return (\@d, \@c);
	}
    }

Here we're using the typeglobs to do symbol table aliasing.  It's a tad
subtle, though, and also won't work if you're using C<my()> variables,
because only globals (well, and C<local()>s) are in the symbol table.

If you're passing around filehandles, you could usually just use the
bare typeglob, like C<*STDOUT>, but typeglobs references would be better
because they'll still work properly under S<C<use strict 'refs'>>.
For example:

    splutter(\*STDOUT);
    sub splutter {
	my $fh = shift;
	print $fh "her um well a hmmm\n";
    }

    $rec = get_rec(\*STDIN);
    sub get_rec {
	my $fh = shift;
	return scalar <$fh>;
    }

If you're planning on generating new filehandles, you could do this:

    sub openit {
	my $name = shift;
	local *FH;
	return open (FH, $path) ? *FH : undef;
    }

Although that will actually produce a small memory leak.  See the bottom
of L<perlfunc/open()> for a somewhat cleaner way using the C<IO::Handle>
package.
-- 
    I already have too much problem with people thinking the efficiency of
    a perl construct is related to its length.  On the other hand, I'm
    perfectly capable of changing my mind next week...  :-) --lwall


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

Date: Thu, 18 Feb 1999 12:51:07 -0500
From: "Professeur Alfred" <ughridk@bbbhotmail.com>
Subject: Problem sending e-mails
Message-Id: <tqYy2.89$KK4.232@weber.videotron.net>

I'm making a cgi script with perl which sends e-mail from a Unix server
using Sendmail. I saw that sometimes, e-mails are lost. So, I would like to
be able to verify if my message is gone.

Does somebody know how my script can receive a confirmation from Sendmail
that the e-mail is well gone or if Sendmail can send some error messages
that my Perl script can manage?

Thank you!

Stephane Gauthier

If you want to answer me by e-mail remove the bbb from my address:
ughridk@bbbhotmail.com





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

Date: 18 Feb 1999 07:41:00 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: RECIPE: Unpublished Tales from the PCB, 2 of 2
Message-Id: <36cc267c@csnews>

Here's another hitherto unpublished recipe.

All measurements listed below should be considered mere guidelines, as I
never measure anything, and didn't prepare it that way.  In short, I'm
just guessing.  Let good taste be your guide.

This is a very hot (in the "picante" rather than the "caliente" sense)
dish, but you can vary its heat.  See the WARNING at the end.  

GREEN TROPICAL CURRY (THAI STYLE)

This will serve enough for 4 ravenously hungry, highly active young men,
or else 6 or more normal humans if you adjust the rice accordingly.  Serve
with a chilled white wine or fresh fruit juice, and plenty of ice water.

    This dish is extremely nutritious, and will easily fulfil your day's
    requirements of fiber, protein, and number and variety of required
    vegetable servings when prepared as directed.  It is extremely
    low in fat -- except for the small amounts of peanuts used (which
    is optional) and the coconut milk, which you really don't want to
    leave out due to its essential flavor; you may, but it's a different
    dish then.  Don't worry too much about the small amount fat (that
    each person would receive) in it -- recent research suggests that
    the chains aren't as hard for the body to deal with as saturated
    fat from animals.  In any event, you won't end up getting very much
    fat from this per serving anyway.  This is essentially a dairy-free
    vegetarian (vegan) dish -- *except* for the nam pla (fish sauce),
    ubiquitous in certain forms of Asian cooking.  If this bothers you,
    feel free to leave it out entirely, or use one of the substitute
    recipes for it occasionally posted to the net.

[ Items marked with a (*) are probably most easily acquired in an Asian
  market.  They are not considered optional, as they convey unique
  flavors, but don't sweat it if you can't get them. ]

Step 0: Start the rice cooking.  It will take 45 minutes.

    3 cups or so rice (enough for everyone to have more rice than food);
	I prefer to use black rice (*) for this, or else you can use
	brown rice.  You may use white rice (jasmine rice is both nice and
	traditional) if you want, although you do lose the fiber benefits
	of the whole grain -- adjust cooking times appropriately if so,
	as white rice doesn't take as long.

Step 1: combine the following in a very large, deep frying pan, 
	stir thoroughly, and heat through:

    4 cups (or so) hot mango sauce [recipe follows this one]

    1  T freshly ground coriander seed 
    1  T freshly ground cumin seed (cominos)
    2+ T freshly ground galanga root (*) or 1 T dried 
	 powder of the same (also called "laos" or "kha") 
    2+ T fresh ginger root, cut into longish slivers 
    6-8  lime leaves, preferably kaffir lime (*) 
    1 14-oz can of coconut milk, 1 can of water
    4 T tamari or soy sauce (or more to taste)
    2 T nam pla (fish sauce) [OPTIONAL] (*) (or more to taste)


Step 2: add the following and cook only until brightly colored and crispy:

    Lots of assorted, fresh vegetables, such as:
	brocolli
	zucchini
	sweet peppers or mild chiles (red preferred in both cases)
	red and/or green onion
	shitake or cloud ear mushrooms
	water chestnuts
	bamboo shoots
	snow peas
	green peas
	carrots
	etc.

	(I used the first six tonight; what important here is to vary the
	 colors and textures involved, but green should dominate with
	 bits of red and/or orange added for a nice effect.)

Step 3: one to two minutes before serving, add these:

    1 large bunch fresh basil [holy or thai basil (*) preferred],
	chopped coursely
    1/2 bunch fresh cilantro, chopped coursely

Step 4: spread over rice on plates, then serve with 

    chopped dry-roasted peanuts to sprinkle at will [OPTIONAL]
    extra sprigs of cilantro for garnish on side



HOT MANGO SAUCE

This will probably make more than you need for the preceding curry.
Save whatever you don't use, for it is an excruciatingly delicious sauce,
suitable for dipping vegetables or tortilla chips, as enchilada sauce,
in cool summer salads, or atop grilled fish or poultry.

    4 T dry-roasted peanuts
    3 T nam pla (*) [OPTIONAL]
    1 T dark sesame oil (chile sesame oil ok) [OPTIONAL]
    juice of one lime, freshly squeezed
    1 large head garlic, peeled (or 2 small heads)
    1 quite large chunk of ginger root, peeled (maybe 6 T?)
    3 habanero or 5-6 thai or 8-9 serrano or jalapen~o chiles [SEE BELOW]
    4-6 tomatillos
    skinned pieces of 6-8 ripe mangos and/or 10-12 papayas 
    2 T sugar or honey (if using fresh fruit not packed in light syrup)
    1/2 bunch (or more) fresh cilantro 

Put these in a blender in the order listed, waiting to add the next
ingredient until the previous one is thoroughly blended.  The end
product should be a smooth, slighly greenish puree, the green mainly
from the cilantro.  This should make 4-6 cups.

			   <*** WARNING ***>
    Be very careful dealing with chiles.  These are serious stuff.
    Seed and remove membrane to decrease hotness, but leave them in
    if you like more of it.  Very few restaurants will make a sauce
    as hot as this one even if you beg them.  While it is conceivable
    that some folks addicted to the rush of the chiles might even want
    a 4th habanero, if you don't normally just die for very hot food,
    cut the number of chiles in half or maybe even down to just one
    third of what's listed there; just don't leave them out altogether.
    The habaneros, while having a delightful flavor, are incredibly
    potent: love and fear them; Never touch any chiles' cut flesh to
    your hands, lest you later touch eyes, lips, nose, or other sensitive
    membranes; consider wearing gloves when dealing with them.	IMPORTANT:
    Do *NOT* poke your face in the blender after the step with the chiles;
    they release capsaicin (the hot stuff) into the air, and you'll get
    it in your eyes and lungs if you aren't quite careful for this stage.

-- 
    "What is the sound of Perl?  Is it not the sound of a wall that
     people have stopped banging their heads against?"
		--Larry Wall in <1992Aug26.184221.29627@netlabs.com>


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

Date: Thu, 18 Feb 1999 12:40:51 -0500
From: "Adam Rudnick" <arudnick@inet.net>
Subject: running through proxy?
Message-Id: <36cc5279.0@news.inet.net>

Is there a way to go through a proxy when pulling content from the web with
perl?




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

Date: 18 Feb 1999 08:03:37 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: SRC: lockarea -- use fcntl for region locking
Message-Id: <36cc2bc9@csnews>


#!/usr/bin/perl -w
# lockarea - demo record locking with fcntl

use strict;

my $FORKS = shift || 1;
my $SLEEP = shift || 1;

use Fcntl;
use POSIX qw(:unistd_h :errno_h);

my $COLS = 80;
my $ROWS = 23;

# when's the last time you saw *this* mode used correctly?
open(FH, "+> /tmp/lkscreen")            or  die $!;

select(FH);
$| = 1;
select STDOUT;

# clear screen
for (1..$ROWS) {
    print FH " " x $COLS, "\n";
}

my $progenitor = $$;
fork while $FORKS-- > 0;

print "hello from $$\n";

if ($progenitor == $$) {
    $SIG{INT} = \&genocide;
} else {
    $SIG{INT} = sub { die "goodbye from $$" };
}

while (1) {
    my $line_num = int rand($ROWS);
    my $line;
    my $n;

    # move to line
    seek(FH, $n = $line_num * ($COLS+1), SEEK_SET)              or next;

    # get lock
    my $place = tell(FH);
    my $him;
    next unless defined($him = lock(*FH, $place, $COLS));

    # read line
    read(FH, $line, $COLS) == $COLS                             or next;
    my $count = ($line =~ /(\d+)/) ? $1 : 0;
    $count++;

    # update line
    seek(FH, $place, 0)                                         or die $!;
    my $update = sprintf($him
			? "%6d: %d ZAPPED %d"
			: "%6d: %d was just here",
		    $count, $$, $him);
    my $start = int(rand($COLS - length($update)));
    die "XXX" if $start + length($update) > $COLS;
    printf FH "%*.*s\n", -$COLS, $COLS, " " x $start . $update;

    # release lock and go to sleep
    unlock(*FH, $place, $COLS);
    sleep $SLEEP if $SLEEP;
}
die "NOT REACHED";				# just in case

# lock($handle, $offset, $timeout) - get an fcntl lock
sub lock {
    my ($fh, $start, $till) = @_;
    ##print "$$: Locking $start, $till\n";
    my $lock = struct_flock(F_WRLCK, SEEK_SET, $start, $till, 0);
    my $blocker = 0;
    unless (fcntl($fh, F_SETLK, $lock)) {
	die "F_SETLK $$ @_: $!" unless $! == EAGAIN || $! == EDEADLK;
	fcntl($fh, F_GETLK, $lock)          or die "F_GETLK $$ @_: $!";
	$blocker = (struct_flock($lock))[-1];
	##print "lock $$ @_: waiting for $blocker\n";
	$lock = struct_flock(F_WRLCK, SEEK_SET, $start, $till, 0);
	unless (fcntl($fh, F_SETLKW, $lock)) {
	    warn "F_SETLKW $$ @_: $!\n";
	    return;  # undef
	}
    }
    return $blocker;
}

# unlock($handle, $offset, $timeout) - release an fcntl lock
sub unlock {
    my ($fh, $start, $till) = @_;
    ##print "$$: Unlocking $start, $till\n";
    my $lock = struct_flock(F_UNLCK, SEEK_SET, $start, $till, 0);
    fcntl($fh, F_SETLK, $lock) or die "F_UNLCK $$ @_: $!";
}

# OS-dependent flock structures

# Linux struct flock
#   short l_type;
#   short l_whence;
#   off_t l_start;
#   off_t l_len;
#   pid_t l_pid;
BEGIN {
    # c2ph says: typedef='s2 l2 i', sizeof=16
    my $FLOCK_STRUCT = 's s l l i';

    sub linux_flock {
	if (wantarray) {
	    my ($type, $whence, $start, $len, $pid) =
		unpack($FLOCK_STRUCT, $_[0]);
	    return ($type, $whence, $start, $len, $pid);
	} else {
	    my ($type, $whence, $start, $len, $pid) = @_;
	    return pack($FLOCK_STRUCT,
		    $type, $whence, $start, $len, $pid);
	}
    }

}

# SunOS struct flock:
#   short   l_type;         /* F_RDLCK, F_WRLCK, or F_UNLCK */
#   short   l_whence;       /* flag to choose starting offset */
#   long    l_start;        /* relative offset, in bytes */
#   long    l_len;          /* length, in bytes; 0 means lock to EOF */
#   short   l_pid;          /* returned with F_GETLK */
#   short   l_xxx;          /* reserved for future use */
BEGIN {
    # c2ph says: typedef='s2 l2 s2', sizeof=16
    my $FLOCK_STRUCT = 's s l l s s';

    sub sunos_flock {
	if (wantarray) {
	    my ($type, $whence, $start, $len, $pid, $xxx) =
		unpack($FLOCK_STRUCT, $_[0]);
	    return ($type, $whence, $start, $len, $pid);
	} else {
	    my ($type, $whence, $start, $len, $pid) = @_;
	    return pack($FLOCK_STRUCT,
		    $type, $whence, $start, $len, $pid, 0);
	}
    }

}

# (Free)BSD struct flock:
#   off_t   l_start;        /* starting offset */
#   off_t   l_len;          /* len = 0 means until end of file */
#   pid_t   l_pid;          /* lock owner */
#   short   l_type;         /* lock type: read/write, etc. */
#   short   l_whence;       /* type of l_start */
BEGIN {
    # c2ph says: typedef="q2 i s2", size=24
    my $FLOCK_STRUCT = 'll ll i s s';   # XXX: q is ll

    sub bsd_flock {
	if (wantarray) {
	    my ($xxstart, $start, $xxlen, $len, $pid, $type, $whence) =
		unpack($FLOCK_STRUCT, $_[0]);
	    return ($type, $whence, $start, $len, $pid);
	} else {
	    my ($type, $whence, $start, $len, $pid) = @_;
	    my ($xxstart, $xxlen) = (0,0);
	    return pack($FLOCK_STRUCT,
		$xxstart, $start, $xxlen, $len, $pid, $type, $whence);
	}
    }
}

# alias the fcntl structure at compile time
BEGIN {
    for ($^O) {
	*struct_flock =                do                           {

				/bsd/  &&  \&bsd_flock
				       ||
			    /linux/    &&    \&linux_flock
				       ||
			  /sunos/      &&      \&sunos_flock
				       ||
		  die "unknown operating system $^O, bailing out";
	};
    }
}

# install signal handler for children
BEGIN {
    my $called = 0;

    sub genocide {
	exit if $called++;
	print "$$: Time to die, kiddies.\n" if $$ == $progenitor;
	my $job = getpgrp();
	$SIG{INT} = 'IGNORE';
	kill -2, $job if $job;  # killpg(SIGINT, job)
	1 while wait > 0;
	print "$$: My turn\n" if $$ == $progenitor;
	exit;
    }

}

END { &genocide }
-- 
Your csh still thinks true is false.  Write to your vendor today and tell
them that next year Configure ought to "rm /bin/csh" unless they fix their
blasted shell. :-)   --Larry Wall in Configure from the perl distribution


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

Date: Thu, 18 Feb 1999 08:56:47 -0800
From: "Guo, Yongping" <GuoY@battelle.org>
Subject: SSI question?
Message-Id: <AEC6D63C67CED011BDFF00609720F64A01D0F837@PNLMSE0.pnl.gov>

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01BE5B5F.ABE4D8F8
Content-Type: text/plain

Hi,

I have a question about the SSI include:
Is it possible to call a Perl script from outside of the local server?
If yes, how?

I have a simple counter in /class-cgi-bin/guo directory. If I call it
from
my local webpage like <!--#exec cgi="/class-cgi-bin/guo/count.pl"-->, it
will
work. But if I change it to
<!--#exec cgi="http://cs.franklin.edu/class-cgi-bin/guo/count.pl"-->,
it give me an error for access the directory.(cs.franklin.edu is the
server)

Any help is appreciated!

Bryan

------_=_NextPart_001_01BE5B5F.ABE4D8F8
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3DUS-ASCII">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2410.0">
<TITLE>SSI question?</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2 FACE=3D"Arial">Hi,</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">I have a question about the SSI =
include:</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Is it possible to call a Perl script =
from outside of the local server? If yes, how?</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">I have a simple counter in =
/class-cgi-bin/guo directory. If I call it from</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">my local webpage like &lt;!--#exec =
cgi=3D&quot;/class-cgi-bin/guo/count.pl&quot;--&gt;, it will</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">work. But if I change it to</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&lt;!--#exec cgi=3D&quot;<A =
HREF=3D"http://cs.franklin.edu/class-cgi-bin/guo/count.pl" =
TARGET=3D"_blank">http://cs.franklin.edu/class-cgi-bin/guo/count.pl</A>&=
quot;--&gt;,</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">it give me an error for access the =
directory.(cs.franklin.edu is the server)</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Any help is appreciated!</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Bryan</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01BE5B5F.ABE4D8F8--



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

Date: Thu, 18 Feb 1999 16:59:35 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: String Manipulation (yet another newbie question)
Message-Id: <36d142b5.7839445@news.skynet.be>

Uri Guttman wrote:

>  TM>    index($field, '_1') >= $[
>
>the use of $[ is deprecated. you shouldn't rely on its existance. perl
>uses zero based indexing for arrays and strings.

!!!

I think it should exist FOREVER. Backward compatibilityn, you know the
drill. It is deprecated to *change* it, however. You preferably should
always use the default value for it (= 0).

	Bart.


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

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

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