[11146] in Perl-Users-Digest
Perl-Users Digest, Issue: 4746 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 25 17:57:15 1999
Date: Mon, 25 Jan 99 14:01:35 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 25 Jan 1999 Volume: 8 Number: 4746
Today's topics:
Re: Perl Criticism <jeromeo@atrieva.com>
Re: Perl Criticism (Larry Rosler)
Re: Perl Criticism <staffan@ngb.se>
Re: Regular Expression Help <bsmith@perf.zko.dec.com>
Request for negative value list indexes <bsmith@perf.zko.dec.com>
Re: Request for negative value list indexes <kprice@cardinal.co.nz>
Re: Request for negative value list indexes <bsmith@perf.zko.dec.com>
Re: searching a binary file ps258@hotmail.com
Re: sorting dates <dennis.kowalski@daytonoh.ncr.com>
Re: sorting dates <bsmith@perf.zko.dec.com>
Re: sorting dates (Randal L. Schwartz)
sybperl on windows <ekarimi@harte-hanks.com>
tryin' to learn <paulturner@home.com>
Re: Want to output $29.85 not $29.8585 ya know? (Bart Lateur)
Why do these two programs give different results? <zzhang@bayou.uh.edu>
Re: Why do these two programs give different results? <staffan@ngb.se>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 25 Jan 1999 10:56:21 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: Perl Criticism
Message-Id: <36ACBE55.20705B0E@atrieva.com>
Staffan Liljas wrote:
>
> James B Crigler wrote:
> > 1. topmind is a CS grad student or professor who has a rigid,
> > inflexible
> > point of view and suffers from hardening of the categories.
> > 2. topmind is Larry Wall looking for legitimate holes in the Perl.
> > 3. (less likely) topmind is Larry Wall trolling for complements on his
> > creation.
>
> I think 1. is unlikely, since topmind doesn't seem to have a clue. For
> two or three, they are amusing. But don't forget
>
> 4. topmind is a stupid troll who doesn't care about the discussion
> 5. topmind is a computor program written by a AI programmer trying to
> become immortal by creating a program that passes the Turing Test,
> and tests it on the perl community.
I like 5 as well, but I think 6 is the most accurate.
6. Topmind is an amateur. He worked in another field where he made use
of desktop computer programs (Excell, Word, etc) and was proficient in
their use, perhaps becoming knowledgeable with their VB interfaces and
macro capabilities. He was the office "Computer Guy." Top started to
believe the hype, and fancied himself a "guru." Top began looking for
work in the field, and padded is resume. When new employers discovered
the gap between Top's mastery of the vernacular and his actual skills,
Top was re-assigned. Top, confused as to why his 10 years in the
industry didn't amount to much, decides that he needs to fix the things
that he can't do, instead of learning to do the things he can't. Top
hopes his criticisms will give him an "expert" standing in the community
to which he so desperately wishes to be a part.
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Mon, 25 Jan 1999 12:03:42 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl Criticism
Message-Id: <MPG.11166dfd47645ccf9899c3@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <36ACAF85.CE3B7526@lmco.com> on Mon, 25 Jan 1999 12:53:09 -
0500, James B Crigler <james.b.crigler@lmco.com> says...
> Larry Rosler wrote responded to my message:
> ... (the C concept of the short-circuit operators is quite
> > different from that of Perl).
>
> Hmmm ... Since receiving Larry's courtesy email, I checked the man page
> for perlop (for the 5.003 here at work) and all the current FAQs
> (available online), and I found there was no mention of this difference
> in the "||" operator for Perl vis-a-vis C, so I incorrectly assumed the
> principle of least surprise, assumed they were the same, and was
> surprised.
> Mea culpa.
>
> FWIW, is there someplace in the public documentation I should have been
> able to find this difference in the operator?
It is in perlop:
"The || and && operators differ from C's in that, rather than returning
0 or 1, they return the last value evaluated."
It is not in the C section of perltrap, probably because the limitations
in semantics are on the C side, while the Perl side is more capable, so
would subsume a direct translation of C code.
Perl's semantics is much more useful:
$a && $b -- the value of $b if $a is TRUE (seldom used, but very
expressive IMO; alternative is $a ? $b : FALSE).
$a || $b -- The value of $a if it is TRUE, else the value of $b (often
used, to provide default values).
As a corollary to the above, in C, each operand is expected to provide a
value that can be converted to a Boolean (and a function returning
'void' does not do so). In Perl, anything goes.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 25 Jan 1999 22:20:02 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: Perl Criticism
Message-Id: <36ACE002.88AE3505@ngb.se>
Jerome O'Neil wrote:
> > > 1. topmind is a CS grad student or professor who has a rigid,
> > > inflexible
> > > point of view and suffers from hardening of the categories.
> > > 2. topmind is Larry Wall looking for legitimate holes in the
> > > Perl.
> > > 3. (less likely) topmind is Larry Wall trolling for complements
> > > on his creation.
> >
> > I think 1. is unlikely, since topmind doesn't seem to have a clue.
> > For two or three, they are amusing. But don't forget
> >
> > 4. topmind is a stupid troll who doesn't care about the discussion
> > 5. topmind is a computor program written by a AI programmer trying
> > to become immortal by creating a program that passes the Turing
> > Test, and tests it on the perl community.
>
> I like 5 as well, but I think 6 is the most accurate.
>
> 6. Topmind is an amateur. He worked in another field where he made use
> of desktop computer programs (Excell, Word, etc) and was proficient in
> their use, perhaps becoming knowledgeable with their VB interfaces and
> macro capabilities. He was the office "Computer Guy." Top started to
> believe the hype, and fancied himself a "guru." Top began looking for
> work in the field, and padded is resume. When new employers discovered
> the gap between Top's mastery of the vernacular and his actual skills,
> Top was re-assigned. Top, confused as to why his 10 years in the
> industry didn't amount to much, decides that he needs to fix the things
> that he can't do, instead of learning to do the things he can't. Top
> hopes his criticisms will give him an "expert" standing in the community
> to which he so desperately wishes to be a part.
Boringly, depressingly and pathetically enough, I'm afraid that 6 is
correct.
------------------------------
Date: Mon, 25 Jan 1999 15:08:05 -0500
From: Ben Smith <bsmith@perf.zko.dec.com>
Subject: Re: Regular Expression Help
Message-Id: <36ACCF25.D33F6DB2@perf.zko.dec.com>
Do it in two steps: 1) generate a list of all the <img...> links; 2)
eliminate the
ones you don't want:
$bigString =
'This is a test <img stuff="something">
and <img stuff="nothing" alt="junk">';
(@all) = ($bigString =~ m/<\s*img[^>]*>/ig);
@less = grep(!/alt\s*/i,@all);
print join("\n","FULL LIST:",@all,"FILTERED LIST:",@less,"\n");
--
work: bsmith@perf.zko.dec.com = Ben Smith = ZKO2-3R55 = 603-884-2836
home: ben@roninhouse.com = 603-924-4131 = FAX: 603-924-3582
------------------------------
Date: Mon, 25 Jan 1999 14:46:33 -0500
From: Ben Smith <bsmith@perf.zko.dec.com>
Subject: Request for negative value list indexes
Message-Id: <36ACCA19.483DCAC2@perf.zko.dec.com>
Perl Porters and Larry Wall,
Wouldn't it be nice to be able to reference a list element from the end
as well as
from the begining.. $array[-1] would be equivalent to $array[$#array]
and
$array[-2] would be equivalent to $array[$#array-1].
After programming Perl for six years or so, this is the only thing I
would ask for
to make the language a little better. I find it would be a great help
when referring
to a list element at or near the end when the manipulation is done by a
method. In other
words, the list is part of an object the details are somewhat hidden
from the
caller. For the time being, I shall write the conversion of negative
indexes into the
method, but wouldn't it be nice to have it part of Perl?
Thanks.
Ben Smith
--
work: bsmith@perf.zko.dec.com = Ben Smith = ZKO2-3R55 = 603-884-2836
home: ben@roninhouse.com = 603-924-4131 = FAX: 603-924-3582
------------------------------
Date: Tue, 26 Jan 1999 09:15:40 +1300
From: Kelvin Price <kprice@cardinal.co.nz>
Subject: Re: Request for negative value list indexes
Message-Id: <36ACD0EC.ABEAEAED@cardinal.co.nz>
Ben Smith wrote:
>
> Perl Porters and Larry Wall,
>
> Wouldn't it be nice to be able to reference a list element from the end
> as well as
> from the begining.. $array[-1] would be equivalent to $array[$#array]
> and
> $array[-2] would be equivalent to $array[$#array-1].
Umm, you can do that. It works on my 5.005_02 anyway.
>
> After programming Perl for six years or so, this is the only thing I
Are you still using the version of Perl you got 6 years ago !? 8-D
> would ask for
> to make the language a little better. I find it would be a great help
> when referring
> to a list element at or near the end when the manipulation is done by a
> method. In other
> words, the list is part of an object the details are somewhat hidden
> from the
> caller. For the time being, I shall write the conversion of negative
> indexes into the
> method, but wouldn't it be nice to have it part of Perl?
>
> Thanks.
'salright
>
> Ben Smith
------------------------------
Date: Mon, 25 Jan 1999 15:35:57 -0500
From: Ben Smith <bsmith@perf.zko.dec.com>
Subject: Re: Request for negative value list indexes
Message-Id: <36ACD5AD.D8A970A5@perf.zko.dec.com>
Kelvin Price wrote:
> Umm, you can do that. It works on my 5.005_02 anyway.
>
> >
> > After programming Perl for six years or so, this is the only thing I
>
> Are you still using the version of Perl you got 6 years ago !? 8-D
No, but I'm still using the brain I had six years ago and it obviously
hasn't kept up. Thanks -ben
--
work: bsmith@perf.zko.dec.com = Ben Smith = ZKO2-3R55 = 603-884-2836
home: ben@roninhouse.com = 603-924-4131 = FAX: 603-924-3582
------------------------------
Date: Mon, 25 Jan 1999 20:58:42 GMT
From: ps258@hotmail.com
Subject: Re: searching a binary file
Message-Id: <78ilts$85j$1@nnrp1.dejanews.com>
In article <ebohlmanF62t49.Gyn@netcom.com>,
Eric Bohlman <ebohlman@netcom.com> wrote:
> ps258@hotmail.com wrote:
> : I want to do the eqivalent of
>
> : find . -name \* -exec grep search_string {} \;
>
> : binary file and just taking it as the eof.
>
> perldoc -f binmode
Thankyou, that's what I needed to know.
>
> : open($FH, "$FileName");
>
> It would make a lot of sense to check if you could actually open the
> file and die with a meaningful error message if not.
very good advice.
>
> Filehandle names shouldn't start with '$'.
The actual routine recurses down directory trees, so the the file handle needs
to be private to each instance of the routine, hence the $FH.
> The quotes are superfluous.
Again you're right, I don't know what I was thinking of there.
> : while (<$FH>)
> : {
> : if (/\bMain::$searchString\b/i)
> : {
> : print "$FileNamet\n";
> : last; # found a string, leave now
> : }
> : }
> : close($FH);
The strange thing is that it still doesn't find all the files. I can't see why
either. It's on an NT system, and 'findstr' won't cut it because it won't take
UNC path names.
Thanks for you help.
Peter
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 25 Jan 1999 14:36:32 -0500
From: Dennis Kowalski <dennis.kowalski@daytonoh.ncr.com>
Subject: Re: sorting dates
Message-Id: <36ACC7C0.E37@daytonoh.ncr.com>
Eric Smith wrote:
>
> Hi Perl
>
> Please forgive me if this question is answered well in the
> literature as I have not found the answer yet.
>
> I have a csv which contains a date field and I would like my
> script to sort the lines by the date field.
>
> csv ->
> 29/09/98,this,that,theother
> 23/09/98,this,that,theother
> 23/04/98,this,that,theother
>
> TIA
> Eric Smith
> eric@fruitcom.com
My 1st suggestion is to store the date in yy/mm/dd format.
Which by the way is not y2k compliant.
Date can be displayed anyway you want but storing them in YMD format
makes sorting easy.
If you can not control the format, do the following
sub mytest
{
}
@sorted = sort mytest @unsorted;
Check out the sort docs for how to code mytest routine.
------------------------------
Date: Mon, 25 Jan 1999 15:29:06 -0500
From: Ben Smith <bsmith@perf.zko.dec.com>
Subject: Re: sorting dates
Message-Id: <36ACD412.FBF64C00@perf.zko.dec.com>
sub ByDate { # sorting routine for dd/mm/yy dates
# rearrange order of split results for
mm/dd/yy dates
my($Aday, $Amonth, $Ayear) = split(/\//,$a);
my($Bday, $Bmonth, $Byear) = split(/\//,$b);
if($Ayear != $Byear) {
return ($Ayear <=> $Byear) ;
} elsif($Amonth ne $Bmonth) {
return ($months{$Amonth} <=> $months{$Bmonth}) ;
} else {
return ($Aday <=> $Bday) ;
}
}
--
work: bsmith@perf.zko.dec.com = Ben Smith = ZKO2-3R55 = 603-884-2836
home: ben@roninhouse.com = 603-924-4131 = FAX: 603-924-3582
------------------------------
Date: 25 Jan 1999 13:31:21 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: sorting dates
Message-Id: <m1lnir9h06.fsf@halfdome.holdit.com>
>>>>> "Ben" == Ben Smith <bsmith@perf.zko.dec.com> writes:
Ben> sub ByDate { # sorting routine for dd/mm/yy dates
Ben> # rearrange order of split results for
Ben> mm/dd/yy dates
Ben> my($Aday, $Amonth, $Ayear) = split(/\//,$a);
Ben> my($Bday, $Bmonth, $Byear) = split(/\//,$b);
Ben> if($Ayear != $Byear) {
Ben> return ($Ayear <=> $Byear) ;
Ben> } elsif($Amonth ne $Bmonth) {
Ben> return ($months{$Amonth} <=> $months{$Bmonth}) ;
Ben> } else {
Ben> return ($Aday <=> $Bday) ;
Ben> }
Ben> }
If you insist on doing all this work in the sort sub, at least take
advantage of the magic of || ...
sub byDate {
my($aday, $amonth, $ayear) = split /\//, $a;
my($bday, $bmonth, $byear) = split /\//, $b;
$ayear <=> $byear
||
$months{$amonth} <=> $months{$bmonth}
||
$aday <=> $bday
}
But a Schwartzian[1] Transform (or something similar) should be used
instead of all those splits inside the subr.
print "Just another Perl hacker,"
[1] Named *for* me, but not *by* me, I must say.
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Mon, 25 Jan 1999 15:35:10 -0600
From: Ezat Karimi <ekarimi@harte-hanks.com>
Subject: sybperl on windows
Message-Id: <36ACE38D.98D227EB@harte-hanks.com>
My apology if this issue been discussed before...
Has anybody been able to install sybperl on windows (95/NT)? I would
appreciate any suggestion from anybody who has. I am trying to install
sybperl.2-10.
Ezat Karimi
------------------------------
Date: Mon, 25 Jan 1999 21:35:40 GMT
From: root <paulturner@home.com>
Subject: tryin' to learn
Message-Id: <36ACE519.9C35DFA0@home.com>
Ok I'm sure this is easy, but I am trying to learn. If there is a group
more suited to beginners please let me know.
I am running the examples from "Learning Perl" by Randal L. Schwartz -
O'reilly. Things are going well 'till page
when it talks about formatting for the write function. The format
section is ended with a single period. My
compiler (perl5.004_04 on Red Hat 5.2) blows up at the period.
format not terminated ...
format not terminated ...
execution aborted ...
format STDOUT =
@<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<
$filename, $name, $word
.
the error refers to the line number with the period
Thank You
------------------------------
Date: Mon, 25 Jan 1999 20:08:10 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Want to output $29.85 not $29.8585 ya know?
Message-Id: <36accbe3.700128@news.skynet.be>
Larry Rosler wrote:
>> * Now you can safely use sprintf('$%.2f',$number) which returns a
>> string.
>
>The last step is a time-wasting no-op. A number is a string is a number
>is a string is a ...
Except that it will pad zero's. And it *might* prevent any round-off
errors from popping up. After all, AFAIK, 1/5 does not have an exact
representation in FP.
print 12/20;
0.6
print sprintf("%.2f", 12/20);
0.60
Bart.
------------------------------
Date: Mon, 25 Jan 1999 14:17:42 -0600
From: Zhengdong Zhang <zzhang@bayou.uh.edu>
Subject: Why do these two programs give different results?
Message-Id: <36ACD166.3C4C@bayou.uh.edu>
I wrote the following two programs as a practice. Both of them list all
the files in a specified directory. To exclude the subdirectories I used
" next if -d; " in both programs. But it works only in the first. I can
not figure out the reason.
------------program 1---------
#! /usr/local/bin/perl
use strict;
my ($dir);
print "This program will list all the files in a directory you
spesified.\n",
"Enter the directory path. You may use dot(.) and double
dot(..).\n";
chomp($dir = <STDIN>);
chdir $dir || die "cannot cd to $dir: $!";
print "The files in the directory $dir are:\n";
foreach (sort <.*>)
{
next if -d;
print "$_\n";
}
foreach (sort <*>)
{
next if -d;
print "$_\n";
}
------------program 2----------
#! /usr/local/bin/perl
use strict;
my($dir);
print "This program will list all the files in a directory you
spesified.\n",
"Enter the directory path. You may use dot(.) and double
dot(..).\n";
chomp($dir = <STDIN>);
opendir(DIR, $dir) || die "no $dir?: $!";
foreach (sort readdir(DIR))
{
next if -d;
print "$_\n";
}
closedir(DIR);
--------------------------------
Thanks.
Z.Zhang
----------------
http://www.bchs.uh.edu/~nzhou/people/current/dong/cover.html
------------------------------
Date: Mon, 25 Jan 1999 22:27:16 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: Why do these two programs give different results?
Message-Id: <36ACE1B4.B9FA6421@ngb.se>
Zhengdong Zhang wrote:
>
> I wrote the following two programs as a practice. Both of them list
> all the files in a specified directory. To exclude the subdirectories
> I used " next if -d; " in both programs. But it works only in the
> first. I can not figure out the reason.
> ------------program 1---------
[snip]
> chdir $dir || die "cannot cd to $dir: $!";
> print "The files in the directory $dir are:\n";
> foreach (sort <.*>)
> {
> next if -d;
[snip]
> ------------program 2----------
[snip]
> opendir(DIR, $dir) || die "no $dir?: $!";
> foreach (sort readdir(DIR))
> {
> next if -d;
[snip]
>From perlfunc readdir
"If you're planning to filetest the return values out of a readdir(),
you'd better prepend the directory in question."
You didn't chdir() in the second example, so you're testing for -d in
the wrong directory.
HTH
Staffan
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 4746
**************************************