[25239] in Perl-Users-Digest
Perl-Users Digest, Issue: 7484 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 4 18:05:43 2004
Date: Sat, 4 Dec 2004 15:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 4 Dec 2004 Volume: 10 Number: 7484
Today's topics:
FAQ 2.15: Archives of comp.lang.perl.misc <comdog@panix.com>
Re: FAQ 2.15: Archives of comp.lang.perl.misc <matthew.garrish@sympatico.ca>
FAQ 4.30: How do I capitalize all the words on one line <comdog@panix.com>
Re: FAQ 7.26: How can I comment out a large block of pe <tadmc@augustmail.com>
File locking <nospam@all.thx>
Re: File locking <1usa@llenroc.ude.invalid>
Re: File locking <nobull@mail.com>
Re: File locking <lawhan@ozemail.com.au>
Free Desktop Computer---Not a Scam eagle101@gmail.com
Re: installing dbd::mysql via cygwin on windows <matthew.garrish@sympatico.ca>
Re: Monitor a dos console perl program running (dan baker)
Re: Monitor a dos console perl program running <1usa@llenroc.ude.invalid>
Re: Obtaining length of binary string <joe@inwap.com>
Re: Obtaining length of binary string <jurgenex@hotmail.com>
Re: Obtaining length of binary string <flavell@ph.gla.ac.uk>
Re: Obtaining length of binary string <jurgenex@hotmail.com>
Re: parse hash by array element seems to run slow <someone@example.com>
Re: parse hash by array element seems to run slow <bik.mido@tiscalinet.it>
Re: parse hash by array element seems to run slow <bik.mido@tiscalinet.it>
Re: parse hash by array element seems to run slow (JRoot)
Re: Perl crashes <joe@inwap.com>
Re: Perl crashes <jkeen_via_google@yahoo.com>
Re: Perl crashes <jodox@sbcglobal.net>
read image file - and process the result (Alx)
Re: RegEx Help Needed <matternc@comcast.net>
Re: RegEx Help Needed <matternc@comcast.net>
Re: Trying to install module with CPAN <joe@inwap.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 4 Dec 2004 17:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 2.15: Archives of comp.lang.perl.misc
Message-Id: <cosqk5$647$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
2.15: Archives of comp.lang.perl.misc
The Google search engine now carries archived and searchable newsgroup
content.
http://groups.google.com/groups?group=comp.lang.perl.misc
If you have a question, you can be sure someone has already asked the
same question at some point on c.l.p.m. It requires some time and
patience to sift through all the content but often you will find the
answer you seek.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Sat, 4 Dec 2004 13:54:45 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: FAQ 2.15: Archives of comp.lang.perl.misc
Message-Id: <UJnsd.30917$Ad3.2314499@news20.bellglobal.com>
"PerlFAQ Server" <comdog@panix.com> wrote in message
news:cosqk5$647$1@reader1.panix.com...
> This message is one of several periodic postings to comp.lang.perl.misc
> intended to make it easier for perl programmers to find answers to
> common questions. The core of this message represents an excerpt
> from the documentation provided with Perl.
>
> --------------------------------------------------------------------
>
> 2.15: Archives of comp.lang.perl.misc
>
> The Google search engine now carries archived and searchable newsgroup
> content.
>
> http://groups.google.com/groups?group=comp.lang.perl.misc
>
> If you have a question, you can be sure someone has already asked the
> same question at some point on c.l.p.m. It requires some time and
> patience to sift through all the content but often you will find the
> answer you seek.
>
Might do good to post this one in high rotation! (i.e., every day... : )
Matt
------------------------------
Date: Sat, 4 Dec 2004 23:03:06 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.30: How do I capitalize all the words on one line?
Message-Id: <cotfna$caf$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
4.30: How do I capitalize all the words on one line?
To make the first letter of each word upper case:
$line =~ s/\b(\w)/\U$1/g;
This has the strange effect of turning ""don't do it"" into ""Don'T Do
It"". Sometimes you might want this. Other times you might need a more
thorough solution (Suggested by brian d foy):
$string =~ s/ (
(^\w) #at the beginning of the line
| # or
(\s\w) #preceded by whitespace
)
/\U$1/xg;
$string =~ /([\w']+)/\u\L$1/g;
To make the whole line upper case:
$line = uc($line);
To force each word to be lower case, with the first letter upper case:
$line =~ s/(\w+)/\u\L$1/g;
You can (and probably should) enable locale awareness of those
characters by placing a "use locale" pragma in your program. See
perllocale for endless details on locales.
This is sometimes referred to as putting something into "title case",
but that's not quite accurate. Consider the proper capitalization of the
movie *Dr. Strangelove or: How I Learned to Stop Worrying and Love the
Bomb*, for example.
Damian Conway's Text::Autoformat module provides some smart case
transformations:
use Text::Autoformat;
my $x = "Dr. Strangelove or: How I Learned to Stop ".
"Worrying and Love the Bomb";
print $x, "\n";
for my $style (qw( sentence title highlight ))
{
print autoformat($x, { case => $style }), "\n";
}
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Sat, 4 Dec 2004 08:42:49 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: FAQ 7.26: How can I comment out a large block of perl code?
Message-Id: <slrncr3j79.4gh.tadmc@magna.augustmail.com>
Erik Wasser <fuzz@uni-paderborn.de> wrote:
> PerlFAQ Server <comdog@panix.com> wrote:
>
>> 7.26: How can I comment out a large block of perl code?
>
> How can I comment out a large block of perl code so that it will not
> appear in the POD doc?
Just the way that this FAQ says to.
> Sometimes I want to write some comments about the
> internal data structures that won't fit into the public man page
> of this module.
Consider putting your comments in, well... comments!
POD should be for the software's users, source code comments should
be for the maintenance programmer.
Any good programmer's editor should be able to add # comment chars
over a block of lines.
Note that this FAQ is about commenting out *code* and you
are speaking of comments, not code.
>=for nobody
>
> all of this stuff here will be ignored by everyone
> % pod2man <foo.pl | nroff -man
[ snip output including the "all of this..." text ]
> There there a way to drop some parts of the pod?
The FAQ has that "See L<perlpod> for more details." at the
end for a reason. :-)
"=for" applies only to the next "paragraph" (until the next blank line).
You need to write the above as:
-----------------------
=for nobody
all of this stuff here will be ignored by everyone
-----------------------
For that para to be ignored in the output.
If you are quoting a block that contains blank lines, then use
=begin/=end instead of =for.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 5 Dec 2004 08:10:57 +1300
From: "MadDogMcGee" <nospam@all.thx>
Subject: File locking
Message-Id: <cot24f$c8g$1@lust.ihug.co.nz>
Hi,
I want to process the contents of a file, but only when it's copied across
to the work folder. Some of the files take a few seconds to bring across.
How do I detect that the file is complete and ready for processing?
Thanks.
------------------------------
Date: 4 Dec 2004 20:13:24 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: File locking
Message-Id: <Xns95B59ADC9777Aasu1cornelledu@132.236.56.8>
"MadDogMcGee" <nospam@all.thx> wrote in
news:cot24f$c8g$1@lust.ihug.co.nz:
> I want to process the contents of a file, but only when it's copied
> across to the work folder. Some of the files take a few seconds to
> bring across. How do I detect that the file is complete and ready for
> processing?
Please note that you are asking an operating system specific question (I am
assuming that the copying of the file is being done outside of your
program. Otherwise the answer would to wait until the copying is done).
Based on your other posts and newsreader, I am assuming you are on a Win32
machine. In this case, you might want to utilize the Windows API to wait
for the file. See http://tinyurl.com/f6a5
Sinan.
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Sat, 04 Dec 2004 20:15:38 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: File locking
Message-Id: <cot5k7$m2n$1@sun3.bham.ac.uk>
MadDogMcGee wrote:
>
> I want to process the contents of a file, but only when it's copied across
> to the work folder. Some of the files take a few seconds to bring across.
> How do I detect that the file is complete and ready for processing?
If the other process is holding a lock on the file (either explicitly or
implicitly as a feature of the OS) you can try locking it.
However the more portable, reliable and widely used approach is to copy
the file using a temporary name then rename it to its final name.
None of ghis, of course, has anything to do with Perl.
If your OS provides a flock(2) like interface to lock files then you can
use the Perl flock() function the access it.
------------------------------
Date: Sun, 05 Dec 2004 09:37:28 +1100
From: Lawson Hanson <lawhan@ozemail.com.au>
Subject: Re: File locking
Message-Id: <J_qsd.344$A6.16953@nnrp1.ozemail.com.au>
MadDogMcGee wrote:
> Hi,
>
> I want to process the contents of a file, but only when it's copied across
> to the work folder. Some of the files take a few seconds to bring across.
> How do I detect that the file is complete and ready for processing?
>
> Thanks.
>
>
One way might be to do something like:
1. Obtain the size (byte count) of the source file
2. Obtain the MD5 message digest checksum
of the source file
3. Copy the file from the source to the target
4. Check the size of the target file every so often
5. When the target file has the same byte count as
the source file, then obtain the MD5 message
digest checksum of the target file
6. Compare the MD5 message digest checksums of the
two files, and proceed only if they are equal.
That might be a bit of overkill, but it should enable
a fairly robust solution to the problem.
Regards,
Lawson
------------------------------
Date: 4 Dec 2004 14:11:45 -0800
From: eagle101@gmail.com
Subject: Free Desktop Computer---Not a Scam
Message-Id: <1102198305.067776.156900@f14g2000cwb.googlegroups.com>
Yes, this is indeed for real!! A company called Gratis Internet (see
BBB report) is actually giving away free desktop computers. It's a very
simple process. Here are the exact steps you need to complete.
1. Create a free account at http://www.FreeDesktopPC.com/?r=8334833
2. Sign-up for any one of the offers on the 'Complete Offer' page...AOL
is good because they offer free trials that can be canceled if you do
not wish to continue using the service. Currently, a credit card is
required for all offers even though they do not charge you.
3. Once you have completed the steps above, you will be given an
referral link, which you have to share it with your friends, so they
can sign-up as well.
4. In order to receive your free Desktop Computer, you will have to
refer at least 10 friends which they will have to sign-up as well for a
free Desktop Computer. Once you have completed the requirements, they
will ship the product for free. GUARANTEED!!!
***Arguments in favor of Free Desktop Computers:
* They are affiliates with high profile sites. AOL, GM, etc, do not
advertise with every scammer on the block, since it would be bad for
business.
* The parent site that runs Free Desktop Computers is Gratis Internet
[aka Gratis Network]. They have several email addresses and phone/fax
numbers on their site, which is professionally done.
* They have been registered with the BBB for several years.
* The economics behind the system make sense.
This is real. Many people have already gotten their free desktop pcs,
so why wait, get yours free right now too. This is not a scam, as many
news websites and channels have been talking about this. Give it a try
and you'll see that this is real. Sign-Up Here:
http://www.FreeDesktopPC.com/?r=8334833
------------------------------
Date: Sat, 4 Dec 2004 14:03:47 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: installing dbd::mysql via cygwin on windows
Message-Id: <mSnsd.31024$Ad3.2317138@news20.bellglobal.com>
"Glenn" <user@example.net> wrote in message
news:jz7sd.6230$ue2.745@news01.roc.ny...
>
> I have installed MySQL in Program Files _prior_ to my install of cygwin..
> is this an issue in and of itself?
>
So far as I know, you can't use the Windows version of MySQL from cygwin,
but you're probably better off asking this question in a MySQL forum. I
suspect that you'll be told you have to compile a version for cygwin,
though.
Matt
------------------------------
Date: 4 Dec 2004 08:25:47 -0800
From: botfood@yahoo.com (dan baker)
Subject: Re: Monitor a dos console perl program running
Message-Id: <13685ef8.0412040825.5dc22416@posting.google.com>
mluvw47@gmail.com (Maverick Ieong) wrote in message news:<d4b6522b.0412031501.52326913@posting.google.com>...
> Hi,
> I have a perl script (script name: doingwork.bat) that doing some
> work that take about 3-4 hour easily on the DOS console. Say output on
> the dos console, like below..
> c:\>doingwork.bat
> == Build Working 1/10000
> Build 1 == done.
> Build 2 == done.
> ...
> ...
>
> Is that a way allow other people to see what doingwork.bat progress
> have done from IE? I know using netmeeting can do it, but I just want
> to connect the machine say..
> http://mymachine.somedomain.com/doingwork.bat will tell me the above
> progress from IE. Do I need to make the above script as CGI script or
> how should I do it?
> ------------------------------------
you are using a DOS machine for a web server? scarey!
its a little hard to tell exactly what you want... to initiate a
script on a web server, it'll have to be in the cgi-bin dir,
executable, and follow whatever naming convension your host defines.
You also need to protect it so that unknown users cant start it up!
If you are running a process on your local PC and just wanting to
display status in a "public" place, that is possible too...
anyway, one approach would be to have your script overwrite or append
to a file somwhere in your loop with "reasonable" frequency which is
either a plain HTML file, or included as a text file in a .shtml file
if your server can handle that. If the HTML has a meta-refresh in the
header, you can make it reload itself periodically, like maybe avery
minute, and display any new status updates. Not "real-time", but
probably close enough.
this is dead simple if the script is running on the server. If the
script is running on some offline machine, you'll have to add steps to
upload the status file to your webserver.
d
------------------------------
Date: 4 Dec 2004 20:15:29 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Monitor a dos console perl program running
Message-Id: <Xns95B59B3782F1Casu1cornelledu@132.236.56.8>
mluvw47@gmail.com (Maverick Ieong) wrote in
news:d4b6522b.0412031501.52326913@posting.google.com:
> Hi,
> I have a perl script (script name: doingwork.bat) that doing some
> work that take about 3-4 hour easily on the DOS console.
http://www.stonehenge.com/merlyn/LinuxMag/col39.html
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Sat, 04 Dec 2004 14:47:35 GMT
From: Joe Smith <joe@inwap.com>
Subject: Re: Obtaining length of binary string
Message-Id: <a6ksd.439392$wV.114538@attbi_s54>
Jürgen Exner wrote:
> Joe Smith wrote:
>
>>Perl User wrote:
>>
>>
>>>I am not sure if the length function is the right way to count the
>>>number of bytes in the string $x.
>>
>>The length() function returns the number of characters in the string.
>>If you're not using Unicode, the number of bytes is the same as
>>the number of characters.
>
>
> That's wrong. Any MBCS or DBCS uses more than one byte for a single
> character.
I was not aware of any non-Unicode version of perl that does
multibyte character sets.
-Joe
------------------------------
Date: Sat, 04 Dec 2004 15:40:53 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Obtaining length of binary string
Message-Id: <9Uksd.5321$PL1.605@trnddc09>
Joe Smith wrote:
> Jürgen Exner wrote:
>> Joe Smith wrote:
>>> Perl User wrote:
>>>> I am not sure if the length function is the right way to count the
>>>> number of bytes in the string $x.
>>>
>>> The length() function returns the number of characters in the
>>> string. If you're not using Unicode, the number of bytes is the
>>> same as the number of characters.
>>
>>
>> That's wrong. Any MBCS or DBCS uses more than one byte for a single
>> character.
>
> I was not aware of any non-Unicode version of perl that does
> multibyte character sets.
I am not sure what a "unicode version of perl" would be, but if the OP sends
lets say Japanese characters in Windows-932 back to the server, then he is
using a DBCS where each character is two bytes long and which has nothing to
do with Unicode.
jue
------------------------------
Date: Sat, 4 Dec 2004 15:58:01 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Obtaining length of binary string
Message-Id: <Pine.LNX.4.61.0412041549470.3715@ppepc56.ph.gla.ac.uk>
On Sat, 4 Dec 2004, Jürgen Exner wrote:
> Joe Smith wrote:
> > Jürgen Exner wrote:
> >>
> >> That's wrong. Any MBCS or DBCS uses more than one byte for a single
> >> character.
> >
> > I was not aware of any non-Unicode version of perl that does
> > multibyte character sets.
>
> I am not sure what a "unicode version of perl" would be,
Presumably one of the recent versions which have native Unicode
support... (5.6 or later, whatever)
> but if the OP sends lets say Japanese characters in Windows-932 back
> to the server, then he is using a DBCS where each character is two
> bytes long and which has nothing to do with Unicode.
But then Perl itself has no concept of "character" in such a piece
of data, and cannot meaningfully be asked to count "characters".
It has to be up to the programmer to count their own characters, if
the only definition of "characters" is some specification external to
Perl.
Or else they use an encode layer, or explicit encoding function, to
convert the external character encoding into native Perl (unicode)
characters, and use Perl's own functions on the result.
Doesn't that seem reasonable?
------------------------------
Date: Sat, 04 Dec 2004 16:23:56 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Obtaining length of binary string
Message-Id: <wwlsd.355$Af2.142@trnddc06>
Alan J. Flavell wrote:
[Very reasonable arguments snipped]
> Doesn't that seem reasonable?
Absolutely.
However it misses the point. Joe wrote:
>>If you're not using Unicode, the number of bytes is the same as
>>the number of characters.
And this is the statement I still don't agree with.
jue
------------------------------
Date: Sat, 04 Dec 2004 14:24:52 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: parse hash by array element seems to run slow
Message-Id: <UMjsd.289338$9b.217782@edtnps84>
JRoot wrote:
> Below I posted my program in it's entirity and I hope that is within
> the guidelines ...
> The program works perectly but it seems to run slower than I had
> expected based on other perl programs I've authored with much more
> data involved.
>
> I've been through the faq's and every web site that focuses on perl
> and to be honest, I'm overwhelmed by the number of ways it's possible
> to use perl so I'm asking if anyone could just look over this program
> and see if it is obvious where the overhead lies so I can remove the
> baggage and speed it up a bit. It runs in about 3-5 seconds on a 1 ghz
> machine but my gut tells me it could be faster or more efficient if
> you will.
Use perl's built-in variables whenever possible as they are usually optimized
for efficiency.
> I'm not asking anyone to do my work for me ... just for a
> pointer from anyone that deals with arrays and hashes a lot.
>
> The roadmap is ...
>
> I create an array from a file (one word per line)
Forget about the array.
> I create a hash from a 2nd file, combining duplicate key words and
> assign the duplicate quantity as the value. A key-val pair would look
> like ... net_name 5
Fill this hash first and then use a while loop on the first file.
> I iterate the array and search the hash keys to find a match
Use perl's exists() function to find matching hash keys instead of using a
foreach loop over keys( %hash ).
> and then
> report the key and val to different reports depending on the val
> (quantity) which is either 0 (not found) 1 (single occurance) or
> multiple which need to be verified.
>
> I suspect I've arrayed and hashed one too many times when it could
> have been done in a more simple manner.
>
> Any help is appreciated -- thank you
Try something like this (UNTESTED):
open TC, 'testpoint_chart' or die "Can't open testpoint_chart for reading: $!";
my %list;
while ( <TC> ) {
next if 1 .. 9;
my ( $netName, $side ) = ( split )[ 2, 3 ];
$list{ $netName }++ if $side eq 'Top' or $side eq 'Bottom';
}
close TC;
open TL, 'tp_list' or die "Can't open tp_list for reading: $!";
my ( @zeroArr, @oneArr, @verifyArr );
while ( <TL> ) {
chomp;
if ( exists $list{ $_ } ) {
push @{ $list{ $_ } == 1 ? \@oneArr : \@verifyArr }, "ARR: $_ --
HASHKEY: $_ VAL: $list{$_}\n";
}
else {
push @zeroArr, "$_\n";
}
}
close TL;
print "\n===== ONES =====\n------------------\n";
print "ONES: $_" for @oneArr;
print "\n===== VERIFY =====\n--------------------\n";
print "VERIFY: $_" for @verifyArr;
print "\n===== ZERO =====\n--------------------\n";
print "ZERO: $_" for @zeroArr;
print " ... D O N e ... \n\n";
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 04 Dec 2004 15:52:57 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: parse hash by array element seems to run slow
Message-Id: <akd3r0h9cltenljuqssvi2144fej5olo8d@4ax.com>
On Sat, 04 Dec 2004 12:59:42 +0100, Michele Dondi
<bik.mido@tiscalinet.it> wrote:
> next unless $. > 10;
s/10/9/; # I'm an idiot...
> <$tc> for 1..10;
s/10/9/; # I'm an idiot...
>Also, you may avoid the C<for @nets> loop in unnecessary, just like
>@nets itself. All in all this should be faster:
"Also, the C<for @nets> loop is unnecessary, just like @nets itself.
All in all this should be faster:"
While we're here, it occurred to me that there's no need to preload
@tp_list all at once either, but one can use a "traditional" C<while>
loop instead. Of course all this is obvious, or even more than
obvious, but since I basically started by translating your script to
something more human, I didn't realize it soon.
I apologize for the repeated errors/inaccuracies. All in all the
"latest version" of the script is:
#!/app/util/perl/bin/perl -l
use strict;
use warnings;
warn "$0: Working...\n";
my %count;
{
open my $tc, '<', 'testpoint_chart' or
die "$0: Can't open `testpoint_chart' for reading: $!\n";
<$tc> for 1..9;
while (<$tc>) {
my ($net_name, $side)=(split)[2,3];
$count{$net_name}++
if $side eq 'Top' or $side eq 'Bottom';
}
}
my @result;
{
open my $tl, '<', 'tp_list' or
die "$0: Can't open `tp_list' for reading: $!\n";
while (<$tl>) {
chomp;
my $c=$count{$_} || 0;
push @{ $result[$c<2 ? $c : 2] }, $_;
}
}
my @msg=qw/ZERO ONES VERIFY/;
for my $i (1,2,0) {
my $head="==== $msg[$i] ====";
print for '', $head, '-' x length $head;
print "$msg[$i]: $_" for @{ $result[$i] };
}
__END__
PS: I understand that yours could have been just a preliminary
version, but I think that it would be sensible to read the required
files from the cmd line rather than hardcoding them in the source.
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: Sat, 04 Dec 2004 15:54:57 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: parse hash by array element seems to run slow
Message-Id: <trj3r0d23qd5sklrdgb9jr233j89p8dnop@4ax.com>
On Sat, 04 Dec 2004 13:04:36 +0100, Michele Dondi
<bik.mido@tiscalinet.it> wrote:
>> if ($. > 9) { # Use $. when reading file line by line
>
>s/9/10/; # or not?
s/^.*$//; # I'm an idiot!
PS: I know of C<$_=''>. I wanted to underline "delete everything of
what I wrote from the beginning to the end"
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: 4 Dec 2004 10:27:56 -0800
From: awkster@yahoo.com (JRoot)
Subject: Re: parse hash by array element seems to run slow
Message-Id: <9efa6216.0412041027.1313527c@posting.google.com>
To everyone that responded to my latest self-made crisis
Thank you so very much for the replies and critique and the bonus
style pointers.
I'm taking all the posts and re-arranging the good, the bad and the
ugly (bad and ugly being the part I did :)) and trying different
scenarios, all of which will certainly be better than what I had, to
speed up the program naturally but also to see what I can learn from
all this.
Youz guyz and galz are truly the perl gods and goddesses. Hanging
around here could turn a person into a real programmer if he's not
careful.
Thanks again and have a good one.
Jorge
------------------------------
Date: Sat, 04 Dec 2004 14:24:24 GMT
From: Joe Smith <joe@inwap.com>
Subject: Re: Perl crashes
Message-Id: <rMjsd.439304$wV.391214@attbi_s54>
James Tolley wrote:
>>sub &total {
>
> This just needs a little editing:
Correcting the typo is not the point.
The point is that perl should output
"Illegal declaration of anonymous subroutine at temp line 4."
and not crash.
-Joe
------------------------------
Date: Sat, 04 Dec 2004 16:04:27 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: Perl crashes
Message-Id: <felsd.1202$IB6.418@trndny06>
Steve Butler wrote:
> Hi all,
>
> I have not posted here before. I am compelled to ask about this code snipet
> crashing perl.exe when attempting a perl -c:
>
> #!/usr/bin/perl -w
> use strict;
>
> sub &total {
> my $sum;
> foreach (@_){
> sum+=$_;
> }
>
> Basically I know the code is bad, but I never expected perl to crash on a
> syntax check. Should I send this bug somewhere or just not write bad code?
One more data point:
[perl 505]$ perl -v
This is perl, v5.8.4 built for darwin-2level
[perl 506]$ test1.pl
Illegal declaration of anonymous subroutine at
/Users/jimk/bin/perl/test1.pl line 5.
------------------------------
Date: Sat, 04 Dec 2004 21:54:44 GMT
From: "Steve Butler" <jodox@sbcglobal.net>
Subject: Re: Perl crashes
Message-Id: <Emqsd.28722$zx1.26012@newssvr13.news.prodigy.com>
Thanks for the feedback all! I sent in a bug via perldoc perlbug last night.
I neglected to mention my platform being windows xp. Sorry for any
confusion. Here is the perl -v loved by all:
E:\My Projects\perl\chapter 6>perl -v
This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2001, Larry Wall
Binary build 638 provided by ActiveState Corp. http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Apr 13 2004 19:24:21
Perl may be copied only under the terms of either the Artistic License or
the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
"Steve Butler" <jodox@sbcglobal.net> wrote in message
news:gn8sd.38110$6q2.16464@newssvr14.news.prodigy.com...
> Hi all,
>
> I have not posted here before. I am compelled to ask about this code
> snipet crashing perl.exe when attempting a perl -c:
>
> #!/usr/bin/perl -w
> use strict;
>
> sub &total {
> my $sum;
> foreach (@_){
> sum+=$_;
> }
>
> Basically I know the code is bad, but I never expected perl to crash on a
> syntax check. Should I send this bug somewhere or just not write bad code?
>
> Thanks!
> Steve
>
------------------------------
Date: 4 Dec 2004 15:01:34 -0800
From: nenamiele@libero.it (Alx)
Subject: read image file - and process the result
Message-Id: <38d4c7d4.0412041501.5ed77f0b@posting.google.com>
I'd like to read an image file - in PBM/PGM format, to perform some
processing on the image itself.
I didnt find exactly what I need on CPAN:
Image::Magick looks powerful, but it seems to let you read and apply
the manipulation methods that itself provides - I'd like instead to
just get a beautiful array @image=(00,FF,CC,...) with pixel color
values.
Do you happen to know what I could use?
Thanks a lot...
Alessandro Magni
------------------------------
Date: Sat, 04 Dec 2004 09:37:54 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: RegEx Help Needed
Message-Id: <e6qdnbjvVONfVizcRVn-3w@comcast.com>
DeepDiver wrote:
> "Sherm Pendley" <spamtrap@dot-app.org> wrote in message
> news:SOydnYD65MRH0izcRVn-tg@adelphia.com...
>>
>> Have a look at HTML::Parser on CPAN.
>>
>
> Thanks, but I'm in need of a pure RegEx solution.
No, you aren't. You may think you are, but you aren't.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Sat, 04 Dec 2004 09:44:13 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: RegEx Help Needed
Message-Id: <teWdnahCQOOiUCzcRVn-hQ@comcast.com>
DeepDiver wrote:
> "David H. Adler" <dha@panix.com> wrote in message
> news:slrncr2pos.j2i.dha@panix2.panix.com...
>> On 2004-12-04, DeepDiver <no-spam@sonic.net> wrote:
>> > "Sherm Pendley" <spamtrap@dot-app.org> wrote in message
>> > news:SOydnYD65MRH0izcRVn-tg@adelphia.com...
>> >>
>> >> Have a look at HTML::Parser on CPAN.
>> >>
>> >
>> > Thanks, but I'm in need of a pure RegEx solution.
>>
>> This of course raises the question: Why?
>
>
> A few reasons:
>
> 1. I'm not programming in Perl. In fact, my experience with Perl was a
> long time ago (and not very extensive even then). I came here because I
> believe that Perl programmers are generally the most proficient with
> regular expressions.
Regular expressions differ subtly but significantly between the languages
that implement them. Solutions formulated for Perl regular expressions
would have a good chance of not working in your language. Ask in a
forum that deals with your language.
>
> 2. I'm writing the current routine in C#. But I would still prefer a
> "pure" RegEx solution so that I have something that is concise and
> (higher-level) language independent.
See above about the portability of regular expressions.
>
> 3. I'm trying to improve my RegEx skills, so the more I can learn how to
> do things like this in RegEx (without "massaging" in a higher-level
> language) the better.
Regular expressions are a very poor tool for parsing HTML. Depending
on your task, using them to do so will range from hair-tearing frustrating
to simply impossible. Parsing HTML is not a trivial task. The main
lesson you would learn trying to parse HTML with regular expressions would
be, if you were paying attention, "don't parse HTML with regular
expressions".
>
> I hope this addresses your concerns.
Hope these address yours.
>
> Thanks,
> Michael
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Sat, 04 Dec 2004 14:44:11 GMT
From: Joe Smith <joe@inwap.com>
Subject: Re: Trying to install module with CPAN
Message-Id: <%2ksd.508866$D%.484280@attbi_s51>
simon wrote:
> The error message I receive is as follows:
>
> [29 lines of normal output]
Did you leave out a line there? I don't see an error message.
-Joe
------------------------------
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 7484
***************************************