[24433] in Perl-Users-Digest
Perl-Users Digest, Issue: 6617 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 27 18:05:45 2004
Date: Thu, 27 May 2004 15:05:06 -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 Thu, 27 May 2004 Volume: 10 Number: 6617
Today's topics:
Re: (repost) Math problem - converting between arbitrar <thundergnat@hotmail.com>
Re: Changing priority and overcoming kill <usenet@morrow.me.uk>
Handling Environmental variables (Satish)
Re: Handling Environmental variables <glex_nospam@qwest.invalid>
Re: Handling Environmental variables <gnari@simnet.is>
Re: How to Pattern match the keys in a hash <ashutosh.jog@pdf.com>
Re: How to Pattern match the keys in a hash <glex_nospam@qwest.invalid>
Re: How to Pattern match the keys in a hash <jtc@shell.dimensional.com>
Re: How to Pattern match the keys in a hash <ashutosh.jog@pdf.com>
Re: How to Pattern match the keys in a hash <jgibson@mail.arc.nasa.gov>
How to pattern match using capture to create a hash <ashutosh.jog@pdf.com>
Re: How to pattern match using capture to create a hash <noreply@gunnar.cc>
Re: How to pattern match using capture to create a hash (Greg Bacon)
Re: How to pattern match using capture to create a hash <noreply@gunnar.cc>
Re: How to pattern match using capture to create a hash <ashutosh.jog@pdf.com>
Re: Making sure that we're dealing with an array (refer <usenet@morrow.me.uk>
Re: Making sure that we're dealing with an array (refer <uri.guttman@fmr.com>
Re: perl hash speed and memory efficiency <jgibson@mail.arc.nasa.gov>
Re: perl hash speed and memory efficiency <usenet@morrow.me.uk>
Re: Perl work? <postmaster@castleamber.com>
Re: Running remote commands on Windows <domenico_discepola@quadrachemicals.com>
Re: Templating system needs help <dha@panix2.panix.com>
Re: Templating system needs help (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 27 May 2004 16:58:51 -0400
From: thundergnat <thundergnat@hotmail.com>
Subject: Re: (repost) Math problem - converting between arbitrary bases in perl - help!
Message-Id: <40b65688$0$3135$61fed72c@news.rcn.com>
! aaa wrote:
> I Posted earlier to Newsgroups: comp.lang.perl,alt.perl,alt.math,
> but this looks like the more appropriate place in hindsight...
>
>
> Hi all - I've been trying to write a small sub to convert form an input base
> (eg: 16) to an output base (eg:64) and back.
>
> The reason is that I need to communicate tristate (base 3) data efficiently
> via DNS (base 37 a-z0-9 and '-').
>
> I *could* do it by converting into a "bigmath binary" structure I guess, but
> I thought there might be a more elegant way...
>
> but such a solution eludes me.
>
> Can anyone think how to approach the problem?
>
Hmmm. I was intrigued and whomped this subroutine together to do base
conversions. I used your "digit" sequence but was having a hard time
following your logic, so I wrote the rest from scratch. It isn't as
efficient as it could be, but it works.
One comment on your script, whitespace is cheap, don't be afraid to use it.
Any lines in the subroutine that aren't indented at least 4 spaces are
part of the previous line. You may need to rejoin them for the script to
work. (News reader wrapping) I broke a few of the lines up to fit in
without wrapping.
#!/usr/bin/perl
use strict;
use warnings;
# Convert any arbitrary base number (up to base 94) to any other
# arbitrary base. Feed the subroutine the base of the existing number,
# the desired base and the the number to be converted. This will
# probably be inaccurate for anthing larger than 32 bit (or whatever
# your native integer is.) If you need larger numbers, you can probably
# adapt this to use Math::BigInt without too much pain.
print baseconvert( 16, 10, 'C0DECAFE' ), "\n";
sub baseconvert{
my ( $from_base, $to_base, $data) = @_;
my $digit_sequence = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'abcdefghijklmnopqrstuvwxyz!"#$%&\'()*+,-./:;<=>?@[\]^'.
'_`{|}~'; # 94 "digits"
my $from_digits = substr( $digit_sequence, 0, $from_base );
my $to_digits = substr( $digit_sequence, 0, $to_base );
my $number = '';
# convert to base 10 integer
my $integer = 0;
my @digit_array = reverse split //, $data;
for ( 0 .. $#digit_array ){
die "$data is not a valid base $from_base number."
if ( index( $from_digits, $digit_array[$_]) < 0 );
$integer +=
index( $from_digits, $digit_array[$_] ) * $from_base ** $_;
}
# then convert to arbitrary base
while ( $integer > 0 ){
my $digit = $integer % $to_base;
$number = substr( $to_digits, $digit, 1 ) . $number;
$integer = int( $integer / $to_base );
}
return $number;
}
------------------------------
Date: Thu, 27 May 2004 19:57:21 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Changing priority and overcoming kill
Message-Id: <c95h71$s9u$3@wisteria.csv.warwick.ac.uk>
Quoth " ! aaa" <ToGroun@NotTo.me>:
> 1. Is there a way to relinquish "root" privs in a script, or, some way to
> let a "nobody" script listen on ports <1024 easily ?
See perlvar, in particular $<, $>, $( and $).
See also your system documentation for setr?e?s?[ug]id.
Ben
--
I've seen things you people wouldn't believe: attack ships on fire off
the shoulder of Orion; I watched C-beams glitter in the dark near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die. ben@morrow.me.uk
------------------------------
Date: 27 May 2004 12:08:20 -0700
From: satishsanthanam@yahoo.com (Satish)
Subject: Handling Environmental variables
Message-Id: <d04d15e8.0405271108.4667d3df@posting.google.com>
Hi,
How do I set/unset unix environmental variables from a perl script?
thanks,
Satish
------------------------------
Date: Thu, 27 May 2004 14:19:32 -0500
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: Handling Environmental variables
Message-Id: <9brtc.131$Ri6.70556@news.uswest.net>
Satish wrote:
> Hi,
>
> How do I set/unset unix environmental variables from a perl script?
It's 'environment' variables. You operated on %ENV.
$ENV{'PATH'} .= ':/some/other/path';
foreach my $var (keys %ENV)
{
print $var, ':', $ENV{$var}, "\n";
}
------------------------------
Date: Thu, 27 May 2004 21:32:56 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Handling Environmental variables
Message-Id: <c95mmv$atg$1@news.simnet.is>
"J. Gleixner" <glex_nospam@qwest.invalid> wrote in message
news:9brtc.131$Ri6.70556@news.uswest.net...
> Satish wrote:
> > Hi,
> >
> > How do I set/unset unix environmental variables from a perl script?
>
> It's 'environment' variables. You operated on %ENV.
>
> $ENV{'PATH'} .= ':/some/other/path';
>
> foreach my $var (keys %ENV)
> {
> print $var, ':', $ENV{$var}, "\n";
> }
unless the OP is referring to
perldoc -q environment
gnari
------------------------------
Date: Thu, 27 May 2004 11:56:53 -0700
From: Ash <ashutosh.jog@pdf.com>
Subject: Re: How to Pattern match the keys in a hash
Message-Id: <10bcef4gfq0io6c@corp.supernews.com>
Hi....
So the suggested methods did not work. So I tried a new way of cpaturing
patterns. Here is my new stuff that I am trying to do. It should work,
but maybe I am doing something wrong.
I have a file which has entries like:
LT-T21-ABC-0000 user1
PC-R30-DEF-888 user2
etc..
I want to grab the left hand side machines named that end with 3 digits
and create a hash which would have entries like
PC-R30-DEF-888 user2 -----> (from the above file)
etc...
Here is my code: (please advice what I am doing wrong)
#!C:/Program~1/Perl/bin
$filea = "D:/scripts/super/wks_name_login.txt"; -->The file with entries
open (A, "<$filea") or die "$!\n";
while(<A>) {
chomp;
/^\s(\w-\w-\w-\d{3})\s* (.*)$/;
$fields{$1} = $2;
}
foreach $n (keys %fields) {
print "$n\n";
print "$n = $fields{$n}\n";
}
Any help is appreciated.
Thanks.
Ash wrote:
> Many Typos there....
>
> Here is what I meant:
> I have a hash which has machinename (as the key) and username (as the
> value). I want to do a pattern match on the machinenames (i.e. keys) in
> the hash to satisfy a certain naming convention.
>
> How can I do a pattern match on my hash keys (i.e. machinenames)and then
> print the key and value pair of newly matched machinenames and usernames
> to a file.
>
> Any help is appreciated.
>
> Thanks.
>
>
> Ash wrote:
>
>> Hi....
>>
>> I have a hash which has machinename (as the key) and username (as the
>> value). I want to do a pattern match on the machinenames (i.e. keys)
>> in the hash to satisfy a certain naming convention.
>>
>> How can I do a pattern match my hash keys (i.e. machinenames)and then
>> print the key and value pair of newly patched machinenames and
>> usernames to a file.
>>
>> Any help is appreciated.
>>
>> Thanks.
>>
>
------------------------------
Date: Thu, 27 May 2004 14:19:33 -0500
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: How to Pattern match the keys in a hash
Message-Id: <abrtc.132$Ri6.70614@news.uswest.net>
Ash wrote:
> Hi....
>
> So the suggested methods did not work. So I tried a new way of cpaturing
> patterns. Here is my new stuff that I am trying to do. It should work,
> but maybe I am doing something wrong.
Since this is a "new" question, and doesn't have anything to do with
matching the keys in a hash, don't reuse the subject and don't top post.
>
> I have a file which has entries like:
>
> LT-T21-ABC-0000 user1
> PC-R30-DEF-888 user2
> etc..
>
> I want to grab the left hand side machines named that end with 3 digits
> and create a hash which would have entries like
>
> PC-R30-DEF-888 user2 -----> (from the above file)
> etc...
>
> Here is my code: (please advice what I am doing wrong)
>
> #!C:/Program~1/Perl/bin
>
> $filea = "D:/scripts/super/wks_name_login.txt"; -->The file with entries
my $filea = 'D:/scripts/super/wks_name_login.txt';
>
> open (A, "<$filea") or die "$!\n";
open (A, "<$filea") or die "Can't open $filea: $!";
>
> while(<A>) {
>
> chomp;
>
> /^\s(\w-\w-\w-\d{3})\s* (.*)$/;
Only use $1 or $2, if you're sure it found a match. Also, ^\s means that
it starts with whitespace, I don't see that in your example data.
$fields{$1} = $2 if /^(\w-\w-\w-\d{3})\s*(.*)$/;
or
Or you could print $1 and $2, to ensure it's matching what you expect.
------------------------------
Date: 27 May 2004 13:19:43 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Re: How to Pattern match the keys in a hash
Message-Id: <slrncbcfql.vmm.jtc@shell.dimensional.com>
In article <10bcef4gfq0io6c@corp.supernews.com>, Ash wrote:
> Hi....
>
> So the suggested methods did not work. So I tried a new way of cpaturing
What do you mean "So the suggested methods did not work."? Probably you
either didn't understand them and made a mistake plugging them into your
code or you are not describing what you want to do accurately. I think
you're throwing away a good solution because you don't understand it.
A better choice would be to explain what you did and what went wrong in
enough detail that we can help you figure out what you're missing.
--
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]
------------------------------
Date: Thu, 27 May 2004 12:24:22 -0700
From: Ash <ashutosh.jog@pdf.com>
Subject: Re: How to Pattern match the keys in a hash
Message-Id: <10bcg2l5cv0ivf1@corp.supernews.com>
HI...
Ok Guys. I tried the suggested methods and gave up after a few tries. So
yes maybe I did not spend too much time on it. Anyway, I put in a new
post since the new method that I am trying (which is just listed) does
not pertain to my current post.
The new post has my code and better explaination of what I want to
achive. Your help would be appreciated.
Thanks
Jim Cochrane wrote:
> In article <10bcef4gfq0io6c@corp.supernews.com>, Ash wrote:
>
>>Hi....
>>
>>So the suggested methods did not work. So I tried a new way of cpaturing
>
>
> What do you mean "So the suggested methods did not work."? Probably you
> either didn't understand them and made a mistake plugging them into your
> code or you are not describing what you want to do accurately. I think
> you're throwing away a good solution because you don't understand it.
> A better choice would be to explain what you did and what went wrong in
> enough detail that we can help you figure out what you're missing.
>
>
------------------------------
Date: Thu, 27 May 2004 12:27:44 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: How to Pattern match the keys in a hash
Message-Id: <270520041227445981%jgibson@mail.arc.nasa.gov>
In article <abrtc.132$Ri6.70614@news.uswest.net>, J. Gleixner
<glex_nospam@qwest.invalid> wrote:
> Ash wrote:
[snip]
> >
> > I have a file which has entries like:
> >
> > LT-T21-ABC-0000 user1
> > PC-R30-DEF-888 user2
> > etc..
> >
> > I want to grab the left hand side machines named that end with 3 digits
> > and create a hash which would have entries like
> >
> > PC-R30-DEF-888 user2 -----> (from the above file)
> > etc...
> >
> > Here is my code: (please advice what I am doing wrong)
> >
> > #!C:/Program~1/Perl/bin
> >
> > $filea = "D:/scripts/super/wks_name_login.txt"; -->The file with entries
> my $filea = 'D:/scripts/super/wks_name_login.txt';
> >
> > open (A, "<$filea") or die "$!\n";
> open (A, "<$filea") or die "Can't open $filea: $!";
> >
> > while(<A>) {
> >
> > chomp;
> >
> > /^\s(\w-\w-\w-\d{3})\s* (.*)$/;
>
> Only use $1 or $2, if you're sure it found a match. Also, ^\s means that
> it starts with whitespace, I don't see that in your example data.
>
> $fields{$1} = $2 if /^(\w-\w-\w-\d{3})\s*(.*)$/;
or better, since there is more than one character in each field:
$fields{$1} = $2 if /^(\w+-\w+-\w+-\d{3})\s*(.*)$/;
>
> or
>
> Or you could print $1 and $2, to ensure it's matching what you expect.
------------------------------
Date: Thu, 27 May 2004 12:15:17 -0700
From: Ash <ashutosh.jog@pdf.com>
Subject: How to pattern match using capture to create a hash
Message-Id: <10bcfhjndqj3k46@corp.supernews.com>
hi....
I am trying to create a hash from data within a text file. The file has
entries like
LT-T21-ABC-0000 user1
PC-R30-DEF-888 user2
[Notice that there is a single 'space' before each line starts]
etc..
I want to be able to create a hash which would have the machinenames
that end with 3 digits instead of 4 as the keys and corresponding values
would be the usernames that are on the right hand side.
So my hash should look like:
PC-R30-DEF-888 user2
[This is the key] [this is the value]
etc..
I am trying to use pattern maching using capturing but somehow it is not
grabbing the right values. Maybe I am doing something wrong. Any
help/clarificaion is appreciated.
My code looks like this:
------------------------------------------------
#!C:/Program~1/Perl/bin
$filea = "D:/scripts/super/wks_name_login.txt"; -->The file with entries
open (A, "<$filea") or die "$!\n";
while(<A>) {
chomp;
/^\s(\w-\w-\w-\d{3})\s* (.*)$/; #So 3digit mc names on the left of
the spaces is the key (i.e. $1) and everything on the right of the space
is value (i.e. $2)
$fields{$1} = $2;
}
foreach $n (keys %fields) {
print "$n\n";
print "$n = $fields{$n}\n";
}
------------------------------------------------
Thanks.
------------------------------
Date: Thu, 27 May 2004 22:02:52 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to pattern match using capture to create a hash
Message-Id: <2hn00fFegme0U1@uni-berlin.de>
Ash wrote:
>
> LT-T21-ABC-0000 user1
> PC-R30-DEF-888 user2
> [Notice that there is a single 'space' before each line starts]
> etc..
<snip>
> /^\s(\w-\w-\w-\d{3})\s* (.*)$/;
That regex does not match because
1. \w does only match a single word character, while the entries
include groups of two or three word characters, and
2. it does not take care of the possible fourth digit.
You may want to try something like this:
/^\s*([-\w]+-\d{3})\d?\s+(.*)/;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 27 May 2004 20:16:12 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: How to pattern match using capture to create a hash
Message-Id: <10bcj4crt6mae58@corp.supernews.com>
In article <10bcfhjndqj3k46@corp.supernews.com>,
Ash <ashutosh.jog@pdf.com> wrote:
: I am trying to create a hash from data within a text file. The file has
: entries like
:
: LT-T21-ABC-0000 user1
: PC-R30-DEF-888 user2
:
: [Notice that there is a single 'space' before each line starts]
: etc..
Maybe there's a transmission problem, but I see two spaces at the
start of each line.
: [...]
: I am trying to use pattern maching using capturing but somehow it is not
: grabbing the right values. Maybe I am doing something wrong. Any
: help/clarificaion is appreciated.
:
: [...]
: /^\s(\w-\w-\w-\d{3})\s* (.*)$/;
: [...]
Your pattern is looking for a *single* word character followed by a
hyphen followed by a *single* word character and so on. Use the +
modifier to match one or more:
$ cat try
#!/usr/local/bin/perl -w
use strict;
use warnings;
my %field;
while (<DATA>) {
chomp;
if (/^\s{2}(\w+-\w+-\w+-\d{3})\s+(\S+)$/) {
$field{$1} = $2;
}
else {
warn "$0: line $.: no match for '$_'\n";
}
}
foreach my $n (keys %field) {
print "$n\n";
print "$n = $field{$n}\n";
}
__DATA__
LT-T21-ABC-0000 user1
PC-R30-DEF-888 user2
$ ./try
./try: line 1: no match for ' LT-T21-ABC-0000 user1'
PC-R30-DEF-888
PC-R30-DEF-888 = user2
$
Hope this helps,
Greg
--
I . . . am in favor of the race to which I belong having the superior
position. I have never said anything to the contrary.
-- Abraham Lincoln, allegedly great president (Ottawa Ill., Aug. 21, 1858)
------------------------------
Date: Thu, 27 May 2004 22:29:22 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to pattern match using capture to create a hash
Message-Id: <2hn1i6Fek9tbU1@uni-berlin.de>
Gunnar Hjalmarsson wrote:
>
> 2. it does not take care of the possible fourth digit.
>
> You may want to try something like this:
>
> /^\s*([-\w]+-\d{3})\d?\s+(.*)/;
-------------------------^^^
Please disregard that suggestion (I misunderstood the spec.). I rather
meant:
/^\s*([-\w]+-\d{3})\s+(.*)/;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 27 May 2004 14:05:17 -0700
From: Ash <ashutosh.jog@pdf.com>
Subject: Re: How to pattern match using capture to create a hash
Message-Id: <10bclvrrhggfn01@corp.supernews.com>
Great suggestions. It worked.
Thanks.
Greg Bacon wrote:
> In article <10bcfhjndqj3k46@corp.supernews.com>,
> Ash <ashutosh.jog@pdf.com> wrote:
>
> : I am trying to create a hash from data within a text file. The file has
> : entries like
> :
> : LT-T21-ABC-0000 user1
> : PC-R30-DEF-888 user2
> :
> : [Notice that there is a single 'space' before each line starts]
> : etc..
>
> Maybe there's a transmission problem, but I see two spaces at the
> start of each line.
>
> : [...]
> : I am trying to use pattern maching using capturing but somehow it is not
> : grabbing the right values. Maybe I am doing something wrong. Any
> : help/clarificaion is appreciated.
> :
> : [...]
> : /^\s(\w-\w-\w-\d{3})\s* (.*)$/;
> : [...]
>
> Your pattern is looking for a *single* word character followed by a
> hyphen followed by a *single* word character and so on. Use the +
> modifier to match one or more:
>
> $ cat try
> #!/usr/local/bin/perl -w
>
> use strict;
> use warnings;
>
> my %field;
>
> while (<DATA>) {
> chomp;
>
> if (/^\s{2}(\w+-\w+-\w+-\d{3})\s+(\S+)$/) {
> $field{$1} = $2;
> }
> else {
> warn "$0: line $.: no match for '$_'\n";
> }
> }
>
> foreach my $n (keys %field) {
> print "$n\n";
> print "$n = $field{$n}\n";
> }
>
> __DATA__
> LT-T21-ABC-0000 user1
> PC-R30-DEF-888 user2
>
> $ ./try
> ./try: line 1: no match for ' LT-T21-ABC-0000 user1'
> PC-R30-DEF-888
> PC-R30-DEF-888 = user2
>
> $
>
> Hope this helps,
> Greg
------------------------------
Date: Thu, 27 May 2004 19:46:02 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Making sure that we're dealing with an array (reference)
Message-Id: <c95ghq$s9u$1@wisteria.csv.warwick.ac.uk>
Quoth Tore Aursand <tore@aursand.no>:
>
> sub init {
> my %ARGS = @_;
>
> my $paths = $ARGS{'paths'} || [];
> }
>
> In the code above, I want $self->{'_paths'} to always be an array
> reference, even if $ARGS{'paths'} is just a plain string. How can I do
> this the best way?
>
> Currently, I'm stuck with code like this:
>
> my $paths = $ARGS{'paths'} || [];
> $paths = ( ref($paths) eq 'ARRAY' ) ? $paths : [ $paths ];
>
> It seems to work, though, but I feel that there's something wrong with
> this approach...?
You could always do
my $paths = $ARGS{paths} ? [ $ARGS{paths} ] : [];
or one of
my $paths = [ grep defined, $ARGS{paths} ];
my $paths = [ grep $_, $ARGS{paths} ];
Obviously this generalises:
my $paths = [ (grep defined, $ARGS{paths}, $ENV{MY_ENV})[0] ];
Ben
--
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
/Alcestis/) [ flame, and falls out of sight. ] ben@morrow.me.uk
------------------------------
Date: 27 May 2004 13:18:18 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: Making sure that we're dealing with an array (reference)
Message-Id: <li8yfdrdph.fsf@localhost.localdomain>
>>>>> "TA" == Tore Aursand <tore@aursand.no> writes:
TA> Currently, I'm stuck with code like this:
TA> my $paths = $ARGS{'paths'} || [];
TA> $paths = ( ref($paths) eq 'ARRAY' ) ? $paths : [ $paths ];
TA> It seems to work, though, but I feel that there's something wrong with
TA> this approach...?
i do the same thing in many places. nothing i know to simplify it.
uri
------------------------------
Date: Thu, 27 May 2004 12:46:57 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: perl hash speed and memory efficiency
Message-Id: <270520041246575160%jgibson@mail.arc.nasa.gov>
In article <de652f7.0405270950.1d0078b8@posting.google.com>, odigity
<ofer@netapt.com> wrote:
> I'm running some tests to try to gauge the speed of perl's hashing
> abilities, as well as the memory footprint. I wrote this function:
>
> sub buildhash
> {
> my %hash;
> foreach my $foo (1..100_000) {
> foreach my $bar ('a'..'z') {
> $hash{"$foo.$bar"} = 1;
> }
> }
> undef %hash;
> }
>
> Then I threw in the Benchmark module, like this:
>
> timethis( 1, "buildhash()" );
>
> It seems to use about 200MB of memory for 2.6 million small key/value
> pairs, which is pretty efficient (~80bytes/pair). However, it doesn't
> release the memory after the undef (I checked by stopping execution at
> that point with a sleep statement and studying memory usage with
> `ps`).
>
> It either takes 11 seconds or 75 seconds depending on how I execute
> it. Let me explain.
>
> I first tried running it once, and it took 11 seconds. I tried twice,
> and it took 86. This didn't make any sense to me. Here's the command
> I used:
>
> timethis( 2, "buildhash()" );
>
> Then I tried unrolling it like this:
>
> timethis( 1, "buildhash()" );
> timethis( 1, "buildhash()" );
>
> And that took 22 seconds (11/each), as I expected the first time.
>
> So the question that is most driving me crazy is: For the sake of
> Pete, why the difference!?
>
> -ofer
On my system[1], timethis(1,"buildhash()") took 170 sec. and
timethis(2,"buildhash()") took 337 sec., so there must be something
else going on here.
[1]: Mac G4 800MHz PPC, Mac OS X 10.2.8, perl 5.8.2 built for darwin.
------------------------------
Date: Thu, 27 May 2004 19:50:23 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: perl hash speed and memory efficiency
Message-Id: <c95gpv$s9u$2@wisteria.csv.warwick.ac.uk>
Quoth ofer@netapt.com (odigity):
> I'm running some tests to try to gauge the speed of perl's hashing
> abilities, as well as the memory footprint. I wrote this function:
>
> sub buildhash
> {
> my %hash;
> foreach my $foo (1..100_000) {
> foreach my $bar ('a'..'z') {
> $hash{"$foo.$bar"} = 1;
> }
> }
> undef %hash;
There is no need for this. %hash will be deallocated at end-of-scope.
> }
>
> Then I threw in the Benchmark module, like this:
>
> timethis( 1, "buildhash()" );
>
> It seems to use about 200MB of memory for 2.6 million small key/value
> pairs, which is pretty efficient (~80bytes/pair). However, it doesn't
> release the memory after the undef (I checked by stopping execution at
> that point with a sleep statement and studying memory usage with
> `ps`).
<sigh>
Under most circumstances, memory once allocated to a process can never
be released. The memory goes into a process-internal free pool, so if
you were to run the sub again memory usage would not go up any further.
Ben
--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
ben@morrow.me.uk
------------------------------
Date: Thu, 27 May 2004 16:59:17 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Perl work?
Message-Id: <40b664b6$0$206$58c7af7e@news.kabelfoon.nl>
Thomas Kratz wrote:
> Jim Cochrane wrote:
>
>> one of the most-recommended Perl books has a picture of a camel on it,
>> eh?
>
> No a dromedary ;-)
Which is just a camel :-D.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
------------------------------
Date: Thu, 27 May 2004 15:42:33 -0400
From: "Domenico Discepola" <domenico_discepola@quadrachemicals.com>
Subject: Re: Running remote commands on Windows
Message-Id: <4vrtc.46741$kc2.708406@nnrp1.uunet.ca>
"Filipe Bonjour" <fb@i.am.nowhere.net> wrote in message
news:pan.2004.05.21.17.53.16.90199@i.am.nowhere.net...
> Hi,
>
> I'm writing a series of scripts to be run on a Windows 2000 server to
> control applications on a series of other Windows servers.
So am I (or trying to)...
>
> I tried to find both generic modules for launching commands remotely (e.g.
> Net::Rsh) or more specific modules (e.g. Win32::Process) but I haven't
> found anything 100% satisfactory. I also thought of building a small
> daemon running on the remote servers that would accepts requests, run
> tlist.exe and return the reply. (I was thinking Net::Daemon, because I
> don't know enough about Windows to write a server in C).
The only application I found was psexec.exe available from sysinternals. I
would prefer a complete Perl solution (without a system call to an external
program like psexec, or having to install telnet or ssh servers). Please
update us on the newsgroup if you have found something.
Regards,
Domenico
------------------------------
Date: Thu, 27 May 2004 18:17:44 +0000 (UTC)
From: "David H. Adler" <dha@panix2.panix.com>
Subject: Re: Templating system needs help
Message-Id: <slrncbcc68.l3u.dha@panix2.panix.com>
On 2004-05-27, Tore Aursand <tore@aursand.no> wrote:
> On Thu, 27 May 2004 10:32:32 +0000, Anno Siegel wrote:
>>> For the record: If I ever finishes this module, and it works as
>>> expected, I will - of course - release it to CPAN. Name suggestions,
>>> anyone? :)
>
>> No. Writing modules is easy. Naming modules is hard. :)
>
> Haha. Excellent point, Anno. May I add that statement to my signature
> collection?
And if Tore may, may I? :-)
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
I bet if I cover my ears, this sounds a *lot* less like crap.
- Tim Jones, http://www.bobbins.org/d/20000918.html
------------------------------
Date: 27 May 2004 18:34:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Templating system needs help
Message-Id: <c95car$dg4$1@mamenchi.zrz.TU-Berlin.DE>
Tore Aursand <tore@aursand.no> wrote in comp.lang.perl.misc:
> On Thu, 27 May 2004 10:32:32 +0000, Anno Siegel wrote:
> >> For the record: If I ever finishes this module, and it works as
> >> expected, I will - of course - release it to CPAN. Name suggestions,
> >> anyone? :)
>
> > No. Writing modules is easy. Naming modules is hard. :)
>
> Haha. Excellent point, Anno. May I add that statement to my signature
> collection?
Sure.
It's true, though. There are a lot of unrelated and partially
conflicting considerations that pertain to naming.
The name should be short and to the point.
The phrases "use <name>", and possibly "no <name>" should make sense.
Possible parameters should go well after "use <name> ...".
The name must fit in the existing CPAN hierarchy. That makes is long
and redundant.
The existing hierarchy is not entirely perspicuous.
There are often multiple places where a given module could go.
Choosing a place is a bit like staking out a claim in the name space,
especially if you have plans for the future.
You want to put the module where it belongs.
You want to put the module where people will find it.
The decision, once made, it hard to revise. Even before release,
a change is a coordinated action of renaming files, changing the
content of (these and other) files accordingly, and explaining
to CVS (or whatever) that you have had second thoughts. After
release the name is hewn in stone.
Anno
------------------------------
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 6617
***************************************