[22679] in Perl-Users-Digest
Perl-Users Digest, Issue: 4900 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 27 09:05:51 2003
Date: Sun, 27 Apr 2003 06:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 27 Apr 2003 Volume: 10 Number: 4900
Today's topics:
ANNOUNCE: CGI::Widget::Tabs v. 1.07 <NO.koos.JUNK.pol.MAIL@raketnet.nl>
Conditional use of perl modules <motis@lyciumnetworks.com>
Re: Conditional use of perl modules <tassilo.parseval@rwth-aachen.de>
Re: Conditional use of perl modules <denshimeiru-sapmctacher@durchnull.ath.cx>
Re: Conditional use of perl modules <tassilo.parseval@rwth-aachen.de>
Re: Conditional use of perl modules <motis@lyciumnetworks.com>
Re: Conditional use of perl modules <denshimeiru-sapmctacher@durchnull.ath.cx>
Re: Conditional use of perl modules <kalinabears@hdc.com.au>
Extracting line from file <tom @ abwaerts . be>
Get PID from process started by "system" - how? <anthony_w@no_spam.bigpond.com>
Re: Get PID from process started by "system" - how? <denshimeiru-sapmctacher@durchnull.ath.cx>
Re: hashes in scalar context? <tassilo.parseval@rwth-aachen.de>
Re: hashes in scalar context? (Tad McClellan)
Re: hashes in scalar context? <No_4@dsl.pipex.com>
Re: help with use lib <mpapec@yahoo.com>
Re: How to send and receive on IP PORT? <sammie@greatergreen.com>
Re: Isolating Sentences (Not Lines) With Regex (Tad McClellan)
Re: regex for word whitespace word <johngros@bigpond.net.au>
Re: Tough question for the guru's; Grep Once, Awk Twice (Agrapha)
Re: Tough question for the guru's; Grep Once, Awk Twice <tassilo.parseval@rwth-aachen.de>
Win32::AdminMisc??? (Gert Vanderstukken)
Re: Win32::AdminMisc??? <kalinabears@hdc.com.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 27 Apr 2003 10:07:22 +0200
From: Koos Pol <NO.koos.JUNK.pol.MAIL@raketnet.nl>
Subject: ANNOUNCE: CGI::Widget::Tabs v. 1.07
Message-Id: <b8g33r$92bbg$1@ID-171888.news.dfncis.de>
Announcement for CGI::Widget::Tabs, version 1.07
This release has been much delayed by distraction. Motorbike driving
lessons (and all that comes with it) have proved to be a formidable
competitor to Perl hacking :-)
The changes for this version are:
1.07 (2003-04-27)
------------------
- Removed the distinction between simple headings and OO headings.
Simple headings are now (as they should be) just a variation of
OO headings. This greatly simplifies programming logic. One
consequence is that the headings() method now only returns OO
headings. (Thanks to Bernhard Schmalhofer
<Bernhard.Schmalhofer@biomax.de> for suggestions and patches.)
- Added a hash as optional initializer for the headings() method.
(Thanks to Bernhard Schmalhofer <Bernhard.Schmalhofer@biomax.de>
for suggestions and patches.)
- Headings can now override the default CSS class using the
class() method. (Suggested by Bernie Ledwick
<bl@man.fwltech.com>)
- Documentation updates
Enclosed is the README for reference.
Best regards,
Koos Pol
CGI::Widget::Tabs
=================
DESCRIPTION
CGI::Widget::Tabs lets you simulate tab widgets in HTML. You could
benefit from a tab widget if you want to serve only one page. Depending
on the tab selected you fetch and display the underlying data. There
are three main reasons for taking this approach:
1. For the end user not to be directed to YAL or YAP (yet another link,
yet another page), but keep it all together: The single point of entry
paradigm.
2. As a consequence the end user deals with a more consistent and
integrated GUI. This will give a better "situational awareness" within
the application.
3. For the Perl hacker to handle multiple related data sources within
the same script environment.
As an example the following tabs could be used on a web page for
someone's spotting hobby:
__________ __________ __________
/ Planes \ / Trains \ / Classics \
------------------------------------------------------
_________
/ Bikes \
------------------------
As you can see, the headings wrap at three and a small indentation is
added to the start of the next row. The nice thing about
CGI::Widget::Tabs is that the tabs know their internal state. So you
can ask a tab for instance which heading has been clicked by the user.
This way you get instant feedback.
DOCUMENTATION
The documentation is included in the module. You can read it's manpage
after installation with `perldoc CGI::Widget::Tabs'. If you prefer you
can read the documentation before installation with `perldoc ./Tabs.pm'
DEPENDENCIES
- CGI, CGI::Minimal or another CGI "object broker"
with the param() method and with similar behaviour
- HTML::Entities
- URI
- A CSS style sheet for the tabs markup
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
DOWNLOAD
You can download CGI::Widget::Tabs from CPAN at http://cpan.perl.org.
The latest version is always available from the CGI::Widget::Tabs
homepage at: http://users.raketnet.nl/koos_pol/en/Tabs/index.html
COPYRIGHT AND LICENCE
Copyright (c) 2003 Koos Pol. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
CHANGES
These changes are against the previous version. For a complete history
log, see the file 'CHANGES' in the distribution.
1.07 (2003-04-27)
------------------
- Removed the distinction between simple headings and OO headings.
Simple headings are now (as they should be) just a variation of
OO headings. This greatly simplifies programming logic. One
consequence is that the headings() method now only returns OO
headings. (Thanks to Bernhard Schmalhofer
<Bernhard.Schmalhofer@biomax.de> for suggestions and patches.)
- Added a hash as optional initializer for the headings() method.
(Thanks to Bernhard Schmalhofer <Bernhard.Schmalhofer@biomax.de>
for suggestions and patches.)
- Headings can now override the default CSS class using the
class() method. (Suggested by Bernie Ledwick
<bl@man.fwltech.com>)
- Documentation updates
$Id: README,v 1.19 2003/04/26 19:51:56 koos Exp $
--
KP
koos _ pol @ raketnet nl
------------------------------
Date: Sun, 27 Apr 2003 10:45:32 +0200
From: "012" <motis@lyciumnetworks.com>
Subject: Conditional use of perl modules
Message-Id: <3eab8ac9@news.012.net.il>
Hi
Is it possible to make the defintion "use modulename" conditional?
Something like:
if ($usewin32)
{
use Win32::OLE qw
}
Thanks a lot
Moti
mailto:motis@lyciumnetworks.com
------------------------------
Date: 27 Apr 2003 08:29:31 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Conditional use of perl modules
Message-Id: <b8g4db$dff$1@nets3.rz.RWTH-Aachen.DE>
Also sprach 012:
> Is it possible to make the defintion "use modulename" conditional?
> Something like:
> if ($usewin32)
> {
> use Win32::OLE qw
> }
Yes. You could use the 'if' module (available from the CPAN):
use if my $cond = eval { require Win32::OLE }, 'Win32::OLE' => qw/.../;
For some reasons a simple
use if eval { require Win32::OLE }, ...;
does not work, though.
You can also get away without any module:
BEGIN {
eval {
require Win32::OLE;
Win32::OLE->import;
};
}
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 27 Apr 2003 08:47:53 GMT
From: Rudolf Polzer <denshimeiru-sapmctacher@durchnull.ath.cx>
Subject: Re: Conditional use of perl modules
Message-Id: <slrnban6a9.db9.denshimeiru-sapmctacher@message-id.durchnull.ath.cx>
Scripsit ille »Tassilo v. Parseval« <tassilo.parseval@rwth-aachen.de>:
> Also sprach 012:
> > Is it possible to make the defintion "use modulename" conditional?
> > Something like:
> > if ($usewin32)
> > {
> > use Win32::OLE qw
> > }
>
> Yes. You could use the 'if' module (available from the CPAN):
>
> use if my $cond = eval { require Win32::OLE }, 'Win32::OLE' => qw/.../;
>
> For some reasons a simple
>
> use if eval { require Win32::OLE }, ...;
>
> does not work, though.
Or, you could use my
CPAN_USERID RPOLZER (Rudolf Polzer <rpolzer@durchnull.de>)
CPAN_VERSION 1.2
CPAN_FILE R/RP/RPOLZER/Detect-Module-1.2.tar.gz
INST_FILE (not installed)
use Detect::Module;
my $w32ole = Detect::Module::Load 'Win32::OLE';
# ...
if($w32ole)
{
$w32ole->call1(); # really calls Win32::OLE::call1
$w32ole->call2(); # really calls Win32::OLE::call2
}
You've found something Detect::Module does not support: using import()
and giving arguments to the module.
--
The year's at the spring The lark's on the wing;
And day's at the morn; The snail's on the thorn:
Morning's at seven; God's in His heaven
The hill-side's dew-pearled; All's right with the world!
------------------------------
Date: 27 Apr 2003 09:14:16 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Conditional use of perl modules
Message-Id: <b8g718$fv6$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Rudolf Polzer:
> Scripsit ille »Tassilo v. Parseval« <tassilo.parseval@rwth-aachen.de>:
>> Also sprach 012:
>> Yes. You could use the 'if' module (available from the CPAN):
>>
>> use if my $cond = eval { require Win32::OLE }, 'Win32::OLE' => qw/.../;
>>
>> For some reasons a simple
>>
>> use if eval { require Win32::OLE }, ...;
>>
>> does not work, though.
>
> Or, you could use my
>
> CPAN_USERID RPOLZER (Rudolf Polzer <rpolzer@durchnull.de>)
> CPAN_VERSION 1.2
> CPAN_FILE R/RP/RPOLZER/Detect-Module-1.2.tar.gz
> INST_FILE (not installed)
Didn't know about it yet.
> use Detect::Module;
> my $w32ole = Detect::Module::Load 'Win32::OLE';
> # ...
> if($w32ole)
> {
> $w32ole->call1(); # really calls Win32::OLE::call1
> $w32ole->call2(); # really calls Win32::OLE::call2
> }
>
> You've found something Detect::Module does not support: using import()
> and giving arguments to the module.
But would it make sense anyway? Your module qualifies function calls so
import() is not required.
Hmmh, does your module handle object oriented modules? Probably not easy
to implement with an interface like yours, I suppose.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sun, 27 Apr 2003 13:51:18 +0200
From: "012" <motis@lyciumnetworks.com>
Subject: Re: Conditional use of perl modules
Message-Id: <3eabb655@news.012.net.il>
O.k.
I'll try to give you some more details since I still can't understand how to
handle this problem.
I don't want to use the module detecting since I already know if the module
exist in my env.
I'm using a script which can work in both UNIX and Windows. In case I use
Windows OS, I have additional features in the script for handling Excel
files. For that I should use the following modules:
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
use Win32::OLE::Variant;
use Win32::OLE::NLS qw(:LOCALE :DATE);
When using the script in UNIX OS the compilation fails since the modules
above don't exist in UNIX.
Is there any way in perl to handle this problem?
I think the best way is to use conditional (use Win32::...)
I've tried using the "eval" command like Tassilo has suggested but I get
warnings because of the test I generate to the modules (Ex. qw(in with))
Thanks again for you help
Moti
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message
news:b8g718$fv6$1@nets3.rz.RWTH-Aachen.DE...
> Also sprach Rudolf Polzer:
>
> > Scripsit ille »Tassilo v. Parseval« <tassilo.parseval@rwth-aachen.de>:
> >> Also sprach 012:
>
> >> Yes. You could use the 'if' module (available from the CPAN):
> >>
> >> use if my $cond = eval { require Win32::OLE }, 'Win32::OLE' =>
qw/.../;
> >>
> >> For some reasons a simple
> >>
> >> use if eval { require Win32::OLE }, ...;
> >>
> >> does not work, though.
> >
> > Or, you could use my
> >
> > CPAN_USERID RPOLZER (Rudolf Polzer <rpolzer@durchnull.de>)
> > CPAN_VERSION 1.2
> > CPAN_FILE R/RP/RPOLZER/Detect-Module-1.2.tar.gz
> > INST_FILE (not installed)
>
> Didn't know about it yet.
>
> > use Detect::Module;
> > my $w32ole = Detect::Module::Load 'Win32::OLE';
> > # ...
> > if($w32ole)
> > {
> > $w32ole->call1(); # really calls Win32::OLE::call1
> > $w32ole->call2(); # really calls Win32::OLE::call2
> > }
> >
> > You've found something Detect::Module does not support: using import()
> > and giving arguments to the module.
>
> But would it make sense anyway? Your module qualifies function calls so
> import() is not required.
>
> Hmmh, does your module handle object oriented modules? Probably not easy
> to implement with an interface like yours, I suppose.
>
> Tassilo
> --
>
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
>
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
>
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 27 Apr 2003 11:04:20 GMT
From: Rudolf Polzer <denshimeiru-sapmctacher@durchnull.ath.cx>
Subject: Re: Conditional use of perl modules
Message-Id: <slrnbanea4.fah.denshimeiru-sapmctacher@message-id.durchnull.ath.cx>
Scripsit ille »Tassilo v. Parseval« <tassilo.parseval@rwth-aachen.de>:
> Also sprach Rudolf Polzer:
>
> > Scripsit ille »Tassilo v. Parseval« <tassilo.parseval@rwth-aachen.de>:
> >> Also sprach 012:
>
> >> Yes. You could use the 'if' module (available from the CPAN):
> >>
> >> use if my $cond = eval { require Win32::OLE }, 'Win32::OLE' => qw/.../;
> >>
> >> For some reasons a simple
> >>
> >> use if eval { require Win32::OLE }, ...;
> >>
> >> does not work, though.
> >
> > Or, you could use my
> >
> > CPAN_USERID RPOLZER (Rudolf Polzer <rpolzer@durchnull.de>)
> > CPAN_VERSION 1.2
> > CPAN_FILE R/RP/RPOLZER/Detect-Module-1.2.tar.gz
> > INST_FILE (not installed)
>
> Didn't know about it yet.
I still think in the OP's case the normal eval-ed require is best together
with explicitly qualifying - or providing a module doing that together
with his program's sources.
> > use Detect::Module;
> > my $w32ole = Detect::Module::Load 'Win32::OLE';
> > # ...
> > if($w32ole)
> > {
> > $w32ole->call1(); # really calls Win32::OLE::call1
> > $w32ole->call2(); # really calls Win32::OLE::call2
> > }
> >
> > You've found something Detect::Module does not support: using import()
> > and giving arguments to the module.
>
> But would it make sense anyway? Your module qualifies function calls so
> import() is not required.
Not really. At least CGI cannot be used using that - one has to explicitly
name CGI:: then to make its AUTOLOAD called (since I already use AUTOLOAD
for my function call interface and check if the function exists - which
will return false if the function SHOULD call AUTOLOAD).
> Hmmh, does your module handle object oriented modules? Probably not easy
> to implement with an interface like yours, I suppose.
Works fine... see manpage, IO::Socket::INET example.
Simply spoken, it just does
eval "require $MODULENAME"
after some checks for characters in the module name. If that works,
the module is already there in the normal namespace - $w32ole is in fact
only a shorthand for the fully qualified Win32::OLE::. So a constructor
works perfectly.
If I load the module using Detect::Module::Use or Detect::Module::Require
(they are synonyms), just the name of the module loaded is returned and
the script die()s if the module isn't there. If multiple module names are
given, the first one which could be loaded is used. So the error can be
ignored by
Detect::Module::Use 'module', 0;
since 'require 0' always succeeds.
NewRef returns a SUB reference to the constructor instead of the module
name. Load returns that function call object I normally prefer.
$module->function(@args);
${($module->(SCALAR => 'scalarname'))} = 17; # $Module::scalarname = 17;
print @{($module->(ARRAY => 'arrayname'))}; # print @Module::arrayname;
same with HASH, CODE, GLOB. CODECHECK returns undef if the function
doesn't exist and it can be checked; CODE sometimes returns a reference
even if there is no such function (AUTOLOAD?).
$module->function();
is just a shorthand for
$module->(CODECHECK => 'function')->();
(see the provided AUTOLOAD function of Detect::Module::Internal)
Unfortunately, CODECHECK doesn't allow the module's AUTOLOAD being
called...
how can I check "perfectly" if
some_module::some_function_name
will result in Perl's "Undefined subroutine" message or not WITHOUT
actually calling the function? Is it even possible?
--
About hexadecimal values
------------------------
Wipe Info uses hexadecimal values to wipe files. This provides
more security than wiping with decimal values.
------------------------------
Date: Sun, 27 Apr 2003 21:53:51 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: Conditional use of perl modules
Message-Id: <3eabc5c8$0$19907@echo-01.iinet.net.au>
"012" <motis@lyciumnetworks.com> wrote in message
news:3eabb655@news.012.net.il...
> O.k.
> I'll try to give you some more details since I still can't understand how
to
> handle this problem.
> I don't want to use the module detecting since I already know if the
module
> exist in my env.
>
If you're prepared to 'require' rather than 'use' the module (and I don't
see any reason that you shouldn't be prepared to do that), then you could:
if ($^O =~ /win32/i) {require Win32::OLE}
Or you could do:
eval{require Win32::OLE};
unless($@) {require Win32::OLE}
Cheers,
Rob
------------------------------
Date: Sun, 27 Apr 2003 14:38:48 +0200
From: Tom <tom @ abwaerts . be>
Subject: Extracting line from file
Message-Id: <1408983.yxk6FWrKHU@abwaerts.be>
Hey ho,
I downloaded an xmms' plugin, which creates a fifo in /tmp, called
xmms-info. It goes like this:
[14:28][tom][~] $ cat /tmp/xmms-info
XMMS protocol version: 2467
InfoPipe Plugin version: 1.3
Status: Playing
Tunes in playlist: 1037
Currently playing: 624
uSecPosition: 99430
Position: 1:39
uSecTime: 309706
Time: 5:09
Current bitrate: 299251
Sampling Frequency: 44100
Channels: 2
Title: Orphx - Mother Tongue (ogg)
File: /home/tom/mp3s/Orphx*Mother_Tongue.ogg
[14:29][tom][~] $
Now I wanted to extract the title of the track currently being played to
print it in my .signature, thus the line starting with "Title: without
that very "Title: " part. With a lot of help from more, ehm, proficient
Perl-users, I managed to get something like this:
#!/usr/bin/perl;
use warnings;
$bestandje = "/tmp/xmms-info";
if (-e $bestandje) {
open(BLEH,"cat /tmp/xmms-info|");
while (<BLEH>) {
if (/^Title:\b(.*$)/) {
print $1;
} else {
print "Something must be wrong...\n";
}
}
close(BLEH);
} else {
print "No music is currently being played.\n";
}
When no music is playing, the correct message is printed. However, when
I *am* listening to some music, it's not the title that gets displayed,
but the line reporting that something's wrong. Moreover, that very line
gets printed as much times as there are lines in the xmms-info file...
Could someone please enlighten me?
If so: thanks a lot.
Greets,
Tom
--
http://%77%77%77%2E%61%62%77%61%65%72%74%73%2E%62%65%2F/
ICQ 303884489
JBR kaiser_der_Mongolei@amessage.be
MSN tom@abwaerts.be
------------------------------
Date: Sun, 27 Apr 2003 18:43:14 +1000
From: "Tony" <anthony_w@no_spam.bigpond.com>
Subject: Get PID from process started by "system" - how?
Message-Id: <pan.2003.04.27.08.43.13.881179@no_spam.bigpond.com>
Hi Guys,
I have searched high and low (Google) and can
not seem to find a way of getting the PID of
a process started when calling an external
program with the "system" call.
Like this:
system "/usr/bin/some_program"
I need to get the PID of "some_program" when it
starts and store it for later use.
Any one know this?
Tony
--
------------------------------------------------------------
A linux user...(No spam mail here please)
------------------------------------------------------------
------------------------------
Date: 27 Apr 2003 11:11:46 GMT
From: Rudolf Polzer <denshimeiru-sapmctacher@durchnull.ath.cx>
Subject: Re: Get PID from process started by "system" - how?
Message-Id: <slrnbaneo4.fah.denshimeiru-sapmctacher@message-id.durchnull.ath.cx>
Scripsit ille aut illa »Tony« <anthony_w@no_spam.bigpond.com>:
> Hi Guys,
>
> I have searched high and low (Google) and can
> not seem to find a way of getting the PID of
> a process started when calling an external
> program with the "system" call.
>
> Like this:
>
> system "/usr/bin/some_program"
>
> I need to get the PID of "some_program" when it
> starts and store it for later use.
>
> Any one know this?
Nobody does. When system returns, your /usr/bin/some_program already
has exited, and its PID doesn't interest anyone.
So you're probably calling a daemon which forks on startup. You could
check if it writes a PID file (normally in /var/run) and if not, make it
write one. Or make it not detach (many daemons have such a command-line
option) and use your own fork-and-exec routine:
sub ForkAndExec(@)
{
if (my $pid = fork())
{
return $pid;
}
else
{
exec { $_->[0] } @_
or exit 0xF001;
}
}
my $pid = ForkAndExec sleep => 3;
print "$pid\n";
my $res = wait;
print "$res exited with code $?\n";
outputs:
19560
19560 exited with code 0
--
Du fingst mit Einem heimlich an,
Bald kommen ihrer mehre dran,
Und wenn dich erst ein Dutzend hat,
So hat dich auch die ganze Stadt.
------------------------------
Date: 27 Apr 2003 07:15:15 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: hashes in scalar context?
Message-Id: <b8g023$b0o$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Andras Malatinszky:
> The perldata man page tells me this:
>
> "If you evaluate a hash in scalar context, it returns false if the hash
> is empty. If there are any key/value pairs, it returns true; more
> precisely, the value returned is a string consisting of the number of
> used buckets and the number of allocated buckets, separated by a slash.
> This is pretty much useful only to find out whether Perl's internal
> hashing algorithm is performing poorly on your data set. For example,
> you stick 10,000 things in a hash, but evaluating %HASH in scalar
> context reveals "1/16", which means only one out of sixteen buckets has
> been touched, and presumably contains all 10,000 of your items. This
> isn't supposed to happen."
>
> Is there a realistic situation when evaluating a hash in scalar context
> may be useful? Anyone ever used this feature?
I used it once for fun after I had the vague feeling that Perl's hashing
algorithm got worse from 5.6.1 to 5.8. I created a lot of hash keys
randomly and stored them all in a hash for 5.00503, 5.6.1 and 5.8.0.
After that I compared the hashes in scalar context to see how many
collisions occured etc. Here is the script that I used:
#! /usr/bin/perl -w
use strict;
use integer;
my %stats;
for (0 .. 100) {
my @keys = map {
my $c; $c .= chr(65 + rand(57)) for 0 .. rand(20);
$c =~ tr/A-Za-z//cd; qq!"$c"! }
0 .. 1023;
my $code = <<CODE;
my %hash;
\@hash{ @{[ join ",", @keys ]} } = ();
print scalar %hash, "\\n";
CODE
qx/perl5.5.3 -e '$code'/ =~ m!(\d+)/(\d+)!;
$stats{ "5.5.3" }->[0] += $1;
$stats{ "5.5.3" }->[1] += $2;
qx/perl -e '$code'/ =~ m!(\d+)/(\d+)!;
$stats{ "5.6.1" }->[0] += $1;
$stats{ "5.6.1" }->[1] += $2;
qx/perl5.8.0 -e '$code'/ =~ m!(\d+)/(\d+)!;
$stats{ "5.8.0" }->[0] += $1;
$stats{ "5.8.0" }->[1] += $2;
}
no integer;
print "-" x 50, "\n";
printf "5.5.3: %1.4f\n", $stats{ "5.5.3" }->[0] / $stats{ "5.5.3" }->[1];
printf "5.6.1: %1.4f\n", $stats{ "5.6.1" }->[0] / $stats{ "5.6.1" }->[1];
printf "5.8.0: %1.4f\n", $stats{ "5.8.0" }->[0] / $stats{ "5.8.0" }->[1];
Btw, the outcome of the above script showed that my assumption was
wrong. The three perls hash pretty comparably.
> On a slightly different track: what are these "buckets"? Are they
> documented somewhere? Is it useful to know about them?
It doesn't hurt, but it's not vital at all. Buckets are spots in which a
key/value combo is stored. The hashing functions maps a key to such a
bucket. If you have eight keys that all happen to map to the same
bucket, you get '1/8' for the hash in scalar context even though eight
pairs are in the hash. Ideally it would show '8/8' which would result in
the fastest look-up. I think Eric gave a more comprehensive explanation
in a parallel posting of this thread. See also
http://perl.plover.com/#badhash
for a program that constructs keys that all map to one bucket.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sun, 27 Apr 2003 06:11:48 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: hashes in scalar context?
Message-Id: <slrnbanenk.gon.tadmc@magna.augustmail.com>
Andras Malatinszky <nobody@dev.null> wrote:
> The perldata man page tells me this:
> This is pretty much useful only to find out whether Perl's internal
> hashing algorithm is performing poorly on your data set.
> Is there a realistic situation when evaluating a hash in scalar context
> may be useful?
A hash in scalar context is useful for a perl programmer, but not
so useful for a Perl programmer.
:-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 27 Apr 2003 12:52:57 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: hashes in scalar context?
Message-Id: <3eabc499$0$29716$cc9e4d1f@news.dial.pipex.com>
Andras Malatinszky wrote:
>
> Is there a realistic situation when evaluating a hash in scalar context
> may be useful?
Yes - checking whether a hash contains any information.
if (%hash) {
<<code to handle hash entries>>
} else {
print "%hash is empty!\n"; # Or whatever
}
--
-*- Just because I've written it here doesn't -*-
-*- mean that you should, or I do, believe it. -*-
------------------------------
Date: Sun, 27 Apr 2003 11:05:45 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: help with use lib
Message-Id: <vf1mav8k2lg5luto46h1on0dmrvs5vn3jh@4ax.com>
X-Ftn-To: Tassilo v. Parseval
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote:
>> my $session = CGI::Session->new("driver:File", undef, {Directory=>'./'});
>
>You have to use() the module as well:
>
> use lib '...';
> use CGI::Session;
> my $session = CGI::Session...;
>
>The error-message you got actually states this quite clearly
>
> ... (perhaps you forgot to load "CGI::Session"?) at ...
Yes, tnx; it works now! I had some strange ideas about "use lib" :)
--
Matija
------------------------------
Date: Sun, 27 Apr 2003 09:50:55 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: How to send and receive on IP PORT?
Message-Id: <3KNqa.639908$F1.85592@sccrnsc04>
Ok thanks, you guys have scared me away from UDP. I have tested EasyTCP
module, and it seems to work nice. However, when I try to compile a small
sample script with perl2exe I get the following error:
Unrecognized character \x90...
I don't think this is module related. I am running ActiveState Perl 5.8 on
WinXP. This also happens when I try using the perlcc compiler. Any ideas? If
I cannot compile, this won't work.
Thanks,
Sammie
"Mina Naguib" <spam@thecouch.homeip.net> wrote in message
news:RJJqa.29162$U01.435093@weber.videotron.net...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> Brad Walton wrote:
> > Thank you Mina, I have been searching all day, looking at Socket() and
> > IO::Socket::INET->new(), trying to find a fairly simple solution. Let me
go
> > into a little more detail, and see if you have any ideas for an easier
> > solution, or may an already existing script.
>
> For a beginner in a simple project such as the one you've outlined,
> IO::Socket::INET is probably the easiest way to go.
>
> >
> > I have a program sitting on a server that already has the data formatted
and
> > ready to send.
> > On the other machine, I simply need to sit there and listen for
information
> > coming from the server. Once that info is received, it grabs it, and
puts it
> > in an array or some sort of results param.
> >
> > It should be real basic, and dumb... meaning neither side should care if
the
> > other side is there. I guess UDP is the way to go for this. Does that
bring
> > any other ideas to mind?
>
> UDP does not guarantee delivery, or even sequence for that matter.
> Think of it like dropping a bunch of letters in the mailbox. That is it,
> end of story.
>
> TCP on the other hand is like an important package with sign-on-receive
> verification.
>
> UDP is usually used in scenarios where some data loss or mangling is
> acceptable, such as online gaming, multimedia streaming, etc. TCP is
> used for almost everything else that requires reliability.
>
> (That is slightly a white lie. You *could* make UDP reliable by layering
> over it most of the features that TCP already does for you).
>
> And so, look over the perlipc page and check the IO::Socket::INET
> examples, it should be a simple copy-and-paste for your project.
>
> Best of luck.
>
>
> -----BEGIN xxx SIGNATURE-----
> Version: GnuPG v1.2.1 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQE+q2f4eS99pGMif6wRAmrlAKC+3A3StIF71QsdRcU2DGyXiSm6ZACgtDNk
> 0sFdmSOJxISdWjaajQp/Bwg=
> =X/yK
> -----END PGP SIGNATURE-----
>
------------------------------
Date: Sun, 27 Apr 2003 06:07:13 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Isolating Sentences (Not Lines) With Regex
Message-Id: <slrnbanef1.gon.tadmc@magna.augustmail.com>
Andras Malatinszky <nobody@dev.null> wrote:
> Scott Edward Skinner wrote:
>
>> Although I'm doing this project in Java,
> trying Text::Autoformat.
I don't think it will work from Java. :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 27 Apr 2003 10:59:59 GMT
From: "John Gros" <johngros@bigpond.net.au>
Subject: Re: regex for word whitespace word
Message-Id: <PKOqa.4071$lD4.21611@news-server.bigpond.net.au>
"Bob Walton" <bwalton@rochester.rr.com> wrote in message
news:3EAB5E6E.4050404@rochester.rr.com...
> John Gros wrote:
>
> > "John Gros" <johngros@bigpond.net.au> wrote in message
> > news:nLFqa.1860$lD4.12990@news-server.bigpond.net.au...
> >
> ...
> > Ok Bob the actual code is,
> ...
> > my @lines = split( / /,$doc); # seperate the html into lines
>
>
> Your problem is on the above line. It splits on every space character,
> including those in your description words. So, for example, the string
Mistake # 1 fixed (thanks Bob).
> Even if that is fixed (by splitting on /\n/), there is still a problem
> with href=AR.HTM>Sha Tim (hk)</FONT
>
> Why don't you just take everything until the next < ? Maybe like:
>
> /([A-Z]{2}\.HTM)>(.*?)</;
I had tried that as my second regex but two mistakes stopped it working, the
split lines and failing to escape the .
> Also, I note that your real data from the web page in your program has
> only \r characters between "lines". Thus, splitting on /[\n\r]/ is
> needed to get the lines you desire and still split the test data (at
> least on Windoze). I note that your expression to knock lines out of
> action if they contain DIVS gets rid of a lot of data due to other
> href's on the same line containing those characters. Hopefully you
> intend that?
Yes those links I intend to access later.
> Also, you are counting on the web site retaining its existing format.
> The same web page display could be generated with radically different
> HTML -- with the sort of code you are writing, you are subject to minor
> changes totally messing up the functioning of your program. Of course,
> that will be the case with any scheme to extract useful information from
> HTML, as HTML is intended to display information, not to make it
> usefully retrievable.
I think that they will keep the format of the links the same and the
description of the links will follow the links, so a regex that finds the
link and extracts the description should hold good. Regardless of most
changes to the page.
>
> HTH
> --
> Bob Walton
>
Thanks Bob, I lack experience to work out where things are going wrong (me
actually going wrong, the code does as it is written)
------------------------------
Date: 27 Apr 2003 00:42:40 -0700
From: brian@box201.com (Agrapha)
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <11aabb15.0304262342.1fc8a2fd@posting.google.com>
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<b8df0e$d8o$1@nets3.rz.RWTH-Aachen.DE>...
>
> A filehandle always refers to one file (socket, pipe or whatever). If
> you need to run through different files, consider to nest the above
> while-loop into a for-loop:
> That you way, you never have more than one open handle.
Tassilo,
I have 1 problem and I can't figure it out. The flies I need to slurp
in are in a linked directory "/proxy/logs/" and the files are named
like
"proxyLogs.20030425, proxyLogs.20030424, proxyLogs.20030423" there is
always 3 files. I thought I could use a reg-expr to grab but just as
you said it didn't like it.
open PROXYD, </^proxyLogs\..*$/> or die "Can't open proxyLogs.*: $!";
produced:
Can't open proxyLogs.*: No such file or directory at ./tri.pl line 9.
I looked up read about and coded some examples of "localtime" but I
didn't understand it very well and didn't see how I could check gmtime
or utime and convert it to "20030425" format easily. How can I use a
wildcard or generate a date and join to the filename?
------------------------------
Date: 27 Apr 2003 08:10:31 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <b8g39n$cjo$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Agrapha:
> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<b8df0e$d8o$1@nets3.rz.RWTH-Aachen.DE>...
>>
>> A filehandle always refers to one file (socket, pipe or whatever). If
>> you need to run through different files, consider to nest the above
>> while-loop into a for-loop:
>
>
>> That you way, you never have more than one open handle.
> I have 1 problem and I can't figure it out. The flies I need to slurp
> in are in a linked directory "/proxy/logs/" and the files are named
> like
> "proxyLogs.20030425, proxyLogs.20030424, proxyLogs.20030423" there is
> always 3 files. I thought I could use a reg-expr to grab but just as
> you said it didn't like it.
>
> open PROXYD, </^proxyLogs\..*$/> or die "Can't open proxyLogs.*: $!";
> produced:
> Can't open proxyLogs.*: No such file or directory at ./tri.pl line 9.
You must have misunderstood what I previously wrote: A filehandle
relates to only one file (unless you use the special handle <> and put
the files into @ARGV; see Bart's post).
In the above you try to open a list of files and associate the handle
PROXYD with this list. You can't do that.
> I looked up read about and coded some examples of "localtime" but I
> didn't understand it very well and didn't see how I could check gmtime
> or utime and convert it to "20030425" format easily. How can I use a
> wildcard or generate a date and join to the filename?
Why do you need the date-calculation at all? From your above pattern it
looks as though you want to open files that match the pattern
/^proxyLogs\..*$/
Now I can only comment on how you deal with a list of files that
satisfy the above pattern.
Basically you have two options here: Either use globbing or use
readdir() and filter the files through the pattern. Your pattern can be
handled by glob(), so I'd use this instead:
for my $file (glob "/proxy/logs/proxyLogs.*") {
open FILE, $file or die "$file: $!";
while (<FILE>) { ... }
close FILE;
}
A readdir approach is more work but also more flexible because you can
use proper Perl regexes instead of simpler glob patterns:
my $dir = "/proxy/logs";
opendir DIR, $dir or die "$dir: $!";
my @files = map { "$dir/$_" }
grep { /^proxyLogs\..*$/ }
readdir DIR;
for my $file (@files) {
# same as above
...
}
closedir DIR;
map() preprocesses the list returned by grep() and prepends the
directory to each of the filesnames returned by readdir(). Unlike glob()
readdir() does not return a full path.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 27 Apr 2003 03:29:31 -0700
From: gert.vanderstukken@pandora.be (Gert Vanderstukken)
Subject: Win32::AdminMisc???
Message-Id: <5eb4ae79.0304270229.191371a@posting.google.com>
Hello all,
I find a lot of useful information about a very useful module:
Win32::AdminMisc.
Only 1 problem, I can not get it to work. I'm somewhat new to Perl, so
I could use some help.
Were can I download it and how do I make it work?
I have the following version of Perl (Activestate):
Perl 5.8.0
Build 805
Kind regards,
Gert Vanderstukken
gert.vanderstukken@pandora.be
Leuven
Belgium
------------------------------
Date: Sun, 27 Apr 2003 21:22:41 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: Win32::AdminMisc???
Message-Id: <3eabbe7a$0$19910@echo-01.iinet.net.au>
"Gert Vanderstukken" <gert.vanderstukken@pandora.be> wrote in message
news:5eb4ae79.0304270229.191371a@posting.google.com...
> Hello all,
>
> I find a lot of useful information about a very useful module:
> Win32::AdminMisc.
>
> Only 1 problem, I can not get it to work. I'm somewhat new to Perl, so
> I could use some help.
>
> Were can I download it and how do I make it work?
>
> I have the following version of Perl (Activestate):
> Perl 5.8.0
> Build 805
>
> Kind regards,
>
> Gert Vanderstukken
> gert.vanderstukken@pandora.be
> Leuven
> Belgium
Afaik it's unavailable for perl 5.8 - and will remain so until the author
either releases the source code, or provides a ppm that is compatible with
perl 5.8.
You might be able to do what you want using the Win32 modules that are
provided with AS perl ....... it depends upon exactly what you're after.
If it's really important I would recommend contacting the author to find out
if a 5.8 release of Win32::AdminMisc is imminent.
Cheers,
Rob
------------------------------
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 4900
***************************************