[19028] in Perl-Users-Digest
Perl-Users Digest, Issue: 1223 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 30 14:05:41 2001
Date: Sat, 30 Jun 2001 11:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993924312-v10-i1223@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 30 Jun 2001 Volume: 10 Number: 1223
Today's topics:
Re: cant modify $_[x] ???? <tinamue@zedat.fu-berlin.de>
Re: cant modify $_[x] ???? <uri@sysarch.com>
Re: converting shell "sort" command to perl.. (Tad McClellan)
Re: Create unique file in dir? (Tad McClellan)
Re: Create unique file in dir? (Greg Andrews)
Re: Faster yet way to count lines in a file (or at leas <ubl@schaffhausen.de>
Re: Faster yet way to count lines in a file (or at leas (Anno Siegel)
Re: getting a defined value from a html page (Tad McClellan)
How can I test that a subroutine exists? <abrice2@home.com>
Re: how do I return a hash var (Tad McClellan)
Re: Is the Perl working...or what have I messed up now <weiss@kung.foo.at>
Re: Is the Perl working...or what have I messed up now <godzilla@stomp.stomp.tokyo>
Re: Merging two hash tables <flavell@mail.cern.ch>
Re: Merging two hash tables (Tad McClellan)
Re: Merging two hash tables (Randal L. Schwartz)
Re: Merging two hash tables <uri@sysarch.com>
Re: Net::DNS zone transfer requires that transfer-forma (Michael Fuhr)
Open or Die - is die the only choice? <gamtci@mpinet.net>
Re: Open or Die - is die the only choice? (Greg Andrews)
Re: Open or Die - is die the only choice? (Anno Siegel)
Re: Passing Large Values via GET <jurgenex@hotmail.com>
readdir(..) function <user@local.net>
Re: readdir(..) function (Anno Siegel)
Re: readdir(..) function (Greg Andrews)
Re: timing can make the difference: (Anno Siegel)
Re: timing can make the difference: <ubl@schaffhausen.de>
Re: timing can make the difference: (Anno Siegel)
Re: unix `ps` <bowman@montana.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 30 Jun 2001 14:47:05 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: cant modify $_[x] ????
Message-Id: <9hkop9$edl7b$1@fu-berlin.de>
nobull@mail.com wrote:
> Tina Mueller <tinamue@zedat.fu-berlin.de> writes:
>> well, variables are always modifiable,
> Not quite true.
uhm, well, at least user defined variables...
>> or if a variable is a
>> reference, then it is the same as the thing it is referencing.
> You are using "reference" here in the sense it which it is used in
> C++. In Perl "reference means something different (closer to
> "pointer" in C++). In Perl the term "alias" is sometimes used to
> label the concept that is called "reference" in C++.
>> $text = "text"; # $text is modifiable, of course, because it
>> #contains a copy of "text"
> True.
>> mysub($text); # $text is modifiable here
> Er, no there's nothing here that effects the modifiablity of $text one
> way or the other.
yeah, ok, i guess i wasn't clear enough. these examples were all meant in
the context of passing it to a subroutine.
>> $text = \$text2; # $text is modifiable only if $text2 is
> Er no, $test is modifiable. ${$text} is modifiable only if $text2 is
>> $text = \3; # $text is *not* modifiable, because
>> 3 is data and no variable, so if you
>> would try to change 3, you would try to change the
>> number 3.
> Er no, $test is modifiable. ${$text} is not modifiable.
ok, right. but i was a little bit surprised by the
following example:
04:29pm tina@lux:tina 533> perl -Mstrict -we'
my $x=\3;
my $y=4;
sub test {
$_[0]=5;
$_[1]=6;
}
test ($x,$y);
print "($x,$y)\n"'
(5,6)
why is $_[0] modifiable? $_[0] is a reference to $x, right?
and $x is a reference to 3. so why can i alter $_[0] here?
because it is an "alias" and no reference?
>> does that help?
> I'd guess on ballence your explaination did more harm than good.
well, i'm sorry. isn't this a discussion group? i'm thankful
for your corrections and clarifications.
and yes, i'll read perlsub more carefully now.
regards,
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx
------------------------------
Date: Sat, 30 Jun 2001 15:20:53 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: cant modify $_[x] ????
Message-Id: <x7y9qa6lkb.fsf@home.sysarch.com>
>>>>> "TM" == Tina Mueller <tinamue@zedat.fu-berlin.de> writes:
TM> my $x=\3;
TM> my $y=4;
TM> sub test {
TM> $_[0]=5;
TM> $_[1]=6;
TM> }
TM> test ($x,$y);
TM> print "($x,$y)\n"'
TM> (5,6)
TM> why is $_[0] modifiable? $_[0] is a reference to $x, right?
TM> and $x is a reference to 3. so why can i alter $_[0] here?
TM> because it is an "alias" and no reference?
you seem to be confused about what is passed to test(). $_[0] is aliased
to $x (not \3). $x is always modifiable so you assign 5 to $_[0] and it
changes.
>>> does that help?
>> I'd guess on ballence your explaination did more harm than good.
TM> well, i'm sorry. isn't this a discussion group? i'm thankful for
TM> your corrections and clarifications. and yes, i'll read perlsub
TM> more carefully now.
well, even in a discussion, one can be corrected and comments can made
about a post that was off target so others won't be misled.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Sat, 30 Jun 2001 09:11:18 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: converting shell "sort" command to perl..
Message-Id: <slrn9jrjvm.qdi.tadmc@tadmc26.august.net>
John W. Krahn <krahnj@acm.org> wrote:
>Patrick Erler wrote:
>> $#ARGV >= 1 or die "Usage:\n\t$0 [logfile]\n";
>
>@ARGV == 1 or die "Usage:\n\t$0 [logfile]\n";
That's good if you'd like to emphasize the condition rather than
the Usage message.
It's only a style choice, but I like to emphasize the action here
rather than the condition:
die "Usage:\n\t$0 [logfile]\n" unless @ARGV == 1;
That even sounds a little Englishy: "die unless one arg".
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 30 Jun 2001 09:16:04 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Create unique file in dir?
Message-Id: <slrn9jrk8k.qdi.tadmc@tadmc26.august.net>
Tony L. Svanstrom <tony@svanstrom.com> wrote:
>you simply check if the file exists before trying to create
^^^^^ ^^^^^^
>it...
Those are not atomic. It is a race condition.
We are discussing a preemptive multitasking environment, right?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 30 Jun 2001 15:45:31 GMT
From: gerg@panix.com (Greg Andrews)
Subject: Re: Create unique file in dir?
Message-Id: <9hks6r$hj5$1@news.panix.com>
tony@svanstrom.com (Tony L. Svanstrom) writes:
>Craig Berry <cberry@cinenet.net> wrote:
>
>> Tony L. Svanstrom (tony@svanstrom.com) wrote:
>> : Personally i use time-pid-[4 random numbers], if that fails then the you
>> : most likely have a lot more serious server-related problems to deal with
>> : then non-unique files. Besides, since you lock the file nothing bad will
>> : happen anyways...
>>
>> I'd prefer something deterministic (I know, I'm obsessive). The FAQ
>> answer (perldoc -q temp, as suggested in another response) involving POSIX
>> tmpnam and sysopen seems to be the right course. I missed finding it
>> because my intended use is not as a temporary file.
>
>well, for time-pid to fail you need to have (dependin on the set up on
>the machine, of course) more than 10'000 processes running at the same
>time
>
Or a directory that's shared among multiple machines which also run the
file-creating script. This is far more common then your 10K processes
scenario.
(but adding hostname/ip to the filename would resolve that particular
source of collisions)
-Greg
--
+++++ Greg Andrews +++ gerg@panix.com +++++
I have a map of the United States that's actual size
-- Steven Wright
------------------------------
Date: Sat, 30 Jun 2001 16:22:09 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Faster yet way to count lines in a file (or at least cooler)
Message-Id: <3B3DEEA1.FFE3AF2@schaffhausen.de>
"R. McGillis" schrieb:
>
> I use the following to count lines in a file:
>
> !#/usr/local/bin/perl -n
>
> END{print "$.\n"};
I dont know whether that be faster, but you could try the straightforward
approach to open the file and let Perl count the lines:
open FILE... # the file
my @lines = <FILE>;
print scalar(@lines);
Use Benchmark.pm to time which is faster.... and if Perl isnt fast enough
use some other language.
->malte
------------------------------
Date: 30 Jun 2001 16:45:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Faster yet way to count lines in a file (or at least cooler)
Message-Id: <9hkvms$3tb$3@mamenchi.zrz.TU-Berlin.DE>
According to Malte Ubl <ubl@schaffhausen.de>:
>
>
> "R. McGillis" schrieb:
> >
> > I use the following to count lines in a file:
> >
> > !#/usr/local/bin/perl -n
> >
> > END{print "$.\n"};
>
> I dont know whether that be faster, but you could try the straightforward
> approach to open the file and let Perl count the lines:
>
> open FILE... # the file
> my @lines = <FILE>;
> print scalar(@lines);
>
> Use Benchmark.pm to time which is faster.... and if Perl isnt fast enough
> use some other language.
Never mind which is faster, it uses more (potentially *much* more)
memory than it has to. Don't slurp files without a reason.
Anno, doing the good work
------------------------------
Date: Sat, 30 Jun 2001 09:03:28 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: getting a defined value from a html page
Message-Id: <slrn9jrjh0.qdi.tadmc@tadmc26.august.net>
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "T" == TuNNe|ing <troll@gimptroll.com> writes:
>
> T> Ok. So, is this better?
> T> #!/usr/bin/perl -w
>
> T> {
> T> $_ = <FILE>;
In addition to Uri's comments, I add yet 2 more:
use strict;
local $_; # stomping on global variables is Not So Good
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 30 Jun 2001 17:18:00 GMT
From: Aaron Brice <abrice2@home.com>
Subject: How can I test that a subroutine exists?
Message-Id: <3B3E0ABA.5D1E4C7B@home.com>
I have a script that's reading the actions it performs out of a separate
state table. So the subroutine is called as a symbollic reference. My
question is how do I check that the subroutine it reads exists? I
tried:
if (defined (&{$action}) {
&{$action}(@parameters);
}
which gave me a syntax error, and
$ref = \&{$action};
if ($ref) { ... }
but $ref seems to be a valid reference even if &$action doesn't exist.
Any other ideas? I'm using perl 5.00503.
------------------------------
Date: Sat, 30 Jun 2001 08:59:26 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: how do I return a hash var
Message-Id: <slrn9jrj9e.qdi.tadmc@tadmc26.august.net>
news.sohoskyway.com <jestersi@metacrawler.com> wrote:
>
>"Tad McClellan" <tadmc@augustmail.com> wrote in message
>news:slrn9jphp3.odt.tadmc@tadmc26.august.net...
>> news.sohoskyway.com <jestersi@metacrawler.com> wrote:
>> >sub rethash {
>> >
>> > local($somehash);
>> ^^^^^
>>
>> my($somehash);
>>
>> You should always use my() instead of local() unless you are
>> expert enough to know why you need local() instead (or if you
>> are local()ing a built-in variable) of my().
>>
>> Perl FAQ, part 7:
>>
>> "What's the difference between dynamic and lexical (static) scoping?
>> Between local() and my()?"
>
>From what I can tell my() makes it so a variable is only available within
>the given scope
So it will be available for you to return() it. That's all you need.
The variable will not "go away" when it goes out of scope if there
are still references to it. There will still be a reference to it
in your main program's $myhash, so things work as you need them
to work.
>where as local() will propagate variables
No, local() will propogate *values* "downwards".
my() is about variables. local() is about _values_ of variables.
Dynamic variables open you up to "action at a distance", something
to be avoided if possible. It is possible with what you are
trying to do, so you should avoid dynamic variables.
>downwards so any
>var decalared inside local() are available to functions called within the
>same scope, where as with my() there not.
I say again: always prefer lexical over dynamic variables.
You do not require dynamic variables for what you are trying
to accomplish. Try them and see if they work. They will.
>> > $somehash{"100"} = 'purple people eater';
>> ^^
>>
>> You did not de-reference the ref that is in $somehash:
>>
>> $somehash->{"100"} = 'purple people eater';
>
>I think I'm going to have to read up on referneces and stuff cuz that really
>did the trick.
You can get most of what you need from:
perldoc perlreftut
If you want more, then:
perldoc perlref
perldoc perllol
perldoc perldsc
perldoc perlobj
You also need to get the lexical vs. dynamic thing down, which is
not directly related to "references".
Maybe this will help:
http://perl.plover.com/FAQs/Namespaces.html
>Is there an analogy out there that describes the similarity's between C and
>perl as far as references go?
Not that I know of.
>> >I think that I perhaps may be
>> >interpreting the jargon "reference" incorrectly?
I don't think so. "reference" is mostly like "pointers" in C,
except you cannot perform arithmetic on addresses. References
are "safe pointers".
What you seemed to be missing (aside from choosing dynamic variables
when lexical will do) was just how do deref a reference.
>> No, Perl has two types of variables. You chose the wrong type.
>> Choose the other one :-)
>And what type would that be?
Lexical variables.
>I want to use a HASH type
scalar, array and hash are _data_ types.
lexical and dynamic are _variable_ types.
apples and oranges.
>> >This is just an stripped down concept version of a func I'm creating that
>> >parses the QUERY_STRING variable
>>
>>
>> That is easy to get wrong, consider using a module to do that for you.
>
>seems simple to me, I just can't seem to return the data into a var
>here's the code I have so far, this is the first function i've ever written
>in perl
[snip URL decoding code]
I am not going to help you reinvent that wheel. Maybe someone else
has time for that. Sorry.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 30 Jun 2001 18:25:57 +0200
From: "Stefan Weiss" <weiss@kung.foo.at>
Subject: Re: Is the Perl working...or what have I messed up now? - happy dance
Message-Id: <3b3dfd30$1@e-post.inode.at>
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> Godzilla!
> --
> @ø=(a .. z);@Ø=qw(6 14 3 25 8 11 11 0 17 14 2 10 18);
> $§="\n";$ß="\b";undef$©;print$§x($Ø[4]/2);
> for($¡=0;$¡<=$Ø[2];$¡++){foreach$¶(@Ø){
> $ø[$¶]=~tr/A-Z/a-z/;if(($¡==1)||($¡==$Ø[2]))
> {$ø[$¶]=~tr/a-z/A-Z/;}print$ø[$¶];if($¶==0)
> {print" ";}if($¶==$Ø[12]){print" !";}&D;}
> print$ßx($Ø[4]*2);}print$§x($Ø[10]*2);
> sub D{select$©,$©,$©,.25;}exit;
Nice.
But if STDOUT is line buffered, you'll only see the text after the
"animation". And you can squeeze it in two lines too. Try this:
$|++;{for(qw(6 14 3 25 8 11 11 0 -33 17 14 2 10 18 -33 -32)){print chr$_+(
($ø%2||$_<0)?65:97);select$©,$©,$©,.1}print"\b"x16;++$ø<4&&redo}print"\n";
cheers,
stefan
------------------------------
Date: Sat, 30 Jun 2001 10:24:03 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Is the Perl working...or what have I messed up now? - happy dance
Message-Id: <3B3E0B33.798497D0@stomp.stomp.tokyo>
Stefan Weiss wrote:
> Godzilla! wrote:
(reference to two-thousand pounds of fresh fish and chilled champagne, snipped)
> > @ø=(a .. z);@Ø=qw(6 14 3 25 8 11 11 0 17 14 2 10 18);
> > $§="\n";$ß="\b";undef$©;print$§x($Ø[4]/2);
> > for($¡=0;$¡<=$Ø[2];$¡++){foreach$¶(@Ø){
> > $ø[$¶]=~tr/A-Z/a-z/;if(($¡==1)||($¡==$Ø[2]))
> > {$ø[$¶]=~tr/a-z/A-Z/;}print$ø[$¶];if($¶==0)
> > {print" ";}if($¶==$Ø[12]){print" !";}&D;}
> > print$ßx($Ø[4]*2);}print$§x($Ø[10]*2);
> > sub D{select$©,$©,$©,.25;}exit;
> Nice.
It's cute. My preference is to make a display of
being a unique person rather than just another
perl hacker geek. I do have a reputation of being
a roque programmer to maintain.
> But if STDOUT is line buffered, you'll only see the text after the
> "animation". And you can squeeze it in two lines too. Try this:
> $|++;{for(qw(6 14 3 25 8 11 11 0 -33 17 14 2 10 18 -33 -32)){print chr$_+(
> ($ø%2||$_<0)?65:97);select$©,$©,$©,.1}print"\b"x16;++$ø<4&&redo}print"\n";
I have saved this. Might be of use someday. Nonetheless, although
your code is well written, almost all deliberate obfuscation is lost.
I am flattered though, you find my unique signature file of interest.
Never begin a sentence with a conjunction, such as "And" or "But"
as this causes me to raise a Vulcan left eyebrow then snap my
English teacher official No. 2 pencil in half.
I have enjoyed reading your code. Thank you.
Godzilla!
--
@©=(a .. z);@®=qw(7 15 4 26 9 12 12 1 18 15 3 11 19);
$Ñ="\n";srand(time()^($$+($$<<15)));for($§=$®[$®[0]];
$§<$®[2];$§++){sub G{rand($®[8])<$®[4]?"\u$1":"\l$1";}
foreach$¿(@®){$¢=$©[$¿-1];$¢=~s¡([a-z])¡G($1)¡gie;
$Ø="$Ø$¢";}$Ø="$Ø! ";$ø=substr($Ø,$®[12]-$®[11],0," ");
$Ø=~s¯(a)(r)¯$1 $2¯i;push (@Ø,$Ø);}print"$Ñ$ÑC:\\>",
"$©[22]$©[$®[0]]$©[14] $©[$®[8]-$®[7]]o$©[$®[2]/2]ks",
" $©[24]o?$©[$®[8]]";undef$z;$Ø="\b";select$z,$z,$z,.5;
print$Ø;select$z,$z,$z,.5;print$Ø;select$z,$z,$z,.75;
print"$©[$®[12]+$®[7]]";select$z,$z,$z,.75;print"?";
select$z,$z,$z,1;print"$Ñ$Ñ";$Ø=.05;foreach$¡(@Ø)
{@©=split(//,$¡);foreach$§(@©){print$§;select$z,$z,$z,
$Ø;}print$Ñ;}@¶=reverse(@Ø);foreach$¶(@¶){@®=split(//,$¶);
foreach$¢(@®){print$¢;select$z,$z,$z,$Ø;}print $Ñ;}exit;
------------------------------
Date: Sat, 30 Jun 2001 15:46:47 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Merging two hash tables
Message-Id: <Pine.LNX.4.30.0106301538340.1006-100000@lxplus003.cern.ch>
On Fri, 29 Jun 2001, Alan J. Flavell carelessly keyed:
> > Learning Perl, 2nd Edition.
..
> @league{{keys %score} = values %score;
^
Please accept my apologies for the obvious typo. At that point, I was
typing-in from the printed book, hence the error. With hindsight, the
same line appears in the online errata: I would have done better to
copy/paste that, just as I did below. "mea culpa"...
> Uh-uh: see http://www.oreilly.com/catalog/lperl2/errata/lperl2.499
>
> {70} In the 5th paragraph in "Hash Slices" section, line of code used
> to read:
>
> @league{keys %score} = values %score;
>
> It now reads:
>
> %league{keys %score} = values %score;
I'm slightly puzzled that this bit doesn't seem to have provoked
any further discussion...?
cheers
------------------------------
Date: Sat, 30 Jun 2001 09:43:38 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Merging two hash tables
Message-Id: <slrn9jrlsa.qkl.tadmc@tadmc26.august.net>
Alan J. Flavell <flavell@mail.cern.ch> wrote:
>On Fri, 29 Jun 2001, Alan J. Flavell carelessly keyed:
>
>> > Learning Perl, 2nd Edition.
>> Uh-uh: see http://www.oreilly.com/catalog/lperl2/errata/lperl2.499
>>
>> {70} In the 5th paragraph in "Hash Slices" section, line of code used
>> to read:
>>
>> @league{keys %score} = values %score;
>>
>> It now reads:
>>
>> %league{keys %score} = values %score;
>
>I'm slightly puzzled that this bit doesn't seem to have provoked
>any further discussion...?
I expect it is errata in the errata and that it was supposed to
be stated the other way around.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 30 Jun 2001 08:14:09 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Merging two hash tables
Message-Id: <m1els2c85a.fsf@halfdome.holdit.com>
>>>>> "Alan" == Alan J Flavell <flavell@mail.cern.ch> writes:
Alan> On Sat, 30 Jun 2001, Minh Van Le wrote:
>> > @table1{keys(%table2)} = values(%table2);
>>
>> cryke. it says here, "%league{keys %score} = values %score" on pg.70 of
>> Learning Perl, 2nd Edition.
Alan> My copy says on page 70
Alan> @league{{keys %score} = values %score;
Alan> Printing History says July 1997: Second Edition.
Alan> Uh-uh: see http://www.oreilly.com/catalog/lperl2/errata/lperl2.499
Alan> {70} In the 5th paragraph in "Hash Slices" section, line of code used
Alan> to read:
Alan> @league{keys %score} = values %score;
Alan> It now reads:
Alan> %league{keys %score} = values %score;
Fsck. The original edition of llama2 had it correct (with "@"). If
there's a printing now with "%", it means the boyz at O'Reilly changed
the page without checking with the authors. That's happened
occasionally. They used to pass EVERYTHING by us, but at some point
decided they knew more than us, and now simply gave us summaries.
And, yes, on further checking, the fifth revision I have shows it with
%. Fsck.
The problem is that they believe nearly anyone who writes in to
complain. You want to insert cruft into an O'Reilly book? Pick a
random book, a random page, then submit a "bug" that changes "3" to
"4" or something to bookquestions@ora.com, and sound a bit hostile
when you do it. Be sure to use a non-traceable email address, of
course. Then sit back nine months, and watch your "correction"
applied. :(
When I used to get cc'ed on the changes, I interrupted this from
happening once. Now that I no longer get the changes, it just
happens, I'm sure.
And they keep telling me there's *NO* process available to even give
me a courtesy copy of the new book as it keeps getting changed. I
keep finding that hard to believe, but that's what they say to one of
their most successful authors. :) I have to go to bookstores, notice
the updated printing date, and then buy it at retail, and compare it
page by page, as my only way to know if they've changed my book.
I suspect this is due to non-responsiveness of authors after-the-fact,
but it still a sign that O'Reilly has had to invent processes that
scale to large numbers of books.
Of course, this matters not now. llama3 is out imminently, with a
whole *new* set of things to complain about. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Sat, 30 Jun 2001 15:26:56 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Merging two hash tables
Message-Id: <x7vgle6la7.fsf@home.sysarch.com>
>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:
RLS> Of course, this matters not now. llama3 is out imminently, with a
RLS> whole *new* set of things to complain about. :)
there is a bug on page 42
:)
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: 30 Jun 2001 08:59:44 -0600
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: Net::DNS zone transfer requires that transfer-format be set to one-answer
Message-Id: <9hkph0$3fo@flatland.dimensional.com>
dshane@qual-pro.com (Darrell Shane) writes:
> It appears that using Net::DNS to perform a zone transfer (the axfr
> method) requires that the nameserver return one record per packet. If
> not, axfr randomly returns an empty list.
>
> Has anyone else experienced this?
I'm not able to duplicate this problem, either with the current version
of Net::DNS on CPAN (0.12) or with the latest development version
(0.20, not yet available). My tests with BIND 8 and BIND 9, both with
"transfer-format many-answers" (the default in BIND 9), work fine.
What version of Net::DNS are you using? What version of Perl? What
operating system? What nameserver & version? What's the output when
you set $res->debug(1)? Is there a publicly-available nameserver from
which I could attempt a zone transfer and duplicate this problem?
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
------------------------------
Date: Sat, 30 Jun 2001 15:44:02 GMT
From: Gary <gamtci@mpinet.net>
Subject: Open or Die - is die the only choice?
Message-Id: <3B3DF426.19D4@mpinet.net>
Every book I have shows "open or die". Isn't there any other way
to determine if the open succeeded? I have been checking for
existence using if (-f $file) first, but I'd still rather know the
open succeeded.
------------------------------
Date: 30 Jun 2001 16:14:11 GMT
From: gerg@panix.com (Greg Andrews)
Subject: Re: Open or Die - is die the only choice?
Message-Id: <9hktsj$iah$1@news.panix.com>
gamtci@mpinet.net writes:
>
>Every book I have shows "open or die". Isn't there any other way
>to determine if the open succeeded? I have been checking for
>existence using if (-f $file) first, but I'd still rather know the
>open succeeded.
>
Most of the example scripts depend on reading the contents of the
file. If they can't, the script loses its meaning and purpose in
life, so using die is appropriate.
Other scripts may want to take corrective action if the open
fails, and try again. Or, they may want to try to fall back
to a default file.
Here's a snipped of a script that tries to open an rc file in
the current directory, falls back to one in the user's home
directory, and then uses the pre-programmed defaults if neither
file can be opened.
# pre-set my defaults
set_defaults()
rcfile = '.myrc';
# update parameters from .myrc file
RCFILE:
{
unless (open(MYRC, "./$rcfile")) {
unless (open(MYRC, "$HOME/$rcfile")) {
last RCFILE;
}
}
while (<MYRC>) {
chomp;
#
# do things with the file's contents
#
}
}
# script continues its merry way
I had a script that renamed a directory to a new name and then
created a symbolic link for the old name that pointed to the
new one. I wrote it to handle an error in renaming the directory
by bailing out of the whole procedure. If the directory rename
worked, but creating the symbolic link failed, it would try to
rename the directory back to the original name. If *that* failed,
it would send an e-mail cry for help to my pager. <smile>
If you're not comfortable with using "unless", you can use the
negated "if", which works the same way:
if (! open(MYRC, "./$rcfile")) {
if (! open(MYRC, "$HOME/$rcfile")) {
last RCFILE;
}
}
It just depends on which syntax you think will be better understood
when you (or someone else) looks at your script a year from now.
-Greg
--
+++++ Greg Andrews +++ gerg@panix.com +++++
I have a map of the United States that's actual size
-- Steven Wright
------------------------------
Date: 30 Jun 2001 16:15:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Open or Die - is die the only choice?
Message-Id: <9hktv0$3tb$1@mamenchi.zrz.TU-Berlin.DE>
According to Gary <gamtci@mpinet.net>:
> Every book I have shows "open or die". Isn't there any other way
> to determine if the open succeeded? I have been checking for
> existence using if (-f $file) first, but I'd still rather know the
> open succeeded.
open() returns a boolean value: true for success and false for
failure. You can test this whichever way you want. "or die ..."
is common because usually a program needs the files it opens and
can't go on without them. If you can do without a file, your
program might look like this:
if ( open( my $fh, 'status' ) {
# fine, we saved a status
%status = read_status( $fh);
} else {
# shrug
%status = build_status()
}
Anno
------------------------------
Date: Sat, 30 Jun 2001 07:35:45 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Passing Large Values via GET
Message-Id: <3b3de3c5@news.microsoft.com>
"BCC" <bcoon@sequenom.com> wrote in message
news:3B3D256F.FA780B64@sequenom.com...
> I have run into a small problem with one of my scripts. In one user
> input form, users can enter a large list of numbers (8000 or so) which
> are processed via post and a mysql query into a result set. This is all
> cool.
>
> But to view results from 8000 queries, I implemented pagination, which
> are simply links back to the same cgi with sql limits on query size.
> But this is only acceptable via the GET method. So of course I am
> getting the 'URI - Requested url length exceeds capacity of server'
> error.
>
> So the question:
> How can I pass such a large string via GET? Is it possible? If this
You don't. This has nothing to do with Perl.
Please ask in one of the many webauthoring NGs why your concept is a bad
idea and what you should do instead.
jue
------------------------------
Date: Sat, 30 Jun 2001 17:38:30 +0200
From: "news.talknet.de" <user@local.net>
Subject: readdir(..) function
Message-Id: <Rnm%6.1095$7v6.47306894@news.tli.de>
Hi all!
can anyone tell me how to filter the directory entries when I read a
directory with the readdir() function (or maybe another way)? I try to make
a directory listing and the directory entries are mixed with the files in
that directory.
For eaxample, I use the following method:
opendir (DIR, ".") || die "I was unable to open the directory";
@dir_items = readdir(DIR);
closedir (DIR);
$cnt = 0;
$total = 0;
foreach $dir_item (@dir_items)
{
$size = (stat $dir_item)[7];
print "$dir_item, ($size)\n";
$total += $size;
$cnt++;
}
print "\t$cnt items\n";
print "\t$total bytes";
... and I get this listing
., (0)
.., (0)
SYSTEM.GIF, (236)
PROGRAMS.GIF, (255)
PROJECTS.GIF, (243)
TEMP.GIF, (219)
CDROM1.GIF, (307)
TPX.GIF, (49)
DOWNLOAD.GIF, (334)
pdesktop.HTM, (1021)
dir.pl, (587)
other, (0) <------------------------- this is a directory
C__PROJECTS.GIF, (285)
nullfile.txt, (0) <------------------------- this is a file
APOLLO.JPG, (144165)
out.txt, (0) <------------------------- this is a file
16 items
147701 bytes
Thanks in advance
Peter
------------------------------
Date: 30 Jun 2001 16:20:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: readdir(..) function
Message-Id: <9hku8j$3tb$2@mamenchi.zrz.TU-Berlin.DE>
According to news.talknet.de <user@local.net>:
> Hi all!
>
> can anyone tell me how to filter the directory entries when I read a
> directory with the readdir() function (or maybe another way)? I try to make
> a directory listing and the directory entries are mixed with the files in
> that directory.
[snip]
Yes, check out Perl's file check operators in "perldoc -f -X". This
will also give you a more readable way to access the file size than
picking out the element from the stat() info.
Anno
------------------------------
Date: 30 Jun 2001 16:30:03 GMT
From: gerg@panix.com (Greg Andrews)
Subject: Re: readdir(..) function
Message-Id: <9hkuqb$ik5$1@news.panix.com>
"news.talknet.de" <user@local.net> writes:
>Hi all!
>
>can anyone tell me how to filter the directory entries when I read a
>directory with the readdir() function (or maybe another way)? I try to make
>a directory listing and the directory entries are mixed with the files in
>that directory.
>
>For eaxample, I use the following method:
>
>opendir (DIR, ".") || die "I was unable to open the directory";
> @dir_items = readdir(DIR);
>closedir (DIR);
>
>$cnt = 0;
>$total = 0;
>
>foreach $dir_item (@dir_items)
>{
> $size = (stat $dir_item)[7];
> print "$dir_item, ($size)\n";
> $total += $size;
> $cnt++;
>}
>
>print "\t$cnt items\n";
>print "\t$total bytes";
>
Here's how I would do it. It uses the '_' symbol for the stat buffer
so you don't have to do two stats for every entry in the directory.
opendir (DIR, ".") || die "Can't open current directory: $!\n";
@dir_items = readdir(DIR);
closedir(DIR);
$cnt = $total = 0;
foreach $dir_item (@dir_items)
{
next if -d $dir_item ; # skips directories, also fills stat buffer
$size = (stat _)[7] ; # gets size from stat buffer
print "$dir_item, ($size)\n";
$total += $size;
$cnt++;
}
print "\t$cnt items\n\t$total bytes\n";
-Greg
--
+++++ Greg Andrews +++ gerg@panix.com +++++
I have a map of the United States that's actual size
-- Steven Wright
------------------------------
Date: 30 Jun 2001 13:50:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: timing can make the difference:
Message-Id: <9hklg2$rqu$2@mamenchi.zrz.TU-Berlin.DE>
According to Yo <miriam@allfineantz.nl>:
> Hi,
>
> Paradox:
>
> I need to execute a script every 20 minutes.
> can't use calendar, cron or other tool.
Why?
> I'm on Pentium II 500 Mhz NT4 SP6a, Perl 5.004_02
>
>
> I want the script to start sleeping at the end of execution, here's code:
>
> while(1=1) {
> ####loadza code here####
> sleep(x)
> }
>
>
> x is the main problem here.... how to get that value in ms?
Why do you want it in ms? sleep() takes its argument in seconds.
perldoc -f sleep.
> I know for 20 minutes x would be 20*60*1000
> But the script's execution would shift the start-time a few seconds every 20
> minutes.
> Get it?
Yes, I suppose most of us have been able to follow.
At the end of a cycle, read the time (perldoc -f time) and calculate
the interval to the next cycle. That's how long you want to sleep.
Anno
------------------------------
Date: Sat, 30 Jun 2001 16:13:13 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: timing can make the difference:
Message-Id: <3B3DEC88.3B811D2D@schaffhausen.de>
Yo schrieb:
> while(1=1) {
> ####loadza code here####
> sleep(x)
> }
>
> x is the main problem here.... how to get that value in ms?
> I know for 20 minutes x would be 20*60*1000
> But the script's execution would shift the start-time a few seconds every 20
> minutes.
> Get it?
I'm not very sure. How about this:
while(1) {
my $script_start_time = time();
# do something
my $script_end_time = time();
sleep(x - ($script_end_time - $script_start_time))
}
This will be a better approximation but you will get rounding errors from
the time call. If thats not good enough use Time::HiRes (overkill?).
->malte
------------------------------
Date: 30 Jun 2001 14:49:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: timing can make the difference:
Message-Id: <9hkoud$14o$1@mamenchi.zrz.TU-Berlin.DE>
According to Malte Ubl <ubl@schaffhausen.de>:
> Yo schrieb:
> > while(1=1) {
> > ####loadza code here####
> > sleep(x)
> > }
> >
> > x is the main problem here.... how to get that value in ms?
> > I know for 20 minutes x would be 20*60*1000
> > But the script's execution would shift the start-time a few seconds every 20
> > minutes.
> > Get it?
>
> I'm not very sure. How about this:
>
> while(1) {
> my $script_start_time = time();
> # do something
> my $script_end_time = time();
>
> sleep(x - ($script_end_time - $script_start_time))
> }
>
> This will be a better approximation but you will get rounding errors from
> the time call. If thats not good enough use Time::HiRes (overkill?).
Yes, that's overkill. With a bit of modulo arithmetic you can set
up a schedule of start times that are exactly so many seconds apart.
Then you sleep until the next scheduled time.
Anno
------------------------------
Date: Sat, 30 Jun 2001 09:12:26 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: unix `ps`
Message-Id: <WYl%6.4634$D92.2323@newsfeed.slurp.net>
"Todd Smith" <todd@designsouth.net> wrote in message
news:Yz4%6.18595$P5.5841196@news1.rdc1.tn.home.com...
> My server was rooted today by some script-kiddie, and ls, ps, and du were
> trojaned. Is there a way to list all the pids and process names with perl,
> similar to the unix ps but without all the options?
at least on linux, most of the information is in /proc. if your ls was
working you'd see a bunch of numbered directories, which are the pids. in
each is a 'cmdline' that contains the name and pid, except for some of the
daemons. assuming 'find', 'grep' and 'cat' aren't trashed, you could cd to
/proc and do something like 'find . -name "cmdline" | cat' or a little more
sophisticated stuff. a little C proggie would do the job as well, if you
can't find the right perl mod.
------------------------------
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 1223
***************************************