[10427] in Perl-Users-Digest
Perl-Users Digest, Issue: 4020 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 20 13:03:13 1998
Date: Tue, 20 Oct 98 10:01:37 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 20 Oct 1998 Volume: 8 Number: 4020
Today's topics:
Re: Perl Cookbook - is this the best perl book? (Daniel Beckham)
Question... (Jerzy Orzeszek)
Re: Raleigh.pm (Raleigh, NC, USA perl mongers) has regi (Joergen W. Lang)
Re: Raleigh.pm (Raleigh, NC, USA perl mongers) has regi (Adam Turoff)
Re: Rounding Problem <andrew.simpson@matcomcorp.com>
Re: Shell commands (Clinton Pierce)
re: sorting file entries by time (Larry Rosler)
Re: sorting file entries by time <jdporter@min.net>
Re: Strict and Global Variables <aqumsieh@matrox.com>
Re: String substition (Tad McClellan)
Re: strip leading zeros (Larry Rosler)
Re: strip leading zeros <murrayb@vansel.alcatel.com>
Re: strip leading zeros (Matthew Bafford)
Re: strip leading zeros (Daniel Beckham)
Re: strip leading zeros (Daniel Beckham)
Re: strip leading zeros (Bart Lateur)
Re: What isn't Perl good for? <featheredfrog@geocities.com>
Re: What isn't Perl good for? (Nathan V. Patwardhan)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 Oct 1998 11:23:42 -0400
From: danbeck@eudoramail.com (Daniel Beckham)
Subject: Re: Perl Cookbook - is this the best perl book?
Message-Id: <MPG.1096750641690f5098968d@news.supernews.com>
If you are new to Perl. I can't recommend enough, "Learning Perl" from
O'Reilly. If you are familiar with Perl, then grab "Programming Perl".
It's more in-depth, but assumes a lot.
I'm about to purchase "Perl Cookbook" myself because I think I will find
the tips and tricks in it very useful, but I would never have bought it
to learn Perl or even bone up on Perl...
Regards,
Daniel Beckham
In article <70gcun$b08$1@nnrp1.dejanews.com>, eugene@vertical.net says...
> Yes, it is the best Perl book.
> "Programming Perl" is also the best Perl book.
> So is "Learning Perl"; and "Perl Complete" comes pretty close.
> (BTW, since we're at it, "The Crying of Lot 49" is also a pretty damn good
> book).
>
------------------------------
Date: Tue, 20 Oct 1998 15:30:04 GMT
From: jurek@univcomp.waw.pl (Jerzy Orzeszek)
Subject: Question...
Message-Id: <362dabf8.26334974@news.icm.edu.pl>
Hello,
I need to run script like this
enter first_number
enter second_number
exec( "find / -size -first_number -size -second_number -exec ls -l
{}\;
exit;
any help?
Jerzy
------------------------------
Date: Tue, 20 Oct 1998 17:16:23 +0100
From: jwl@_munged_worldmusic.de (Joergen W. Lang)
Subject: Re: Raleigh.pm (Raleigh, NC, USA perl mongers) has registered
Message-Id: <1dh7i46.n8bsq01kt4aweN@host014-210.seicom.net>
Adam Turoff <ziggy@panix.com> wrote:
> (And, last time I checked, Belgian Scotch was mostly illegal, except
> for the technicalities, like that Scotch made in the south of France...)
Is that the "Couvreur" stuff you're talking about ? He has a scottish
address on the bottles, but is in France, actually. Very good, indeed,
but veeeery expensive. (I once got paid in Scotch for a job...*).
Joergen
* as a musician, though. ;-) very appropriate.
--
To reply by email please remove _munged_ from address Thanks !
-------------------------------------------------------------------
"Everything is possible - even sometimes the impossible"
HOELDERLIN EXPRESS - "Touch the void"
------------------------------
Date: 20 Oct 1998 11:49:13 -0400
From: ziggy@panix.com (Adam Turoff)
Subject: Re: Raleigh.pm (Raleigh, NC, USA perl mongers) has registered
Message-Id: <70ibdp$qu4@panix.com>
Joergen W. Lang <jwl@_munged_worldmusic.de> wrote:
>Adam Turoff <ziggy@panix.com> wrote:
>> (And, last time I checked, Belgian Scotch was mostly illegal, except
>> for the technicalities, like that Scotch made in the south of France...)
>
>Is that the "Couvreur" stuff you're talking about ? He has a scottish
>address on the bottles, but is in France, actually. Very good, indeed,
>but veeeery expensive. (I once got paid in Scotch for a job...*).
I'm not sure of the name, but it's the canonical example of legal scotch
that's not blended in Scotland. The purveyor is a French blender who
buys barrels after they've aged the minimum 3 (?) years on Scotland.
Now if I could only find the story behind of 'pe[a]rl sake'...
Z.
------------------------------
Date: Tue, 20 Oct 1998 10:23:55 -0500
From: "Drew" <andrew.simpson@matcomcorp.com>
Subject: Re: Rounding Problem
Message-Id: <70ia6u$oca$1@nntp.gulfsouth.verio.net>
>First off, 0.32499999..... rounded to 3 decimal
>places is 0.325. 0.325 CHOPPED at 3 places is
>0.324.
Embarassment.
In terms of hardware, chopping is much easier
>than rounding. Second, perl by default is using double
>precision numbers. In IEEE arithmetic, a double
>precision number has 16+ significant figures, not 20!
I saw 20 somewhere?
>Third, your supplied subroutine does not do what
>is intended for negative numbers. You need to
>deal with the sign before you do the add 0.5 business.
>And then put the sign back in later.
Thanks, this code is from a widely used module and I did
not think it needed testing. The results from this module
are the same as that from sprintf, is it possible they are
using the same code?
Drew.
------------------------------
Date: 20 Oct 1998 13:43:07 GMT
From: cpierce1@cp500.fsic.ford.com (Clinton Pierce)
Subject: Re: Shell commands
Message-Id: <70i41b$guo1@eccws1.dearborn.ford.com>
In article <70fkrn$6la$1@nnrp1.dejanews.com>,
eugene@vertical.net writes:
>I think he nitpicked the wrong word. People (read Tom Christiansen) like to
>insist on the difference between a UNIX system call and Perl system()
>command: "chech the system() call" would be wrong, though "Check the
>system() command" is OK.
To be pedantic, I always thought:
Commands were sections #1 [1], System Calls were section #2 [2], and
Library calls (functions) were section #3.[3] Functions, subroutines
and procedures were things that the language designer and programmer
invented...
This assumes, of course, that your OS makes a clear distinction between
the layers of abstraction like UNIX does...
[1] man -s 1 intro
[...]
DESCRIPTION
This section describes, in alphabetical order, commands
available with this operating system. [...]
[2] DESCRIPTION
This section describes all of the system calls.
[3] DESCRIPTION
This section describes functions found in various libraries,
other than those functions that directly invoke UNIX system
primitives, which are described in Section 2 of this volume.
--
+------------------------------------------------------------------------+
| Clinton A. Pierce | "If you rush a Miracle Man, | http://www. |
| cpierce1@ford.com | you get rotten miracles" | dcicorp.com/ |
| fubar@ameritech.net |--Miracle Max, The Princess Bride| ~clintp |
+------------------------------------------------------------------------+
GCSd-s+:+a-C++UALIS++++P+++L++E---t++X+b+++DI++++G++e+>++h----r+++y+++>y*
------------------------------
Date: Tue, 20 Oct 1998 08:07:41 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: re: sorting file entries by time
Message-Id: <MPG.1096471882fda7e69898cf@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and copy mailed.]
In article <362C9614.7002FF99@juno.ltd.uk> on Tue, 20 Oct 1998 14:54:28
+0100, lee <lee@juno.ltd.uk> says...
...
> i have formatted the text in the file so that the part to be
> sorted by is always at the same offset.
>
> the script i'm now trying is:
>
> open(T, "writefile");
> $line = <T>;
>
> while ($line ne "") {
> chop($line);
> @words = $line;
> @words2 =
> map {substr($_,6) }
> sort
> map (substr($_,25,6),$_}
> @words;
> $line = <T>;
> print ("@words\n");
> }
You are not sorting the lines at all. You are assigning one line at a
time to the array @words, then sorting it (!) [actually, itself and a
piece of itself] into the array @words2. Each of these gets overwritten
each time through your loop.
First gather all your lines into an array:
open(T, "writefile") or die "Couldn't read write(!)file. $!\n";
@words = <T>;
Then sort them:
@words2 =
map {substr($_,6) }
sort
map {substr($_,24,6).$_} # Note: *three* changes on this line!
@words;
And print them:
print @words2; # The newlines have never gone away.
Comments on the three errors:
A transcription error ('(' for '{') -- it's better to cut-and-paste code
that compiles correctly rather than to type it in again so it doesn't.
An off-by-one counting error -- offsets for substr start from 0.
Another transcription error (',' for '.'). See above.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 20 Oct 1998 11:49:56 -0400
From: John Porter <jdporter@min.net>
Subject: Re: sorting file entries by time
Message-Id: <362CB124.F5D22E15@min.net>
lee wrote:
>
> maybe i'm just doing something stupid,
Yes.
> but i can't seem to get this working.
>
> i have formatted the text in the file so that the part to be
> sorted by is always at the same offset.
>
> open(T, "writefile");
> $line = <T>;
> while ($line ne "") {
> chop($line);
> @words = $line;
> @words2 =
> map {substr($_,6) }
> sort
> map (substr($_,25,6),$_}
> @words;
> $line = <T>;
> print ("@words\n");
> }
Why do you sort the array on each iteration of the loop?
The only thing you want to do inside the loop is add each new
line to the array of lines. Then you can sort them all
*after* the loop has done reading the file.
You also have a bug in the first (i.e. the lower) map:
That should be
substr($_,25,6).$_
^DOT
NOT
substr($_,25,6),$_
^COMMA
You should also use chomp instead of chop.
You should also have -w on your perl command line.
You should also use while (<>) the way every Perl tutorial
presents it.
You should also try using strict to encourage good programming habits.
You have also committed Sin #0: Failing to Check the Result of Open.
This is better:
my @lines;
open(T,"< $file") or die "open $file: $!";
while (<T>) {
next unless /\S/; # skip blank lines
push @lines, $_;
}
close T;
my @sorted_lines =
map { substr($_,6) }
sort
map { substr($_,25,6).$_ }
@lines;
foreach ( @sorted_lines ) {
print "$_\n";
}
Of course, that reading loop can be abbreviated thusly:
my @lines = grep { /\S/ } <T>;
chomp @lines;
Then the whole program can be reduced to:
#!/usr/bin/perl -w
open T, "< $file" or die "open $file: $!";
foreach (
map { substr($_,6) }
sort
map { /\S/ ? substr($_,25,6).$_ : () }
<T>
) {
print;
}
close T;
Note, no \n on the print because I never chomped the lines.
Many other optimizations are possible.
> with the lines to be sorted now in the form :
>
> BUNDDEC98 BUY 19981008 155036 50132 ....
> BUNDDEC98 BUY 19981008 155036 50133 ....
> BUNDDEC98 SELL 19981008 080902 259 ....
> BUNDDEC98 BUY 19981008 162531 55819 ....
> .... |-------|
> .... these six digits are the timestamps
May I suggest that you not compose your messages in a
proportionally-spaced font, so that these things actually line up
the way you want them to? Thanks. (And that means no tabs, too.)
> that the lines should be sorted by, as you can see
> the time jumps all over the place.
You have a bug:
the beginning offset of the timestamp is 24, not 25.
--
John "Gashlycrumb" Porter
"A fugitive and lurid gleam
Obliquely gilds the gliding stream." -- EG
------------------------------
Date: Tue, 20 Oct 1998 11:51:52 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
To: Michael Girone <mgirone@caip.rutgers.edu>
Subject: Re: Strict and Global Variables
Message-Id: <Pine.SUN.3.96.981020114647.10783A-100000@tigre.matrox.com>
[Posted and CC mailed]
On Mon, 19 Oct 1998, Michael Girone wrote:
> Hello.
> I'm trying to write a Perl script that is somewhat optimized for
> speed. To this end, I'd like to use global variables. I'd also, however,
> like to "use strict".
So far so good.
> So, I was wondering if the way to have global variables while
> satisfying strict was to both "my" and then "local" every global variable
> at the outermost level of code. Like this:
Declaring your variables as lexical variables (using my()) will localize
them to your enclosing block. Thus, declaring my() variables at the
"outermost level of code" will make these variables visible from
everything within your program; effectively, these variables becomes
global to your program.
>
> #!/usr/local/bin/perl5 -w
>
> use strict;
>
> my $name; #satisfy strict
> local $name; #make the variable visible throughout the entire program
This will generate an error:
Can't localize lexical variable $name at - line x.
You dont need to use local() here. Also, I think you know that using
lexical variables is faster than using local variables.
> Although globals are usually frowned upon, given that globals will
> be used, is this practice acceptible (and will it work)?
why don't you try and see for yourself? :)
>
> Thank you,
>
> Mike
Hope this helps,
--
Ala Qumsieh email: aqumsieh@matrox.com
ASIC Design Engineer phone: (514) 822-6000 x7581
Matrox Graphics Inc. (old) webpage :
Montreal, Quebec http://www.cim.mcgill.ca/~qumsieh
------------------------------
Date: Tue, 20 Oct 1998 07:40:19 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: String substition
Message-Id: <jb0i07.ar6.ln@flash.net>
k.thomson@scet.com wrote:
: I have a variable called $user
: I have a string replace statement that goes like so.
: $_ =~ s/other/$user/g;
: how do I make this replace the sting other with the value of user
You do it just like you wrote it.
Did you even try it?
Sheesh!
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 20 Oct 1998 08:13:36 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: strip leading zeros
Message-Id: <MPG.1096487e41a2d2089898d0@nntp.hpl.hp.com>
In article <83vhlfs456.fsf@vcpc.univie.ac.at> on 20 Oct 1998 16:24:05
+0200, Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at> says...
...
> Put the value into an integer context, viz.
>
> $v = '000000005';
>
> $w = int $v;
Or just use it as an integer:
$w = $v + 0;
or in place:
$v += 0;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 20 Oct 1998 07:39:26 -0700
From: Brad Murray <murrayb@vansel.alcatel.com>
Subject: Re: strip leading zeros
Message-Id: <uhfwz8fhd.fsf@vansel.alcatel.com>
"Tim Schelfhout" <tim.schelfhout@telenet.be> writes:
> another newbie question. Is there any way to strip leading zeros from
> numbers.
>
> ex. 000005 --> 5
> 000032 --> 32
$new = sprintf "%d", $old;
--
BMurray "What they [young Americans] do have now is an unordered
SW Analyst tangle of rather ordinary passions, running through their
Alcatel consciousness like a monochrome kaleidoscope."
(Alan Bloom)
------------------------------
Date: Tue, 20 Oct 1998 11:35:58 -0400
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: strip leading zeros
Message-Id: <MPG.109669d7e25654e19896df@news.scescape.net>
In article <<01bdfc29$9586cca0$4737000a@tl000143>>,
tim.schelfhout@telenet.be (Tim Schelfhout) pounded the following:
=> Hi there,
=>
=> another newbie question. Is there any way to strip leading zeros from
=> numbers.
=>
=> ex. 000005 --> 5
=> 000032 --> 32
=>
As yet another option (one that borders on Tony's), add 0 to the
number:
% perl -we '$_ = "000004"; print $_+0, "\n";'
4
% perl -we '$_ = "000000"; print $_+0, "\n";'
0
%
The problem with Tim & Daniel's suggestions is they turn '000000' into
'', not the 0 you probably want.
This thread was covered not too long ago, do a search on deja for more
info.
=> Thanks
Hope This Helps!
--Matthew
------------------------------
Date: Tue, 20 Oct 1998 11:48:00 -0400
From: danbeck@eudoramail.com (Daniel Beckham)
Subject: Re: strip leading zeros
Message-Id: <MPG.10967ab97412523e989690@news.supernews.com>
$crazy_num = 000005;
$crazy_num now equals 5, perl does it for you. =);
Regards,
Daniel Beckham
In article <01bdfc29$9586cca0$4737000a@tl000143>,
tim.schelfhout@telenet.be says...
> Hi there,
>
> another newbie question. Is there any way to strip leading zeros from
> numbers.
>
> ex. 000005 --> 5
> 000032 --> 32
>
> Thanks
>
------------------------------
Date: Tue, 20 Oct 1998 11:52:46 -0400
From: danbeck@eudoramail.com (Daniel Beckham)
Subject: Re: strip leading zeros
Message-Id: <MPG.10967bd9ec3f90b7989691@news.supernews.com>
This might work better than my suggestion since he is probably working
with text in the first place and not a number.
This is quicker though:
$w = int '000005';
Regards,
Daniel Beckham
In article <83vhlfs456.fsf@vcpc.univie.ac.at>,
Tony.Curtis+usenet@vcpc.univie.ac.at says...
> Re: strip leading zeros, Tim <tim.schelfhout@telenet.be>
> said:
>
> Tim> Hi there, another newbie question. Is there any way to
> Tim> strip leading zeros from numbers.
>
> Tim> ex. 000005 --> 5 000032 --> 32
>
> Put the value into an integer context, viz.
>
> $v = '000000005';
>
> $w = int $v;
>
> hth
> tony
>
------------------------------
Date: Tue, 20 Oct 1998 17:48:17 GMT
From: bart.mediamind@ping.be (Bart Lateur)
Subject: Re: strip leading zeros
Message-Id: <362fccc2.31739344@news.ping.be>
Daniel F. Crisman wrote:
>> another newbie question. Is there any way to strip leading zeros from
>> numbers.
>>
>> ex. 000005 --> 5
>> 000032 --> 32
Hmmm... This was asked just a few weeks ago...
>$num =~ s/^0*//;
OI! Don't forget to leave at least one digit!
$num =~ s/^0+(\d)/$1/;
is one possibility. Use Dejanews to see any other (better?) solutions.
Bart.
------------------------------
Date: Tue, 20 Oct 1998 11:03:01 -0400
From: "Michael D. Hofer" <featheredfrog@geocities.com>
Subject: Re: What isn't Perl good for?
Message-Id: <362CA625.4D0D@geocities.com>
Earl Westerlund wrote:
>
> Elaine -HappyFunBall- Ashton wrote:
>
> > The day Perl makes coffee and muffins
> > for me in the morning, I'll never have eyes for another language. :)
>
> So which language does this?? :)
>
> --
> +-----------------+----------------------------------------+
> | Earl Westerlund | Kodak's Homepage: http://www.kodak.com |
> +-----------------+----------------------------------------+
> | The opinions expressed herein are mine and mine alone |
> | (most people don't seem to want them anyway) |
> +----------------------------------------------------------+
"Please, darling" and "Thank You, dearest"
--
Cian ua'Lochan /mka/ Michael D. Hofer
I'm not a medievalist - I just play one on weekends!
http://www.geocities.com/SoHo/Lofts/9800/
------------------------------
Date: Tue, 20 Oct 1998 15:21:15 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: What isn't Perl good for?
Message-Id: <LT1X1.50$3i7.6260@news.shore.net>
Earl Westerlund (earlw@kodak.com) wrote:
: So which language does this?? :)
Ummm, Java? :-)
--
Nate Patwardhan|root@localhost
"Fortunately, I prefer to believe that we're all really just trapped in a
P.K. Dick book laced with Lovecraft, and this awful Terror Out of Cambridge
shall by the light of day evaporate, leaving nothing but good intentions in
its stead." Tom Christiansen in <6k02ha$hq6$3@csnews.cs.colorado.edu>
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 4020
**************************************