[23680] in Perl-Users-Digest
Perl-Users Digest, Issue: 5887 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 3 11:05:45 2003
Date: Wed, 3 Dec 2003 08:05:12 -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 Wed, 3 Dec 2003 Volume: 10 Number: 5887
Today's topics:
Re: [Newbie]Problem reading text file (Ingo Menger)
Re: Capture external command output line by line on Win <bik.mido@tiscalinet.it>
Re: Capture external command output line by line on Win (Tad McClellan)
Descending sort <colossus_NOSPAM_@freemail.it>
Re: Descending sort (Anno Siegel)
Re: Descending sort <colossus_NOSPAM_@freemail.it>
Re: Descending sort (Anno Siegel)
Re: Don't Read - Testing <ben.liddicott@comodogroup.com>
Re: Don't Read - Testing <REMOVEsdnCAPS@comcast.net>
Re: Don't Read - Testing <ben.liddicott@comodogroup.com>
Re: Intermittent errors when loading modules in ActiveP (Louie)
newbie regular expression question (John)
Re: newbie regular expression question <asu1@c-o-r-n-e-l-l.edu>
Re: newbie regular expression question <ben.liddicott@comodogroup.com>
Re: newbie regular expression question <xx087@freenet.carleton.ca>
Perl program for sending/receiving files via a serial (Manoj K.S)
Re: Perl program for sending/receiving files via a ser (William Herrera)
Re: Perl program for sending/receiving files via a ser (William Herrera)
Re: s// problem <usenet@morrow.me.uk>
Re: Session Management? <ubl@schaffhausen.de>
Re: skipping files that are not present <bik.mido@tiscalinet.it>
Re: Using GetOptions twice in the script (Johan Vromans)
Re: Your code doesn't work <colossus_NOSPAM_@freemail.it>
Re: Your code doesn't work <noreply@gunnar.cc>
Re: Your code doesn't work <colossus_NOSPAM_@freemail.it>
Re: Your code doesn't work (Anno Siegel)
Re: Your code doesn't work (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 3 Dec 2003 03:58:54 -0800
From: quetzalcotl@consultant.com (Ingo Menger)
Subject: Re: [Newbie]Problem reading text file
Message-Id: <d8184eb8.0312030358.74eff36c@posting.google.com>
Senthil Raja <senthil.raja@adcc.alcatel.be> wrote in message news:<3FCC23C1.1ED31E49@adcc.alcatel.be>...
> Hello All,
>
> I have problem reading a test file, line by line. I've written the
> following code :-
>
> /* $parse has a file path */
> if (!-e $parse) { die ("Error - File \"$parse\" does not exists\n"); }
There is a semicolon missing in the previous line after "if (!-e parse)".
> Is there anything wrong in the algorithm I use?
Yes. Even if you insert the missing semicolon, this code does the following:
- it checks, if the file with the path name that is in $parse exists
- if so, it tries to match something complicated in $_
- finally it dies unconditionally with "Error - File ... does not exists"
> Am I missing a basic concept?
How to write comments, I guess.
------------------------------
Date: Wed, 03 Dec 2003 09:42:01 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Capture external command output line by line on Windows 98, shell problem.
Message-Id: <i2mpsvg9nnnqps4jh75jg2l04b09q2gl9l@4ax.com>
<OT>
On Tue, 2 Dec 2003 10:42:22 +0200, "Dib Urim" <DibUrim@hotmail.com>
wrote:
>print ("$_");
print ($_);
print $_;
print;
</OT>
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: Wed, 3 Dec 2003 07:46:04 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Capture external command output line by line on Windows 98, shell problem.
Message-Id: <slrnbsrq8s.3ha.tadmc@magna.augustmail.com>
Michele Dondi <bik.mido@tiscalinet.it> wrote:
><OT>
^^^^
^^^^
> print ($_);
> print $_;
> print;
></OT>
^^^^^
^^^^^
That sure looks like Perl to me...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 03 Dec 2003 11:48:23 +0100
From: Colossus <colossus_NOSPAM_@freemail.it>
Subject: Descending sort
Message-Id: <bqkeur$23jc88$1@ID-154800.news.uni-berlin.de>
Hi,
I have a flat database file this way:
A00469.PE1 SSGGH.PE1 HBG011318 1.26943 39
A00469.PE1 SGGH2.PE1 HBG011318 1.26943 110
A14829.PE1 SSAPOLAI.PE1 HBG004257 1.88791 39
A14829.PE1 DRAPLIPAI.PE1 HBG004257 1.96625 386
A14829.PE1 AF042219.PE1 HBG004257 2.03983 110
The fields are tab separated. I want it this way:
A00469.PE1 SGGH2.PE1 HBG011318 1.26943 110
A00469.PE1 SSGGH.PE1 HBG011318 1.26943 39
A14829.PE1 DRAPLIPAI.PE1 HBG004257 1.96625 386
A14829.PE1 AF042219.PE1 HBG004257 2.03983 110
A14829.PE1 SSAPOLAI.PE1 HBG004257 1.88791 39
I grabbed this piece of code but it doesn't work:
foreach my $MyData (sort { $a->[1] <=> $b->[1] } map{[$_, /^(\d+)/]} @temp)
{
printf "%-15s%5d: %-s\n", ' ', $MyData->[1], $MyData->[0];
}
I understand the problem is regular expression in map. I also
tried to use $b->4 <=> $a->4 because the field I have to order by
is at fourth position but nothing to do ! Could anyone help me please ?
--
Bye,
Colossus
------------------------------
Date: 3 Dec 2003 11:37:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Descending sort
Message-Id: <bqkhtu$im8$1@mamenchi.zrz.TU-Berlin.DE>
Colossus <colossus_NOSPAM_@freemail.it> wrote in comp.lang.perl.misc:
> Hi,
>
> I have a flat database file this way:
>
> A00469.PE1 SSGGH.PE1 HBG011318 1.26943 39
> A00469.PE1 SGGH2.PE1 HBG011318 1.26943 110
> A14829.PE1 SSAPOLAI.PE1 HBG004257 1.88791 39
> A14829.PE1 DRAPLIPAI.PE1 HBG004257 1.96625 386
> A14829.PE1 AF042219.PE1 HBG004257 2.03983 110
>
> The fields are tab separated. I want it this way:
> A00469.PE1 SGGH2.PE1 HBG011318 1.26943 110
> A00469.PE1 SSGGH.PE1 HBG011318 1.26943 39
> A14829.PE1 DRAPLIPAI.PE1 HBG004257 1.96625 386
> A14829.PE1 AF042219.PE1 HBG004257 2.03983 110
> A14829.PE1 SSAPOLAI.PE1 HBG004257 1.88791 39
What is this? A puzzle to amuse the regulars? Believe me, we can do
without those.
No column in your proposed output data is sorted, neither ascending
nor descending. An example fine, but it is is never enough to explain
your intentions. You must also explain in words what you want to do.
> I grabbed this piece of code but it doesn't work:
>
> foreach my $MyData (sort { $a->[1] <=> $b->[1] } map{[$_, /^(\d+)/]} @temp)
> {
> printf "%-15s%5d: %-s\n", ' ', $MyData->[1], $MyData->[0];
Your sprintf format provides for three data elements, but you're only
printing two. It can never print anything like your proposed output.
> }
That's a Schwartz transform for sorting strings that contain a number
into descending order. What on earth made you think it is applicable
to your problem?
> I understand the problem is regular expression in map. I also
You'd need a pretty formidable regex to extract fields that sort
according to your example. Why do you believe you need a regex
to extract sort fields? Sort field extraction is trivially done
through split(), it is not your problem.
> tried to use $b->4 <=> $a->4 because the field I have to order by
If you did try that, Perl would have told you it is a syntax error.
Please take some care in reporting what you tried. You may have tried
"$b->[4] <=> $a->[4]", but that is still nonsense because each array
has only two elements.
> is at fourth position but nothing to do ! Could anyone help me please ?
Your example output is consistent with a combined sort strategy: Sort
(alphabetically, descending) by the first field. If the first fields
are equal, sort (numerically, ascending) by the fifth field.
Here is how it can be done:
#!/usr/bin/perl
use strict; use warnings; $| = 1; # @^~`
# build an array of arrays, each containing the fields of one line
my @raw = map [ split ], <DATA>;
# sort them
my @sorted = sort { $a->[ 0] cmp $b->[ 0] or $b->[ 4] <=> $a->[ 4] } @raw;
# show the output
use Text::Table;
my $tb = Text::Table->new( ( '') x 5);
$tb->load( @sorted);
print $tb;
__DATA__
A00469.PE1 SSGGH.PE1 HBG011318 1.26943 39
A00469.PE1 SGGH2.PE1 HBG011318 1.26943 110
A14829.PE1 SSAPOLAI.PE1 HBG004257 1.88791 39
A14829.PE1 DRAPLIPAI.PE1 HBG004257 1.96625 386
A14829.PE1 AF042219.PE1 HBG004257 2.03983 110
Anno
------------------------------
Date: Wed, 03 Dec 2003 13:25:36 +0100
From: Colossus <colossus_NOSPAM_@freemail.it>
Subject: Re: Descending sort
Message-Id: <bqkkl4$2423no$1@ID-154800.news.uni-berlin.de>
Anno Siegel wrote:
> Your example output is consistent with a combined sort strategy: Sort
> (alphabetically, descending) by the first field. If the first fields
> are equal, sort (numerically, ascending) by the fifth field.
I took that code from the newsgroup perl.beginners in a message of 2002:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=utf-8&threadm=113A7A0D1F47D511B92E00D0B7E03DAB033B24A1%40pmail02.vikingfreight.com&rnum=6&prev=/groups%3Fq%3Dascending%2Bsort%2Bperl%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3Dutf-8%26selm%3D113A7A0D1F47D511B92E00D0B7E03DAB033B24A1%2540pmail02.vikingfreight.com%26rnum%3D6
I tried to adapt to my problem but without success. Could you please explain
me why I have to sort alphabetically the first fields and then sort by the
fifth one ? Can I sort directly by the fifth one ?
Thank you so much for your answer.
--
Bye,
Colossus
------------------------------
Date: 3 Dec 2003 12:49:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Descending sort
Message-Id: <bqkm4s$l8r$1@mamenchi.zrz.TU-Berlin.DE>
Colossus <colossus_NOSPAM_@freemail.it> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Your example output is consistent with a combined sort strategy: Sort
> > (alphabetically, descending) by the first field. If the first fields
> > are equal, sort (numerically, ascending) by the fifth field.
>
> I took that code from the newsgroup perl.beginners in a message of 2002:
>
> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=utf-8&threadm=113A7A0D1F47D511B92E00D0B7E03DAB033B24A1%40pmail02.vikingfreight.com&rnum=6&prev=/groups%3Fq%3Dascending%2Bsort%2Bperl%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3Dutf-8%26selm%3D113A7A0D1F47D511B92E00D0B7E03DAB033B24A1%2540pmail02.vikingfreight.com%26rnum%3D6
>
> I tried to adapt to my problem but without success. Could you please explain
> me why I have to sort alphabetically the first fields and then sort by the
> fifth one ?
What's to explain? *You* gave the example, and that's a way to reproduce
your example.
> Can I sort directly by the fifth one ?
You can, but that won't give you the sequence of your example.
Anno
------------------------------
Date: Wed, 3 Dec 2003 10:14:09 -0000
From: "Ben Liddicott" <ben.liddicott@comodogroup.com>
Subject: Re: Don't Read - Testing
Message-Id: <bqkd6k$1jh$1@kylie.comodogroup.com>
Hi Alquemius,
Ignore the nettiquette police. Post away.
Cheers,
Ben Liddicott
"Alquemius" <Alquemius@hotmail.com> wrote in message =
news:bqiu9a$h4i3@eui1nw.euskaltel.es...
> Dont Read, that's a test!
>=20
>
------------------------------
Date: Wed, 03 Dec 2003 06:25:48 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Don't Read - Testing
Message-Id: <Xns94464BC26FE28sdn.comcast@216.196.97.136>
"Ben Liddicott" <ben.liddicott@comodogroup.com> wrote in
news:bqkd6k$1jh$1@kylie.comodogroup.com:
> Hi Alquemius,
>
> Ignore the nettiquette police. Post away.
Sure, post anything you want. Job postings, your resume, ads for penis-
enlargement pills and breast-enlargement creams.
--
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
------------------------------
Date: Wed, 3 Dec 2003 12:46:02 -0000
From: "Ben Liddicott" <ben.liddicott@comodogroup.com>
Subject: Re: Don't Read - Testing
Message-Id: <bqklui$ltn$1@kylie.comodogroup.com>
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message =
news:Xns94464BC26FE28sdn.comcast@216.196.97.136...
> "Ben Liddicott" <ben.liddicott@comodogroup.com> wrote in
> news:bqkd6k$1jh$1@kylie.comodogroup.com:=20
Alquemius,
> >=20
> > Ignore the nettiquette police. Post away.
>=20
> Sure, post anything you want. Job postings, your resume, ads for =
penis-
> enlargement pills and breast-enlargement creams.
I meant that he should post whatever question prompted him to join the =
group.
I was also suggesting ignore the people who think that it's beneficial =
to spin off a whole thread castigating someone for wasting bandwidth. =
Now they have publically flamed and killfiled him, he has no reason to =
take account of their preferences.
Cheers,
Ben Liddicott
------------------------------
Date: 3 Dec 2003 05:07:55 -0800
From: elesel@myrealbox.com (Louie)
Subject: Re: Intermittent errors when loading modules in ActivePerl 5.8.0
Message-Id: <33e4b810.0312030507.4a6defb6@posting.google.com>
"Ben Liddicott" <ben.liddicott@comodogroup.com> wrote in message news:<bqibeq$v1i$1@kylie.comodogroup.com>...
> Hi Louie,
>
> "Louie" <elesel@myrealbox.com> wrote in message
> news:33e4b810.0312020449.24cafcb6@posting.google.com...
> > I'm getting intermittent strange error messages when I try to load any
> > module in even a very simple Perl script, such as:
> >
> > ------------------------
> > #!/usr/local/bin/perl -w
> >
> > use strict;
> > use Digest::MD5;
> > ------------------------
> >
> > The above script will run fine (yes, I know it doesn't do anything)
> > sometimes and other times generate the following error:
>
>
> When you say "sometimes" and "other times", are there any other
> differences other than the time?
>
> In other words, might it be to do with who you are logged in as, working
> directory, library paths, environment variables and so forth? Might it
> also be to do with what is currently mounted via NFS?
>
> I suggest you dump the environment to a file when it works, and again on
> some occasion when it doesn't, and diff the files.
>
> Cheers,
> Ben Liddicott
Unfortunately, the "sometimes" and "other times" are within seconds of
each other, with the same environment, user, etc. I can just run the
same script over and over again and it sporadically throws errors.
- Louie
------------------------------
Date: 3 Dec 2003 05:42:32 -0800
From: news2003@wanadoo.es (John)
Subject: newbie regular expression question
Message-Id: <3bd6db81.0312030542.179acccd@posting.google.com>
I would like to know which regular expression will match a number with
decimals between 0 and 1.
I have tried and fail with:
/\d/ #match any number
\/[0-1]?\.?[0-9]*/ # match any number
/[0-1]||(0\.[0-9]+)/ # match also 0.24.0220
note the number can be expressed as 0.28, 0.03455, .0123432 but never
with [+-] symbols.
Any help
Cheers
J
------------------------------
Date: 3 Dec 2003 14:07:21 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: newbie regular expression question
Message-Id: <Xns94465CCD5D842asu1cornelledu@132.236.56.8>
news2003@wanadoo.es (John) wrote in
news:3bd6db81.0312030542.179acccd@posting.google.com:
> I would like to know which regular expression will match a number with
> decimals between 0 and 1.
perldoc -q " How do I determine whether a scalar is a
number/whole/integer/float?"
The line above will be wrapped by my newsreader ... instead enter it as one
long line.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Wed, 3 Dec 2003 14:10:39 -0000
From: "Ben Liddicott" <ben.liddicott@comodogroup.com>
Subject: Re: newbie regular expression question
Message-Id: <bqkqv4$396$1@kylie.comodogroup.com>
Hi John,
\d matches any single digit. To match a number, you need \d+.
m/
\d* # match optional leading digits
\. # decimal point
\d+ # digits following the decimal
/x # allow embedded comments and whitespace
If the numbers following the decimal are optional (i.e., 123 is allowed) =
this will do the trick:
m/
\d* # match optional leading digits
(?: # either
(?: # this group:
\. # decimal point
\d+ # digits following the decimal
) # end group
| # or
(?<\d) # preceeding digit exists... presumably matched by =
\d* above
) # end either/or group
/x # allow embedded comments and whitespace
If you need to match "123." as well... well, I have given you a starting =
point.
Oh, and=20
perldoc perlre
perldoc perlrequick
perldoc perlretut
=20
obviously.
Cheers,
Ben Liddicott
"John" <news2003@wanadoo.es> wrote in message =
news:3bd6db81.0312030542.179acccd@posting.google.com...
> I would like to know which regular expression will match a number with
> decimals between 0 and 1.
>=20
> I have tried and fail with:
>=20
> /\d/ #match any number
> \/[0-1]?\.?[0-9]*/ # match any number
> /[0-1]||(0\.[0-9]+)/ # match also 0.24.0220
>
------------------------------
Date: 3 Dec 2003 14:47:36 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: newbie regular expression question
Message-Id: <slrnbsrtto.4h0.xx087@smeagol.ncf.ca>
John <news2003@wanadoo.es> wrote:
> I would like to know which regular expression will match a number with
> decimals between 0 and 1.
Why use a regex for this?
do_something() if (0 <= $n and $n <= 1)
However
my $re = qr{^(?:(?:[01](?:\.0*)?)|(?:0?\.\d+))$};
do_something() if $n =~ /$re/;
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: 3 Dec 2003 02:33:44 -0800
From: mks76@rediffmail.com (Manoj K.S)
Subject: Perl program for sending/receiving files via a serial port
Message-Id: <6d46130e.0312030233.3576f3c6@posting.google.com>
Hi
I am a new bie to perl.
Could any one provide me some links that have perl scripts to
send receive files a serial port ?
Thanks
------------------------------
Date: Wed, 03 Dec 2003 15:08:29 GMT
From: posting.account@lynxview.com (William Herrera)
Subject: Re: Perl program for sending/receiving files via a serial port
Message-Id: <3fcdfc3d.304122892@news2.news.adelphia.net>
On 3 Dec 2003 02:33:44 -0800, mks76@rediffmail.com (Manoj K.S) wrote:
>Hi
>I am a new bie to perl.
>Could any one provide me some links that have perl scripts to
>send receive files a serial port ?
>
>Thanks
I ported x/y/zmodem to Perl once, I regret to say. Dog slow, though easily
workable with today's gigahertz machines. I would still suggest the following:
to send:
perl -e '`sz filename`';
to receive:
perl -e '`rz`';
:).
---
Use the domain skylightview (dot) com for the reply address instead.
------------------------------
Date: Wed, 03 Dec 2003 15:04:18 GMT
From: posting.account@lynxview.com (William Herrera)
Subject: Re: Perl program for sending/receiving files via a serial port
Message-Id: <3fcdfa89.303687371@news2.news.adelphia.net>
On 3 Dec 2003 02:33:44 -0800, mks76@rediffmail.com (Manoj K.S) wrote:
>Hi
>I am a new bie to perl.
>Could any one provide me some links that have perl scripts to
>send receive files a serial port ?
>
>Thanks
I ported x/y/zmodem to Perl once, I regret to say. Dog slow, though easily
workable with today's gigahertz machines. I would still suggest the following:
to send:
perl -e 'sz filename';
to receive:
perl -e 'rz';
:).
---
Use the domain skylightview (dot) com for the reply address instead.
------------------------------
Date: Wed, 3 Dec 2003 08:56:51 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: s// problem
Message-Id: <bqk8gj$2hd$1@wisteria.csv.warwick.ac.uk>
Tore Aursand <tore@aursand.no> wrote:
> If you're running Linux, you can launch the CPAN interface from the
> command line:
>
> perl -MCPAN -e shell
s/Linux/an OS with a command line/
There are more than a few modules which require a C compiler, though,
so if you're on Win32 you'd be better off using ppm (invoked as such
from the command line) which will install pre-built binary versions.
--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk
------------------------------
Date: Wed, 03 Dec 2003 09:18:12 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Session Management?
Message-Id: <bqk9af$5p4$1@news.dtag.de>
Z Monteca wrote:
> no matter what I change the DefaultExpiresIn time to, my session variables
> last max two minutes? Does anybody have any idea why this is happening?
No, I'm sorry
> Also, to use a persistent session, I would have to essentially tie %session
> in every file where I want this session to exist, correct?
I don't know what you are referring to. My projects usually only have a
single front end file, that instatiates the controller of the application.
The code that instantiates your session can be loaded in via require or
use just like any other code.
bye
malte
------------------------------
Date: Wed, 03 Dec 2003 15:57:06 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: skipping files that are not present
Message-Id: <cfqrsvoa63lr9s6s1194p9tkp6jh31a39s@4ax.com>
On Wed, 03 Dec 2003 05:01:13 GMT, "John" <provicon@earthlink.net>
wrote:
>I have downloaded a bunch of web pages with information I need to process
>using LWP.
^^^^^^^^^
>The files names are:
>
>1.html
>2.html
>3.html and so on..
>
>However, in the downloading process, because of some reason, certain numbers
>are missing.
>
>Now I run the code below to process the files above with some missing
>sequence:
As others have correctly pointed out, your approach seems rather
awkward. To add my personal consideration, since you say that you used
LWP in the first place, then why don't you process the pages as you
retrieve them rather than saving them to disk? (Unless of course you
need to do that for other reasons!)
Also, as a side note, it is my personal experience[*] that it is not a
good idea populating a directory under (some) Win* fs's with that many
files, as this may introduce a noticeable overhead in terms of time
elapsed to add more files to that directory.
>$number = 1;
>while ($number < 17000) {
>my $ns="C:\\JapanUSA\\$number.html";
Well, here's one more WTDI:
for (map 'C:/JapanUSA/' . $_ . '.html', 1..17000) {
-f or
warn("`$_' either doesn't exist or is not a regular file\n"),
next;
...
}
or, if you are concerned by memory usage,
for (1..17000) {
$_='C:/JapanUSA/' . $_ . '.html';
-f or
...
}
>When I run the code above, if, for example, 110.html is missing, the program
>gets stuck. Is there anyway to change above codes so that if 110.html is
>missing, for instance, it goes to 111.html instead rather than get stuck??
Hope the above helps, but then please read 'perldoc -f -X'.
[*] To be sure, I just checked if I was saying something utterly
nonsensical with the following script (run in an initially empy
directory):
#!/usr/bin/perl -l
use strict;
use warnings;
use Time::HiRes;
my ($i,$last)=(1,Time::HiRes::time);
while(1) {
open my $fh, '>', $i or die "D'Oh! $!\n";
next if $i++ % 500;
my $curr=Time::HiRes::time;
print $curr - $last;
$last=$curr;
}
__END__
On Win98 the results are:
1.09999990463257
1.05000007152557
1.41999995708466
1.82000005245209
2.25
[*16 lines snipped*]
8.8400000333786
9.16999995708466
10.2200000286102
To be fair, the same script run under Linux (2.4.21, i686, ReiserFS)
yields:
0.0201660394668579
0.0200669765472412
0.0200920104980469
0.0200769901275635
0.0199500322341919
[*1076 lines snipped*]
0.0226060152053833
0.0227500200271606
0.02286696434021
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: 03 Dec 2003 13:40:40 +0100
From: jvromans@squirrel.nl (Johan Vromans)
Subject: Re: Using GetOptions twice in the script
Message-Id: <m28yluhy5z.fsf@phoenix.squirrel.nl>
"Moti Shtrobach" <motis@lyciumnetworks.com> writes:
> It looks like only the first "GetOptions" command processed (getA) since I
> get "Unknown option" message for all arguments in second subroutine (getB).
> Is there any way to make both subroutines get the options ?
Yes. Copy @ARGV.
@saveargv = @ARGV;
&getA;
@ARGV = @saveargv;
&getB;
Alternatively, use the "pass_through" config option. This will have
the first call leave all unrecognized options in @ARGV, so the second
call can process them.
Happy hacking,
-- Johan
------------------------------
Date: Wed, 03 Dec 2003 13:40:13 +0100
From: Colossus <colossus_NOSPAM_@freemail.it>
Subject: Re: Your code doesn't work
Message-Id: <bqklgh$244vt9$1@ID-154800.news.uni-berlin.de>
@array = ("A00469.PE1 SSGGH.PE1 HBG011318 1.26943 39",
"A00469.PE1 SGGH2.PE1 HBG011318 1.26943 110",
"A02759.PE1 XLA298150.APP HBG000051 0.12417 592",
"A08691.RAP1A AF032713.PE1 HBG009351 0.63293 333",
"A08802.PE1 AF349034.PE1 HBG000071 0.82133 386",
"A14829.PE1 SSAPOLAI.PE1 HBG004257 1.88791 39",
"A14829.PE1 DRAPLIPAI.PE1 HBG004257 1.96625 386",
"A14829.PE1 AF042219.PE1 HBG004257 2.03983 110");
my @sorted = sort { $a->[ 0] cmp $b->[ 0] or $b->[ 4] <=> $a->[ 4] }
@array;
foreach $indice(0..$#sorted)
{
print $sorted[$indice],"\n";
}
Output:
A00469.PE1 SSGGH.PE1 HBG011318 1.26943 39
A00469.PE1 SGGH2.PE1 HBG011318 1.26943 110
A02759.PE1 XLA298150.APP HBG000051 0.12417 592
A08691.RAP1A AF032713.PE1 HBG009351 0.63293 333
A08802.PE1 AF349034.PE1 HBG000071 0.82133 386
A14829.PE1 SSAPOLAI.PE1 HBG004257 1.88791 39
A14829.PE1 DRAPLIPAI.PE1 HBG004257 1.96625 386
A14829.PE1 AF042219.PE1 HBG004257 2.03983 110
That is exactly the same starting array.
--
Bye,
Colossus
------------------------------
Date: Wed, 03 Dec 2003 13:46:32 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Your code doesn't work
Message-Id: <bqkm1c$22t21u$1@ID-184292.news.uni-berlin.de>
Colossus wrote:
> That is exactly the same starting array.
Have you possibly considered to "grab" some Perl documentation, rather
than grabbing various pieces of code that you don't understand?
A suitable starter might be
perldoc -f sort
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 03 Dec 2003 14:21:47 +0100
From: Colossus <colossus_NOSPAM_@freemail.it>
Subject: Re: Your code doesn't work
Message-Id: <bqknuf$23js9h$1@ID-154800.news.uni-berlin.de>
Gunnar Hjalmarsson wrote:
> A suitable starter might be
What you call suitable is a very difficult
explanation on how to sort an array of more fields.
--
Bye,
Colossus
------------------------------
Date: 3 Dec 2003 13:28:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Your code doesn't work
Message-Id: <bqkoe0$mg1$1@mamenchi.zrz.TU-Berlin.DE>
Colossus <colossus_NOSPAM_@freemail.it> wrote in comp.lang.perl.misc:
> Gunnar Hjalmarsson wrote:
>
> > A suitable starter might be
>
> What you call suitable is a very difficult
> explanation on how to sort an array of more fields.
So you want to use the sort function, but the documentation is too
difficult? "Suitable" isn't the same as "simple".
Anno
------------------------------
Date: 3 Dec 2003 14:33:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Your code doesn't work
Message-Id: <bqks7l$pft$1@mamenchi.zrz.TU-Berlin.DE>
Colossus <colossus_NOSPAM_@freemail.it> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> >So you want to use the sort function, but the documentation is too
> >difficult? "Suitable" isn't the same as "simple".
>
> Still your code doesn't work, I think it is much
> better for you not to answer at all. Did you read
> the documentation about sort ? You write perl code
> that works only in your brain.
Sure it works. You botched it when you gave my sort routine an array
of strings instead an array of arrays of fields. If you had switched
on warnings or strictures, you'd already know that something was
wrong. You should always switch them on in troublesome code.
I get the impression you have very little experience in programming.
There's nothing wrong with that, but you have probably bitten off
a little more than you can chew at the moment. Get acquainted with
the basics first. What *is* wrong is to over-estimate your own
abilities.
Anno
------------------------------
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 5887
***************************************