[10891] in Perl-Users-Digest
Perl-Users Digest, Issue: 4492 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 24 09:07:27 1998
Date: Thu, 24 Dec 98 06:00:21 -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 Thu, 24 Dec 1998 Volume: 8 Number: 4492
Today's topics:
Re: ADO (Jan Dubois)
Berkeley DB <wain@tyeepoint.com>
Re: Binary read/write/change qustions... (M.J.T. Guy)
Re: Can I change a varible on the fly. <off-duty@entheosengineering.com>
Re: counterintuitive behavior of "shift" (Dragomir R. Radev)
Re: Forcing To Lowercase - Another Way? <jamesht@idt.net>
Re: Forcing To Lowercase - Another Way? (Bart Lateur)
Re: hashes with arrays as values? (Bart Lateur)
Re: help with indirect reference for pattern match (Steven Barbash)
Re: help with indirect reference for pattern match (Steven Barbash)
Re: How do I catch this eval exception? (M.J.T. Guy)
Re: link checker help (Clay Irving)
Mail from PERL using variable mail address nemanij@hotmail.com
Re: Nested sorting (Micha3 Rutka)
Re: Reference Troubles (M.J.T. Guy)
require & use <marty@catnmoose.com>
Re: sizeof() function? (Bart Lateur)
Re: sizeof() function? <ebohlman@netcom.com>
Re: sizeof() function? (Bart Lateur)
Re: sort it ? (Micha3 Rutka)
Re: sort it ? (Micha3 Rutka)
Re: string problem <ebohlman@netcom.com>
Re: The quine page <bb@jesusfish.xmission.com>
Re: Using the same filehandle twice (M.J.T. Guy)
Re: What's the Right Way to detect an Array Ref? (M.J.T. Guy)
Re: what's wrong with this bit of code? :) <off-duty@entheosengineering.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 24 Dec 1998 12:52:43 +0100
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: ADO
Message-Id: <368928ec.7273749@news3.ibm.net>
[mailed & posted]
On Wed, 23 Dec 1998 23:46:59 GMT, cade@acm.org wrote:
>It appears that ->Value is not an lvalue, but ->{Value} is. Can anyone
>explain why you can extract data from what appears to be a reference without
>an explicit dereference, yet you cannot assign data without an explicit
>dereference?
$obj->Value calls the Value method of $obj whereas $obj->{Value} accesses
the Value property. We are talking about methods and properties of OLE
objects and not of Perl objects here. This is encapsulated in Win32::OLE:
$obj is a reference to a tied hash. The method calls are caught be the
AUTOLOAD mechanism of the Win32::OLE package and are translated to OLE
methods calls. The hash references are caught by the tied hash mechanism
and translated into OLE property accesses (get and put).
So why can you use $obj->Value and $obj->{Value} interchangeably in an
rvalue context? This works because OLE allows read access to properties
both through method call and property get semantics. Both cases above
actually use (DISPATCH_METHOD | DISPATCH_PROPERTYGET) when dispatching the
request to the OLE layer.
This only works for reading but not for writing properties. You have to
use the hash reference to set a property (or the $obj->SetProperty method
to set properties taking parameters, but I really don't want to go there
now :-).
-Jan
------------------------------
Date: Thu, 24 Dec 1998 01:33:43 -0800
From: Wain Dobson <wain@tyeepoint.com>
Subject: Berkeley DB
Message-Id: <36820A77.F16E186E@tyeepoint.com>
The tests for my compile of perl 5.005_02 and db 2.6.4 indicate two
failures:
lib/db_btree (Fails on test 36)
lib/db_hash (Fails on test 31)
Both these test are testing for R_NOOVERWRITE.
(1) OS=solaris x86 (2.6)
(2) COMPILER=gcc 2.8.1
(3) DB=2.6.4 which was compiled with --enable-compat185 and placed in
/usr/local{include,lib}
(4) the compile of perl was run with no changes to the configuration.
Any ideas as to the cause of the errors?
Thanks in advance.
------------------------------
Date: 24 Dec 1998 13:20:48 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Binary read/write/change qustions...
Message-Id: <75tf3g$jub$1@pegasus.csx.cam.ac.uk>
In article <75j4n6$f7f$1@monet.op.net>, Mark-Jason Dominus <mjd@op.net> wrote:
>In article <367CC0A4.652D@hotmail.com>, Ryan <rich_guy@hotmail.com> wrote:
>> sysread (FILE, $var_1, 100);
>> sysread (FILE, $var_2, 26);
>> sysread (FILE, $var_3, 2);
>> sysread (FILE, $var_4, 45); # etc.
>
>unless (sysread(FILE, $record, 173) == 173) {
> warn "Incomplete record.\n";
>}
>@vars = unpack "A100 A26 A2 A45", $record; # There's your `unpack'.
>
>> $var_1 =~ s/^\s+//; $var_1 =~ s/\s+$//;
>> $var_2 =~ s/^\s+//; $var_2 =~ s/\s+$//;
>> $var_3 =~ s/^\s+//; $var_3 =~ s/\s+$//;
>> $var_4 =~ s/^\s+//; $var_4 =~ s/\s+$//;
>
>foreach $var (@vars) {
> $var =~ s/^\s+//; $var =~ s/\s+$//; # Or see perlfaq4
>}
>
>> return ($var_1, $var_2, $var_3, $var_4);
>
>return @vars;
Or if you're into one liners, combine those three as
return map { s/^\s+//; s/\s+$//; $_ } unpack "A100 A26 A2 A45", $record;
Mike Guy
------------------------------
Date: Wed, 23 Dec 1998 17:42:47 +0000
From: Rich Grise <off-duty@entheosengineering.com>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Can I change a varible on the fly.
Message-Id: <36812B97.445B47E4@entheosengineering.com>
Larry Rosler wrote:
> Rich Grise wrote
> > Double-quoting your "EOC" for your here document will make
> > it interpolate variables on the way.
>
> So will not quoting the EOC at all, which is more usual.
This here document stuff is entirely new to those of us who came "up"
from the
dos/windows environment. I spent some time looking through all the perl
doc's
I have (the full set that came with perl 5.004_04, that came with
Slackware
Linux 3.3.0), and found very minimal information on the here document.
The
problem for those of us who have been scarred by WinDoze is that here
documents
are covered in depth in the shell doc's, which win kids have never even
heard
of. I wonder if that's a feature, or if I should write up another little
blurb
on here doc's from the shell doc's, to make available to winkids who are
trying
to learn perl on a crippled machine. It just seems that in one of the
books
I DID read, that it mentioned double-quoting the WORD would cause it to
interpolate,
(must have been an introduction to shell chapter in a generic Unix
book), and I
didn't know until just now that Perl will interpolate regardless. Thank
you.
(And yes, I know, it's in the books SOMEWHERE. This can be a little
frustrating
at times, not knowing where to look for specific things.)
Gut that still leaves the original question unanswered.
> > Or, do it with individual print statements, where the
> > double-quotes will interpolate for you.
>
> Why???
Dunno. Sounded like a good idea at the time. :)
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Company
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
--
Rich Grise
off-duty@entheosengineering.com
(No need to futz with my e-mail: I have a "delete" button!)
------------------------------
Date: 24 Dec 1998 04:34:57 -0500
From: radev@ocean.cs.columbia.edu (Dragomir R. Radev)
Subject: Re: counterintuitive behavior of "shift"
Message-Id: <75t1s1$b0o@ocean.cs.columbia.edu>
In article <75rgit$t1d$1@pegasus.csx.cam.ac.uk>,
M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
...
>Other responses have indicated how to fix this up using defined(),
>but I consider it better practice not to do shift() on an empty array in
>such cases. Instead you can do something like
>
> $par1 = @ARGV ? shift : 1;
Very neat! Thanks.
Drago
>
>
>Mike Guy
--
Dragomir R. Radev http://www.cs.columbia.edu/~radev
Natural Language Processing Group Columbia University CS Department
Home: 212-749-9770 Office: 914-784-7899, 212-939-7121
------------------------------
Date: Thu, 24 Dec 1998 03:10:10 -0500
From: jamesht <jamesht@idt.net>
To: Ralph Freshour <ralph@primemail.com>
Subject: Re: Forcing To Lowercase - Another Way?
Message-Id: <3681F6E2.E1CBD469@idt.net>
Hello,
$str = "HI!";
$lcstr = lc($str);
James
------------------------------
Date: Thu, 24 Dec 1998 11:55:48 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Forcing To Lowercase - Another Way?
Message-Id: <36842b2f.635262@news.skynet.be>
Ralph Freshour wrote:
>I'm using tr/A-Z/a-z/ to force a string to all lowercase - however, I
>noticed that this statement does not always show up when I am stepping
>thru my code in the debugger. Is there another way I can force a
>string to all lowercase, I'd like to try it out and see if it displays
>in my debugger. I am using perl 5.
Perl 5? then you have (at least; covering my butt ;-) two more options.
$lowercased = lc($somestring);
or
$lowercased = "\L$somestring";
The latter has the advantage that you can apply it to part of the
string, like:
$capitalized= "\u\L$somestring\E$somemore";
Bart.
------------------------------
Date: Thu, 24 Dec 1998 10:31:30 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: hashes with arrays as values?
Message-Id: <368d1367.9979048@news.skynet.be>
M.J.T. Guy wrote:
>Bart Lateur <bart.lateur@skynet.be> wrote:
>> @{$hash{mango}} = (9,8,7,6,5,4,3,2,1,0);
>>
>>For some reason, you may NOT drop the outer braces in this case. I don't
>>feel like searching on the why, as I personally would find it less
>>readable. Yes, I actually LIKE the @{...} or %{...} syntax. :-)
>
>Operator precedence. Without the (), that would be the same as
>
> ( @{$hash{mango}} = 9 ),8,7,6,5,4,3,2,1,0;
You got me wrong. I ment that the next doesn't do the same as the above
(and yes, I've tested it):
@$hash{mango} = (9,8,7,6,5,4,3,2,1,0); # oops!
Bart.
------------------------------
Date: Thu, 24 Dec 1998 07:34:48 -0500
From: stevenba@ccpl.carr.org (Steven Barbash)
Subject: Re: help with indirect reference for pattern match
Message-Id: <MPG.10ebfef467e9f6e1989684@www.siast.sk.ca>
Tad,
Thanks for your response and info.
I must apologize. My earlier follow up had a typo :-(
I wrote:
> : I'm back to my original question -- with the qualifier that I need to do
> : this in perl version 5.005
when I meant to write version 5.003. (that is: PRE 5.005)
So again, is there a way in 5.003?
Thanks,
Steve
------------------------------
Date: Thu, 24 Dec 1998 08:39:20 -0500
From: stevenba@ccpl.carr.org (Steven Barbash)
Subject: Re: help with indirect reference for pattern match
Message-Id: <MPG.10ec0e1356902070989687@www.siast.sk.ca>
Greetings to all,
And thanks to the good people who responded.
RESOLUTION:
I think I found the answer -- I feel (quite relieved yet) embarrassed.
It seems I tried all sorts of permutations except the most obvious:
$x =~ /$pattern/ !!! :-)
I can input $pattern from a prompt or other source.
>From the perlop doc:
"PATTERN may contain variables, which will be interpolated (and the
pattern recompiled) every time the pattern search is evaluated. "
I just missed it.
I hope this info can help somebody else.
Regards,
Steve
------------------------------
Date: 24 Dec 1998 13:07:41 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: How do I catch this eval exception?
Message-Id: <75teat$j4f$1@pegasus.csx.cam.ac.uk>
Tk Soh <r28629@email.sps.mot.com> wrote:
> that's how you get the syntax error into $@, as
>promised by eval():
>
> If there is a syntax error or runtime error,
> or a die() statement is executed, an undefined
> value is returned by eval(), and $@ is set to
> the error message.
>
>However, assuming q() is used, 'use strict' somehow changes (how?) this
>property of eval, and $@ never get the error message, but I still managed the
>trap the error by checking the return value of eval():
It's nothing to do with 'use strict;'. The above (accurate) quote isn't
quite correct. Some compilation errors cause a die(), so the error
ends up in $@ and does not get printed to STDERR. Other errors cause
a warn() instead, so the error isn't set in $@. To capture all error
messages, you need to do something like
{ my $warnings = '';
local $SIG{__WARN__} = sub { $warnings .= shift };
print "eval failed:\n$warnings$@" unless defined eval $try;
}
You may also need to consider the possibility that the eval may succeed
and return 'undef', for example if $try eq 'undef'. This is left as
an exercise for the reader.
Mike Guy
------------------------------
Date: 24 Dec 1998 08:35:41 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: link checker help
Message-Id: <75tfvd$dbj@panix.com>
In <ebohlmanF4GJuB.4qI@netcom.com> Eric Bohlman <ebohlman@netcom.com> writes:
>Clay Irving <clay@panix.com> wrote:
>: In <3681470F.C67BDFC0@melsud.res.ray.com> Mike Godfrey <mtg82814@melsud.res.ray.com> writes:
>:> I would like to use perl to check if an internet site exists or not,
>:>for a link checker. I really don't have any idea of how to do it.
>: Perl Modules are your friend. It could be as simple as:
>:
>: #!/usr/local/bin/perl -w
>:
>: use LWP::Simple;
>:
>: $url = "http://www.perl.com";
>:
>: if(!head($url)) {
>: print "Bad URL: $url\n";
>: }
>:
>AFAIK some servers will refuse HEAD requests for certain documents, so if
>a HEAD fails, it's a good idea to try a GET before giving up.
Yeah, but its still simple -- You don't have to beat your head against the
wall as some folks are so prone to doing. Try a GET also:
use LWP::Simple;
$url = "http://www.perl.com";
if((!head($url)) or (!get($url))) {
print "Bad URL: $url\n";
}
--
Clay Irving
clay@panix.com
------------------------------
Date: Thu, 24 Dec 1998 13:25:21 GMT
From: nemanij@hotmail.com
Subject: Mail from PERL using variable mail address
Message-Id: <75tfc0$ig6$1@nnrp1.dejanews.com>
Hello, I have this problem where I have to mail using the perl script from
my UNIX system. The mailing address that I have to mail to will also come
from the perl script. So can anyone pls tell me how I can do that? I tried
something like this but this did not work.
open(MAIL, '|mail "$address"') || die" unable to mail $!\n";
print MAIL <<"endofmail";
text
endofmail
close(MAIL) || die "error closing mail $!\n";
Thanks for you reffort
Merry Christmas and a Happy New Year
Jagannath
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 24 Dec 1998 11:53:26 +0100
From: rutka@lucent.com (Micha3 Rutka)
Subject: Re: Nested sorting
Message-Id: <wsmzp8dg6ah.fsf@hzsac328.nl.lucent.com>
lr@hpl.hp.com (Larry Rosler) writes:
> + Here it is (for unsigned, signed case is a simple excercise):
> If you have a simple way for the signed case, please show it to us.
I still think that it is a simple excercise. However, I have a bad
experince of sending simple (good) things here. There are people here,
which takes an idea, use it, want become famous by publishing it, and
are not fair enough to credit a guy who had the idea first.
It is not the first case in history. The inventor of the "Hook Law",
had the same problem. Hook law is so simple that Hook was afraid that
others would not credit him for such a simple formula. Therefore, he
published it, but encrypted. So, here is a simple way for the signed
case ;-):
Version: 2.6.3i
hIwDCUa07xKVfG0BA/4rI6pwvrVBzQBH456mIgh+Y6sPGG2unD/Mj+0ni/+ixf63
qY2cMNLSzLRNyhMT9B4UYt0wFhVTk8Zw+5E7C5oWOa0hW48Z98K3lnKmwQy4ZGRg
HS2ZrWYQ7xvjeW7QiM6ROUYnwFbvsBZePkeVh8IkbbGBdMUIhCE3tiUaN9TIzKYA
AAFcuGCASh98aXJJQ8TqB4GujP/8Ds5s5Xk8vS5YJUSHZ5sV980eHYw4DiqltZMG
XuTTQ7iPNeSrtIRwIX5gfwaNuk50MjNv2u645f3si/jS5A50oP1EGIHoAq8K2OOw
8+owihWLWTinF05oRPOw++W8UJ3BT5SIzwmvuHQoRWjfxOhBm4UI2IxNB+CXTGDy
iIluM9Im6nVbMS8M9KoASxYZySRGzrzvngEcW2x//+lqit9ke0hKZhGtkk/iA1Gg
5LRwGeaHiPc/bV+L9zZdzYtVP5dv+HELGpLF82qDUmUC85je9nMOSaJ1dbMCo39S
OUu0nRoiUoQGJyuQA1bzZ7AJO3zxK1ak8pj9k+dsvrvoInD7n3lFtRJ2Y6PsmF9n
OS5g8vtdnAHQkoika3Dyz2FEcxgXBfMGVBf0GgBsayh2zB8bdVYYRaZSSNxCa6MR
mQXUhqnxlwkypAC/mjpA
=mK8x
-----END PGP MESSAGE-----
As you see, this code is explained by pseudocode. It covers a
big-endian only. For making it portable just use the same strategy as
previous.
> + @sorted_array_by_floats = map { substr($_,4) }
> + sort
> + map {
> + ($big_endian?pack("f",extract_float_from($_)):
> + swap(pack("f",extract_float_from($_)))
> + ).$_
> + }
> + @unsorted_array_containing_floats;
> +
> + where swap() is:
> <SNIP implementation (via a loop on substr) of the 'reverse scalar'
> function>
Thx for remiding me about reverse scalar.
> + and $big_endian points on machine architecture. It can be a portable
> + function too (simple one), but as used in the map loop it is better to
> + use an initialized variable (can be initialized by the function).
> The variable can be initialized by a simple experiment, for example,
> $big_endian = pack('L', 1) eq pack('N', 1);
I said that it is a simple one, didn't I?
> + The code is portable now, but slower.
> It needn't be significantly slower.
Is it slower or not? It is slower. Not much, I agree, but still.
> I gave you the clue in my post,
> which you snipped:
> + > One then has to reverse the bytes in the packed representation.
Then why you did not implemented it? I have also idea, that the best
product on the market would be a wireless power supply. Can you
implement it for me?
Regards,
Michal
--
Dr. Ir. Michal Rutka Lucent Technologies - Huizen, The Netherlands
Senior System Engineer mailto:rutka@lucent.com
------------------------------
Date: 24 Dec 1998 11:24:42 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Reference Troubles
Message-Id: <75t89q$e8t$1@pegasus.csx.cam.ac.uk>
In article <75cfsm$ppt$1@monet.op.net>, Mark-Jason Dominus <mjd@op.net> wrote:
> %hash = Bonzo;
>
>is exactly the same; the parentheses weren't adding any meaning. In
>this case, Perl' just ignores the extra item and makes the hash empty.
Small detail: Perl doesn't ignore the extra value; instead it makes a
hash with one key 'Bonzo' and value undef.
Mike Guy
------------------------------
Date: Thu, 24 Dec 1998 07:09:50 -0500
From: Marty Landman <marty@catnmoose.com>
Subject: require & use
Message-Id: <36822F0E.4DA1396B@catnmoose.com>
I'm trying to learn the proper way to (1) be explicit in my declares,
and (2) have some of my routines come from other files.
Currently I do 'use strict' following by 'use vars qw(var1 ... varn)'
forall my global vbls. And verify by 'perl -w -c mypgm' from the
command line. Later I 'require filenm' for the file containing
additional routines. My understanding though is that use executes at
compile time whereas require is a run time thing. Shouldn't require be
used only when the thing to be required is determined at run-time? Else
if it's a static reference I'd rather do a use so I get the benefit of
forewarning. Yes?
But require allows me to specify the file while use allows individual
sub names. Right? How can I use use to not require require </doh>.
Also, and I admit this is only related because it has to do with the
same program....
how can I parameterize vble global ref's? IOW, say I have a database
accessor routine. I'll call it with a single key. So far, so good.
But the db accessor is an external routine, not customized for each
app. After retrieving a row it needs to populate the global vbls
declared with a 'use vars' in the caller. How can I do this?
If I haven't said it before, thanks to all. This ng has been extremely
helpful to me and made my journey through the desert far easier than it
would be w/o you all.
--
_____ Marty Landman _______ http://www.catnmoose.com/ ______
Living Glass http://www.catnmoose.com/livinglass
Mountain Man http://www.catnmoose.com/mountainman
__________Cat 'n Moose Web Site Design & Development_________
------------------------------
Date: Thu, 24 Dec 1998 10:31:32 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: sizeof() function?
Message-Id: <368e1450.10211326@news.skynet.be>
Paul Makepeace wrote:
>Abigail wrote in message <75rac2$ht4$3@client3.news.psi.net>...
>> print $foo, "\n";
>
>I see this construct a lot. What's the appeal?
>
>print "$foo\n";
Another alternative:
$\ = "\n";
print $foo;
Very readable, and in my mind the nicest option if ALL print statements
need to be terminated with a newline.
Bart.
------------------------------
Date: Thu, 24 Dec 1998 11:19:36 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: sizeof() function?
Message-Id: <ebohlmanF4GvGo.88K@netcom.com>
Bart Lateur <bart.lateur@skynet.be> wrote:
: Another alternative:
: $\ = "\n";
: print $foo;
: Very readable, and in my mind the nicest option if ALL print statements
: need to be terminated with a newline.
Best localized within a block.
------------------------------
Date: Thu, 24 Dec 1998 11:52:33 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: sizeof() function?
Message-Id: <36832a91.477408@news.skynet.be>
Eric Bohlman wrote:
>: Another alternative:
>
>: $\ = "\n";
>: print $foo;
>
>: Very readable, and in my mind the nicest option if ALL print statements
>: need to be terminated with a newline.
>
>Best localized within a block.
Yes, and no. I'm not so much worried about the global variable $\
gettting cluttered, but of the programmer loosing overview, of where it
is set to newline or to undef (the default). It's confusing. Therefore,
I think it's best to either use it (almost) everywhere, or nowhere.
Bart.
------------------------------
Date: 24 Dec 1998 10:02:47 +0100
From: rutka@lucent.com (Micha3 Rutka)
Subject: Re: sort it ?
Message-Id: <wsm67b1hpzc.fsf@hzsac328.nl.lucent.com>
mjtg@cus.cam.ac.uk (M.J.T. Guy) writes:
> Micha3 Rutka <rutka@lucent.com> wrote:
> >You can speed up even more if you use the original technique (without a
> >name yet) rather than 'strigify' version of it:
> >
> >@vendors = map{ substr($_,4) }
> > sort
> > map{ pack("f",(split " ",$_)[$field]).$_ } @vendors;
> >
> >No asumption about vendors is required anymore :-).
>
> But you're making a horrific assumption about the native floating point
> format. Highly non-portable.
Yes, indeed :-). If you want portable code, here it is:
if(pack('n',1) eq pack('s',1)){ # Endian check here
# Big endian case
@vendors = map{ substr($_,4)}
sort
map{ pack("f",(split " ",$_)[$field]).$_ } @vendors;
}else{
# Little endian case
@vendors = map{ substr($_,4)}
sort
map{ reverse (pack("f",(split " ",$_)[$field])).$_ }
@vendors;
}
Michal
--
Dr. Ir. Michal Rutka Lucent Technologies - Huizen, The Netherlands
Senior System Engineer mailto:rutka@lucent.com
------------------------------
Date: 24 Dec 1998 10:23:24 +0100
From: rutka@lucent.com (Micha3 Rutka)
Subject: Re: sort it ?
Message-Id: <wsm3e65hp0z.fsf@hzsac328.nl.lucent.com>
lr@hpl.hp.com (Larry Rosler) writes:
> + John Porter <jdporter@min.net> writes:
> + > Doesn't need a name.
> We are calling it 'default sort' for now.
Yeah, I noticed. But are you and John talking about the same thing?
This is the question which concerns me, or rather why he says to me
that it doesn't need a name and not to you?
> + > Remember, kids: use the built-in sort comparison if the performance
> + > of your sorts is a concern.
> + Reports,
> + Benchmark: timing 1000 iterations of Int sort, Str sort...
> + Int sort: 3 secs ( 3.76 usr 0.00 sys = 3.76 cpu)
> + Str sort: 6 secs ( 5.94 usr 0.01 sys = 5.95 cpu)
> + So, your rule-of-thumb gave me almost 2x slow-down. Or maybe you
> + should add some sub-rule-of-thumbs to your rule-of-thumb?
[some good remarks, but unfortunally, sent to the wrong thread, removed]
> It is possible that you are the only follower of this discussion who
> chose to ignore this obvious distinction.
I do *not* ignore anything. I'm just pointing that the rule-of-thumb
is not true. There is nothing in the rule about 'trivial' or 'field'
(which BTW should be called 'indexed', because it is similar to
indexing of a database record) sort. Moreover, discussion about it is
in absolutly different thread :-).
Of course, the rule-of-thumb can become true when I change benchmark
parameters. But this is not a point.
Another thing is that I've benchmarked also non-trivial cases, which
showed that my technique is sometimes slower than ST. But again, I
used the simplified to minimum example here (i.e. trivial), to show a
point. John says 'use the built-in sort' and I showed that when I do
this then I slow down my sort. Uff, I think that I am clear enough now
:-).
Regards,
Michal
--
Dr. Ir. Michal Rutka Lucent Technologies - Huizen, The Netherlands
Senior System Engineer mailto:rutka@lucent.com
------------------------------
Date: Thu, 24 Dec 1998 07:58:34 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: string problem
Message-Id: <ebohlmanF4GM5M.6vy@netcom.com>
Larry Rosler <lr@hpl.hp.com> wrote:
: Yes, it is possible. With varying efficiencies, these are some of the
: ways:
: if (index($mystring, '|') >= 0) { it's there ... }
: if ($mystring =~ tr/|//) { it's there ... }
: if ($mystring =~ /\|/) { it's there ... }
use Benchmark;
my $mystring='a' x 500 . '|' . 'b' x 500;
my $found;
timethese(10000, {
Index=> sub {$found=(index($mystring, '|') >= 0)},
Tr=> sub {$found=($mystring =~ tr/|//)},
Regex=>sub {$found=($mystring =~ /\|/)}
});
Benchmark: timing 10000 iterations of Index, Regex, Tr...
Index: 1 secs ( 0.78 usr 0.02 sys = 0.80 cpu)
Regex: 1 secs ( 0.88 usr 0.12 sys = 1.00 cpu)
Tr: 3 secs ( 1.82 usr 0.23 sys = 2.05 cpu)
Tr seems to be the loser here. IIRC, index() and regex matching use the
same algorithm (Boyer-Moore, which is quite fast) for matching literal
strings, so the similar times aren't surprising.
------------------------------
Date: Thu, 24 Dec 1998 02:45:31 -0700
From: "Brandon Burt" <bb@jesusfish.xmission.com>
Subject: Re: The quine page
Message-Id: <75t2uv$a2e$1@news.xmission.com>
Gary Thompson II wrote in message <3681E060.C4E2626E@sun.iwu.edu>...
>Hi there,
> I thought this group might be interested in my new page, The Quine
>Page
Heh, nice page, Gary. Good job.
-Brandon
------------------------------
Date: 24 Dec 1998 11:47:55 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Using the same filehandle twice
Message-Id: <75t9lb$fbb$1@pegasus.csx.cam.ac.uk>
Anton Voronin <anton@urc.ac.ru> wrote:
>The use of an existing filehandle associated with opened file is incorrect
>like in the following situation:
>
>open FH, "testfile.txt";
>print scalar ( <FH> );
>&routine;
>print scalar ( <FH> ); # this won't work if routine open()s with FH too
>without localizing *FH
>close FH;
It will work if &routine localises any filehandles it uses, with
local *FH;. It's good practice always to localise filehandles whose
only use is within one subroutine.
>But if we do:
>
>open FH, "testfile.txt";
>...
>close FH;
># and then we use FH again:
>open FH, "testfile2.txt";
>...
>close FH;
>
>In most cases it works fine, but I have a perl application which sometimes
>die()s (though rarely) because either close() does not return true or SIGPIPE
>is received. I am not sure if it happens right where FH is used again or
>not... So I am asking - is it absolutely safe or not?
It certainly *ought* to work. If you have an example of a *small*
script which shows the effect, even intermittently, please post it
so we can try and track down the bug.
Mike Guy
------------------------------
Date: 24 Dec 1998 12:21:27 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: What's the Right Way to detect an Array Ref?
Message-Id: <75tbk7$h2a$1@pegasus.csx.cam.ac.uk>
Bart Lateur <bart.lateur@skynet.be> wrote:
>dg50@chrysler.com wrote:
>
>>What I want is for - in this one instance - to ALWAYS return an array ref,
>>even if there is only one element in the name=value hash.
>>
>>To do this, my tortured and overworked little brain came up with:
>># Ohhhh, this is ugly!
>>$promotees_raw = [ ("$promotees_raw") ] if ($promotees_raw !~ /^ARRAY/);
>
>Try the function "ref".
>
> $promotees_raw = [ $promotees_raw ]
> unless ref($promotees_raw) eq 'ARRAY';
>
>but I think if ref returns anything not false, it must be an array ref:
>
> $promotees_raw = [ $promotees_raw ] unless ref($promotees_raw);
That may be true in this particular case, but it could cause trouble in
general.
And in general, testing ref() for equality is a Bad Thing - it won't
do what you want if there any blessed objects about.
I always recommend UNIVERSAL::isa for these situations:
$promotees_raw = [ $promotees_raw ]
unless UNIVERSAL::isa($promotees_raw, 'ARRAY');
Mike Guy
------------------------------
Date: Wed, 23 Dec 1998 17:45:38 +0000
From: Rich Grise <off-duty@entheosengineering.com>
To: Martien Verbruggen <mgjv@comdyn.com.au>
Subject: Re: what's wrong with this bit of code? :)
Message-Id: <36812C42.75B0EE5@entheosengineering.com>
Martien Verbruggen wrote:
> See another post of mine in response to one of yours about this exact
> subject :)
>
> the -t flag tells sendmail to parse the message for To:, Cc: and Bcc:
> fields, and makes it ignore any addresses that were passed in as
> arguments.
>
> Martien
Well, I guess that's egg on my face for avoiding the sendmail doc's all
of this time. I'll go sit in the corner and RTFM now.
Thanks. :)
--
Rich Grise
off-duty@entheosengineering.com
(No need to futz with my e-mail: I have a "delete" button!)
------------------------------
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 4492
**************************************