[9884] in Perl-Users-Digest
Perl-Users Digest, Issue: 3477 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 18 18:07:27 1998
Date: Tue, 18 Aug 98 15:00:20 -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 Tue, 18 Aug 1998 Volume: 8 Number: 3477
Today's topics:
Re: Another invocation problem (_does_ seem to be a per <chuckp@SiTera.com>
Re: can "foreach ..." and "while ..." share loop contro <Robert.Lopez@abq.sc.philips.com>
Re: can perl be compiled into EXE format? (Andrew M. Langmead)
Re: Filehandle associated file name (Andrew M. Langmead)
Re: filehandle in CGI.pm (I.J. Garlick)
Re: here's an implementation of diff in perl (Abigail)
IIS, Perl: Coping with signals in CGI. (Andrew Haveland-Robinson)
Multi-proc/multi-thread support in Perl/Unix <james@js.prysm.net>
Re: Multi-proc/multi-thread support in Perl/Unix (Greg Bacon)
mv, move, or some way to move files in perl (Thomas Frederick O'Connell)
Re: pattern matching with uc and lc (Andrew M. Langmead)
Re: print "Content-type:text/html\n\n"; and redirection (I.J. Garlick)
reference to anonymous scalar? <Brett.W.Denner@lmco.com>
Re: reference to anonymous scalar? (Kelly Hirano)
Re: reference to anonymous scalar? <jdf@pobox.com>
Re: reference to anonymous scalar? (Greg Bacon)
Re: reference to anonymous scalar? <jdf@pobox.com>
regular expression. Help !!!! nguyen.van@imvi.bls.com
Re: request for comments... (M.J.T. Guy)
Re: socket client on Windows 95 machine <dcameron@bcs.org.uk>
Re: test post -- please ignore (Greg Bacon)
Testing for input <hamiltaj@cray.com>
Re: Testing for input (Greg Bacon)
Re: Why dont people read the FAQs <alan@find-it.furryferret.uk.com>
Re: Yet another invocation line mystery (does seem to b <hansmu@xs4all.nl>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Aug 1998 21:13:29 GMT
From: Chuck Phillips <chuckp@SiTera.com>
Subject: Re: Another invocation problem (_does_ seem to be a perl problem!)
Message-Id: <35D9C89D.89A2E622@SiTera.com>
Quentin Fennessy wrote:
> From perlrun(1):
> #!/bin/sh -- # -*- perl -*- -p
> eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
> if $running_under_some_shell;
>
> to let Perl see the B<-p> switch.
This doesn't always work. It happens to work on Solaris 2.6 -- depending
on what patches you have installed, but it doesn't work on HPUX 10.20 or
Redhat 5.x. (It used to not work on our Solaris 2.6 box, but now it does.)
On HPUX 10.20 I get:
-- # -*- perl -*- -p: A specified flag is not valid for this command.
On Redhat 5.x I get:
sh: --: bad option
There *is* a bug -- in the perlrun man page. Until it's fixed, we will
periodically get deserved complaints from people who try it and fail. Here
is another kludge that happens to work a lot more often. It doesn't
require that SHELL environment variable be set to anything you wouldn't
normally use.
Please also note that the use of "if $running_under_some_shell" causes a
spurious warning if "-w" is one of the flags you want used. "if 0" is
better.
----------------8<----------------8<----------------8<----------------
exec perl -Sx $0 ${1+"$@"} # -*-perl-*-
#!perl -w
print STDOUT "$a howdy!\n"; # Something Perl -w specific.
----------------8<----------------8<----------------8<----------------
Anyone else proposing an alternative, please use the above "print" line to
verify "-w" and "$0" are working as expected. The "-*-perl-*-" is a hint
to emacs about the type of file. Note that the second line could be:
#!/Any/Path/You/Want/perl -w
Basically, you can take any perl script and prepend the above "exec" line
to have PATH searched for the perl executable and the flags to perl
observed. I reported the bug in the perlrun man page, gave an explanation
why and an alternative, and got no response. (I'm including a copy of my
email below.) I'd be happy to update the perlrun man page if allowed to do
so.
Hope this helps,
Chuck Phillips chuckp@SiTera.com
P.S. Following is a copy of what I sent to perlbug in May containing a more
detailed explanation. The work-around in perlrun(1) didn't used to work on
our Solaris 2.6 machine back then -- although it appears to now. (I've
installed patches since then.) Also, you can invoke the script with "perl
myscript" from the command line *if* you insert "if 0;" between lines one
and two. Better, invoke it via "perl -x myscript" to get the flags
intended by the script.
----------------8<----------------8<----------------8<----------------
>From chuckp Mon May 4 16:07:39 1998
Date: Mon, 4 May 98 16:07:39 MDT
>From: Chuck Phillips <chuckp@muon.fusionmm.com>
To: perlbug@perl.com
Cc: rwp@fc.hp.com
Subject: perlrun(1): #!/bin/sh -- # -*- perl -*- (long)
X-Location: Longmont, Colorado, USA
Synopsis:
1. The "#!/bin/sh -- # -*- perl -*-" construct mentioned in perlrun(1)
doesn't work on HPUX 10.20, Solaris 2.6 or Redhat 5 Linux with the
2.0.32 kernal. Following is an explanation and another way to do it
in the form of a reply to email.
2. An answer to the question: "How do I invoke the perl interpreter in a
script based on PATH, rather than hard-wiring something that may not
always work?"
3. A security/reliability warning about the use of "-S" in scripts.
rwp@fc.hp.com writes:
> #!/bin/sh -- # -*-perl-*-
> eval 'exec perl -S $0 "$@"'
> if 0;
>
> If I use /bin/ksh I can get the above construct to work like a charm.
>
> But if I try to use /bin/sh I get errors because the options are not
> ignored. If I remove the "-*-perl-*-" then perl feeds itself to sh
> again and I get another syntax error at the -S option. This also fails
> when I use /bin/bash or bash linked to /bin/sh on my linux machine.
Without the token "perl" on the #! line, perl will try to hand this off to
sh -- which complains about the "-S" option. Unfortunately, when exec()
parses the #! line, it often derives exactly two values. The first is the
command to execute. The second can be only the next token -- or in this
case, the rest of the line concatenated together as one string.
Thus, a first line of "#!/bin/sh -- # -*-perl-*-" in YourShellScript
translates into:
/bin/sh '-- # -*-perl-*-' YourShellScript
Apparently, there's a bug in some AT&T-derived ksh's such that any flag
*beginning* with "--" is treated as if it is *exactly* "--". (I see this
on both the HPUX and Solaris versions of ksh.) It appears that the Linux
ksh (and HPUX's POSIX shell) have not duplicated this bug. That's why
using ksh *appears* to work -- for now -- on HPUX and Solaris.
Unfortunately, I can't think of any other way to include the string "perl"
on the #! line without side effect. Nice hack, though. :-)
You could write a script that would use PATH to find perl then exec that on
YourShellScript and call that script defaultperl or some such. Then your
#! line would look something like:
#!/usr/local/bin/defaultperl
"defaultperl" could be written in Perl, shell, Python, C or whatever. This
seems like the most reliable way to me. However, this requires that
/usr/local/bin/defaultperl be installed on every machine -- something I
suspect you were hoping to avoid.
Alternately, the top of the script could be a (whatever) script that treats
the perl part as data and passes that on to perl. This approach really
stinks when you use a syntax-aware editor like emacs. No matter how you
set it up, at least part of the file will be (indented, highlighted, etc.)
wrong -- quite possibly even if you use Perl.
There's a definite bootstrapping problem. You need to know an absolute
path to something -- and how it behaves -- *or* you could use a still more
devious hack:-) E.g.,
Revised YourShellScript:
----------------8<----------------8<----------------8<----------------
exec perl -x $0 ${1+"$@"} # -*-perl-*-
#!perl -w
print STDOUT "$a howdy!\n"; # Something Perl -w specific.
----------------8<----------------8<----------------8<----------------
(If everything works correctly, you should get an "uninitialized value"
complaint, and it should print out " howdy!".)
Can you guess why this works for almost every login shell on almost every
version of UNIX? ;^)
^L
Why this (usually) works:
o The first line is intended to be executed by a Bourne shell derivitive
(e.g., ksh, bash, ash, POSIX shell) -- and it sets the mode for emacs.
o The second line and beyond will never be seen by Bourne shell derivatives
because of the "exec".
o Perl will ignore everything before the #!perl line. See perlrun(1) about
the "-x" switch.
o exec() typically defaults to the value of the SHELL environment variable
for interpreting executable text files without a #!. If exec() instead
defaults to a Bourne shell derivative, that also works.
o csh and derivatives have an interesting algorithm for executable text files:
1. If there's a "#!" directive on the first line, use that.
2. OTHERWISE, if the first character of the first line is a "#", use csh.
3. OTHERWISE, use /bin/sh. (Path may vary.)
NOTE: "csh YourShellScript" will die with a syntax error, unlike Bourne
shell derivitives. However, YourShellScript still works as a command.
(Of course, to invoke perl directly, you'll need to use "perl -x
YourShellScript ...".)
o zsh is close enough to Bourne shell that "zsh YourShellScript" works.
For all I know, zsh may also share the csh-ism described above.
Disclaimer: I wouldn't be surprised if there is an actual login shell out
there for which this admittedly horrible hack would not work. (The Plan 9
shell, perhaps?)
WARNING: Perl's "-S" option can actually cause problems if you invoke
YourShellScript via an explicit path. If YourShellScript is not in PATH at
all, perl won't find it. If there is another file called YourShellScript
earlier in PATH, *that* will be found by perl instead. You only need "-S"
for shells and/or OS's that screw up $0. Also, it should be slightly
faster to leave "-S" out. I personally recommend avoiding "-S" if possible
for reliability and security. If not possible, change the "-x" to "-Sx".
ALSO REGARDING SECURITY/RELIABILITY: You should use an explicit path to to
the perl interpreter on line one if you can know it ahead of time. (Of
course in that case, you'd probably use a regular "#!" line instead.) Note
that any path to perl can be used on line two -- and that it will be
ignored. This means that you can merely prepend one line to an existing
Perl script to make it search PATH for perl.
WARNING: Folks who print stuff (change directory, other side effects) in a
per-noninteractive-shell startup file -- notably .kshrc combined with older
versions of ksh (or, I believe, the POSIX shell) combined with a poorly
chosen ENV variable -- could see unexpected behavior with the above scheme
-- and in a *lot* of other situations. If you have only one or a few
users experiencing problems with the above scheme, check this out. (Of
course, if perl isn't in their PATH, that could be a problem also.:-)
Historical note: It was a commonly used optimization in BSD 4.[23] to begin
Bourne shell scripts with ":" on line one instead of an explicit "#!" and
rely on the above described behavior. This often avoided an extra shell
process. (I don't remember all the details, but I observed it myself.) Of
course, this is a lousy thing to do in terms of reliability or security,
but then, the *intent* in this case is to rely on an unpredictable PATH
anyway.
Hope this helps,
Chuck Phillips chuckp@FusionMM.com
------------------------------
Date: 18 Aug 1998 15:47:04 -0600
From: Robert Lopez <Robert.Lopez@abq.sc.philips.com>
Subject: Re: can "foreach ..." and "while ..." share loop control?
Message-Id: <jc6yasmklnr.fsf@abqn07.ato.sca.philips.com>
Abigail,
Thank you very much. I used your
> foreach (my $i = 0; $i < @my_array; $i ++) {
> $line = $my_array [$i];
> while ($line =~ /,$/ && $i < @my_array) {
> $line .= $my_array [++ $i];
> }
> ...
suggestion and it works like a charm. I appreciate the help.
Peace and regards,
-Robert Lopez
abigail@fnx.com (Abigail) writes:
> Robert Lopez (Robert.Lopez@abq.sc.philips.com) wrote on MDCCCXII
> September MCMXCIII in <URL: news:jc6zpd3kwl6.fsf@abqn07.ato.sca.philips.com>:
> ++
> ++ It worked fine for a while but now the source file has to have some
> ++ lists added to it that have hundreds of names and are organized like:
> ++
> ++ department_2315: evan.adams,bill.anthony,carol.armenta,frank.armstrong,
> ++ anna.baker,carol.balder,frank.carter,duane.caston.linda.david,
> ++ ...
> ++ cindy.williams,ted.vromans
> ++
> ++ I was reading the source file into an array and then processing with
> ++ foreach $line (@my_array) {
> ++ ...
> ++ }
> ++
> ++ My question is:
> ++ Inside of the foreach block is there a way to have a sub-block that
> ++ shares the function of grabbing the next line so it can grab the
> ++ entire list off of multiple lines?
>
> Yes, but not if you have 'foreach $line (my_array)'.
>
> What would work are:
>
> while (defined ($line = <FILE>)) {
> while ($line =~ /,$/) {
> $line .= <FILE>; # Assumes no trailing , on last line.
> }
> ....
> }
>
> or
>
> while (@my_array) {
> $line = shift @my_array;
> while ($line =~ /,$/ && @my_array) {
> $line .= shift @my_array;
> }
> ...
> }
>
> or
>
> foreach (my $i = 0; $i < @my_array; $i ++) {
> $line = $my_array [$i];
> while ($line =~ /,$/ && $i < @my_array) {
> $line .= $my_array [++ $i];
> }
> ...
>
>
> or you split the file differently:
>
> undef $/;
> my $text = <FILE>;
> @my_array = split /(?<!,)\n/, $text;
> foreach $line (@my_array) {
> ....
>
>
> or if the line ending with a comma is followed by a line starting with
> white space, and you don't have perl 5.005:
>
> undef $/;
> my $text = <FILE>;
> @my_array = split /\n(?!\s)/, $text;
> foreach $line (@my_array) {
> ....
>
>
> Abigail
> --
> sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
> "$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
> *_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
> _::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))
------------------------------
Date: Tue, 18 Aug 1998 21:36:44 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: can perl be compiled into EXE format?
Message-Id: <ExwMp9.7s6@world.std.com>
wings <xuchu@comp.nus.edu.sg> writes:
>sometimes i do feel perl is running slowly.. is there anyway to make an
>EXE file out of a .pl? i am using ActiveState Perl5.005 in Windows NT4.0.
If it is only "sometimes" that you feel perl is running too slowly,
there may be a couple of things to check out first.
Does the same script with the same input vary tremendously in the
amount of time it takes to run? If so, then you might want to check
the performance of the machine itself. (The amount of processor time
used, free memory, etc.) Chances are that the system is busy doing
something other than running your script.
Does the same script with different input vary tremendously in the
amount of time it takes to run? Or do different scripts take a widely
varying time to findish? If so, maybe the algorithms you are using are
inefficient. You might want to take a look at the Devel::DProf module
to find where your script is taking the most time. If you think your
code is about as efficient as it can be, then maybe perl isn't the
language for this application.
--
Andrew Langmead
------------------------------
Date: Tue, 18 Aug 1998 21:48:13 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Filehandle associated file name
Message-Id: <Exwn8D.FA2@world.std.com>
Kare Hansen <hansen@sharptech.win-uk.net> writes:
>I currently having to modify some Perl functions which are being used
>extensively by other modules. The functions writes to stdout and stderr
>but I need to know if these filehandles have been associated with a
>specific file and if they have, the name of the actual files.
If you are running your programs in the Unix environment, this entry
from the comp.unix.questions FAQ may be of interest to you:
4.3) How do I find the name of an open file?
In general, this is too difficult. The file descriptor may
be attached to a pipe or pty, in which case it has no name.
It may be attached to a file that has been removed. It may
have multiple names, due to either hard or symbolic links.
If you really need to do this, and be sure you think long
and hard about it and have decided that you have no choice,
you can use find with the -inum and possibly -xdev option,
or you can use ncheck, or you can recreate the functionality
of one of these within your program. Just realize that
searching a 600 megabyte filesystem for a file that may not
even exist is going to take some time.
--
Andrew Langmead
------------------------------
Date: Tue, 18 Aug 1998 18:42:24 GMT
From: ijg@csc.liv.ac.uk (I.J. Garlick)
Subject: Re: filehandle in CGI.pm
Message-Id: <ExwEMo.Hw1@csc.liv.ac.uk>
In article <6r1ksp$96t15@id4.nus.edu.sg>,
wings <xuchu@iscs.nus.edu.sg> writes:
> i'm writing an upload script with CGI. as told in CGI.pm,
> $q->param('file') returns both the filename as a string and a handle.
> so here is part of my codes:
>
> $srcfile = $q->param('file');
> # assuming that $srcfile='d:\test\a.html'
>
> open (FP, ">d:\\test\\b.html") || die "cant write";
> while (<$srcfile>) {
> print FP $_;
This is not ^^^^^^ wrong but
print FP;
will work exactly the same.
> }
>
I don't see the problem?
What box are you uploading to? Unix? Sun? Windows? although it shouldn't
matter.
I have/am doing this now, once you have amde the jump, as you have, in
understanding about what CGI.pm returns then it should be easy.
The only thing i am doing differently is stripping the dos path off to get
at the underlying file name.
Sorry if this doesn't help but you have figured the hard part out. I would
look at something else as being the problem.
BTW I am doing it on NS4 under both UNIX and PC, so contrary to another post
here I doubt that that is the problem.
> i always get zero bytes in b.html. where am i doing wrong?
>
> thx for any help.
Oh. One further thought, where are you printing the Content-Type header
line bfore or after you read and print out the file?
It's just a thought as I have had problems with this but cannot remember
exactly if it was to do with this.
--
--
Ian J. Garlick
ijg@csc.liv.ac.uk
Your conscience never stops you from doing anything. It just stops you
from enjoying it.
------------------------------
Date: 18 Aug 1998 21:58:58 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: here's an implementation of diff in perl
Message-Id: <6rctf2$ivr$1@client3.news.psi.net>
Greg Bacon (gbacon@cs.uah.edu) wrote on MDCCCXIII September MCMXCIII in
<URL: news:6rcdf6$rfm$20@info.uah.edu>:
++ In article <6rc8f2$7sa$1@client3.news.psi.net>,
++ abigail@fnx.com (Abigail) writes:
++ : Greg Bacon (gbacon@cs.uah.edu) wrote on MDCCCXIII September MCMXCIII in
++ : <URL: news:6rbuke$rfm$6@info.uah.edu>:
++ : ++ How precise is it to label an O(1) algorithm O(n!)? :-) I agree with
++ : ++ you that it is correct, but I would say such a labeling is an abuse
++ : ++ of the notation. If it were the common practice, the notation would
++ : ++ stop conveying any information.
++ :
++ : Bullshit. The notation doesn't stop conveying any information. If you
++ : want to use big-Oh notation for tight upperbounds, then just simply
++ : say the upperbound is tight.
++
++ Do you disagree that it's misleading to say comparing strings by
++ comparing corresponding characters takes O(n!) time?
No.
++ : ++ I always found demonstrating that Quicksort is O(n lg n) tricky. :-)
++ :
++ : Since quicksort isn't O (n log n), that's very tricky indeed.
++
++ O(n + n lg n) is the same as O(n lg n).
And crows are black. Your point?
Abigail
--
perl -MNet::Dict -we '(Net::Dict -> new (server => "dict.org")\n-> define ("foldoc", "perl")) [0] -> print'
------------------------------
Date: Tue, 18 Aug 1998 21:11:47 GMT
From: andy@osea.demon.co.uk (Andrew Haveland-Robinson)
Subject: IIS, Perl: Coping with signals in CGI.
Message-Id: <35d9ed0a.28631218@news.demon.co.uk>
I have a script that amends a data file on the server, I want to ensure that
if the user presses the stop button the data file is not going to be
corrupted. Within a script, run from the command line, the following would
catch an interrupt.
MAIN:
{
.....
$SIG{'INT'} = \&cleanup;
$SIG{'HUP'} = \&cleanup;
$SIG{'QUIT'} = \&cleanup;
.....
}
sub cleanup()
{
print "<H4>Cleanup()</H4>\n";
exit 1;
} # End of cleanup
But this does not work in a CGI script. Does anyone know if the interrupts
can be caught and if so how?
If not, is there any other way that this can be dealt with?
Cheers,
Andy.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HRA Web Services, 17 Williams Way, Fleet, Hants GU13 9EU, England
Tel. +44 (0)1252-811670 ICQ: 1331640 Web: http://www.1HR.net
------------------------------
Date: Tue, 18 Aug 1998 16:34:54 -0500
From: James Schmidt <james@js.prysm.net>
Subject: Multi-proc/multi-thread support in Perl/Unix
Message-Id: <Pine.LNX.3.96.980818162506.924A-100000@js.prysm.net>
I've got an app that I am developing using Perl 5 on a Sun Ultra
Enterprise 5500 with 6 300MHz Ultra-SPARC II processors in it. Since this
application is going to be chewing vast amounts of data and multiple large
files at any given time, I would like to know is if there is a way
to bind certain commands, or functions to idle CPU's?
I can achieve some-what "multiproc" support by spawning off individual
perl programs to do what I need and return the results back, which
utilizes some of the other idle cpus, but this is sloppy and tedious at
best.
I haven't been able to find much documentation on the subject and was
wondering if anyone has had any experience in this area or has any good
ideas, suggestions, etc. I sure hate to leave those other 5 cpu's sitting
there twiddling their thumbs while the other is pegged out at redline :)
Thanks for any information or pointers or available documentation.
Please reply to james@js.prysm.net if at all possible.
Sincerely,
James Schmidt
james@js.prysm.ent
------------------------------
Date: 18 Aug 1998 21:56:13 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: Multi-proc/multi-thread support in Perl/Unix
Message-Id: <6rct9t$g0r$6@info.uah.edu>
In article <Pine.LNX.3.96.980818162506.924A-100000@js.prysm.net>,
James Schmidt <james@js.prysm.net> writes:
: I've got an app that I am developing using Perl 5 on a Sun Ultra
: Enterprise 5500 with 6 300MHz Ultra-SPARC II processors in it. Since this
: application is going to be chewing vast amounts of data and multiple large
: files at any given time, I would like to know is if there is a way
: to bind certain commands, or functions to idle CPU's?
This happens at the operating system level. Perl has no notion of
CPU or handing some task to a CPU.
: I can achieve some-what "multiproc" support by spawning off individual
: perl programs to do what I need and return the results back, which
: utilizes some of the other idle cpus, but this is sloppy and tedious at
: best.
Sloppy? Tedious? How so? You need to hint to the OS that you have
some new task that it can send to an idle processor if it's so inclined.
The only other way (that I know of) would be threading. forking off a
child is the simplest and safest way that I can think of.
Greg
--
A Freudian slip is when you say one thing when you're thinking about a mother.
-- Cliff Clavin
------------------------------
Date: Tue, 18 Aug 1998 16:39:47 -0500
From: tfo@telalink.net (Thomas Frederick O'Connell)
Subject: mv, move, or some way to move files in perl
Message-Id: <tfo-1808981639470001@jesus.telalink.net>
is there a good way other than
system( "mv ..." );
to move directory trees across filesystems in perl? i could have sworn
that there used to be a mv function in File::Copy, but when i went looking
today, it wasn't there. but my memory of looking for something similar is
about a year old, so i could be wrong. i would also rather avoid
copy( ... );
unlink( ... );
why isn't there a File::Move module, incidentally?
any info or pointers to info come much appreciated.
-freddie
------------------------------
Date: Tue, 18 Aug 1998 21:20:46 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: pattern matching with uc and lc
Message-Id: <ExwLyM.JD8@world.std.com>
John Porter <jdporter@min.net> writes:
>julzrulz@my-dejanews.com wrote:
>>
>> if (!open(LIST, "../list.pl")){
>> print "can't open file";
>> }
>Bug. You should have an exit (or return, or goto, or
>something) in the block that gets executed if the file
>doesn't open.
Not necessarily. Since the readline operator simply returns undef for
reads on unopened filehandles, and since closing an unoponed
filehandle harmless, it is sometimes convenient to just keep on going
through the code. Notice the readline operation on the magic null
filehandle (the "<>" construct) simply warn()s, not die()s on errors.
But in this case, the code goes through a whole lot of nothing if it
can't open the file.
--
Andrew Langmead
------------------------------
Date: Tue, 18 Aug 1998 18:53:27 GMT
From: ijg@csc.liv.ac.uk (I.J. Garlick)
Subject: Re: print "Content-type:text/html\n\n"; and redirection...
Message-Id: <ExwF53.IEt@csc.liv.ac.uk>
In article <slrn6tikge.mh7.maurice@we-24-130-48-83.we.mediaone.net>,
maurice@hevanet.com (Maurice Aubrey) writes:
> On Tue, 18 Aug 1998 11:52:57 +0200, Wouter Hermans <whermans@mail.dma.be> wrote:
>
>>for some weird reason "Content-type:text/html" shows up in my browser when i
>>run a perl script on a microsoft iis3 server. don't know if it happens on
>>unix servers...
>
> Are you using CGI.pm?
>
>>also: i'm trying to read in a value (=url) from a form, and then let the cgi
>>relink the user through to that url. any ideas?
>
> #!/usr/bin/perl -Tw
>
> use CGI;
>
> $cgi = new CGI;
> print $cgi->redirect( $cgi->param('newurl') );
Ahhhhhh.... I hate you. I have been doing a complicated dance with the
Location header and search and replavce of spaces on params I need to pass
on.
I don't really hate you but this will make my life easier no end. It's
what I get for not reading the pod I suppose, but it's so damned big.
--
--
Ian J. Garlick
ijg@csc.liv.ac.uk
Your conscience never stops you from doing anything. It just stops you
from enjoying it.
------------------------------
Date: Tue, 18 Aug 1998 16:17:30 -0500
From: Brett Denner <Brett.W.Denner@lmco.com>
Subject: reference to anonymous scalar?
Message-Id: <35D9EF6A.1F11CBFB@lmco.com>
>From the Camel book, references to anonymous arrays, hashes, and
subroutines may be created by:
$arrayref = [1, 2, ['a', 'b', 'c']];
$hashref = { 'Adam' => 'Eve', 'Clyde' => 'Bonnie' };
$coderef = sub { print "Boink!\n" };
Is there a similar way to compose a reference to an anonymous
scalar? (Yes, I do have a need for such a thing.)
$scalarref = ????
Thanks,
Brett
--
Brett W. Denner Lockheed Martin TAS
Brett.W.Denner@lmco.com P.O. Box 748
(817) 935-1144 (voice) Fort Worth, TX 76101
(817) 935-1212 (fax) MZ 9332
------------------------------
Date: 18 Aug 1998 14:39:57 -0700
From: hirano@Xenon.Stanford.EDU (Kelly Hirano)
Subject: Re: reference to anonymous scalar?
Message-Id: <6rcsbd$4oi@Xenon.Stanford.EDU>
In article <35D9EF6A.1F11CBFB@lmco.com>,
Brett Denner <Brett.W.Denner@lmco.com> wrote:
>From the Camel book, references to anonymous arrays, hashes, and
>subroutines may be created by:
>
> $arrayref = [1, 2, ['a', 'b', 'c']];
> $hashref = { 'Adam' => 'Eve', 'Clyde' => 'Bonnie' };
> $coderef = sub { print "Boink!\n" };
>
>Is there a similar way to compose a reference to an anonymous
>scalar? (Yes, I do have a need for such a thing.)
>
> $scalarref = ????
>
$scalarref = \'string';
--
Kelly William Hirano Stanford Athletics:
hirano@cs.stanford.edu http://www.gostanford.com/
hirano@alumni.stanford.org (WE) BEAT CAL (AGAIN)! 100th BIG GAME: 21-20
------------------------------
Date: 18 Aug 1998 17:47:13 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: Brett Denner <Brett.W.Denner@lmco.com>
Subject: Re: reference to anonymous scalar?
Message-Id: <g1et29hq.fsf@mailhost.panix.com>
Brett Denner <Brett.W.Denner@lmco.com> writes:
> Is there a similar way to compose a reference to an anonymous
> scalar? (Yes, I do have a need for such a thing.)
perlref has this to say:
*foo{THING} returns undef if that particular THING hasn't been used
yet, except in the case of scalars. *foo{SCALAR} returns a reference
to an anonymous scalar if $foo hasn't been used yet. This might change
in a future release.
Which, I dunno about you, leads me to this idea:
use Symbol qw( gensym );
my $anon = *{ +gensym }{SCALAR};
$$anon = 42;
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf/
------------------------------
Date: 18 Aug 1998 21:46:37 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: reference to anonymous scalar?
Message-Id: <6rcsnt$g0r$4@info.uah.edu>
In article <35D9EF6A.1F11CBFB@lmco.com>,
Brett Denner <Brett.W.Denner@lmco.com> writes:
: Is there a similar way to compose a reference to an anonymous
: scalar? (Yes, I do have a need for such a thing.)
Go to DejaNews and search for `reference "anonymous scalar"' (without
the single quotes).
I wonder if the answer should be in the FAQ.
Greg
--
People who comprehend a thing to its very depths rarely stay faithful to it
forever. For they have brought its depths into the light of day: and in the
depths there is always much that is unpleasant to see.
-- Nietzsche
------------------------------
Date: 18 Aug 1998 17:50:40 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: hirano@Xenon.Stanford.EDU (Kelly Hirano)
Subject: Re: reference to anonymous scalar?
Message-Id: <d89x29bz.fsf@mailhost.panix.com>
hirano@Xenon.Stanford.EDU (Kelly Hirano) writes:
> Brett Denner <Brett.W.Denner@lmco.com> wrote:
> >Is there a similar way to compose a reference to an anonymous
> >scalar? (Yes, I do have a need for such a thing.)
> $scalarref = \'string';
That creates a read-only value, which is, of course, sometimes exactly
what you want. But the analogous anonymous structures Brett gives are
all refs to lvalues.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf/
------------------------------
Date: Tue, 18 Aug 1998 21:19:52 GMT
From: nguyen.van@imvi.bls.com
Subject: regular expression. Help !!!!
Message-Id: <6rcr5o$5up$1@nnrp1.dejanews.com>
Hi Guys,
I'm new to perl; however I try to do something with but face a big problem.
The following is my problem:
For instance, in a file I have the following lines:
xxxxxxxxxx&crno=1111222&xxxxxxxxx xxxxxxx xxxxxx AOL 3.0
/?crno=1111111xxxxxxxxx xxxxxxxx xxxxxxxxxx AOL 3.1
xxxxxxxxxxxxx xxxxxxxx&crno=8757555 xxxxxxx AOL 2.0
In this case "crno=number" also increase over time, and it also can be
located any where but last file which is the versions of browsers. What I
want to do is to pull out from the line only "crno=number" (i.e crno=1111222,
etc) and AOL X.X (i.e AOL 3.0, etc). Your help is highly appreciated.
Thanks
Van Nguyen
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: 18 Aug 1998 21:02:30 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: request for comments...
Message-Id: <6rcq56$5cr$1@pegasus.csx.cam.ac.uk>
Bill Jones, FCCJ Webmaster <bill@astro.fccj.cc.fl.us> wrote:
> $first = (((rand(time)) >> (11 + 1 - 8)) & ~(~0 << 7));
^^^^
What's all this nonsense? time() can't ever be a sensible argument to
rand().
Mike Guy
------------------------------
Date: 18 Aug 1998 21:26:31 GMT
From: "Duncan Cameron" <dcameron@bcs.org.uk>
Subject: Re: socket client on Windows 95 machine
Message-Id: <01bdcaee$f87227e0$e5e7abc3@dns.btinternet.com>
Bruno
You have probably got your internet browser set to automatically dial when
needed. I use Microsoft Internet Explorer and on the Connection tab within
Properties there is a check-box marked 'Connect to the Internet as needed'.
Turn this off and it should solve your problem.
HTH
Duncan Cameron
Bruno Pagis - 1320NM systems <pagib@aur.alcatel.com> wrote in article
<35D88D64.C2582688@aur.alcatel.com>...
> I tried the example of the Camel book for client and server
> socket on my ActivePerl 502 release for Win32.
> Everything goes fine except that when I try to start my
> client, the first thing that happens is that it starts my
> dial-up networking that is set up to access my ISP (Internet
> Service Provider). If I hit the cancel button, then it connect
> to my Perl server.
> Is there a way to avoid starting my dial-up networking first.
> I am using localhost as the machine hostname, and port 2345 to
> listen (like in the camel book).
>
> Thanks.
>
------------------------------
Date: 18 Aug 1998 21:38:01 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: test post -- please ignore
Message-Id: <6rcs7p$g0r$3@info.uah.edu>
[Posted and mailed]
In article <MPG.1042d2d643da45f8989681@news.tmlp.com>,
stevenba@carr.org (Steven Barbash) writes:
: test post -- please ignore
How many test posts are you planning on sending our way?
This is not the place for test posting. Test posting belongs in one
or more of alt.test, misc.test, or misc.test.moderated.
Thanks,
Greg
--
Those who do not understand UNIX are condemned to reinvent it -- badly.
-- Henry Spencer
------------------------------
Date: Tue, 18 Aug 1998 16:27:28 -0500
From: Andrew Hamilton <hamiltaj@cray.com>
Subject: Testing for input
Message-Id: <35D9F1C0.46F74CC4@cray.com>
--------------6FF7A6B492E7F8BC7F3B8A9A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I've searched www.perl.com, looked through Programming Perl, and tried
some things on my own, but I still can't find a way to test for input
without having to read input. There may be some way to do this in UNIX
(so I could do a system call), but I'm not aware of it. I haven't
searched exhaustively, but I did give it a good effort.
A little background...
I'm writing a client/server program in which the socket alerts the
client(s) and lets them know if a message file has been modified, if it
has the clients retrieve the file and write it to STDOUT. The program
itself works ok, but I would like to add a way for a client to end it's
session whenever it wants. Ideally, it would work something like this:
...
program setup
...
while (1) {
if ($_ = <STDIN>) { # (a)
if ($_ =~ /^q$/) { exit }
}
else {
#
# rest of program
#
}
sleep 120;
}
# end of script
The only problem with this is if I use <STDIN> for input at (a) at all
(even with $_ = <STDIN> as suggested by Programming Perl), the program
waits for input to be entered before continuing. In effect, the only
way I can end the program is to kill off the process, but what I want to
do is exit if a "q" has been entered, otherwise (including if there's no
input), continue. There must be an easier way to see if input was
entered (in order to quit the program), without having to enter input.
Sorry for dragging this on, but this seems rather hard to explain, so I
thought I'd try to explain it a couple of different ways.
I assume there has to be a way to do this, but I can't figure it out.
Any help would be greatly appreciated.
Andrew Hamilton
--------------6FF7A6B492E7F8BC7F3B8A9A
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<HTML>
I've searched www.perl.com, looked through Programming Perl, and tried
some things on my own, but I still can't find a way to test for input without
having to read input. There may be some way to do this in UNIX (so
I could do a system call), but I'm not aware of it. I haven't
searched exhaustively, but I did give it a good effort.
<P>A little background...
<BR>I'm writing a client/server program in which the socket alerts the
client(s) and lets them know if a message file has been modified, if it
has the clients retrieve the file and write it to <TT>STDOUT</TT>.
The program itself works ok, but I would like to add a way for a client
to end it's session whenever it wants. Ideally, it would work something
like this:
<P><TT>...</TT>
<BR><TT>program setup</TT>
<BR><TT>...</TT><TT></TT>
<P><TT>while (1) {</TT>
<BR><TT> if ($_ = <STDIN>) {
# (a)</TT>
<BR><TT> if ($_ =~ /^q$/) { exit
}</TT>
<BR><TT> }</TT>
<BR><TT> else {</TT>
<BR><TT> #</TT>
<BR><TT> # rest of program</TT>
<BR><TT> #</TT>
<BR><TT> }</TT>
<BR><TT> sleep 120;</TT>
<BR><TT>}</TT>
<BR><TT># end of script</TT>
<BR><TT></TT> <TT></TT>
<P>The only problem with this is if I use <TT><STDIN></TT> for <TT>input</TT>
at <TT>(a)</TT> at all (even with <TT>$_ = <STDIN></TT> as suggested
by Programming Perl), the program waits for input to be entered before
continuing. In effect, the only way I can end the program is to kill
off the process, but what I want to do is exit if a "q" has been entered,
otherwise (including if there's no input), continue. There must be
an easier way to see if input was entered (in order to quit the program),
without having to enter input. Sorry for dragging this on, but this
seems rather hard to explain, so I thought I'd try to explain it a couple
of different ways.
<P>I assume there has to be a way to do this, but I can't figure it out.
Any help would be greatly appreciated.
<P>Andrew Hamilton</HTML>
--------------6FF7A6B492E7F8BC7F3B8A9A--
------------------------------
Date: 18 Aug 1998 21:52:00 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: Testing for input
Message-Id: <6rct20$g0r$5@info.uah.edu>
In article <35D9F1C0.46F74CC4@cray.com>,
Andrew Hamilton <hamiltaj@cray.com> writes:
: A little background...
: I'm writing a client/server program in which the socket alerts the
: client(s) and lets them know if a message file has been modified, if it
: has the clients retrieve the file and write it to STDOUT. The program
: itself works ok, but I would like to add a way for a client to end it's
: session whenever it wants. Ideally, it would work something like this:
[snip]
Well, there is the FIONREAD ioctl that tells you how many bytes are
waiting to be read on a socket. Use select on your sockets as usual
(I'm assuming you're using select), and if there's activity on the
socket, but FIONREAD ioctl returns 0, the client has shutdown its side
of the socket.
I wrote a little extension to do the FIONREADing. You can find it at
<URL:http://www.cs.uah.edu/~gbacon/perl/pserv/Fionread.tar.gz>
: <HTML>
Please don't post HTML-encoded messages in this group.
Greg
--
Democracy: Two wolves and a sheep voting on what's for dinner.
------------------------------
Date: Tue, 18 Aug 1998 22:41:47 +0100
From: Alan Silver <alan@find-it.furryferret.uk.com>
Subject: Re: Why dont people read the FAQs
Message-Id: <kVSwabAbUf21Ewpv@find-it.uk.com>
In article <ant171908b49Rr9i@waveney.demon.co.uk>, Richard Proctor
<Richard@waveney.demon.co.uk> writes
>0) People cant read (if so why are they writing)
Ah, a pure scientist. Who else would have the elagance of taste to start
counting at zero ?
Sorry, I couldn't help myself.
Alan (who has read bits of the FAQ and always tries to read more before
posting - honest).
--
Alan Silver
Please remove the furryferret when replying by e-mail
------------------------------
Date: 18 Aug 1998 20:43:07 GMT
From: Hans Mulder <hansmu@xs4all.nl>
Subject: Re: Yet another invocation line mystery (does seem to be perl related)
Message-Id: <6rcp0r$j2h@news.euro.net>
Martin Gregory <mgregory@asc.sps.mot.com> wrote:
>
>In a previous post I observed that
>
>
> #!/bin/sh
> eval 'exec perl -w -S $0 ${1+"$@"}' # Use the -*- perl -*- on our path.
> if 0;
>
> print "yay\n";
>
>
>does not work.
>
>How come it does work if you remove the #! line!?
In a response to your previous post, Quentin Fennessy quoted the
relevant paragraph from perlrun:
If the #! line does not contain the word "perl", the program named after
the #! is executed instead of the Perl interpreter. This is slightly
bizarre, but it helps people on machines that don't do #!, because they
can tell a program that their SHELL is /usr/bin/perl, and Perl will then
dispatch the program to the correct interpreter for them.
Thus if you feed this:
#!/bin/sh
echo "yay"
into perl, it will work, in the sense that perl will recognize the #!
line and feed your script into /bin/sh .
Obviously, if you leave off the #! line, this effect no longer occurs.
Hope this helps,
-- HansM
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3477
**************************************