[24838] in Perl-Users-Digest
Perl-Users Digest, Issue: 6989 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 10 18:06:41 2004
Date: Fri, 10 Sep 2004 15:05:10 -0700 (PDT)
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, 10 Sep 2004 Volume: 10 Number: 6989
Today's topics:
Re: "RFC": re [un]pack() <bik.mido@tiscalinet.it>
Re: $| (undocumented) magic? <bik.mido@tiscalinet.it>
Re: $| (undocumented) magic? <bik.mido@tiscalinet.it>
Re: $| (undocumented) magic? <bik.mido@tiscalinet.it>
Re: Array of file names <tore@aursand.no>
Re: list of numbers <bik.mido@tiscalinet.it>
Re: Network Scanner <bigal187@invalid.rx.eastcoasttfc.com>
Re: Network Scanner <ceo@nospam.on.net>
Re: parsing XML using a regular expression <dmagda+trace040726@ee.ryerson.ca>
Re: Perl 6 and OOP <bik.mido@tiscalinet.it>
Repeatedly parsing a file to "clean" it. (Graeme Stewart)
Re: Repeatedly parsing a file to "clean" it. <notvalid@email.com>
Re: Repeatedly parsing a file to "clean" it. <wolf@code-wizards.com>
Re: Repeatedly parsing a file to "clean" it. <tadmc@augustmail.com>
Re: Set-Cookie with discard in a perl CGI? <nospam@bigpond.com>
Re: Socket holding pattern <nospam@thanks.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 10 Sep 2004 23:55:20 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: "RFC": re [un]pack()
Message-Id: <dc84k0hj7hvmceeckh5kvsf0kqcd5k0v7n@4ax.com>
On Thu, 09 Sep 2004 23:15:25 +0200, Michele Dondi
<bik.mido@tiscalinet.it> wrote:
>Coming to the point, it often happens to resort to "cascaded"
>[un]pack()s. In my specific case I have
[snip]
Any cmt on this?!?
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Fri, 10 Sep 2004 21:39:19 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: $| (undocumented) magic?
Message-Id: <6m04k0948gjrer43thrqti0p0dn2ek2uuo@4ax.com>
On Thu, 09 Sep 2004 22:12:59 GMT, Ala Qumsieh <notvalid@email.com>
wrote:
>> # perl -le 'print $|=10'
>
>What's more interesting is the magic associated with decrementing $|:
>
> perl -le 'print --$| for 1 .. 10'
I know, I've done some experiments myself, "obviously"! ;-) As Jeff
"japhy" Pinyan pointed out, it's really magic associated with the
underlying code implementing $|.
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: Fri, 10 Sep 2004 21:39:20 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: $| (undocumented) magic?
Message-Id: <5sl2k09bjphin9alc8nhrubvacg66mkqat@4ax.com>
On Fri, 10 Sep 2004 00:57:20 -0400, Jeff 'japhy' Pinyan
<pinyaj@rpi.edu> wrote:
>[posted & mailed]
Don't!
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: Fri, 10 Sep 2004 23:55:19 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: $| (undocumented) magic?
Message-Id: <un74k0t9g74s1askdo1meu4uad0eucmr6q@4ax.com>
On Fri, 10 Sep 2004 00:57:20 -0400, Jeff 'japhy' Pinyan
<pinyaj@rpi.edu> wrote:
>The C code implementing $| basically says "if the value assigned to $| is
>true, have $| return 1, otherwise have it return 0". This leads to the
(Having not seen the actual code, and not being to) I *think* that
basically it should say "if the result of an assignment is true then
actually store 1 in it, otherwise store 0 in it". Isn't this closer?
Thank you for the kind explanation, anyway...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Fri, 10 Sep 2004 17:36:32 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Array of file names
Message-Id: <pan.2004.09.10.15.36.31.706135@aursand.no>
On Fri, 10 Sep 2004 15:44:27 +0200, MM wrote:
> Does anyone know a nice way to create an array with names of the files
> in a path? That is, each element in the array is a name (just the name!)
> of one of the files in the path.
Use the File::Find::Rule module, as it's quite useful (not tested);
#!/usr/bin/perl
#
use strict;
use warnings;
use Data::Dumper;
use File::Find::Rule;
my $dir = '/some/directory';
my @files = File::Find::Rule->file()->relative()->in( $dir );
print Dumper( \@files );
Please read the documentation for more details;
perldoc File::Find::Rule
This module - and many other - is available from CPAN;
<http://www.cpan.org/>
--
Tore Aursand <tore@aursand.no>
"USA Today has come out with a new survey - apparently, three out of
every four people make up 75% of the population." (David Letterman)
------------------------------
Date: Fri, 10 Sep 2004 21:39:17 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: list of numbers
Message-Id: <d9l2k0pjtaoaftqnuvm03n02pmgne2ba5a@4ax.com>
On Thu, 09 Sep 2004 23:36:36 GMT, Ala Qumsieh <notvalid@email.com>
wrote:
>> perl -lape'$_=pop@F'
>
>Golf, eh?
>
> perl -pe's/.*\t//'
D'Oh!
Michele (who is slightly ashamed because he's been thinkg of this very
same solution *in connection with sed* mentioned in Abigail's post,
and even does something similar with either "/" or "\." instead of
"\t" almost on a daily basis either with perl or sed...),
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: Fri, 10 Sep 2004 09:03:12 -0700
From: "187" <bigal187@invalid.rx.eastcoasttfc.com>
Subject: Re: Network Scanner
Message-Id: <2qe1i1Fub64tU1@uni-berlin.de>
Sam Holden wrote:
> On 9 Sep 2004 20:11:57 -0700, Chad Brown <chad@wononline.net> wrote:
>> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
>> news:<chp59q$kin$2@mamenchi.zrz.TU-Berlin.DE>...
>>> Chad Brown <chad@wononline.net> wrote in comp.lang.perl.misc:
>>>> I cant figure this one out... I initialized the variable and it
>>>> still brings up the warning.
>>>>
>>>> Use of uninitialized value in pack at
>>>> G:\PHASIC\PROJECTS\NETSCAN\netsweep.pl line 136.
>>>>
>>>> this is the line thats causing it...
>>>> my $this = pack($sockaddr,$AF_INET,0,my $thisaddr);
>>> ^^^^^^^^^^^^
>>>
>>> Apart from other possibilities, "my $thisaddr" is guaranteed to
>>> be undefined. What's the mystery?
>>>
>>> Anno
>>
>> Im new to perl... outside the datatypes of pack and unpack im unsure
>> of the rest...
>> I know the use of "my" is simple.
>> Anyone have any input on the data typing in perl?
>> Im so stuck to laws of VB and C++.
>>
>> What is the difference between my and local?
>
> perldoc -f my
> perldoc -f local
>
> Followed by perldoc perlsub, since both of those say 'See "..." in
> perlsub'.
>
> You don't have to get permission from here before reading the manual.
Not meaning to step o nyour toes, but it seems to me, people like the
fellow you just replied to, have just stepped into thr world of Perl,
and such a person may not know at all that such a document exists or
just not realize it.
If you are using Perl on a unix/linux-ish system, Perldoc is your
friend, but some other operating systems, such as the Win32 ActiveState
version have some nice TML based documentation, akin to the online
version.
------------------------------
Date: Fri, 10 Sep 2004 18:21:56 GMT
From: ChrisO <ceo@nospam.on.net>
Subject: Re: Network Scanner
Message-Id: <8hm0d.9623$ZC7.3452@newssvr19.news.prodigy.com>
Chad Brown wrote:
> I put together a script for scaning a network. Features are DNS
> resolution, selective port scan, scanning of multiple addresses at one
> time, and ping sweep. Ports can be customized depending on what is
> being sought on a network. If anyone decides to add more ideas to this
> please send me a copy. Im very interested in input. (:
>
Are you doing this for a learning exercise? Because there are already
mature, open source network scanners that even a mature, very
knowledgable Perl developer would be hard put to match.
-ceo
------------------------------
Date: 10 Sep 2004 17:03:33 -0400
From: David Magda <dmagda+trace040726@ee.ryerson.ca>
Subject: Re: parsing XML using a regular expression
Message-Id: <86656l25wa.fsf@number6.magda.ca>
Tad McClellan <tadmc@augustmail.com> writes:
> You CAN cool your beer with a jet engine though!
>
>
> "The World's First Jet Powered Beer Cooler"
>
> http://www.asciimation.co.nz/beer/
>
>
> Some people have too much time on their hands...
Everyone needs a hobby.
--
David Magda <dmagda at ee.ryerson.ca>, http://www.magda.ca/
Because the innovator has for enemies all those who have done well under
the old conditions, and lukewarm defenders in those who may do well
under the new. -- Niccolo Machiavelli, _The Prince_, Chapter VI
------------------------------
Date: Fri, 10 Sep 2004 23:55:20 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl 6 and OOP
Message-Id: <i984k01jrmmf20atq3v9serems23eh7dmf@4ax.com>
On 10 Sep 2004 07:04:12 -0700, jl_post@hotmail.com (J. Romano) wrote:
> Now to my question: Knowing that Perl 6 will have better OO
>handling, does that mean that Data::Dumper will lose its usefulness on
>Perl 6 objects? Or will it still be able to let a programmer peer
>into them and let him/her tinker with their data using the debugger?
There will be a predefined method for this. Only, the definitive name
has not been chosen yet. Proposals include, not surprisingly C<.code>,
C<.dump>, etc. Larry has been thinking about C<.perl>, envisioning a
possible future for, say, C<.python>, C<.ruby>, etc.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 10 Sep 2004 10:20:06 -0700
From: g_stewart@hotmail.com (Graeme Stewart)
Subject: Repeatedly parsing a file to "clean" it.
Message-Id: <61d476af.0409100920.77af6254@posting.google.com>
All,
I've done some lurking and found the answers to most of my questions,
but this one is more of a "best practice" issue, I've not been able to
find an answer for - my apologies if this is blantantly obvious and
I'm a looser newbie for even asking!
I've got a perl script that repeatedly opens and closes a couple of
files then excutes a while loop against those open files (example
below). Rather than repeatedly open and close the files, can I do this
in a better / more efficient way?
The objective is to take a jumbled text file and create individual
lines (records) that I can later manipulate.
*******************************************************
#!C:\perl\bin\perl.exe # Yes Windows! Don't hate me!
use strict;
open FILE, "./QM1.txt" or die "Can not open QM1.txt $!\n";
open COMMENTS, ">./temp/comments.txt" or die "Can not create
comments.txt $!\n";
while (<FILE>){
etc
etc
}
close FILE;
close COMMENTS;
open COMMENTS, "./temp/comments.txt" or die "Can not create
comments.txt $!\n";
open TEMPFILE, ">./temp/temp.txt" or die "Can not create temp.txt
$!\n";
while (<COMMENTS>){
etc
etc
}
close TEMPFILE;
close COMMENTS;
open COMMENTS, ">./temp/comments.txt" or die "Can not create
comments.txt $!\n";
open TEMPFILE, "./temp/temp.txt" or die "Can not create temp.txt
$!\n";
while (<TEMPFILE>){
etc
etc
}
close TEMPFILE;
close COMMENTS;
open COMMENTS, "./temp/comments.txt" or die "Can not create
comments.txt $!\n";
open TEMPFILE, ">./temp/temp.txt" or die "Can not create temp.txt
$!\n";
while (<COMMENTS>){
etc
etc
}
close TEMPFILE;
close COMMENTS;
*******************************************************
------------------------------
Date: Fri, 10 Sep 2004 17:31:27 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Repeatedly parsing a file to "clean" it.
Message-Id: <Pxl0d.13904$QJ3.1171@newssvr21.news.prodigy.com>
Graeme Stewart wrote:
> I've got a perl script that repeatedly opens and closes a couple of
> files then excutes a while loop against those open files (example
> below). Rather than repeatedly open and close the files, can I do this
> in a better / more efficient way?
You can seek() to the beginning of your file instead of closing it and
opening it each time:
seek COMMENTS, 0, 0;
checkout 'perldoc -f seek'.
--Ala
------------------------------
Date: Fri, 10 Sep 2004 20:55:59 +0200
From: Wolfgang Hommel <wolf@code-wizards.com>
Subject: Re: Repeatedly parsing a file to "clean" it.
Message-Id: <chstc2$krg$06$1@news.t-online.com>
Hi Graeme,
> I've got a perl script that repeatedly opens and closes a couple of
> files then excutes a while loop against those open files (example
> below). Rather than repeatedly open and close the files, can I do this
> in a better / more efficient way?
Not sure what exactly you consider as "efficient", but it's rather
unlikely that the performance of your program suffers from opening and
closing files. Instead, regarding the code you posted, I'd recommend
a) using subfunctions instead of repeating code :-)
b) "slurp mode" for reading each of those textfiles and splitting the
whole thing by line breaks instead of reading them in line by line.
If you really want to just avoid closing and re-opening a file, indeed
seek() is your friend.
Regards,
Wolfgang
------------------------------
Date: Fri, 10 Sep 2004 15:29:25 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Repeatedly parsing a file to "clean" it.
Message-Id: <slrnck43l5.9vh.tadmc@magna.augustmail.com>
Wolfgang Hommel <wolf@code-wizards.com> wrote:
>> can I do this
>> in a better / more efficient way?
>
> Not sure what exactly you consider as "efficient", but it's rather
> unlikely that the performance of your program suffers from opening and
> closing files. Instead, regarding the code you posted, I'd recommend
>
> a) using subfunctions instead of repeating code :-)
That is "anti in-lining", I guess.
Seems that would move things toward a more INefficient way,
with regards to performance, what with all that pushing/popping
stack accessing and whatnot.
It _would_ move it toward a more efficient way with regards
to maintenance however.
As Wolfgang said, "efficient" doesn't help us help the OP.
Tell us what you want to "optimize".
Optimize performance? Optimize for labor? Optimize memory usage? ...
Speed at the expense of maintainability, or maintainability
at the expense of speed?
Which costs you more, CPU cycles or labor?
<wait for the answer>
Optimize that one.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 11 Sep 2004 01:25:00 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Set-Cookie with discard in a perl CGI?
Message-Id: <2qdv6sFu5tiqU1@uni-berlin.de>
Gunnar Hjalmarsson wrote:
>> Besides building my response from scratch and a Socket connect,
>
> ?
Indeed. You dont need to open a socket to print to stdout!
gtoomey
------------------------------
Date: Wed, 08 Sep 2004 22:32:51 +0100
From: Gordon <nospam@thanks.com>
Subject: Re: Socket holding pattern
Message-Id: <chntq7$1bn$1@domitilla.aioe.org>
> Gordon <clemmons@gmail.com> wrote in comp.lang.perl.misc:
>
>>I've written a non-forking server using IO::Socket / IO::Select
>>based on Cookbook recipe 17.3. I need the ability to "quietly"
>>restart the server without dropping the connections. Currently
>>I'm using the hackish method of removing the 'use'd modules and
>>reloading them but that doesn't allow the core code to be
>>reloaded and I would prefer to have a clean start/stop anyway.
>>
>>If I setup a separate 'holding' server on an alternate port,
>>does anyone know of a way to switch the connections over to it?
>>I would like to plug the connections into this holding server
>>while the main server reboots, then reconnect them.
>
>
> If the duration of each connection is limited, an "overlapping restart"
> is a possibility.
>
> On a signal (or something), the server forks and execs a new copy.
> It also ceases to accept new connections, but continues serving
> the old ones. When the last connection is gone, it dies. All
> new requests are served by the new process.
>
> If you have unlimited connection time, and can't afford to break
> long-lasting ones, this simple scheme won't work. Sketchy as it
> is, it may well not work for other reasons.
>
> Anno
Yeah, this is for unlimited connection times - it's a mud server.
-gordon
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6989
***************************************