[18903] in Perl-Users-Digest
Perl-Users Digest, Issue: 1071 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 6 06:05:35 2001
Date: Wed, 6 Jun 2001 03:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <991821911-v10-i1071@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 6 Jun 2001 Volume: 10 Number: 1071
Today's topics:
Re: 2 questions about flock (Anno Siegel)
Re: 2 questions about flock (Anno Siegel)
Re: Connection Pooling... <N.Hirani@hgmp.mrc.ac.uk>
Re: Connection Pooling... <gnarinn@hotmail.com>
Re: context explain <krahnj@acm.org>
Re: Decimal to Hex (Falk Friedrich)
Having a difficult time expanding file names <mondotrasho@home.com>
Re: Having a difficult time expanding file names (Bernard El-Hagin)
Re: Having a difficult time expanding file names <tinamue@zedat.fu-berlin.de>
Re: Help a script to prompt to input and have those inp (David Combs)
How to sort by number first then sort by english name? <cad@uk2.net>
Re: How to sort by number first then sort by english na (Bernard El-Hagin)
Re: Multiple Line printing (David Combs)
Re: Multiple Line printing (David Combs)
Re: Multiple Line printing (David Combs)
Re: Multiple Line printing (Bernard El-Hagin)
Re: Newbie: $ character end string? What is wrong? (Bernard El-Hagin)
Re: Newbie: $ character end string? What is wrong? (Villy Kruse)
parallel port modle <cloud@aknet.kg>
Re: parsing perl again (David Combs)
Re: parsing perl again (Damian Conway)
Re: parsing perl again: NEED FOR GENERIC LEXICAL-SCANNE (David Combs)
Perl is dead! Long live Perl! <spamnoo@earthlink.net>
Re: perl2exe question <bart.lateur@skynet.be>
Problems with Threads and Signal handlers <arbman@dhmail.net>
Re: Recursing a directory tree (Bernard El-Hagin)
seek backwards, huge file <pef@trasra.noXX>
Re: seek backwards, huge file (Anno Siegel)
Re: The FlakeyMind/Bryce Jacobs FAQ (v0.1) <Attila.Feher@lmf.ericsson.se>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Jun 2001 08:48:39 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: 2 questions about flock
Message-Id: <9fkqp7$44u$1@mamenchi.zrz.TU-Berlin.DE>
According to Abigail <abigail@foad.org>:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCXXXV
> September MCMXCIII in <URL:news:9fi9oh$1ll$1@mamenchi.zrz.TU-Berlin.DE>:
> <> According to Mark Grimshaw <m.grimshaw@salford.ac.uk>:
>
> <> > Any ideas about flock and a db_fle that is tie'd? Would I have to
> <> > open() the db_file for writing, then LOCK_EX it before tieing it?
> <>
> <> That is a possibility. It is more common to keep an extra lock file
> <> besides the database file(s) and lock that.
>
> And that's an excellent example of why you might want to use LOCK_UN.
> A long living program that repeatedly accesses a database file, using
> an extra lock file to monitor access, might want to open the lock file
> once, and lock using LOCK_SH/LOCK_EX and unlock with LOCK_UN, avoiding
> the need to repeatedly open the lock file.
True. When the file you'e locking and the file(s) you are protecting
aren't the same there is no advantage in combining unlock and close.
Anno
------------------------------
Date: 6 Jun 2001 09:03:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: 2 questions about flock
Message-Id: <9fkrl3$44u$2@mamenchi.zrz.TU-Berlin.DE>
According to Mark Grimshaw <m.grimshaw@salford.ac.uk>:
>
>
> Anno Siegel wrote:
> >
> > According to Mark Grimshaw <m.grimshaw@salford.ac.uk>:
> > > Garry Williams wrote:
> > > >
> > > > On Tue, 05 Jun 2001 09:51:52 +0100, Mark Grimshaw
> > > > <m.grimshaw@salford.ac.uk> wrote:
> > > >
> > > > > Any ideas about flock and a db_fle that is tie'd?
> > > >
> > > > Yes. Don't. See the DB_File manual page for why. Use Anno's
> > > > suggestion instead.
> > > >
> > >
> > > Final question about flock I hope. I'm locking the db_file by locking
> > > another file alongside it. To test this, I have the following script
> > > which just locks the file and sits in a loop forever until I ^C it at
> > > which point I assume the LOCK_EX is relinquished:
> > >
> > >
> > > #!/usr/local/bin/perl -w
> > >
> > > use Fcntl qw(LOCK_EX);
> > > $lock = 'db/lock';
> > >
> > > open(LOCK, ">$lock") || die "$!\n\n";
> > > flock(LOCK, LOCK_EX);
> > > for(;;)
> > > {
> > >
> > > }
> >
> > Better just sleep() for a long time here. sleep() can also be
> > interrupted by ^C.
> >
> > > exit;
> > >
> > > In my CGI script, I have the following:
> > >
> > > use Fcntl qw(LOCK_EX);
> > > $lock = 'db/lock';
> > > for(;;)
> > > {
> > > last if(open(LOCK, ">$lock"));
> > > }
> > >
> > > # continue with script
> > >
> > > If I've got the logic correct, the second script sits in the for(;;)
> > > loop until it can open the $lock file which it can only do (assuming I
> > > have all permissions correct which I do) when the LOCK_EX is
> > > relinquished from the first script by ^C'ing it. However, after
> > > termination of the first script, the second continues in its loop. What
> > > am I doing wrong?
> >
> > You misunderstand the advisory character of file locking. Even an
> > exclusive lock won't stop another program from opening the file.
>
>
> In which case why is the for(;;) loop not exited when the file is
> open'd?
It *is* exited, immediately. The open() will succeed whether or not
another process holds a lock to the file.
> > It *will* stop it from getting another lock (of any kind) to the
> > file. So the relevant part of your "CGI script" should be
> >
> > open LOCK, $lock or die "Can't read $lock\n";
> > flock LOCK, LOCK_SH or die "Can't lock $lock\n";
> > print "got shared lock\n";
> >
> > This will print "got shared lock" as soon as the first script gives
> > up its lock, but not before.
>
> I've modifed what you put above in the CGI script with:
>
> for(;;)
> {
> flock(LOCK, LOCK_SH) or next;
> last;
> }
>
> It still sits in the loop when the locking script exits.
That loop does nothing for you because lock() itself waits until
the lock becomes available. So it will hang on the lock() once
until the other process exits. Then it will execute "last" and
never look at the loop again. Only when you use the LOCK_NB
flag will an attempt to get an unavailable lock return an error.
You really ought to read some of the documentation about flock.
Note that most of the details aren't in the perldoc page about
flock, but in the corresponding system man pages.
Anno
------------------------------
Date: Wed, 06 Jun 2001 08:56:59 +0100
From: Naran Hirani <N.Hirani@hgmp.mrc.ac.uk>
To: "Dintelmann, Peter" <Peter.Dintelmann@Dresdner-Bank.com>
Subject: Re: Connection Pooling...
Message-Id: <3B1DE24B.D08E9915@hgmp.mrc.ac.uk>
Hi Peter,
I take your point but what I am trying to do is slightly different.
The problem briefly is as follows: we have numerous perl scripts written by
various people which basically connect to our in-house database make some
simple
query and then disconnect. Some of these scripts are used frequently during
the day,
other's once or twice a week, etc. I have optimized this database now quite
considerably
so that even tho' we use this silly inefficient model for querying it, the
response times are
fairly acceptable, i.e. < 3-5(s) in most cases.
However, clearly a better approach is to have a pool of connections sitting
there ready
to be dished out as and when requested by a trusted user/host/IP
address/script?
We operate behind a fire wall so I was thinking that I might be able to get
away with a
minimal amount of authentication.
So my plan was to write a connection pool server and have these scripts
request a connection
from this server rather than go directly to the database to see if I can
speed up response time
any further. I doubt if it will be possible to improve the response time by
much any more,
but it would still be a useful little excercise in learning perl for me, I
guess.
I hope that this explains what I am to a bit better.
I look forward to any ideas or suggestions you might have.
Many thanks,
Naran
"Dintelmann, Peter" wrote:
> Hi,
>
> "Naran Hirani" <N.Hirani@hgmp.mrc.ac.uk> wrote in message
> news:<3B1B760D.B21BF7F@hgmp.mrc.ac.uk>...
>
> > Is there a module which does connection pooling to a sybase database in
> > perl?
> >
> > I have tried looking in the usual places and found nothing suitable.
>
> I don't think you need one.
>
> > If not can someone give me some hints on how best to go about
> > implementing such a
> > thing in perl. Some template example would be brilliant.
>
> If you are doing multiple things in parallel (with several
> threads or processes) just make up a new connection for
> each process.
>
> If you are doing some webstuff use Apache::DBI. It lets you
> preopen a db connection for each webserver childs on its
> startup. You thus have a persistent connection for each
> client request. It works great with Sybase...
>
> Can you please tell me what exactly you need a conn. pooling
> for?
>
> Cheers,
>
> Peter
>
> --
> Dr. Peter Dintelmann
> Dresdner Bank AG
> UB Transaction Banking
> MIS - MIS@ Products
> Mainzer Landstr. 16
> D-60301 Frankfurt
> Germany
>
> Tel.: +49-(0)69-97168-115
> Email: Peter.Dintelmann@dresdner-bank.com
>
> http://www.dresdner-bank.com
> http://mis.dresdner-bank.com
------------------------------
Date: Wed, 6 Jun 2001 09:23:52 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Connection Pooling...
Message-Id: <991819432.793170866090804.gnarinn@hotmail.com>
In article <3B1DE24B.D08E9915@hgmp.mrc.ac.uk>,
Naran Hirani <N.Hirani@hgmp.mrc.ac.uk> wrote:
>
>The problem briefly is as follows: we have numerous perl scripts written by
>various people which basically connect to our in-house database make some
>simple
>query and then disconnect. Some of these scripts are used frequently during
>the day,
>other's once or twice a week, etc. I have optimized this database now quite
>considerably
>so that even tho' we use this silly inefficient model for querying it, the
>response times are
>fairly acceptable, i.e. < 3-5(s) in most cases.
>
>However, clearly a better approach is to have a pool of connections sitting
>there ready
>to be dished out as and when requested by a trusted user/host/IP
>address/script?
>
>So my plan was to write a connection pool server and have these scripts
>request a connection
>from this server rather than go directly to the database to see if I can
>speed up response time
>any further.
have you tried to test how long the actual connect takes? I cannot believe
that it is significant if the total query takes 3 to 5 seconds.
gnari
------------------------------
Date: Wed, 06 Jun 2001 07:25:30 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: context explain
Message-Id: <3B1DDAE9.AC9E4A@acm.org>
David Xu wrote:
>
> Hi all,
>
> I am confused by following piece of code:
> $scalar1 = (3, 2, 1);
$ perl -le '$_ = (7,8,9); print'
9
This is how the comma operator works.
perldoc perlop
Comma Operator
Binary "," is the comma operator. In scalar context it
evaluates its left argument, throws that value away, then
evaluates its right argument and returns that value. This
is just like C's comma operator.
> @array=(3, 2, 1);
> $scalar2 = (@array);
$ perl -le '@x = (7,8,9); $_ = @x; print'
3
An array evaluated in a scalar context returns the number of elements in
the array.
perldoc perldata
If you evaluate a named array in a scalar context, it
returns the length of the array. (Note that this is not
true of lists, which return the last value, like the C
comma operator, nor of built-in functions, which return
whatever they feel like returning.)
> print "scalar1=$scalar1, scalar2=$scalar2\n";
>
> it prints
> "scalar1=1, scalar2=3"
> why is (@array) different with (3, 2, 1)?
John
--
use Perl;
program
fulfillment
------------------------------
Date: 06 Jun 2001 11:03:00 +0200
From: falk@gmx.de (Falk Friedrich)
Subject: Re: Decimal to Hex
Message-Id: <82Km$4mMrWB@frodo.prima.de>
Winston Kotzan (winz@prodigy.net) wrote:
>I'm writing a CGI program for the registration of shareware. The
>trouble I'm having is converting a long decimal number to a
>hexadecimal number. I tried something similar to this:
>
> $CodeStr = 25194917170125117;
> $RegCode = sprintf("%X", $CodeStr);
>
>
>However, the result of printing RegCode yielded FFFFFFFF. What did I
>do wrong, and is there an alternative to the sprintf() command?
AFAIK is the value too big für 32bit-integer. You can use Math::BigInt.
My perl is not good. Please optimize it.
Dec: 25194917170125117
Hex: 5982a4c812193d
-Falk
#!/usr/bin/perl -w
use Math::BigInt;
$CodeStr = '25194917170125117';
$i = Math::BigInt->new($CodeStr);
@code=qw("0 1 2 3 4 5 6 7 8 9 a b c d e f");
while($i)
{
unshift @RegCode,$code[$i%16];
$i=$i/16;
}
$RegCode=join "",@RegCode;
print "Dec: $CodeStr\n";
print "Hex: $RegCode\n";
------------------------------
Date: Wed, 06 Jun 2001 08:42:01 GMT
From: "MondoTrasho" <mondotrasho@home.com>
Subject: Having a difficult time expanding file names
Message-Id: <20010606.014210.2086206725.1422@home.com>
I have been a professional software developer for over 20 years, but am
very new to perl and Linux. I am trying to use the following
piece of code to get a list of file names.
..
while ($fname = <${filepattern}>) {
print "$fname\n";
}
...
This is working, as long as the file pattern does not
contain any spaces. What can I do if I need spaces in the file pattern?
Just a nudge in the right direction should suffice. Thank you very much.
------------------------------
Date: Wed, 6 Jun 2001 08:46:26 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Having a difficult time expanding file names
Message-Id: <slrn9hrqp3.com.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 06 Jun 2001 08:42:01 GMT, MondoTrasho <mondotrasho@home.com> wrote:
>I have been a professional software developer for over 20 years, but am
>very new to perl and Linux. I am trying to use the following
>piece of code to get a list of file names.
>
>..
>while ($fname = <${filepattern}>) {
> print "$fname\n";
>}
>...
>
>This is working, as long as the file pattern does not
>contain any spaces. What can I do if I need spaces in the file pattern?
>Just a nudge in the right direction should suffice. Thank you very much.
Check out the glob function:
perldoc -f glob
For example, to list all files with the extension 'html' you
can do:
print for glob("*.html");
Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'
------------------------------
Date: 6 Jun 2001 09:11:15 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Having a difficult time expanding file names
Message-Id: <9fks3j$47lk7$1@fu-berlin.de>
MondoTrasho <mondotrasho@home.com> wrote:
> I have been a professional software developer for over 20 years, but am
> very new to perl and Linux. I am trying to use the following
> piece of code to get a list of file names.
> ..
> while ($fname = <${filepattern}>) {
> print "$fname\n";
> }
> ...
> This is working, as long as the file pattern does not
> contain any spaces. What can I do if I need spaces in the file pattern?
> Just a nudge in the right direction should suffice. Thank you very much.
you want:
perldoc -f opendir
perldoc -f readdir
perldoc -f grep
opendir DIR, "dir" or die $!;
my @files = grep /pattern/, readdir DIR;
close DIR;
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx
------------------------------
Date: 6 Jun 2001 08:14:47 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Help a script to prompt to input and have those input add or append certain lines in a text file
Message-Id: <9fkopn$qr7$2@news.panix.com>
In article <A779E843681012E9.A830A653F5EEA175.616A0F8174F5503E@lp.airnews.net>,
Charles K. Clarkson <c_clarkson@hotmail.com> wrote:
>
>"Steve" <stpham@qwest.net> wrote in message
>news:P9QO6.220$a32.34759@news.uswest.net...
>: Hi all,
>:
>: I am new to perl and I need help to write to perl script
>: that will ask certain values and have those values enter
>: or modify on a certain of a specific text file.
>:
>: For example: Let say I have a text file that looks like
>: this when I open with a notepad.
>:
>: [UserDate]
>: ComputerName = computer1
>:
>: [Params.TCPIP.Adapter1]
>: IPAddress = 10.0.0.5
>: SubnetMask = 255.0.0.0
>: DefaultGateway = 10.0.0.1
>:
>: [Etc....]
>:
>: I wanted to change or modify the line ComputerName,
>: IPAddress, SubnetMask, and DefaultGateway, Etc...
>:
>: I would I go about writting a perl script to do
>: that I think you are a perl programmer it would not
>: be so hard to write this script.
First, learn some real EDITOR -- especially, a general-purpose
one, like vi or vim or emacs (for NT or unix) or whatever
programmers use on pc/M$ machines. VI or VIM might be
your best bet, considering you want to learn perl,
because lots of the regex concepts for substition
are the same, and likely where perl's originally
were based on.
>
> I wrote a short sub to do just this when I was
>learning about wantarray, please feel free to fold,
>spindle, and mutilate it to your hearts content.
>
> You can find it at:
><http://groups.yahoo.com/group/perl-beginner/files/ini.pl.txt>
>
Uh, what I find there is some BS about signing up
for a yahoo listserv, creating one -- or maybe it's
just for free email. Didn't look closely.
But for sure it was NOT anything to do with PERL!
Now, problem is probably that I use LYNX as browser
(from a shell-acct on my ISP), and lynx understands
nothing about javascript -- just plain html, not even
2-dim tables.
Have you a better url for the above?
David
>
------------------------------
Date: Wed, 06 Jun 2001 09:41:02 GMT
From: "jack" <cad@uk2.net>
Subject: How to sort by number first then sort by english name?
Message-Id: <OUmT6.61416$ko.984916@news1.frmt1.sfba.home.com>
need help on sort problem...
I have a data after perl handle already save to $out
I need to sort 2 times to change the print out order
first sort by number(right side) , and after that,,
sort by english name(left name)
then print the $out,
I have difficult for handling sort and hash ,, can anyone give me
some instrunctions? thanks!
_DATA_
core1Kx256 3
sect256 0
core1Kx128 3
sect128 0
sect512r 0
core1Kx512 3
sect512 0
secsi16 2
secsi256 2
core1Kx2 3
sectsi 0
sect64up 0
core16x32 4
core256x32 2
tnwell 2
dumrow_ecl 2
drain2_nc 2
drain_nc_cap 2
drain2_nc_cap 2
dumrow16 2
dumrow256 2
core2nc 2
tnwell_nc 2
tnwell_nc_cap 2
corenc_cap 2
core2nc_cap 2
corenc 2
core2 2
drain_nc 2
drain2 2
redunENDCAP 2
core1Kx64 3
sect64down 0
------------------------------
Date: Wed, 6 Jun 2001 09:43:31 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: How to sort by number first then sort by english name?
Message-Id: <slrn9hru44.com.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 06 Jun 2001 09:41:02 GMT, jack <cad@uk2.net> wrote:
>need help on sort problem...
>I have a data after perl handle already save to $out
>I need to sort 2 times to change the print out order
>first sort by number(right side) , and after that,,
>sort by english name(left name)
>then print the $out,
>
>I have difficult for handling sort and hash ,, can anyone give me
>some instrunctions? thanks!
[snipped data]
Show us the code you came up with so far and we'll help you fix it.
Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'
------------------------------
Date: 6 Jun 2001 07:29:33 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Multiple Line printing
Message-Id: <9fkm4t$qb8$1@news.panix.com>
In article <a2051d6.0105230401.5f5a46c7@posting.google.com>,
Gary <grobitaille@mail.com> wrote:
>I need to parse a text file and when a pattern is matched I need to
>print that line and the next 6 lines. Can someone provide me with a
>perl solution
>
>
>Thanks
(gnu)egrep -A6 'regex' text-file > output
And it does it RIGHT -- eg if the 3rd line of the 6
ALSO matches -- and it MARKS IT UP right too.
Not so easy to write from scratch in perl (or any
other language), I bet.
Maybe easiest way: go look at source for (gnu) grep, and
convert (cleverly) into perl.
david
------------------------------
Date: 6 Jun 2001 07:33:00 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Multiple Line printing
Message-Id: <9fkmbc$qb8$2@news.panix.com>
In article <slrn9gnd23.m2v.bernard.el-hagin@gdndev32.lido-tech>,
Bernard El-Hagin <bernard.el-hagin@lido-tech.net> wrote:
>On 23 May 2001 05:01:44 -0700, Gary <grobitaille@mail.com> wrote:
>>I need to parse a text file and when a pattern is matched I need to
>>print that line and the next 6 lines. Can someone provide me with a
>>perl solution
>
>while(<DATA>){
> if(/PAT/ and print){
> defined($_ = <DATA>) and print for (1..6);
> }
>}
>
>Cheers,
>Bernard
Yes, but suppose the third of the six ALSO matches.
That output won't be much fun to read, what with
lines being duplicated.
To see the difficulties, and also which you might
like to end up with as nifty output:
Try gnu grep: grep -A6 'regex' thefile
David
------------------------------
Date: 6 Jun 2001 07:52:43 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Multiple Line printing
Message-Id: <9fkngb$qr7$1@news.panix.com>
In article <3B0C1C09.E5C40F45@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>nobull@mail.com wrote:
> ...
>> This is also a misuse of the term "Cargo Cult". The metaphor "Cargo
>> Cult" alludes to people from primative cutures building things that
>> look like airports to try to attract "airplane gods". (This story is
>> IITR apocryphal). I can, however, quite resonably send air-cargo
>> without having understand all the avionics, excise reguations, money
>> transfers and so on that is needed to make all this work.
>
>
>This is a classic cargo cult misconception. This term Cargo Cult
>originated during the nineteenth century, long before the Wright
If you study this kind of thing, you are probably correct.
But the first time I heard the term was from a book about
World War II, something about all the (U.S.) airplanes
(after the war) being pushed off cliffs into the water,
huge supply camps dismantled and shipped off, and
the result (from the indigenents) being a "cargo cult".
They (the US forces) left the islands as berift of
things-modern and money and goodies as before they
arrived. So the indigenents (sp?) wished, waited
for all the ships and airplanes and thousands of men
to return (and bring prosperity and food, etc?)
GDZ: please explain some more about this interesting
set of beliefs. Also how you and others use it in
your emails here, eg when someone accuses someone else
of having a cargo cult -- about perl! -- please explain the
usage.
THANKS!
>boys decided to flap their arms and fly about. Earliest studies
>of these cultural phenomenonas trace back to Melanesia and
>New Guenia during the European time of colonialism / imperialism,
>just prior to the Age of New Imperialism. Indigenous populations
>did not fall to their knees before metallic birds falling from
>their skies but rather marveled at wooden ships chasing after
>sheets filled with trade winds.
>
------------------------------
Date: Wed, 6 Jun 2001 08:23:33 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Multiple Line printing
Message-Id: <slrn9hrpe5.com.bernard.el-hagin@gdndev25.lido-tech>
On 6 Jun 2001 07:33:00 GMT, David Combs <dkcombs@panix.com> wrote:
>In article <slrn9gnd23.m2v.bernard.el-hagin@gdndev32.lido-tech>,
>Bernard El-Hagin <bernard.el-hagin@lido-tech.net> wrote:
>>On 23 May 2001 05:01:44 -0700, Gary <grobitaille@mail.com> wrote:
>>>I need to parse a text file and when a pattern is matched I need to
>>>print that line and the next 6 lines. Can someone provide me with a
>>>perl solution
>>
>>while(<DATA>){
>> if(/PAT/ and print){
>> defined($_ = <DATA>) and print for (1..6);
>> }
>>}
>
>Yes, but suppose the third of the six ALSO matches.
The OP clearly states that when we find a line which matches a pattern
we should print that line and the next 6 lines. The restriction that
none of those six lines can match the same pattern was never specified.
Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'
------------------------------
Date: Wed, 6 Jun 2001 07:16:14 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Newbie: $ character end string? What is wrong?
Message-Id: <slrn9hrlfv.com.bernard.el-hagin@gdndev25.lido-tech>
On Tue, 05 Jun 2001 18:54:00 +0200, Valentin 30IR976 <radiotito@yahoo.com>
wrote:
>Hello people, and sorry for this newbie question.
>
>I have this code:
>
>------------------------------------
>$string="Hello world";
>
>if ($string =~ /$Hello/)
>{
> print"Hello is at the the end\n";
>}
>
>----------------------------------------
>And...what does the message print? $Hello doesnt match if Hello appears
>at the end of $string?
If you had used strictures and warnings Perl would have told you
what the problem is.
Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'
------------------------------
Date: 06 Jun 2001 08:00:59 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Newbie: $ character end string? What is wrong?
Message-Id: <slrn9hropr.cj9.vek@pharmnl.ohout.pharmapartners.nl>
On Tue, 05 Jun 2001 17:19:23 GMT, Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "CM" == Ciaran McCreesh <keesh@users.sf.net> writes:
>
> >> if ($string =~ /$Hello/)
>
> CM> /$Hello/ won't match because it means "The end of the string
> CM> followed by 'Hello'", which ain't possible (ignoring
> CM> modifiers). You're probably
>
>actually it means "interpolate the variable $Hello and use its value as
>the regular expression". $ only means end of string anchor if it is at
>the end of the regex (or subregex).
>
Isn't that one of the DWIM features in Perl? If it looks like a variable,
$Hello, then it is a variable. If it looks like the end of a string then
it is the end of a string.
In either case a backslash before $ will turn it into itself.
Villy
------------------------------
Date: Wed, 6 Jun 2001 13:42:22 +0600
From: "Timophey" <cloud@aknet.kg>
Subject: parallel port modle
Message-Id: <9fkmrp$c14$1@alpha.elcat.kg>
Hi all.
Does anybody know where can I get a module which allows to work with LPT
port?
I need some special fucnctions like: reading the status of port, setting
special lines of LPT to defined level (0 or 1) and so on.
I know a module for Serial ports... Devce-SerialPort but haven't found any
for Parallel Ports.
Thanx in advance,
Timophey.
------------------------------
Date: 6 Jun 2001 08:34:35 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: parsing perl again
Message-Id: <9fkpur$r7e$1@news.panix.com>
In article <9ejsvl$jrn$1@towncrier.cc.monash.edu.au>,
Damian Conway <damian@cs.monash.edu.au> wrote:
>jdimov@cis.clarion.edu (Jordan Dimov) writes:
>
>>Thank you, Damian. Would appreciate a notice when you get to that point of
>>The ToDo List :-)
>
>I'm sure it will be loudly heralded ;-)
>
>>P.S. I take it this implies your belief that RecDescent is capable of
>>performing the monsterous task?
>
>Not as it stands. But a new version of RecDescent is also on the ToDo list!
>
>Damian
I thought that Perl was somewhat like C, and thus
MIGHT also need a "LALR" bottom-up(?) kind of
hairy parsing, best assisted via use of YACC.
ie, that recursive-descent just wouldn't hack it.
(This is memory of dragon-book chapter or two
that I never did ald likely never will
comprehend!)
David
------------------------------
Date: 6 Jun 2001 09:00:12 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: parsing perl again
Message-Id: <9fkres$old$1@towncrier.cc.monash.edu.au>
dkcombs@panix.com (David Combs) writes:
>I thought that Perl was somewhat like C, and thus
>MIGHT also need a "LALR" bottom-up(?) kind of
>hairy parsing, best assisted via use of YACC.
>ie, that recursive-descent just wouldn't hack it.
Actually, Perl *is* like C in that regard except the other way around:
it needs a recursive descent parser because LALR just doesn't hack it. ;-)
You should take a peek some time at the evil they have to do to the
lexer (the file is toke.c) to induce a yacc-based parser to parse Perl?
Be *very* afraid.
I'm confident a recursive descent parser for Perl will be *much* cleaner.
The downside is that it will also be noticeably slower.
Damian
------------------------------
Date: 6 Jun 2001 09:26:35 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: parsing perl again: NEED FOR GENERIC LEXICAL-SCANNER!
Message-Id: <9fkt0b$som$1@news.panix.com>
In article <9f7074$q38$1@towncrier.cc.monash.edu.au>,
Damian Conway <damian@cs.monash.edu.au> wrote:
>jdimov@cis.clarion.edu (Jordan Dimov) writes:
>
>>How do I use it to extract a list of arguments passed to a function? The
>>assumption is that the code is nice and clean (passed through Deparse,-p for
>>example). How do I get from here:
>
>'Twere me doing it, I'd write an extract_subcall() subroutine along the
>lines of the other extract_whatevers in Text::Balanced. That sub would
>first match an identifier, then a left paren, then use a call to
>extract_multiple() to extract strings, variables, other sub calls
>(i.e. recursively using extract_subcall()!), expressions, and commas. Then
>match a closing paren, throw away the commas, and Bob's your
>non-gender-specific-parental-sibling!
>
>And once you've done it, send it to me and I'll add it to Text::Balanced ;-)
>
>Damian
What, my naive opinion, perl REALLY needs are a set of
"lexical scanners" (as in compilers and parsing, the "lexical analysis"
stage of) -- some routine that knows SOMETHING about
the "language" you are parsing, and then:
you init it to "found nothing yet, start of line".
it eats through the line, "thing" by "thing" it sees
on it.
When it sees something, eg a name, or an integer number
(eg 122873), or a floating pt number (eg 3.13), or a
quoted-string (eg, "now is the time for all good men to come.",
or maybe even 'hello there'), or octal numbers, or hex,
or this or that.
When it sees(and eats!) that construct (integer, float,
string, ...), and then it RETURNS the TYPE of thing that
it just found (and ate), eg "string", "reserved word",
ineger 3, float 3.14, ...
Further, with a way for it to "backup" un-eating the
thing it just ate.
When it saw a "*" or a "(" or "}", etc, it would
return type "operator" (and via a returned param,
which one).
---
plus some parameters (args) that tell it HOW to work:
if it sees a "-23", what does it return, ie
what has it (the lexer) decided it just "saw".
In one mode, you'd want it to return the value "-23"",
whee in other cases (classrooms), you'd want it
to return first a minus, then when called again,
a (positive) "23".
This mode could be passed in as an arg.
---
Given the immense usefullness of something like this,
for checking whether prepared input is correct,
"parsing" files of data, say, would be FAR easier --
AND much less error-prone than via some regex-scheme
or the like.
David
PS: Annother nifty need:
This language I (pay to) use, "Mainsail" (MAchine INdependent SAIL)
(SAIL: Stanford A I Language, circa late 70's),
this Phd-Thesis splitoff VASTLY updated since then, cross-compiles
and result actually works -- has many very neat tricks --
strangely still unique to mainsail even after all these
years.
One is a routine they call "scan".
One of the args is a "set" of ascii chars.
Another is a string (maybe a line from a file)
that it is to "scan".
The third tells it exactly HOW it is to "scan"
the string.
eg: proceed eating and excreting (out the other end)
all characters UNTIL you come to one that's in that set of
chars you specified, and then return via arg that char
that it stopped at.
Also re that stopped-by ie stopped-at char, eat it
and toss it away, eat it and append it to the
string being excreted, or just keep it there in
the "source" it came from.
I think it's pretty obvious how it works, at least
for ASCII -- an array, its length being the size
of the universe of chars, ie for 7bit-ascii, 128,
for 8-bit ascii, 256. For every char in the "set"
you have specified, put a 1 in the cell indexed by
that chars ascii-value.
Super simple, super fast. For perl, would obviously
be written in C, since there is a tight loop charging
through the string being scanned. (And they all say
that by far the most cpu-time-consuming part of
compilers, etc, is the lexical-scanning -- which
is what this might be part of).
Then I wrote my own "scan" (in "mainsail"), a better
one for my purposes, that would also go from right
to left, ie backwards.
Of course, it takes some time to take that set of
chars arg and spread it via ones in that array
(zeros elsewhere), and surely you don't want
to redo that work at EACH call.
So you have an init "method" (or something) that does
that once, and returns some kind of handle (perl object,
simple integer, whatever is fastest for getting
that tight-loop c program going again), and your
scan routine uses that "handle".
Let me tell you -- THAT "SCAN" ROUTINE IS BLOODY USEFUL!
----
So, (Damian,) have I provided two rather simple but
incredibly useful features to add, one way or another,
to perl?
David Combs
------------------------------
Date: Wed, 06 Jun 2001 09:17:08 GMT
From: Andrew Lee <spamnoo@earthlink.net>
Subject: Perl is dead! Long live Perl!
Message-Id: <3B1DF75B.559B4D51@earthlink.net>
Now that corporate reins are tightened and Java is all the rage -- what
manager would invite chaos into her/his system with crazy Perl hacks?
So much better to leave the mind behind -- Programming with a mouse can
be fun! Yes it can!
Soon, very soon unix will be a a footnote in the history of the Almighty
Microsoft.
Beware beware ... Perl angels look down upon us -- from the unemployment
line.
Larry and Tom and Randall have gigs -- what about you? Your manager is
willing to support your crazy Perl antics? When will he do the RIGHT
thing and turn to Java???
Come -- join me on the unemployment line! Be a statistic! Be all that
this horrible language can let you be!
So! Stop talking!!!! and get in the unemployment line!!!! Learn to
flip burgers with regular expressions -- it is all the rave!
------------------------------
Date: Wed, 06 Jun 2001 03:33:29 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: perl2exe question
Message-Id: <l29rhtc8mc26vqlv3qe6ge81cv90n9g7jt@4ax.com>
Miriam Smit wrote:
>Anyone have experience with the perl2exe, as offered by indigostar????
>
>I was wondering how QUERY_STRING and STDIN got handeled if converting a
>regular web-"application"
The same, I guess. Mainly, it's $0 and $^X that are different.
>Does the .EXE improve executionspeed? Or, does it run faster than the perl
>itself did?
No it doesn't. That is because the script is NOT actually compiled, but
slightly encrypted and stored into the executable, together with modules
it uses, and even DLL's.
You cand verify this by have a script that won't run because of a syntax
error. perl2exe will not complain about this, but you'll get a runtime
error.
--
Bart.
------------------------------
Date: Wed, 06 Jun 2001 11:34:24 +0200
From: Scott Rutherford <arbman@dhmail.net>
Subject: Problems with Threads and Signal handlers
Message-Id: <3B1DF920.FE661033@dhmail.net>
Hello,
I was wondering if anyone cen tell me why this doesn't work. The basic
framework is for a multi-forking client to parse multiple documents from
several sources and the basics work fine if I comment out the downloader
thread. Then the child signal handler reaps it's children like it's
supposed to and a constant number of client processes can be maintained.
However uncommenting the thread causes the signals to be ignored or
something, any ideas anyone????????
Cheers Scott
P.S if this looks familar it's based on a recipe from the CookBook.
(multi-forking server)
/usr/local/bin/perl -w
#always
use strict;
#lots of CPAN modules
use POSIX;
use Thread;
use Thread::Queue;
use vars qw(%SIG %CHILDREN $CHILDREN $RUNNING);
$CHILDREN= 0;
%CHILDREN = ();
my $dq = new Thread::Queue;
my $pq = new Thread::Queue;
my $dt = new Thread \&downloader;
sub REAPER {
$SIG{CHLD} = \&REAPER;
my $pid = wait;
$CHILDREN --;
$pq->enqueue($CHILDREN{$pid});
delete $CHILDREN{$pid};
}
sub HUNTSMAN {
local($SIG{CHLD}) = 'IGNORE';
kill 'INT' => keys %CHILDREN;
$RUNNING = 0;
$dq->enqueue(undef);
$pq->enqueue(undef);
exit;
}
$RUNNING = 1;
my $maxclients = 2;
$SIG{INT} = \&HUNTSMAN;
$SIG{CHLD} = \&REAPER;
init_downloads();
init();
run();
#########################child processes below######################
sub downloader {
while($RUNNING){
my $file = $pq->dequeue;
sleep 1;
print "downloader just got $file\n" if $file;
}
}
###########################end of main############################
sub init {
for (my $i = $CHILDREN; $i < $maxclients; $i++) {
my $rf = $dq->dequeue;
make_child($rf);
}
}
sub run {
while ($RUNNING) {
sleep;
print $CHILDREN,"\n";
init();
}
}
sub init_downloads {
for my $i ( 1 .. 10 ) {
print "SENT :: ",submit($i),"\n";
}
}
sub submit {
my $hp = shift;
$dq->enqueue($hp);
return $hp;
}
sub make_child {
my $command = shift;
my $pid;
my $sigset;
my @requests = split(' ',$command);
my $remotefile = $requests[0];
my $localfile = $requests[1];
$sigset = POSIX::SigSet->new(SIGINT);
sigprocmask(SIG_BLOCK, $sigset)
or die "Can't block SIGINT for fork $!\n";
die "fork: $!" unless defined($pid = fork);
if ($pid) {
sigprocmask(SIG_UNBLOCK, $sigset)
or die "Can't block SIGINT for fork: $!\n";
$CHILDREN++;
$CHILDREN{$pid} = $localfile;
print "Daughter $pid launched, getting $remotefile\n";
return;
}
else {
sleep 1.5;
$SIG{INT} = 'DEFAULT';
sigprocmask(SIG_UNBLOCK, $sigset)
or die "Can't block SIGINT for fork: $!\n";
sleep 1;
print "Daughter finished\n";
exit;
}
}
------------------------------
Date: Wed, 6 Jun 2001 07:44:04 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Recursing a directory tree
Message-Id: <slrn9hrn46.com.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 06 Jun 2001 04:42:07 GMT, Nan Wang <nwang@shell3.shore.net> wrote:
>Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>> On Mon, 04 Jun 2001 19:58:41 GMT,
>> Nan Wang <nwang@shell3.shore.net> wrote:
>>> Eric Bohlman <ebohlman@omsdev.com> wrote:
>>>> Nan Wang <nwang@shell3.shore.net> wrote:
>>>>> I don't know why you think I was being defensive, I have nothing to be
>>>>> ashamed off. Like I said I write scripts to get things done, not for
>>>>> people to frame it and stick it on the wall and boggle at how few lines it
>>>>> took. I was rather pissed off at his nitpicking, anal retentiveness and
>>>>> his holier-than-thou attitude. Can I improve my code? Definitely, but
>>>>> I'll improve it the way I want, not as Martien mandates.
>>>
>>>> He wasn't *mandating* anything, just *suggesting* things based on his own
>>>> experience and that of a lot of other very experienced programmers.
>>>
>>> What makes you think I wanted his suggestions in the first place?
>
>> You posted your code here. The code didn't work, and couldn't work in
>> the way you said it should. Posting crap to this newsgroup gets your
>> free code reviews.
>
>> Rest assured, you won't get any more from me. You state you write code
>> to get the job done, which is obviously not true, judging by the
>> sample you posted. You are obviously not interested in improving your
>> code, or your attitude towards coding, so..
>
>I already admitted that I goofed on that part before ever had the displeasure
>of talking to you. WTF was your problem?
>
>> see ya. or rather, won't.
>
>Big loss, not!
See, Chris, this is a typical case of someone who deserves a public
plonking.
*plonk*
Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'
------------------------------
Date: Wed, 06 Jun 2001 11:27:39 +0200
From: "P.Eftevik" <pef@trasra.noXX>
Subject: seek backwards, huge file
Message-Id: <3B1DF78B.7B79B523@trasra.noXX>
Scanning through a file with a while (< >). Occasionally I also
do a backward seek. Work well for moderate files.
Not work for big ( say 6 MB ) files.
Does seek have any limitation on large files ?
Are there any other large-file-dangers I should be aware of ?
Thanx for a hint.
Pefte
------------------------------
Date: 6 Jun 2001 09:56:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: seek backwards, huge file
Message-Id: <9fkunm$44u$3@mamenchi.zrz.TU-Berlin.DE>
According to P.Eftevik <pef@trasra.noXX>:
>
> Scanning through a file with a while (< >). Occasionally I also
> do a backward seek. Work well for moderate files.
> Not work for big ( say 6 MB ) files.
In which way does it not work? Does the seek operation fail? With
what error message? If it doesn't fail, what do you expect it to do,
and what does it do instead? Show some code.
> Does seek have any limitation on large files ?
No.
> Are there any other large-file-dangers I should be aware of ?
None before you hit the 2GB limit.
Anno
------------------------------
Date: Wed, 06 Jun 2001 11:01:32 +0300
From: Attila Feher <Attila.Feher@lmf.ericsson.se>
Subject: Re: The FlakeyMind/Bryce Jacobs FAQ (v0.1)
Message-Id: <3B1DE35C.BD1882AC@lmf.ericsson.se>
Topmind wrote:
>
> > I think the best strategy on USENET is to steel yourself and assume
> > that the readers whose opinions you care about will be able to decide
> > which responses are legit and which are bogus. Let's not worry about
> > defaming people explicitly; hopefully the people whose opinions we
> > care about, can see that the people we hate are as dumb as we think
> > they are.
> >
> >
> > Lex
> >
> >
>
> I don't understand why he doesn't create a FAQ about my frequently
> used anti-OO arguments and simply refer his "warnees" to that
> *instead*. That would be much more professional than, "Look at
> the stupid thing topmind said back in 1998 about Perl......".
>
> -T-
I guess it is fairly simple. He is not your employee to work instead of
you. You are free to make such FAQ. Will help to proove your level of
(not) understanding OO anyways. Your behaviour and empty agruments here
did not create you friends... so you can expect fed up people to do
things like this. Say thanx to yourself... and go away.
A
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.
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 V10 Issue 1071
***************************************