[23981] in Perl-Users-Digest
Perl-Users Digest, Issue: 6182 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 23 09:05:50 2004
Date: Mon, 23 Feb 2004 06:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 23 Feb 2004 Volume: 10 Number: 6182
Today's topics:
Re: (most probably) OT: /dev/random and /dev/urandom (Villy Kruse)
Re: Compatibility of perl on different HPUX-Versions <h.m.brand@hccnet.nl>
Re: Configuration question <Joe.Smith@inwap.com>
Re: finding common words <noreply@gunnar.cc>
Re: finding common words (viv2k)
Re: finding common words <tore@aursand.no>
Re: finding common words <noreply@gunnar.cc>
Re: finding common words <noreply@gunnar.cc>
Re: finding common words <matthew.garrish@sympatico.ca>
How to use different PM in different cases. <pengtaoli@hotmail.com>
Re: How to use different PM in different cases. <noreply@gunnar.cc>
how to use the pm in other location instead of current <pengtaoli@hotmail.com>
Perl + FTP + Windows -- Unable to capture the rate of D (Anand Kumar V)
Re: Perl + FTP + Windows -- Unable to capture the rate $_@_.%_
Re: Perl complex data structure ... how to get more fle <tassilo.parseval@rwth-aachen.de>
Re: perl fileio <Joe.Smith@inwap.com>
Re: Protecting Source code of a perl script <ian.cass@mblox.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Feb 2004 08:25:12 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: (most probably) OT: /dev/random and /dev/urandom
Message-Id: <slrnc3je78.huf.vek@station02.ohout.pharmapartners.nl>
On 22 Feb 2004 15:55:11 GMT,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>Michele Dondi <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
>> I apologize in advance for posting this question that I feel is most
>> probably OT (if it actually is OT). I have this small script:
>>
>> #!/usr/bin/perl
>>
>> use strict;
>> use warnings;
>>
>> $/=\0x100_000;
>> open my $fh, '<:raw', '/dev/urandom' or die $!;
>> print scalar <$fh>;
>>
>> __END__
>>
>> If I run it I get:
>>
>> # ./foo.pl | wc -c
>> 1048576
>
>...as expected.
>
>[...]
>
>> If I change /dev/urandom to /dev/random, then I get:
>>
>> # ./foo.pl | wc -c
>> 89
>
>That behavior is wrong. The only difference in /dev/urandom and /dev/random
>is that random may block when it runs out of entropy while urandom continues
>to deliver random data of lower quality. Stick to urandom until the other
>can be repaired.
>
However, if there are at least one byte available in /dev/random then
I would expect that the read call would return the available bytes
and only blocks when no bytes are available. Tha is the behaviour you
get when reading from a pipe or a socket.
Villy
------------------------------
Date: Mon, 23 Feb 2004 13:01:24 +0100
From: "H. Merijn Brand" <h.m.brand@hccnet.nl>
To: comp.lang.perl.misc
Subject: Re: Compatibility of perl on different HPUX-Versions
Message-Id: <Xns9498847B477FDMerijn@192.0.1.90>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in news:c15muk$l05$3
@mamenchi.zrz.TU-Berlin.DE:
> Alex F. <v2af@yahoo.de> wrote in comp.lang.perl.misc:
>> Hi folks,
>>
>> is it possible to call perl running on HPUX11.xy from a
>> HPUX10.xy-machine
No, unless the perl binary on 11.x is compiled with +DAportable (HP C-ANSI-C)
or with -mpa-risc-1-1 (GNU gcc) and even then, there is no guarantee it'll
work. It will work the other way round: calling a 10.20 binary from 11.x
It will never work if you call from itanium to pa-risc or vise versa
>> - donīt care which perl-version and which modules,
>> just the perl-exe itself...
>
> That would be better asked in a HPUX group. The perl binary isn't special,
> I'd expect it to behave like other binaries.
>
> Anno
>
--
H.Merijn Brand Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)
using perl-5.6.1, 5.8.0 & 633 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
WinNT 4, Win2K pro & WinCE 2.11 often with Tk800.024 &/| DBD-Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
------------------------------
Date: Mon, 23 Feb 2004 08:29:02 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Configuration question
Message-Id: <hRi_b.41822$Xp.190189@attbi_s54>
chatiman wrote:
> do doesn't reexport variables set from a files if I remember.
I'd say you remember incorrectly.
do $file or die "Unable to process $file - $!";
Does not import() or export() anything; variables are
added to the current symbol table directly.
-Joe
------------------------------
Date: Mon, 23 Feb 2004 09:27:04 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: finding common words
Message-Id: <c1ce1g$1dm3ar$1@ID-184292.news.uni-berlin.de>
David K. Wall wrote:
> How about this?
>
> my %ListA = ( apple => 1.1, banana => 2.2, cat => 3.3 );
> my %ListB = ( apple => 100, boy => 500, cat => 1000 );
> my (%count, @intersection);
> for my $element (keys %ListA, keys %ListB) {
> push @intersection, $element if ++$count{$element} > 1;
> }
> my (%new_ListA, %new_ListB);
> @new_ListA{@intersection} = @ListA{@intersection};
> @new_ListB{@intersection} = @ListB{@intersection};
>
> It's a bit different from the FAQ, but was directly inspired by
> it... <shrug>
I still don't think that the FAQ approach is good here. The FAQ deals
with arrays, and since we are starting with hashes here, you'd better
take advantage of the ability to look up elements in a hash.
> If memory is a consideration
The FAQ approach is indeed memory expensive. OP mentioned "two very
long lists of words", and this solution creates 6(!) variables with
lists: %ListA, %ListB, %count, @intersection, %new_ListA and
%new_ListB.
> I'd go with deleting the non-intersecting elements. Neat idea, and
> one that didn't occur to me.
If you want to keep the original hashes intact, I personally find
Matt's solution to be the neatest.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 23 Feb 2004 01:37:13 -0800
From: viv2k@hotmail.com (viv2k)
Subject: Re: finding common words
Message-Id: <6fd673b3.0402230137.54604d5e@posting.google.com>
Thanks for the tips. But does that mean I will have to manually write
and create the two lists before comparing them?
Because my list is actually a txt file where after each word there is
a space and then the number associated and then a comma and then the
next word and so on. Example:
apple 1.1, banana 2.2, cat 3.3, etc
Is there a way of taking the whole text file as input and using
'space' and 'comma' as delimiters to do the task?
Thanks
viv
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<c1b7qa$1fpfks$1@ID-184292.news.uni-berlin.de>...
> my %ListA = ( apple => 1.1, banana => 2.2, cat => 3.3 );
> my %ListB = ( apple => 100, boy => 500, cat => 1000 );
>
> for (keys %ListA) {
> delete $ListA{$_} unless exists $ListB{$_};
> }
> for (keys %ListB) {
> delete $ListB{$_} unless exists $ListA{$_};
> }
>
> print "ListA\n";
> print "$_\t$ListA{$_}\n" for sort keys %ListA;
> print "\n";
> print "ListB\n";
> print "$_\t$ListB{$_}\n" for sort keys %ListB;
------------------------------
Date: Mon, 23 Feb 2004 10:48:12 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: finding common words
Message-Id: <pan.2004.02.23.09.45.46.801097@aursand.no>
On Sun, 22 Feb 2004 13:20:54 -0800, viv2k wrote:
> ListA ListB
>
> apple 1.1 apple 100
> banana 2.2 boy 500
> cat 3.3 cat 1000
>
> And I want the result to look something like:
>
> ListA ListB
> apple 1.1 apple 100
> cat 3.3 cat 1000
You have probably already seen a few very good solutions from other
people, but I thought I would give you mine;
my %ListA = ( apple => 1.1, banana => 2.2, cat => 3.3 );
my %ListB = ( apple => 100, boy => 500, cat => 1000 );
my @common = grep { $ListB{$_} } keys %ListA;
for ( sort @common ) {
print "$_\t$ListA{$_}\t$_\t$ListB{$_}\n";
}
Anything wrong with this one? I thought about using 'map' for the 'grep'
part above, but couldn't find a nice way to have it _not_ return anything
when there's no match, ie;
my @common = map { (exists $ListB{$_}) ? $_ : undef } keys %ListA;
foreach ( sort @common ) {
next unless defined;
# ...
}
Comments/suggestions/corrections are appreciated!
--
Tore Aursand <tore@aursand.no>
"Writing is a lot like sex. At first you do it because you like it.
Then you find yourself doing it for a few close friends and people you
like. But if you're any good at all, you end up doing it for money."
-- Unknown
------------------------------
Date: Mon, 23 Feb 2004 11:18:41 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: finding common words
Message-Id: <c1ckja$1h59e6$1@ID-184292.news.uni-berlin.de>
[ Please respond below the quoted text. ]
viv2k wrote:
> Thanks for the tips. But does that mean I will have to manually
> write and create the two lists before comparing them?
Only if they are only on a sheet of paper, or something. :)
> Because my list is actually a txt file where after each word there
> is a space and then the number associated and then a comma and then
> the next word and so on. Example:
>
> apple 1.1, banana 2.2, cat 3.3, etc
>
> Is there a way of taking the whole text file as input and using
> 'space' and 'comma' as delimiters to do the task?
Yes, of course. Assuming that neither the words nor the numbers can
include spaces, this is one way:
my %ListA;
open my $fh, '< ListA.txt' or die "Couldn't open ListA.txt $!";
while (<$fh>) {
for (split /,\s*/) {
my ($key, $value) = split;
$ListA{$key} = $value;
}
}
close $fh;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 23 Feb 2004 11:29:42 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: finding common words
Message-Id: <c1cl81$1h0mb3$1@ID-184292.news.uni-berlin.de>
Tore Aursand wrote:
> You have probably already seen a few very good solutions from other
> people, but I thought I would give you mine;
>
> my %ListA = ( apple => 1.1, banana => 2.2, cat => 3.3 );
> my %ListB = ( apple => 100, boy => 500, cat => 1000 );
> my @common = grep { $ListB{$_} } keys %ListA;
> for ( sort @common ) {
> print "$_\t$ListA{$_}\t$_\t$ListB{$_}\n";
> }
<snip>
> Comments/suggestions/corrections are appreciated!
Nice. :)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 23 Feb 2004 07:58:07 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: finding common words
Message-Id: <vNm_b.2602$253.345793@news20.bellglobal.com>
"Tore Aursand" <tore@aursand.no> wrote in message
news:pan.2004.02.23.09.45.46.801097@aursand.no...
> On Sun, 22 Feb 2004 13:20:54 -0800, viv2k wrote:
> > ListA ListB
> >
> > apple 1.1 apple 100
> > banana 2.2 boy 500
> > cat 3.3 cat 1000
> >
> > And I want the result to look something like:
> >
> > ListA ListB
> > apple 1.1 apple 100
> > cat 3.3 cat 1000
>
> You have probably already seen a few very good solutions from other
> people, but I thought I would give you mine;
>
> my %ListA = ( apple => 1.1, banana => 2.2, cat => 3.3 );
> my %ListB = ( apple => 100, boy => 500, cat => 1000 );
> my @common = grep { $ListB{$_} } keys %ListA;
> for ( sort @common ) {
> print "$_\t$ListA{$_}\t$_\t$ListB{$_}\n";
> }
>
> Anything wrong with this one? I thought about using 'map' for the 'grep'
> part above, but couldn't find a nice way to have it _not_ return anything
> when there's no match, ie;
>
> my @common = map { (exists $ListB{$_}) ? $_ : undef } keys %ListA;
> foreach ( sort @common ) {
> next unless defined;
> # ...
> }
>
I like your first solution (I wasn't thinking about *not* using a hash,
myself). As for the second, the best way I can see to use map would be
without checking the return value:
my @common;
map { push @common, $_ if exists $ListB{$_} } keys %ListA;
Matt
------------------------------
Date: Mon, 23 Feb 2004 16:46:04 +0800
From: "Franklin Lee" <pengtaoli@hotmail.com>
Subject: How to use different PM in different cases.
Message-Id: <c1cel0$mti@netnews.proxy.lucent.com>
Hi ALl,
I have two different libs:
/opt/myapp/lib1/utils.pm
/opt/myapp/lib2/utils.pm
In the main program, I will get parameter, for example, $lib.
If $lib eq lib1, then I want to use /opt/myapp/lib1/utils.pm
If $lib eq lib2, then I want to use /opt/myapp/lib2/utils.pm
How can I design my program?
Thank you!
Franklin
------------------------------
Date: Mon, 23 Feb 2004 10:08:30 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to use different PM in different cases.
Message-Id: <c1cgfc$1gu0kj$1@ID-184292.news.uni-berlin.de>
Franklin Lee wrote:
> I have two different libs:
> /opt/myapp/lib1/utils.pm
> /opt/myapp/lib2/utils.pm
>
> In the main program, I will get parameter, for example, $lib.
>
> If $lib eq lib1, then I want to use /opt/myapp/lib1/utils.pm
>
> If $lib eq lib2, then I want to use /opt/myapp/lib2/utils.pm
>
> How can I design my program?
require "/opt/myapp/$lib/utils.pm";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 23 Feb 2004 17:36:22 +0800
From: "Franklin Lee" <pengtaoli@hotmail.com>
Subject: how to use the pm in other location instead of current one.
Message-Id: <c1chj9$n7c@netnews.proxy.lucent.com>
Hi All,
Now I have some pl and pm files in /opt/myapp/bin.
But some pm (the same name with previous) may exit dir /opt/myapp/newbin.
If this dir exist, I want to use the pm in it.
So I write below codes:
/opt/myapp/bin/app.pl
**********************************************
BEGIN {
if(-r /opt/myapp/newbin) {
unshift(@INC, "/opt/myapp/newbin");
} else {
unshift(@INC, "/opt/myapp/bin");
}
}
#my code begin....
require "mymodule.pm";
use strict;
....
***************************************************
It seems work. The program load the PM in /opt/myapp/newbin/mymodule.pm.
But I don't see this kind of example some where.
So I want to know if it is a good one orthere exist better solution?
Thank you!
Franklin
------------------------------
Date: 23 Feb 2004 01:52:43 -0800
From: anand_rectian@yahoo.co.in (Anand Kumar V)
Subject: Perl + FTP + Windows -- Unable to capture the rate of Data Transfer.
Message-Id: <8525036.0402230152.52fd0b58@posting.google.com>
Hi,
I want to write a Perl code which does FTP to a server, does data
transfer in both directions (get and put) and capture the rates in
which data is getting transfered.
I got the FTP module Net::FTP to open, get and put the files. But I am
not able to capture the data rate in the Perl Module. Is there any
method that supports this feature ?.
The data rate (speed) is displayed normally when you run a FTP client
in Windows platform.
Regards
Anand.
------------------------------
Date: Mon, 23 Feb 2004 11:31:47 GMT
From: $_@_.%_
Subject: Re: Perl + FTP + Windows -- Unable to capture the rate of Data Transfer.
Message-Id: <Dwl_b.71531$KV5.10804@nwrdny01.gnilink.net>
>
>Hi,
>
>I want to write a Perl code which does FTP to a server, does data
>transfer in both directions (get and put) and capture the rates in
>which data is getting transfered.
>
>I got the FTP module Net::FTP to open, get and put the files. But I am
>not able to capture the data rate in the Perl Module. Is there any
>method that supports this feature ?.
>
>The data rate (speed) is displayed normally when you run a FTP client
>in Windows platform.
>
>Regards
>Anand.
Hash - If given a reference to a file handle (e.g., "\*STDERR"),
print hash marks (#) on that filehandle every 1024 bytes. This
simply invokes the "hash()" method for you, so that hash marks are
displayed for all transfers. You can, of course, call "hash()"
explicitly whenever you'd like.
------------------------------
Date: 23 Feb 2004 08:12:42 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Perl complex data structure ... how to get more flexible access? how to avoid eval?
Message-Id: <c1cclq$6ji$1@nets3.rz.RWTH-Aachen.DE>
Also sprach valued customer:
> ### QUESTION
> You have a complex perl data structure that you want to access using a
> flexible 'xpath-like' syntax supplied in a simple string. How can this
> be done elegantly??
>
> ### EXAMPLE
> Suppose you have a perl data structure that looks something like this
> ...
>
> $news = {};
> $news->{top_stories} = ##* ... code-omitted ...*;
> $news->{sports} = ##* ... code-omitted ...*;
> $news->{weather} = ##* ... code-omitted ...*
>
> You can infer what the omitted parts look like from the following
> sample data nodes ...
>
> ### get stuff about todays top story
> print $news->{top_stories}[0]{headline};
> print $news->{top_stories}[0]{bodytext};
>
> ### get stuff about the weather
> print $news->{weather}{forecast}[3]{temp}; ## forecast day 3
> print $news->{weather}{current}{temp};
>
> ### PROBLEM DETAILS
> How do you allow a user to arbitrarily access any single data node of
> any arbitrary depth in the data structure, simply by specifying a
> single query string?
>
> eg; 'news/top_stories/[0]/headline'
> eg; 'news/weather/current/temp'
> eg; 'news/weather/forecast/[2]/temp'
> eg; 'news/classifieds/for_sale/vehicles/trucks/[12]/asking_price'
>
> Is there a more elegant solution than splitting the string,
> concatenating
> and then doing 'eval'? Dereferencing with '${}' does not seem flexible
> enough because
> the application does not know in advance how many 'path steps' the
> user will
> supply in the query string. Is there an XPath-like syntax module
> available, or an alternative approach?
You will certainly have to split them. There is no way around that.
However, you can do without string-eval. Here's what a find() function
would look like:
my $news;
$news->{top_stories}[0]{headline} = "bla";
print find($news, "top_stories/[0]/headline");
sub find {
my ($ref, $path) = @_;
return $ref if not ref $ref and not $path;
return if not ref $ref;
my ($branch, $remain) = split /\//, $path, 2;
find ($branch =~ /\[(.*)\]/ ? $ref->[$1]
: $ref->{$branch},
$remain);
}
Depending on where your path comes from, I'd still use string-eval
though because it will give better performance than calling a function
and recursing into it.
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: Mon, 23 Feb 2004 09:03:38 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: perl fileio
Message-Id: <Klj_b.246083$U%5.1696877@attbi_s03>
toylet wrote:
> That depends on how you use the word server. Anyway, I don't want to
> expand thhis sub-thread, pls.
>
> I was worrying about perl's memory management related to
> $buffer=<INFILE>, which quite on-topic I beleive.
When you run programs from the C:\> prompt, your PC is not running
in a client/server mode. Here is a command-line program you can
run without a server:
C:\>perl -le "$_=1;while(1){print length;$_.=$_;}"
It will give a hint to the question "what's the biggest string perl can
handle on my computer".
-Joe
------------------------------
Date: Mon, 23 Feb 2004 10:02:12 GMT
From: "Ian Cass" <ian.cass@mblox.com>
Subject: Re: Protecting Source code of a perl script
Message-Id: <Eck_b.47$5V7.833760@news-text.cableinet.net>
chatiman wrote:
> How does PAR protect source code ? From the web site I see that it
> create a zipped archive of the source code. Does it do more that
> simply compressing the code ?
http://search.cpan.org/~autrijus/PAR-0.79/lib/PAR/Filter.pm
--
Ian Cass
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6182
***************************************