[6525] in Perl-Users-Digest
Perl-Users Digest, Issue: 150 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 20 21:07:25 1997
Date: Thu, 20 Mar 97 18:00:27 -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, 20 Mar 1997 Volume: 8 Number: 150
Today's topics:
%SIG (root)
Re: /RE/ for Dummies - It is even hard for experts! <tchrist@mox.perl.com>
[Q] Finding the contents of a directory? amas@lhr-sys.dhl.com
Re: [Q] Finding the contents of a directory? (Tad McClellan)
Re: [Q] Finding the contents of a directory? <eric@NetTown.com>
Checking a '/' chr. is not present <pdenman@ims.ltd.uk>
Converting Perl to c++ andy@wwdatalink.com
Re: Do sysopen() and open() create equivalent filehandl <tchrist@mox.perl.com>
download search engine for web site ? (Nicola Gordon)
Re: download search engine for web site ? (Doug Wegscheid)
Re: Getting Perl 5 <tchrist@mox.perl.com>
How to get file time and date stamps? <camelo@itanet.com.br>
How to use modules in Perl5? (Barry G Reville)
Mail from perl - input read error (Jon Hamlin)
Re: Perl 100 times slower ... <tchrist@mox.perl.com>
Re: Perl 100 times slower ... <tchrist@mox.perl.com>
Perl for NT list? <josh@dowdell.com>
Re: Problems with flock() <tchrist@mox.perl.com>
Re: QUESTIONNAIRE FOR PERL GURUS <agent.email@NetTown.com>
Response headers <mipotech@novice.uwaterloo.ca>
Re: Signal catching with alarm (Ollivier Robert)
Re: simple counter <tchrist@mox.perl.com>
Re: Sort question (David Bell)
trouble matching multiple fields <psrc@exmachina.com>
undef() fails when given a list of arguments (Patrick Duff)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Mar 1997 15:23:49 GMT
From: root@nitram.socs.com.fr (root)
Subject: %SIG
Message-Id: <5grkq5$3rm@nitram.demon.co.uk>
I am having one heck of a problem catching SIGCHLD. No matter what I attempt to do, I end up with zombie processes and can't catch their status. Is this right:
$SIG{"SIGCHLD"} = "child_handler";
I have also tried
$SIG{"SIGCLD"} = "child_handler";
and 'IGNORE' in both.
Martin Bartlett
===========================================================
_/ _/_/_/_/
_/_/ _/_/ _/
_/ _/_/ _/_/_/_/ Martin John Bartlett
_/ _/ _/ _/ (martin@nitram.demon.co.uk)
_/ _/_/_/_/
_/
_/ _/
_/_/
===========================================================
------------------------------
Date: 20 Mar 1997 13:46:00 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: /RE/ for Dummies - It is even hard for experts!
Message-Id: <5grf2o$a3e$4@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Kevin Hawkins <khawkins@ncsa.uiuc.edu> writes:
: $word =~ tr/A-Z/a-z/;
That's not uppercase letters. That's your idea of uppercase letters,
and it isn't even sufficient for English. See the FAQ for a better way.
Anything else is a NAOVE FAGADE of correctness, and SECRETARY PEQA
would not be amused.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
Sometimes when you fill a vacuum, it still sucks. --Rob Pike
------------------------------
Date: Thu, 20 Mar 1997 07:33:08 -0600
From: amas@lhr-sys.dhl.com
Subject: [Q] Finding the contents of a directory?
Message-Id: <858864569.5671@dejanews.com>
I am writing a program and part of what it has to do is find the
contents of the directory. What I would be looking for is something
like:
GetDirContents($contents,$type,$regexp)
$contents would be an array listing the contents of the directory,
$type would be a set of Folder,File,Symbolic Link
$regexp would be a regular expression used as a filter, so for example
if I wanted to find file names that started with 5 alphnumeric characters
followed by a full-stop, followed by an unknown number of alphanumeric
characters, I would have something like "?????.*"
I am in the process of moving from awk, partly becuase of the greater
functionality of Perl and partly because Perl is available on many more
platforms.
If anyone can help me I would appreciat this very much. If it makes any
difference my target platform is primarily Unix, though it could be
anything.
Andre
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Thu, 20 Mar 1997 15:54:48 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: [Q] Finding the contents of a directory?
Message-Id: <8nbsg5.3d3.ln@localhost>
[ posted, and emailed to the anonymous apparition ]
Tom Christiansen (tchrist@mox.perl.com) wrote:
: [courtesy cc of this posting sent to cited author via email]
: In comp.lang.perl.misc,
: Opera Ghost <agent.email@NetTown.com> writes:
: :amas@lhr-sys.dhl.com wrote:
: :aside...
: :yo, why dont u take a quick look at a index of some perl book before
: :asking the world wide comunity? well i guess u have ur reasons...
: :
: :so, no anwser, but here's an 'index' i wrote last nite...
: :http://nettown.com/site_perl/search.cgi
: :search for 'find', choose that first link
: lissen, dood. ewe hev da simppel choyse uv riting yo poosts
: or bee laik tootellie ignorificated bai da rayest uv us. ewe
: arrent koooool, and ewe arrent clevver. ewe arre oonlie raiting
: like an annoyalting punker, and ewe reelie disurv kialfailling.
: In short: get a clue, or get lost. You aren't helping anyone.
^^^^^^^^^^^^^^^^^^^^^^^^^
I already killfiled him/her.
I don't have time to spend on cutesy foolishness...
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Thu, 20 Mar 1997 19:24:47 +0000
From: Eric <eric@NetTown.com>
To: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: [Q] Finding the contents of a directory?
Message-Id: <33318EFF.69073A4B@NetTown.com>
Tom Christiansen wrote:
>
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc,
> Opera Ghost <agent.email@NetTown.com> writes:
> :amas@lhr-sys.dhl.com wrote:
> :aside...
> :yo, why dont u take a quick look at a index of some perl book before
> :asking the world wide comunity? well i guess u have ur reasons...
> :
> :so, no anwser, but here's an 'index' i wrote last nite...
> :http://nettown.com/site_perl/search.cgi
> :search for 'find', choose that first link
>
> lissen, dood. ewe hev da simppel choyse uv riting yo poosts
> or bee laik tootellie ignorificated bai da rayest uv us. ewe
> arrent koooool, and ewe arrent clevver. ewe arre oonlie raiting
> like an annoyalting punker, and ewe reelie disurv kialfailling.
>
> In short: get a clue, or get lost. You aren't helping anyone.
>
> --tom
> --
> Tom Christiansen tchrist@jhereg.perl.com
>
> f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.
I just got this message and I am very sorry about the shorthand. I have
gained so much from perl, its modules and newsgroups that I just want to
give some back and maybe learn a thing or two. Well I guess I learned
one lesson! Thanks!
--
Eric
<mailto:eric@NetTown.com>
[http://NetTown.com/site_perl/]
have a good day!
------------------------------
Date: Thu, 20 Mar 1997 11:14:25 +0000
From: "Paul Denman" <pdenman@ims.ltd.uk>
Subject: Checking a '/' chr. is not present
Message-Id: <01bc3522$f454f560$9d02a8c0@192.168.2.1.ims.ltd.uk>
Hello,
I have written a username/password script, and need to check that
the following characters are not in either; ":", "/" and " " (space).
I am using the syntax:
if (($FORM{username} !~ /:/) && ($FORM{username} !~ / /)) {
...
}
I can't work out how to check for the '/' character. (!~ /// doesn't work).
Can anyone help me on this?
Thanks,
Paul Denman
pdenman@ims.ltd.uk
------------------------------
Date: Thu, 20 Mar 1997 18:02:11 -0700
From: andy@wwdatalink.com
Subject: Converting Perl to c++
Message-Id: <3331DE13.1B1B@wwdatalink.com>
Does anyone know of a program that can convert a perl program into c++.
Andrew Koons
andy@wwdatalink.com
------------------------------
Date: 20 Mar 1997 13:41:36 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Do sysopen() and open() create equivalent filehandles?
Message-Id: <5greqg$a3e$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
jsm@best.com (James Marshall) writes:
:If I open a file with sysopen() and appropriate flags, are there any
:subtle differences between that filehandle and one opened with open()?
:I wanna start using sysopen() for all my file needs, but don't want
:to get bitten later. I assume the answer is "yes", but I can't find
:definitive word anywhere.
It's the same.
:Tangential idea: With all the CGI going on, it may be useful for open()
:to grow a "lockable" option. Not only would it be convenient, but many
:people need locking without realizing it.
No, I don't want to make it more convenient. Locking is tough stuff.
They will learn to do it right, or stop pretending to be programmers.
(After bitterly wading through more idiofrickingotic "my hit counter is
broken" postings and email than you want to know about.)
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
echo "I can't find the O_* constant definitions! You got problems."
--The Configure script from the perl distribution
------------------------------
Date: 20 Mar 1997 13:16:19 GMT
From: nicola@uoguelph.ca (Nicola Gordon)
Subject: download search engine for web site ?
Message-Id: <5grdb3$sju@ccshst05.cs.uoguelph.ca>
Hi, can anyone advise me on this subject...
I would like to download a search engine to allow users to search my web
site. Do you know any sites that allow this either for free or for a
reasonable charge.
I understand that they are often written in Perl/CGI and that these
should not be too hard to implement. I hope there is something out there
that you can suggest...
Thanks a lot for your help!
- Nicola
ps if it is convinient, can you reply to me at
nicola@snowhite.cis.uoguelph.ca
Thanks again for your help...
--
*---------------------------------------------------------------*
* Nicola Gordon - University of Guelph *
* - email: nicola@snowhite.cis.uoguelph.ca *
* - web page: http://www.uoguelph.ca/~nicola *
*---------------------------------------------------------------*
------------------------------
Date: Thu, 20 Mar 1997 14:48:19 GMT
From: wegscd@whirlpool.com (Doug Wegscheid)
Subject: Re: download search engine for web site ?
Message-Id: <33314ae8.4321440@ghost.whirlpool.com>
On 20 Mar 1997 13:16:19 GMT, nicola@uoguelph.ca (Nicola Gordon) wrote:
>Hi, can anyone advise me on this subject...
>I would like to download a search engine to allow users to search my web
>site. Do you know any sites that allow this either for free or for a
>reasonable charge.
this is not a perl question, it's a www question. try www-related
newsgroups, or take a look at the www faq http://www.boutell.com/faq/
("How can I make my www site searchable?")
good luck.
--
Doug Wegscheid
wegscd@whirlpool.com
Q. How many bassists does it take to screw in a light bulb?
A. None, the keyboardists left hand does it for them.
------------------------------
Date: 20 Mar 1997 21:53:12 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Getting Perl 5
Message-Id: <5gsbk8$48m$1@csnews.cs.colorado.edu>
In comp.lang.perl.misc,
"Jonathan Barry Neufeld" <jneufeld@rapidnet.net> writes:
:How can I get a Perl 5 compiler and a documentation for it?
Now guys, let's not all mail him the FAQ at once. :-)
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"Sometimes the sins of the fathers are visited on the nephews and nieces."
--Larry Wall
------------------------------
Date: 20 Mar 1997 12:16:59 GMT
From: "Marcelo de Azevedo Camelo" <camelo@itanet.com.br>
Subject: How to get file time and date stamps?
Message-Id: <01bc3526$e9ff8e00$LocalHost@marcelo>
I'm writing a CGI script in Perl 5, and I need it to
read both time and date stamps from a file residing
in current directory. Is it possible? If so, how can I
do it?
Thank you very much,
--
Marcelo A. Camelo - Sao Paulo - SP - Brazil
------------------------------
Date: 20 Mar 1997 15:09:32 GMT
From: breville@uoguelph.ca (Barry G Reville)
Subject: How to use modules in Perl5?
Message-Id: <5grjvc$6d4@ccshst05.cs.uoguelph.ca>
Although I currently use the CGI.pl module in my scripts I
still don't understand how to use and include modules.
In my scripts currently I have:
#!/usr/local/bin/perl5.003
use lib '/var/local/httpd/cgi-bin';
use CGI qw(:standard);
and this works perfectly for my system but..
I would also like to use the 'use diagnostics' and 'use strict'
commands as well as the 'use CGI::Carp qw(fatalsToBrowser);' that I've
seen around and would be really handy but I can't seem to get them to
work for me.
Any help would be appreciated.
Barry Reville
University of Guelph
Computing and Communications Services
breville@uoguelph.ca
www.uoguelph.ca/~breville
------------------------------
Date: 20 Mar 1997 16:19:31 GMT
From: jhamlin@ai.uga.edu (Jon Hamlin)
Subject: Mail from perl - input read error
Message-Id: <5gro2j$2u3$1@cronkite.cc.uga.edu>
I'm working on a program that mails its output to the administrator. The
program runs and completes, but I get an input read error just before the
prompt returns (right as the close statement on the output is executed).
If I send the output straight to a file (not through mail), it works without
an error. If I send it through mail (using "|mail username" as the
outfile filename), the entire output is mailed, but I also get the error.
Any ideas as to how to mail this output and clean up the error?
------------------------------------------------------------------------------
Jon Hamlin, Sys Admin jhamlin@ai.uga.edu
Artificial Intelligence Center http://www.ai.uga.edu/~jhamlin
University of Georgia Voice: (706) 542-0358
------------------------------
Date: 20 Mar 1997 18:28:21 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl 100 times slower ...
Message-Id: <5grvk5$mjb$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Opera Ghost <agent.email@NetTown.com> writes:
:the perl compilier should give u an idea of what ur 'new features' costs
:http://www.perl.com/perl has links to compiler and info
:
:the best thing to do is check out the perl source code (in c)
:for the parts that u think r slow. it just so happens that i have
plz stp rtng gky duhm hkrz tlk. ts2hrd2rd.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
I use `batshit' in an idiosyncratic fashion. --Andrew Hume
------------------------------
Date: 20 Mar 1997 13:32:58 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl 100 times slower ...
Message-Id: <5greaa$a3e$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Opera Ghost <agent.email@NetTown.com> writes:
:if u du check out the internals of perl,
PlsPstInEnglsh.ThtCrpIsHrd2Rd.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
Actually, you'll know we're nearing the end when I make |$foo| mean
"absolute value"... :-) Larry Wall in <1994Feb25.192042.17196@netlabs.com>
------------------------------
Date: Thu, 20 Mar 1997 09:38:27 -0600
From: Josh Dowdell <josh@dowdell.com>
Subject: Perl for NT list?
Message-Id: <333159F3.67A@dowdell.com>
Does anyone know if there is a newsgroup specific to NT issues?
Specifically, the newest version I've found that supports ISAPI
correctly is 5.001m. I found a 5.003 but when it installed, there was
no ISAPI.DLL at all. I've been all over perl.com and download servers
so either I missed something or I already have the latest version for
ISAPI.
Thanks
Josh
------------------------------
Date: 20 Mar 1997 22:40:37 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Problems with flock()
Message-Id: <5gsed5$6hr$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
rudolf@metadesign.de (Jim Rudolf) writes:
:I don't understand why you recommend avoiding shared locks.
Because people do dumb things. This is very common:
get read lock
read counter
upgrade to write lock
add one to counter
write back to file
close file
Do you see the bug? We cannot fix integrity and transaction
processing bugs with flock fixes.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"You're flame-proof in the same sense that certain plastics are fluorine-proof."
--Larry Wall
------------------------------
Date: Thu, 20 Mar 1997 08:36:20 +0000
From: Opera Ghost <agent.email@NetTown.com>
To: Jonathan Barry Neufeld <jneufeld@rapidnet.net>
Subject: Re: QUESTIONNAIRE FOR PERL GURUS
Message-Id: <3330F704.4A5BA378@NetTown.com>
Jonathan Barry Neufeld wrote:
>
> Hi, my name is Jonathan Neufeld and I am very curious of how
> people get into Perl, learn it, and use it in the future. I would like
> to have this information that I might see what the road of Perl is
> going to be like before I set out on it.
>
> If you would take the time to answer a couple of questions I think
> you'll greatly enlighten many people including me! So let's get
> started:
>
> 1. How long have you been programming in Perl?
> 2. What made you start learning Perl?
> 3. What has learning Perl been like for you? i.e. troubles etc.
> 4. How has Perl changed your outlook on programming?
> 5. For what applications do you use Perl?
> 6. Overall what is your general opinion of Perl?
>
> Thank you for your time, it is greatly appreciated by many and I
> hope to conference with you some time in the future.
>
> --
> Jonathan B. Neufeld
> Solar Tech Enterprises and Consulting
> NT-Online Technologies:
> http://www.ntonline.com
> Ph: 793-3657 Fax: 793-3659
ill only answer if u can give me a link to all anwsers
(if u need help with this just email me)
--
<i>Opera Ghost
<mailto:agent.email@NetTown.com>
[http://NetTown.com/site_perl/]
have a good day!
------------------------------
Date: Thu, 20 Mar 1997 10:09:03 -0800
From: Micah Potechin <mipotech@novice.uwaterloo.ca>
Subject: Response headers
Message-Id: <33317D3F.68D8@novice.uwaterloo.ca>
I am attempting to create a personalized mail script to be used with an
online application form. My test of the program terminates properly
from the command line (although it does not actually send the mail), but
does not work using the CGI interface. All the forms are correct, as I
have tested the form in several other ways.
My error log shows this when I attempt to use the CGI interface:
did not produce a valid header (program terminated without a valid CGI
header. Check for core dump or other abnormal termination)
Below is the excerpt from my script that deals with the mail. The print
statements were used to see where my code stopped functioning.
I would appreciate any help on this topic.
Thanks,
Micah Potechin
Intermediate programmer
print("Opening Files\n");
open (JOBLIST, "/opt/ns-home/docs/appform/jobs.dat") || die("\n");
open (OFFICES, "/opt/ns-home/docs/appform/offices.dat") || die("\n");
print("Finding Office\n");
do {
$job = <JOBLIST>;
chop($job);
($number, $office) = split(/:/,$job,2);
print("$number $office\n");
} until ($number eq $in{'Reference number'});
do {
$job = <OFFICES>;
chop($job);
($off, $mail) = split(/:/,$job,2);
print("$off $mail\n");
} until($office eq $off);
print("Opening mail program\n");
$host=$ENV{'REMOTE_HOST'}?$ENV{'REMOTE_HOST'}:$ENV{'REMOTE_ADDR'};
open(MAILOFFICE, "| $mail") || die("\n");
print("Writing to mail program\n");
print MAILOFFICE <<"ENDAPP";
Cc: mipotech\@novice.uwaterloo.ca
From: $in{'E-mail address'}
To: $mail
Reply-To: $in{'E-mail address'}
Errors-To: $in{'E-mail address'}
Sender: $in{'E-mail address'}
Subject: Application for web-advertised job #$in{'Reference number'}
X-Mail-Gateway: Micah Potechin's mail script
X-Real-Host-From: $host
RESUME
$in{'Resume'}
ENDAPP
print("Closing mail program (to send mail)\n");
close(MAILOFFICE);
------------------------------
Date: 20 Mar 1997 15:45:56 GMT
From: roberto@eurocontrol.fr (Ollivier Robert)
Subject: Re: Signal catching with alarm
Message-Id: <5grm3k$i8v$2@polaris.eurocontrol.fr>
[courtesy cc of this posting sent to cited author via email]
In article <5g9gqn$cip@mikey.convex.com>,
David DeSimone <fox@convex.com> wrote:
> Thus, sleep() is incompatible with alarm().
Depends on you implementation of sleep(3).
4.4BSD's one doesn't use SIGALRM.
--
Ollivier ROBERT -=- Eurocontrol EEC/TS -=- Ollivier.Robert@eurocontrol.fr
Usenet Canal Historique FreeBSD: there are no limits !
------------------------------
Date: 20 Mar 1997 13:38:41 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: simple counter
Message-Id: <5grel1$a3e$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
"R. Vince" <rvince@sprynet.com> writes:
:Can anyone send me a simple perl 5 counter....I'm just looking for
:something really simple, more as a learning tool. thx, Ralph
Didn't read the FAQ, eh? Visit http://www.perl.com/perl/faq/ for
details.
NAME
perlfaq5 - Files and Formats ($Revision: 1.19 $)
DESCRIPTION
This section deals with I/O and the "f" issues: filehandles,
flushing, formats, and footers.
.......
How can I lock a file?
Perl's built-in flock() function (see the perlfunc manpage for
details) will call flock(2) if that exists, fcntl(2) if it
doesn't (on perl version 5.004 and later), and lockf(3) if
neither of the two previous system calls exists. On some
systems, it may even use a different form of native locking.
Here are some gotchas with Perl's flock():
1 Produces a fatal error if none of the three system calls (or
their close equivalent) exists.
2 lockf(3) does not provide shared locking, and requires that
the filehandle be open for writing (or appending, or
read/writing).
3 Some versions of flock() can't lock files over a network (e.g.
on NFS file systems), so you'd need to force the use of
fcntl(2) when you build Perl. See the flock entry of the
perlfunc manpage, and the INSTALL file in the source
distribution for information on building Perl to do this.
The CPAN module File::Lock offers similar functionality and
(if you have dynamic loading) won't require you to rebuild
perl if your flock() can't lock network files.
What 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, 0644)
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 involving link() have
been suggested, but these tend to involve busy-wait, which is
also subdesirable.
I still don't get locking. I just want to increment the number in
the file. How can I do this?
Didn't anyone ever tell you web-page hit counters were
useless?
Anyway, this is what to do:
use Fcntl;
sysopen(FH, "numfile", O_RDWR|O_CREAT, 0644) or die "can't open numfile: $!";
flock(FH, 2) or die "can't flock numfile: $!";
$num = <FH> || 0;
seek(FH, 0, 0) or die "can't rewind numfile: $!";
truncate(FH, 0) or die "can't truncate numfile: $!";
(print FH $num+1, "\n") or die "can't write numfile: $!";
# DO NOT UNLOCK THIS UNTIL YOU CLOSE
close FH or die "can't close numfile: $!";
Here's a much better web-page hit counter:
$hits = int( (time() - 850_000_000) / rand(1_000) );
If the count doesn't impress your friends, then the code
might. :-)
--
Tom Christiansen tchrist@jhereg.perl.com
if (rsfp = mypopen("/bin/mail root","w")) { /* heh, heh */
--Larry Wall in perl.c from the perl source code
------------------------------
Date: 20 Mar 1997 16:49:27 -0700
From: dbell@azstarnet.com (David Bell)
Subject: Re: Sort question
Message-Id: <5gsie7$hl0@web.azstarnet.com>
In article <5gs5su$irn@mailman.xilinx>, Milan Saini <milan@xilinx.com> wrote:
>
>Hi
>
>I want to sort a hash but am not getting the order I seek:
>
>#!/usr/local/gnu/bin/perl
>
>%list1=("1_2.9" => 1,"1_2.7" => 1,"1_2.11" => 1);
>
>foreach $keys (sort keys %list1)
(posted and CC'd)
You didn't say whether this is the only case you need to handle, or what
other keys might look like.
Assuming they always start with "1_2.", you could do something like this:
sort { substr($a,4) <=> substr($b,4) } keys %list1
If you want something more general, in which there could be different numbers
before and after the _ and you want each section sorted, you could define
a sort subroutine such as:
sub myway {
$a =~ m/(\d+)_(\d+)\.(\d+)/ or die "wrong format: $a";
my ($a1, $a2, $a3) = ($1, $2, $3);
$b =~ m/(\d+)_(\d+)\.(\d+)/ or die "wrong format: $b";
my ($b1, $b2, $b3) = ($1, $2, $3);
($a1 <=> $b1) # sort by first field
or ($a2 <=> $b2) # ... or by second if first are same
or ($a3 <=> $b3); # ... or by third if first two are same
}
and then you'd use:
sort myway keys %list1
(there are faster ways if you have a humongous list to sort.) Check out the
blue Camel pp. 217-219 if you haven't used sort subroutines before.
Dave
------------------------------
Date: Thu, 20 Mar 1997 18:44:31 -0500
From: Paul S R Chisholm <psrc@exmachina.com>
Subject: trouble matching multiple fields
Message-Id: <3331CBDF.3B4C@exmachina.com>
I have lines of the form:
name field=value field=value
and want to match the results with a minimum of fuss. I first tried:
m/^(\w+)(?:\s+(\w+)=(\S+))*$/
(match the first word, then successive field=value pairs). Interesting
result: three things are always matched, and $2 and $3 are undefined if
there are no field=value pairs. Here's some sample text and what appears
to be matched:
foo (foo, undefined, undefined) why match three?
foo one=1 (foo, one, 1) okay
foo one=1 two=2 (foo, two, 2) what happened to one and 1?
I tried:
m/\s+(\w+)=(\S+)*$/g
for matching all but the first field; I don't match undefined pairs if
there are no pairs, but I still only match the last pair if there's more
than one. Similarly for:
while (m/\s+(\w+)=(\S+)*$/g)
(the /g is needed to avoid an infinite loop).
perl -v ouput:
This is perl, version 5.003 with EMBED
built under solaris at Sep 13 1996 18:40:53
+ suidperl security patch
Complete program to demonstrate the behavior:
#!/usr/local/bin/perl -w
while (<>) {
my (@fields) = ($_ =~ m/^(\w+)(?:\s+(\w+)=(\S+))*$/);
if (! defined(@fields) || ! scalar(@fields)) {
print "no match\n";
next;
}
my $field;
foreach $field (@fields) {
if (! defined($field)) {
$field = '<undefined!>';
}
}
print join(':', @fields), "\n";
# try picking the other fields up in one m//g match
@fields = ($fields[0]); # first field as per before
push @fields, (m/\s+(\w+)=(\S+)*$/g);
print join(':', @fields), "\n";
# try picking the other fields up in a loop
@fields = ($fields[0]); # first field as per before
while (m/\s+(\w+)=(\S+)*$/g) {
push @fields, $1, $2;
}
print join(':', @fields), "\n";
}
Interesting input to above program:
foo
foo one=1
foo one=1 two=2
foo one=1 two=2 three=3
Yes, I've read Jeffrey Friedl's MASTERING REGULAR EXPRESSIONS (do you
think I could have gotten into this much trouble by myself?) (great
book, by the way).
Help? --PSRC, mailto:psrc@exmachina.com
------------------------------
Date: Fri, 21 Mar 1997 00:54:38 GMT
From: pduff@airmail.net (Patrick Duff)
Subject: undef() fails when given a list of arguments
Message-Id: <3331dbc6.344732613@news.airmail.net>
Chapter 3 in the blue camel "Programming Perl" book (Perl 5) documents
the syntax of local, my, and undef as follows:
local EXPR
my EXPR
undef EXPR
It then proceeds to give examples where local and my are passed a list
of variable names instead of a single variable name. However, when I
do something like
undef(%one,%two,%three);
in Perl (Win NT build 302, v5.003) I get the error messages:
Useless use of "%two" in void context.
Useless use of "%three" in void context.
Changing the line to:
undef(%one);
undef(%two);
undef(%three);
works fine. In my application I have about thirty hashes to undefine,
and I had assumed that one call to undef would be more efficient than
thirty calls.
IMHO, undef should do what I mean when I pass it a list of variable
names.
--
regards, Patrick Duff (pduff@airmail.net)
------------------------------
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 150
*************************************