[7394] in Perl-Users-Digest
Perl-Users Digest, Issue: 1019 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 13 01:17:20 1997
Date: Fri, 12 Sep 97 22:00:26 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 12 Sep 1997 Volume: 8 Number: 1019
Today's topics:
Re: Calling a Perl Script... (Ken C.)
chat script webmaster@startrekker.net
Re: Declaring dynamically named lexical variables (Dan Sumption)
Re: flock in Win32? (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Re: Forking problem (Charles DeRykus)
Form to Mail Scripts Won't Mail. <honza@honza.com>
Free Perl CGI Scripts, password protection michael.nilsson@maze.se
Re: Free Perl CGI Scripts, password protection (brian d foy)
Help with perl!! Please!! <kpahlevan@hotmail.com>
HELP: Wierd sendmail problem <areeves@us.ibm.com>
Re: How to make 'beep' sound in perl? (Faust Gertz)
Re: How to make 'beep' sound in perl? <alan@mattress.atww.org>
How to make this program faster? (Mark K. Pettit)
Re: Howto Parse data in spaced columns??? (Steve Monson)
HTTPD::GroupAdmin Question (Trei B.)
Re: Illegal character \015 (carriage returns) -- HELP <jwbacon@ix.netcom.com>
Re: is there a better way to do this subroutine? (Matthew Cravit)
Re: Perl on SunOS question <rael@zx80.dnai.com>
Re: Please help me with locking! Using NDBM! <mf@fishbone.ruhr.de>
Re: Strange behavior with undefined subroutine <chrisl@earthlink.net>
Re: strict-module problem <mf@fishbone.ruhr.de>
Re: Strip spaces in filenames <dtrobert@ladc.lockheed.com>
Re: Strip spaces in filenames (Tad McClellan)
what's the case <edbishop@hotmail.com>
Re: what's the case (Tad McClellan)
Why can't I talk directly to the mail daemon? (Brian Kendig)
Re: Win 95 Perl & Tk <ase@seanet.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 13 Sep 1997 00:55:15 GMT
From: n8ptt@ibm.net (Ken C.)
Subject: Re: Calling a Perl Script...
Message-Id: <3419e500.0@news2.ibm.net>
1) From my Novell server here's an example of what I use
in an html. The extension of the html is SSI, i haven't figured out how
to get it work from an extension of htm <sigh...>. Probably something
simple..... (do you know?)
<!--#exec cgi="/perl/phone.pl?loc=Ann Arbor" -->
(I'm passing variable loc=Ann Arbor to the perl program)
2) no idea. never tried it.
Ken C.
In article <3415975E.3DF34B61@ait.acl.ca>, Guy Doucet <gdoucet@ait.acl.ca>
wrote:
>(1) I want to know how to call a Perl script from an HTML/JavaScript
>document, other than the <form method="post"... or "get"... What I'm
>getting at is I'd like to know if a JavaScript can call the Perl script
>directly.
>
>(2) I am running on a Novell Web Server and I was wondering how to call
>a Perl script that doesn't return anything to the web page. When I try,
>I get Document contains no data.
>
>Guy Doucet - new to Perl
>
------------------------------
Date: Fri, 12 Sep 1997 18:01:35 -0600
From: webmaster@startrekker.net
Subject: chat script
Message-Id: <874105074.7406@dejanews.com>
Hello!
I'm in the process of moving my homepage to a new server. The old
server was WinNT, the new one is Linux. I changed all my scripts and
they appear to run smoothly, the only script I have problems with is
the chat script.
For some time it works perfectly, but then, suddenly I get some
"Document contains no data" messages, if I try again later,
everything works fine again.
Could ANYONE of you please help me?
The script is at
http://www.dragonfire.net/~base/chat/chat.htm
or
http://base.dragonfire.net/chat/chat.htm
thank you VERY much
mike
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Fri, 12 Sep 1997 22:22:37 GMT
From: dan@gulch.demon.co.uk (Dan Sumption)
Subject: Re: Declaring dynamically named lexical variables
Message-Id: <3419bcb5.12757914@news.demon.co.uk>
On Fri, 12 Sep 1997 12:07:38 GMT, zawodny@hou.moc.com (Jeremy D.
Zawodny) wrote:
>[cc'd automagically to original author]
>
>On Fri, 12 Sep 1997 08:03:34 GMT, dan@gulch.demon.co.uk (Dan Sumption)
>wrote:
>
>>Can someone tell me how I would declare a lexical variable whose name
>>is determined by another variable. I had thought that placing a
>>variable name inside a block would return a variable whose name was
>>the product of the block, e.g.
>> $varname1 = 'foo';
>> $varname2 = 'bar';
>> my ${$varname1} = ${$varname2};
>>would be the equivalent of saying:
>> my $foo = $bar;
>>
>>However, it seems I was wrong, and that this produces a reference,
>>generating the error 'Can't declare scalar deref in my'
>>
>>Can someone tell me how I would declare the my variables correctly?
>
>I believe there were examples of how to do this in the old Camel book,
>using eval. I'd check the section on eval(). It may or may not appear
>in the new book (don't have a copy handy).
>
>In any case, what's wrong with a reference? :-)
I have been scouring the second edition for a solution to this, and
just checked the section on eval in the first edition - nowhere that I
have found is the matter of dynamically named lexical (i.e. 'my')
variables discussed. I believe that if I use an eval to name the
variable, then (as it is a 'my' variable) it will only last for the
scope of the eval.
There are 2 reasons why I don't want to use references - one is
because the variables I am creating are temporay copies of global
variables, which are then changed and then reset to their original
values before the copy goes out of scope. To create a reference, I
would still need to copy the original somewhere before taking the
reference (otherwise reference would point to the changed value). The
second reason is because the variables I am copying from are the
public interface to the program, and they must contain scalar values
rather than references to scalar values - this is so that templates
passed to the program can be created using a set of simple to remember
variables, like $name, $description, $content
Actually, I sort of solved the problem by making a lexically scoped
hash, and adding each item as a member of the hash, e.g. instead of
my ${$varname1} = blah blah blah;
I put
$myhash{$varname1} =
&globalswap_in($varname1,$self->$varname1);
However, I'm still having some problems under the hood - in the
globalswap_in subroutine. I'll have a hack at it - but I may be back
soon!
Have fun.
Dan Sumption, Technical Director dan@gulch.demon.co.uk
Hard Reality, Canary Wharf, London E14 dan@hardnet.co.uk
http://www.hardnet.co.uk/dan/
------------------------------
Date: Fri, 12 Sep 97 19:53:24 -0400
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: flock in Win32?
Message-Id: <3419d62c$6$ofn$mr2ice@speaker.kf8nh.apk.net>
In <34199681.66F6609@atc.boeing.com>, on 09/12/97 at 07:22 PM,
Paul Hovnanian <hovnania@atc.boeing.com> said:
+-----
| This might be complicated by the variety of file systems that Win95/NT can
| run on. I believe there's at least 2, possibly 3 (FAT, FAT32, NTFS(?)).
+--->8
Add that NT3.51 comes with and NT4 can be retrofitted with HPFS.
--
brandon s. allbery [Team OS/2][Linux] bsa@void.apk.net
cleveland, ohio mr/2 ice's "rfc guru" :-) FORZA CREW!
Warpstock '97: OS/2 for the rest of us! http://www.warpstock.org
------------------------------
Date: Sat, 13 Sep 1997 01:11:51 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Forking problem
Message-Id: <EGF9zt.FKF@bcstec.ca.boeing.com>
In article <5vc0pl$8fe@netline.jpl.nasa.gov>,
Peter Scott <Peter.J.Scott-remove-to-email@jpl.nasa.gov> wrote:
> This is bizarre. I have a program which forks children that appear to
> be executing *after* they have exited and signalled the parent!
>
> The following code forks six subprocesses, each of which creates an empty
> file in /tmp called "test" plus the child's pid. It then waits for each
> child to finish, and deletes the corresponding file.
>
> $| = 1;
> foreach (1..6) {
> if ($pid = fork) {
> $p{$pid} = 1; # parent
> print "Spawn $pid\n";
> }
> else {
> exit &bar; # child
> }
> }
> while (keys %p) {
> $pid = wait until exists $p{$pid};
> print "Harvest $pid: ";
> print "can't find its file!!!" unless -e "/tmp/test$pid";
> print "\n";
> unlink "/tmp/test$pid";
> delete $p{$pid};
> }
>
> sub bar {
> open (F, ">/tmp/test$$");
> close F;
> return 0;
> }
>
> The result:
>
> Spawn 1771
> Spawn 1772
> Spawn 1773
> Spawn 1774
> Spawn 1775
> Spawn 1776
> Harvest 1776: can't find its file!!!
> Harvest 1773:
> Harvest 1772:
> Harvest 1771:
> Harvest 1775:
> Harvest 1774:
>
> Yet /tmp/test1776 exists! Here's what I've been able to find out:
>
> I need to create 6 or more children to see this effect, although it
> doesn't always happen with 6, so if you don't see this happen, increase
> the count to 8 or 10.
>
> If I change the $pid = wait until line to:
> do
> {
> $pid = wait;
> } until exists $p{$pid};
>
> there is no problem.
>
> If I truss the parent, I still get the behavior. If I truss the children
> as well, I don't (so much for debugging).
>
> A test after the close in bar() for the existence of the file never fails.
>
> The file not found is always the one from the last forked child in this
> program. However, in the more complicated program where I first saw this
> behavior, I have seen it happen to multiple children.
>
> Perl 5.004_01 on Solaris 2.5.1. Not running on a multiprocessor machine.
> /tmp is local, not NFS mounted.
>
Race condition. If $p{$pid} exists, then the loop may exit
prematurely without the wait call. That's why forcing the
condition test to follow the wait with a do-until loop works.
HTH,
--
Charles DeRykus
------------------------------
Date: 13 Sep 1997 01:58:24 GMT
From: "Honza" <honza@honza.com>
Subject: Form to Mail Scripts Won't Mail.
Message-Id: <01bcbfe8$7c0d5e20$d884accf@default>
Help-- I've tried a number of form2mail scripts, and while they appear to
work, the mail is never sent. I'm running them on Perl5 and Apache 1.2 on
SunOS 5.5.1 -- any ideas?
Thanks
------------------------------
Date: Fri, 12 Sep 1997 18:01:50 -0600
From: michael.nilsson@maze.se
Subject: Free Perl CGI Scripts, password protection
Message-Id: <874104574.6967@dejanews.com>
New free perl script protect.pl http://www.maze.se/freeware/
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Fri, 12 Sep 1997 20:14:17 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Free Perl CGI Scripts, password protection
Message-Id: <comdog-ya02408000R1209972014170001@news.panix.com>
In article <874104574.6967@dejanews.com>, michael.nilsson@maze.se wrote:
>New free perl script protect.pl http://www.maze.se/freeware/
thanks for sharing with the world! :)
i took a look at your source - give me telnet and i can defeat it.
checking HTTP_REFERER is not security. you'll also run into
problems with proxies by trying to block IP numbers.
you might want to look at the various server products to see
which ones don't implement these sorts of protection features
already.
good luck :)
--
brian d foy <comdog@computerdog.com>
------------------------------
Date: 12 Sep 1997 20:28:25 GMT
From: "Kaveh Pahlevan" <kpahlevan@hotmail.com>
Subject: Help with perl!! Please!!
Message-Id: <01bcbf99$1f1b0fe0$048ec7cf@azno.dgsys.com>
Hi,
I have successfully created a script that takes the input of a form and
puts it into another file. The file that it puts the information in is
depended on the user's input into the form. Anyways, the scripts works
fine, but I would like to know how many people are filling out the form.
How would I go about adding a number to a variable everytime someone fills
out the form. If you want, you can take a look at the modem players list by
going to http://www.mystation.com/ram and clicking on the modem players
list icon on the left nav. bar once you are there. Please take a look and
tell me how I can keep track of the number of people filling out the form.
Thanks a lot!
- Kaveh Pahlevan
- Red Alert Madness
- http://www.mystation.com/ram
------------------------------
Date: Fri, 12 Sep 1997 17:26:25 -0700
From: Adam Reeves <areeves@us.ibm.com>
Subject: HELP: Wierd sendmail problem
Message-Id: <3419DDB1.5B0@us.ibm.com>
In one of my programs I have the following code:
open(MAIL, "|/usr/bin/sendmail -F\"$sender\" -f\"$sender_email\"
\"$recipient\"")
or bail("Cannot send mail to $recipient: $OS_ERROR");
print MAIL <<EMAIL;
blah blah blah
EMAIL
close(MAIL)
or bail("Could not complete the email to $recipient:$OS_ERROR");
It will work fine from the command line and from a browser on server A,
but it won't work on server B.
On server B I get the following error message:
Could not complete the email to xxx@xxx: No child processes
Is there something I need to know about sendmail?
Does it have to do anything with the environment?
How do I go about debugging this?
How do I capture the error messages from a forked process?
Any help would be GREATLY appreciated!
Cheers,
Adam Reeves
areeves@us.ibm.com
------------------------------
Date: Fri, 12 Sep 1997 22:33:48 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: How to make 'beep' sound in perl?
Message-Id: <3419bc26.784988@news.wwa.com>
On Fri, 12 Sep 1997 12:51:26 -0700, "Christopher M. Lee"
<chrisl@earthlink.net> wrote:
>I got both to work on a solaris server
>
> print "\a";
>
>and
>
> print "\07";
>
>Now I have an additional question. How would you get multiple beeps. Doing this
>does not work:
>
>print "\a\a\a";
Maybe you are getting three very fast beeps. :-) I can't get a bell
sound or to perl from this terminal, so I can't test it out, but could
you do something like:
for ($i = 0; $i < 3; $i++) {
sleep $i;
print "\a";
}
Which I guess would give you three beeps like this.
Beep
Sleep one second
Beep
Sleep two seconds
Beep
But on second thought, I bet it won't. It will sleep for three
seconds and then
print "\a\a\a";
because the three "\a"s will be in the print buffer. Try just
printing 'a ' instead of "\a" to see what I mean. So you will
probably have to empty the print buffer after each time you print "\a"
and then sleep to get the sound of three distinct bells.
And other thoughts?
Streben nach Wahrheit
Faust Gertz
Philosopher at Large
------------------------------
Date: 13 Sep 1997 00:12:52 GMT
From: A. Reichert <alan@mattress.atww.org>
Subject: Re: How to make 'beep' sound in perl?
Message-Id: <5vclq4$um2$1@mattress.atww.org>
On Fri, 12 Sep 1997 22:33:48 GMT, Faust Gertz <faust@wwa.com> wrote:
: On Fri, 12 Sep 1997 12:51:26 -0700, "Christopher M. Lee"
: <chrisl@earthlink.net> wrote:
[...]
: Maybe you are getting three very fast beeps. :-) I can't get a bell
: sound or to perl from this terminal, so I can't test it out, but could
: you do something like:
: for ($i = 0; $i < 3; $i++) {
: sleep $i;
: print "\a";
: }
: Which I guess would give you three beeps like this.
: Beep
: Sleep one second
: Beep
: Sleep two seconds
: Beep
: But on second thought, I bet it won't. It will sleep for three
: seconds and then
: print "\a\a\a";
: because the three "\a"s will be in the print buffer. Try just
: printing 'a ' instead of "\a" to see what I mean. So you will
: probably have to empty the print buffer after each time you print "\a"
: and then sleep to get the sound of three distinct bells.
: And other thoughts?
I think your first one is correct, one second delay, then two seconds...
Just replace your "sleep $i:" with "sleep 1;" for a constant delay.
- Alan
------------------------------
Date: 12 Sep 1997 20:55:18 -0700
From: mpettit@geocities.com (Mark K. Pettit)
Subject: How to make this program faster?
Message-Id: <x7n2lheul5.fsf@geocities.com>
Hi, everone.
I have a Perl script that runs every night, processing web server
logs. However, since our site is growing every day (plug plug), the
program is taking longer and longer to run. Today's version took 12
hours to complete, and that's really too long. We would like to speed
this process up. I was hoping someone could give me some hints.
Here's what it does. It reads a line containing a bunch of fields
separated by tabs. It "split()"s it into an array, and then looks at
the total number of fields (there are two possible legal line
lengths). Based on that result, it assigns the array to an aggregate
(is that the right term?) like this:
($foo, $bar, $baz, ...) = @array;
Then, it uses a rather complicated regexp to clean up the URL (one of
the fields in the array):
$url =~ s#^http://www[0-9]*\.geocities\.com\.*(:[0-9]*)?##i;
$url =~ s#^http://192\.216\.191\.[0-9]{1,3}(:[0-9]*)?##i;
$url =~ s#^http://205\.180\.58\.[0-9]{1,3}(:[0-9]*)?##i;
Finally, it calls a subroutine (find_category) to determine what
category a given URL should belong to. I think that probably this is
the part that is slowest.
Here is the subroutine (it's short):
=====================================================================
sub find_category {
my ($url) = @_;
if ($url =~ m#^/*(main/|BHI/)?(index\.html)?$#) {
return "MainPage";
}
foreach (keys %VisitorFeatures) {
if ($url =~ /$_/) {
return $VisitorFeatures{$_};
}
}
foreach (keys %HomesteaderTools) {
if ($url =~ /$_/) {
return $HomesteaderTools{$_};
}
}
foreach (keys %Neighborhoods) {
if ($url =~ /$_/) {
return $Neighborhoods{$_};
}
}
return "Other";
}
=====================================================================
I have three hashes set up, like this:
%Neighborhoods = (
"^/*(cgi-bin/(homestead/hood_addr/|starpt_fetch_ad/))?Area51" => "Area51",
"^/*(cgi-bin/(homestead/hood_addr/|starpt_fetch_ad/))?Athens" => "Athens",
"^/*(cgi-bin/(homestead/hood_addr/|starpt_fetch_ad/))?Augusta" => "Augusta",
[etc.]
Each one contains a regexp as the key, with the category as the
value. Most of the ones in %HomesteaderTools and %VisitorFeatures are
simpler regexp's than the ones above, but some aren't.
I guess my main question is this: What is more efficient, doing a
regular expression like the one above, or breaking it out like this:
%Neighborhoods = (
"^/*Area51" => "Area51",
"^/*cgi-bin/homestead/hood_addr/Area51" => "Area51",
"^/*cgi-bin/starpt_fetch_ad/Area51" => "Area51",
[etc.]
In the first case, I have one regexp that handles all three possible
URLs. In the second case, I have a much simpler regexp, but there are
three lines for each Neighborhood. There are nearly 40
Neighborhoods, and the log files contain nearly 9 million entries.
That's a *LOT* of lines to go through.
My program already runs in linear time, so that's great, but the
problem is the constant factor :-). I need to bring that puppy
*DOWN*! Any help would be greatly appreciated.
--
------------------+--------------------------------------------
Mark K. Pettit | SpamGard(tm) in effect. To send me mail,
pettit@acm.org | include the word "tiger" in the subject.
------------------+--------------------------------------------
------------------------------
Date: 12 Sep 1997 15:00:47 -0500
From: smonson@tri.sbc.com (Steve Monson)
Subject: Re: Howto Parse data in spaced columns???
Message-Id: <5vc71f$14r@euphony.tri.sbc.com>
Gip <nospam.gibsonc@aztec.asu.edu> wrote:
>
>How do I parse data out of the following computed text file, you can
>assume no tabs, just plain old spaces:
>
>
1 2 3 4 5 6
1234567890123456789012345678901234567890123456789012345678901234567890
>column 1 column 2 column 3 column 4
>
>aaa bbb ccc
>ddd
>eee fff
>
>I want to be able to know that fff is in column 4, and that ccc is in
>column 3.
>From your sample, it's not clear that "fff" is in column 4. For our
purposes, let's say that the column headings are left-justified
(making "fff" lie in column 3, but you can adapt the numbers as you
need to).
column 1 is 17 characters wide (1-17)
column 2 is 23 characters wide (18-40)
column 3 is 24 characters wide (41-64)
column 4 is the rest.
$line =~ /^(.{1,17})(.{1,23})(.{1,24})(.*)/;
@cols = ($1,$2,$3,$4);
will divide up the text into @cols[0..3], allowing for the fact
that there may not be data in every column. Then you can strip off
any leading/trailing spaces if you want, and process the columns' data.
Steve Monson
--
The difference between chimps and Chicago drivers is that chimps
display their fangs whereas Chicago drivers display their middle
finger.
-- Allen R. Sampson
------------------------------
Date: Fri, 12 Sep 1997 19:41:33 -0600
From: trei@clockwerks.com (Trei B.)
Subject: HTTPD::GroupAdmin Question
Message-Id: <874110435.12458@dejanews.com>
I am using the HTTPD::GroupAdmin module to work with my .htgroup file.
Everything is great except that I can't delete entire groups and their
users from the .htgroup file. The docs have a reference to this ability,
but no example code. Does anyone know how this is done? I don't want to
delete a user from a group, I want to delete the entire group from the
.htgroup file.
thanks,
Trei Brundrett - trei@clockwerks.com
the ClockWerks - Internet Production
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 13 Sep 1997 02:19:41 GMT
From: J. Bacon <jwbacon@ix.netcom.com>
Subject: Re: Illegal character \015 (carriage returns) -- HELP
Message-Id: <5vct7t$4fe@sjx-ixn3.ix.netcom.com>
In article <874035814.11389@dejanews.com>,
pittelli@ehsct7.envmed.rochester.edu says...
>
>With perl -c in a shell, all the cgi scripts on a client's Unix Apache
>server, JUST upgraded to Perl 5.004_01, return:
>
>"Illegal character \015 (carriage return) at ...
>(maybe you didn't strip carriage returns after a network transfer)"
>
> ...when they ALL worked in 5.002.
>I undertand the error, read the FAQ on \n versus \r and different
>platforms, BUT:
>
>1) How do I actually strip the carriage returns in all of those scripts?
>Even a manual {:-< edit with PICO (sp?) doesn't catch those hidden
>critters. Or is there a way to PREVENT the occurrence BEFORE file
>transfer (development and transfer using Win95/WS-FTP)?
>
>2) Why is this only a problem now? I've installed several hundred scripts
>on all sorts of Unix servers w/all versions of Perl, but have gotten two
>of this particular report (another 5.004 Unix machine), only in the past
>week. Is this something particular to 5.004?! Why did they work before?
>
>Thanks
>-Randy
When I had a Linux box working (for about a week) I used the "tr" command to
do that to all the stuff I had copied from my Windows '95 machine.
------------------------------
Date: 12 Sep 1997 16:00:46 -0700
From: mcravit@best.com (Matthew Cravit)
Subject: Re: is there a better way to do this subroutine?
Message-Id: <5vchiu$lot$1@shell3.ba.best.com>
>> > local(*p,*plog)=@_;
>> ^^^^^^^^
>
>oh really cant recognize two arrays being passed in ... this is right
>out of the perl5 book example
Yes, but if you read the rest of the page that's on (the bottom of page 117
in the blue Camel), it says that you're effectively doing symbol table
aliasing, and you then need to invoke this function like:
(*something) = Function(\@p, \@plog);
Is that what you used?
In any case, the safer way to pass multiple arrays to a subroutine is to
use a reference, like so:
# Call with Subname(\@array1, \@array2)
sub Subname {
my ($ary1ref, $ary2ref) = @_;
my (@ary1) = @$ary1ref;
my (@ary2) = @$ary2ref;
...
}
Passing typeglobs around was a perl 4 way of doing stuff, in general, and
is frowned upon in perl 5 except in 2 specific cases:
- Passing a filehandle: Do_Something(\*STDIN);
- Symbol table aliasing (like above)
>if my string is empty then append $ple
>
>else do this cause i dont want leading pipes
It might be faster to always do the append, and then strip off the leading
pipe when you're done. That way you don't have to do the decision logic in
your loop every time. If you're iterating over a large number of entries,
you might find it worth it to do a quick test with the Benchmark module and
see how much time you'd save by leaving out the if.
/MC
--
Matthew Cravit, N9VWG | Experience is what allows you to
E-mail: mcravit@best.com (home) | recognize a mistake the second
mcravit@taos.com (work) | time you make it.
------------------------------
Date: 12 Sep 1997 16:21:58 -0700
From: Rael Dornfest <rael@zx80.dnai.com>
Subject: Re: Perl on SunOS question
Message-Id: <87vi06azjd.fsf@zx80.dnai.com>
williamw@rooster.igs.deleteTheRooster.net (William Wue(2xP)elma(2xN)) writes:
[deletia]
> chop($input = <STDIN>);
> works just fine, but
>
> chomp($input = <STDIN>);
> and
> @files = glob($input);
>
> generate syntax errors, though they work fine under Win95 (which makes
> them truly exceptional :) ).
Try perl -v or just check your path to perl -- you'll probably find
that you're using Perl4.
% perl4 -e 'chomp($input = <STDIN>); @files = glob($input);'
syntax error in file /tmp/perl-e007748 at line 1, next 2 tokens "chomp("
syntax error in file /tmp/perl-e007748 at line 1, next 2 tokens "glob("
Execution of /tmp/perl-e007748 aborted due to compilation errors.
% perl -e 'chomp($input = <STDIN>); @files = glob($input);'
[waits for input]
Rael
______________________________________________________________________
Rael Dornfest "What is the sound of Perl?
Webmaven Is it not the sound of a wall
DNAI (Direct Network Access) that people have stopped
rael@dnai.com banging their heads against?"
http://www.dnai.com -- Larry Wall
------------------------------
Date: 12 Sep 1997 19:10:30 +0200
From: Martin Fischer <mf@fishbone.ruhr.de>
Subject: Re: Please help me with locking! Using NDBM!
Message-Id: <5vbt26$2pj$1@fishbone.ruhr.de>
Richard Bellavance <charlot@CAM.ORG> wrote:
>In article <5v8ffo$8cl$1@brie.direct.ca>,
>Jason Hazzard <hazzard@usa.net> wrote:
>>Hello Perlers,
>>
>> I am using Tie() with NDBM_File, and I am very confused about locking.
>> How can I make sure that the DBM is locked properly? When using a tie, how
>>can I make sure it is locked, if another tie() is being tried. Basically, on
>>a webpage, if a CGI opens the DBM, and another user runs the same cgi, how can
>>I make sure the first is closed, before the other is allowed to run?
>>
>I had a need for this while implementing my homebrew database. What I ended
>up doing is using a "lock file" (just an empty file) on which I need to get
>a lock before tie'ing. I use something like:
>open(LOCKFILE, ">lockfile");
>flock(LOCKFILE, 2);
>tie(...);
>untie(...);
>flock(LOCKFILE, 8);
>close(LOCKFILE);
Another possibility is:
$db = tie (...)
$fd = $db->fd;
open (DB_FH, "+<&=$fd") or die;
unless (flock (DB_FH, 2 | 4)) {
print "Waiting for lock ($!) ...";
unless (flock (DB_FH, 2)) { die "flock: $!" }
}
your code here...
$db->sync();
flock (DB_FH, 8);
untie (...)
undef $db;
What are the pro's/contra's of each method?
ciao
Martin
--
Martin Fischer <mf@fishbone.ruhr.de> -------------------
<martinfi@geocities.com> | Comp Sci Student
PGP key: http://geocities.com/SiliconValley/Park/3082/ | FH-Bochum, Germany
Unsolicited commercial e-mail will be proof-read for $199/hr.
------------------------------
Date: Fri, 12 Sep 1997 14:49:13 -0700
From: "Christopher M. Lee" <chrisl@earthlink.net>
Subject: Re: Strange behavior with undefined subroutine
Message-Id: <3419B8D9.8A341B07@earthlink.net>
This is not a complete answer to your question but you should always put in
a || to your statements as below:
print copy($filepath, $wd.$file.'.bak') || die "Unable to run copy\n";
This would help by having the script die and tell you something is wrong.
-chrisl
Chris Schoenfeld wrote:
> Recently I wrote a routine which uses File::Copy's copy() funtcion.
>
> With the line:
> copy($filepath, $wd.$file.'.bak');
>
> Works fine. So I cut and pasted the function into another script, but
> forgot to also include the
> use File::Copy;
> statement.
>
> I was running perl5.004_03 -w and use strict;
> so what do you think happened?
> Nothing!
> No warnings, no errors, and, of course, the function did not copy.
> I even did a
> print copy($filepath, $wd.$file.'.bak');
>
> And it produced no output!
>
> So I realized my lack of the use File::Copy, and corrected this, and it
> worked perfectly.
>
> But the question remains - what was Perl doing with that statement?
>
> Chris Schoenfeld
> Director, Advanced Technology
> IX Development Laboratories
> Santa Rosa, Ca 95401
> (707)-543-8030 Ext. 12
------------------------------
Date: 12 Sep 1997 19:13:41 +0200
From: Martin Fischer <mf@fishbone.ruhr.de>
Subject: Re: strict-module problem
Message-Id: <5vbt85$2qd$1@fishbone.ruhr.de>
Anke Thede <anke@pan.ncrome.romesc.ibm.com> wrote:
>To all Perl Freaks!
>If I do the following all is OK :
>perl.inc
>--------
>$myvar1 = "abcdef";
>$myvar2 = 12345;
>perlprog.pl
>-----------
>do 'perl.inc';
>print "My include variable \$myvar1 holds $myvar1\n";
>but if I want to use the 'use strict;' clause in my perlprog.pl I
>correctly get an error "$myvar1 requires explicit package name ..."
>because I cannot apply the my() function.
>How should I correctly employ "C-like includes" in my programs without
>having to cancel the "use strict" construct ???
Take a look at 'man strict'. There are some examples too.
ciao
Martin
--
Martin Fischer <mf@fishbone.ruhr.de> -------------------
<martinfi@geocities.com> | Comp Sci Student
PGP key: http://geocities.com/SiliconValley/Park/3082/ | FH-Bochum, Germany
Unsolicited commercial e-mail will be proof-read for $199/hr.
------------------------------
Date: Fri, 12 Sep 1997 14:55:20 -0700
From: David Roberts <dtrobert@ladc.lockheed.com>
To: Kuntal Daftary <daftary@cisco.com>
Subject: Re: Strip spaces in filenames
Message-Id: <3419BA48.41C6@ladc.lockheed.com>
Kuntal Daftary wrote:
>
> Mukund Rao wrote:
>
> > #!/bin/ksh
> > # find and replace all occurrences of $1 with $2
> > # from current directory onwards (ie. all files/subdirectories below)
> >
> > perl -pi -e 's/$1/$2/;' `find . -type f -print`
>
> here is a fluke:
>
> perl -pi -e 's/$1/$2/;' `find . -type f -print | sed 's/ /\\ /g'`
>
> test before use
> --
> Kuntal M. Daftary Cisco Systems Inc
> Ph: 408 527 9789 170 W. Tasman Dr
> daftary@cisco.com San Jose CA 95134
is this command good for say replacing a .txt with a .bak on a files in
a specific directory. i tried :
perl -pi -e 's/\.bak$/\.txt/;' `find . -type f -print`
but had no luck.
according to Oreilly, there's a really simple way to do the replacement.
perl -e rename 's/\.bak$//' *.bak
but i can't seem to get this to work either, any suggestions?
thanks
--
| David Roberts (AKA "aeroman") || ...One tactical thermonuclear |
| dtrobert@ladc.lockheed.com || weapon can ruin your whole day:) |
| work (805)572-5778 || (send complaints to "/dev/null") |
=====================================================================
------------------------------
Date: Fri, 12 Sep 1997 20:07:22 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Strip spaces in filenames
Message-Id: <a0pcv5.u74.ln@localhost>
David Roberts (dtrobert@ladc.lockheed.com) wrote:
: is this command good for say replacing a .txt with a .bak on a files in
: a specific directory. i tried :
: perl -pi -e 's/\.bak$/\.txt/;' `find . -type f -print`
: but had no luck.
That's not going to work.
It will attempt the substitution on the *contents* of the files,
not on the filenames...
: according to Oreilly, there's a really simple way to do the replacement.
Which O'Reilly book?
What page?
I'm having a hard time believing that the below came from ORA...
: perl -e rename 's/\.bak$//' *.bak
: but i can't seem to get this to work either, any suggestions?
perl -e 'while ($_=shift) {s/\.bak$//; rename "$_.bak", "$_.txt"}' *.bak
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 12 Sep 1997 11:15:24 -0700
From: Edwin Bishop <edbishop@hotmail.com>
Subject: what's the case
Message-Id: <341986BC.AA3@hotmail.com>
I have the following line which matches
User id input against a text file.
It is working fine, except, I want it
to ignore case (upper/lower)....
if ($database_row =~ "$username") {
print (@input);
}
I have tried putting the /i switch on both
variable, but no success.
thanks for any help, e-mail edbishop@hotmail.com
if you can help...again thanks.
E Bishop
edbishop@hotmail.com
------------------------------
Date: Fri, 12 Sep 1997 20:11:51 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: what's the case
Message-Id: <n8pcv5.u74.ln@localhost>
Edwin Bishop (edbishop@hotmail.com) wrote:
: It is working fine, except, I want it
: to ignore case (upper/lower)....
: if ($database_row =~ "$username") {
: print (@input);
: }
if ($database_row =~ /$username/i) {
Quotes are for strings.
Pattern matches are what you want there, not a string...
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 13 Sep 1997 00:14:33 GMT
From: bskendig@netcom.com (Brian Kendig)
Subject: Why can't I talk directly to the mail daemon?
Message-Id: <bskendigEGF7CA.DAy@netcom.com>
I'm trying to write a simple test Perl script which, when run, will send
me email. (I don't want to use sendmail for this.) The script below
runs and gives no errors, but doesn't send any email to me, and I can't
figure out why:
#!/usr/bin/perl
open(MAIL, "|telnet localhost 25") || die "Couldn't telnet: $!\n:;
$| = 1;
print MAIL "MAIL FROM: foo\@bar\n";
print MAIL "RCPT TO: bskendig\@netcom.com\n";
print MAIL "DATA\n";
print MAIL "From: foo\@bar\n";
print MAIL "To: bskendig\@netcom.com\n";
print MAIL "Subject: My Test Email\n\n";
print MAIL "Test Line 1\n";
print MAIL "Test Line 2\n\n";
print MAIL ".\n";
print MAIL "QUIT\n";
close (MAIL);
But if I telnet to port 25 of localhost by hand, and enter this:
MAIL FROM: foo@bar
RCPT TO: bskendig@netcom.com
DATA
From: foo@bar
To: bskendig@netcom.com
Subject: My Test Email
Test Line 1
Test Line 2
.
QUIT
the mail comes through fine. Why isn't the Perl script working? What's
the difference between what the Perl script did and what I did by hand?
--
_/_/_/ Be insatiably curious. Je ne suis fait comme aucun
/_/_/ Ask "why" a lot. de ceux que j'ai vus; j'ose croire
_/_/ n'etre fait comme aucun de ceux qui existent.
/ Brian Kendig Si je ne vaux pas mieux, au moins je suis autre.
/ bskendig@netcom.com -- Rousseau
http://people.netscape.com/brian/
------------------------------
Date: Fri, 12 Sep 1997 21:29:37 -0700
From: "Allen Evenson" <ase@seanet.com>
Subject: Re: Win 95 Perl & Tk
Message-Id: <5vd4qf$nlr@q.seanet.com>
Harold Corbin wrote in article <340F31AC.7D86@erols.com>...
>
>I have just downloaded 00402-bindist04-bc.tar.gz from
>ftp://ftp.cis.ufl.edu/pub/perl/CPAN/ports/win95/Gurusamy_Sarathy/
>
>This is Perl5 with Tk. It seem to work well with Win95, even though the
>install.bat was expecting NT.
>
>I haven't run much yet, just the widget demo and there is only one way
>to describe it - WOW, WOW!!!!!!! Thank You Gurusamy Sarathy and
>everyone who helped make this available.
I second this emotion! I have also had success downloading and installing
the port on my Win95 box.
The only trouble i've had to date, is with argv globbing that used to work
with a
previosly installed activeware port.
my old script (a grading program) used to work untouched with the following
invocation:
'perl -w grader key *.grd'
with the new port i received "*.grd" not found, until I READ THE
DOCUMENTION!
I needed to 'use File::DosGlob 'glob'; # override CORE::glob'
and modify my script to glob each argv element into a list and then work
with the elements of the list.. The entire script follows for everyone's
amusement...
#!/usr/bin/perl
# grader.pl
# grading script
#
# the first command line arg is the master file
# the rest are students files
#
use File::DosGlob 'glob'; # override CORE::glob
$keyfile =shift(@ARGV); # Extract First argument as grading key file
#open the file
open(KEY, $keyfile) || die "Can't open $keyfile :$!\n";
#process each line
while (<KEY>) {
chop ; #remove the newline
($key_name,$possible,$percent) = split(/:/, $_);
$possible{$key_name} = $possible;
$percent{$key_name} = $percent;
}
close KEY;
$num_students = 0; # number of students graded
$class_total = 0; # cumulative class score
#process each student file against master.
while ($student = shift(@ARGV)) {
@slist= glob $student; #if its a glob i get 'em all if not i get just
one :)
foreach $s (@slist) {
open(STUDENT, $s) || die "Can't open $student :$!\n";
$num_students += 1;
while(<STUDENT>) {
($key_name,$score) = split(/:/, $_);
if( grep($key_name,keys(%possible)) ) {
$score{$key_name} = ($score / $possible{$key_name} *
$percent{$key_name});
$total[$num_students-1] += $score{$key_name} ;
}
}
close STUDENT;
#write report to stdout
print "\nGrades for:",$s, "\n";
printf("%20s%8s%8s", "Category:","Score:","Out of:\n");
print "-" x 36, "\n";
foreach $key (sort keys(%score)) {
printf("%20s%7.2f%7.2f\n", $key, $score{$key},$percent{$key});
}
print "-" x 36, "\n";
printf("%20s%7.2f\n", "Total:",$total[$num_students - 1]);
$class_total += $total[$num_students-1];
}
}
#write statistics
if ($num_students >= 2) {
print "\nClass Statistics:";
print "-" x 36, "\n";
printf("%20s%7.2f","Students Graded:",$num_students);
printf("%20s%7.2f","Average Grade:",$class_total / $num_students);
}
# end of listing
Yes, I know what your thinking.. "Who cares...." Well if you don't GREAT.
If you do
even better! At least I didn't ask a question covered in the FAQ's.
------------------------------
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 1019
**************************************