[30915] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2160 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 26 18:09:44 2009

Date: Mon, 26 Jan 2009 15:09:13 -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, 26 Jan 2009     Volume: 11 Number: 2160

Today's topics:
        How to remove a module from CPAN? <Steve.Roscio@hp.com>
    Re: How to remove a module from CPAN? sln@netherlands.com
    Re: How to remove a module from CPAN? (Randal L. Schwartz)
    Re: How to remove a module from CPAN? sln@netherlands.com
        I need a job in C/C++/Perl immediately. Telecomute only sln@netherlands.com
    Re: I need a job in C/C++/Perl immediately. Telecomute  <tadmc@seesig.invalid>
    Re: I need a job in C/C++/Perl immediately. Telecomute  sln@netherlands.com
    Re: inputting the ephemerides <tadmc@seesig.invalid>
    Re: inputting the ephemerides <tadmc@seesig.invalid>
    Re: inputting the ephemerides <larry@example.invalid>
    Re: inputting the ephemerides sln@netherlands.com
    Re: inputting the ephemerides <larry@example.invalid>
    Re: inputting the ephemerides sln@netherlands.com
    Re: inputting the ephemerides <tadmc@seesig.invalid>
    Re: inputting the ephemerides <tadmc@seesig.invalid>
    Re: Which is faster - hash or array lookup xhoster@gmail.com
    Re: Which is faster - hash or array lookup sln@netherlands.com
    Re: Which is faster - hash or array lookup xhoster@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 26 Jan 2009 14:21:31 -0700
From: Steve Roscio <Steve.Roscio@hp.com>
Subject: How to remove a module from CPAN?
Message-Id: <gll9gt$jp$1@usenet01.boi.hp.com>

Howdy -

First, this should probably be posted on c-l-p-modules but there's near
zero activity in that newsgroup.  So I'm posting here.

My question: How can I remove one of my modules from CPAN?  I don't mean
a module I installed using CPAN, but from CPAN.org itself.   Do I delete
it from PAUSE?  Nothing there indicates that it'll go away from CPAN if
I do that.

Thanx!
- Steve


------------------------------

Date: Mon, 26 Jan 2009 21:43:42 GMT
From: sln@netherlands.com
Subject: Re: How to remove a module from CPAN?
Message-Id: <sdbsn45rpnpeassg8e4e48cd1kprirbp1s@4ax.com>

On Mon, 26 Jan 2009 14:21:31 -0700, Steve Roscio <Steve.Roscio@hp.com> wrote:

>Howdy -
>
>First, this should probably be posted on c-l-p-modules but there's near
>zero activity in that newsgroup.  So I'm posting here.
>
>My question: How can I remove one of my modules from CPAN?  I don't mean
>a module I installed using CPAN, but from CPAN.org itself.   Do I delete
>it from PAUSE?  Nothing there indicates that it'll go away from CPAN if
>I do that.
>
>Thanx!
>- Steve

Whoah, from CPAN itself, public domain.  I often (well sometimes) wonder how
do I remove 'sln' from newsgroups, so to keep anonymininindtmy when I apply
for secret security clearences with the Federal gubbment (CIA) and all.

I guess your fucked !!!
hahahahahahaaaaaaaaaaaaaaaaaaaaaaaa

sln


------------------------------

Date: Mon, 26 Jan 2009 13:47:00 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Steve Roscio <Steve.Roscio@hp.com>
Subject: Re: How to remove a module from CPAN?
Message-Id: <86r62peo4r.fsf@blue.stonehenge.com>

>>>>> "Steve" == Steve Roscio <Steve.Roscio@hp.com> writes:

Steve> My question: How can I remove one of my modules from CPAN?  I don't mean
Steve> a module I installed using CPAN, but from CPAN.org itself.   Do I delete
Steve> it from PAUSE?  Nothing there indicates that it'll go away from CPAN if
Steve> I do that.

Yes.  Delete it using PAUSE, and it takes 3 days to propogate as I recall.

Of course, BackPAN will hold it forever.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


------------------------------

Date: Mon, 26 Jan 2009 22:13:28 GMT
From: sln@netherlands.com
Subject: Re: How to remove a module from CPAN?
Message-Id: <hadsn4tcv250637q0h9g7crhiilk5836gm@4ax.com>

On Mon, 26 Jan 2009 13:47:00 -0800, merlyn@stonehenge.com (Randal L. Schwartz) wrote:

>>>>>> "Steve" == Steve Roscio <Steve.Roscio@hp.com> writes:
>
>Steve> My question: How can I remove one of my modules from CPAN?  I don't mean
>Steve> a module I installed using CPAN, but from CPAN.org itself.   Do I delete
>Steve> it from PAUSE?  Nothing there indicates that it'll go away from CPAN if
>Steve> I do that.
>
>Yes.  Delete it using PAUSE, and it takes 3 days to propogate as I recall.
>
>Of course, BackPAN will hold it forever.

BackPAN, I'm rolling on the floor in laughter !!!!!!!!

sln


------------------------------

Date: Mon, 26 Jan 2009 21:24:28 GMT
From: sln@netherlands.com
Subject: I need a job in C/C++/Perl immediately. Telecomute only. Full-Time. Regex/XML/Database/Parsing(et all) Expert. Will work for 60k the first year guaranteed !!
Message-Id: <gr9sn4978o27l9nkhdmrfpa145ghsglcg2@4ax.com>

$txt = "i need a job rast";
$txt =~ s/rast/fast/;

Perl related. Extensive experience, BS degree, some medical school,
some general genious. IQ ~ 160+, sex ok  (sometimes), driven (when off meds).

Will work for food if it comes to that.

sln


------------------------------

Date: Mon, 26 Jan 2009 16:00:51 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: I need a job in C/C++/Perl immediately. Telecomute only. Full-Time. Regex/XML/Database/Parsing(et all) Expert. Will work for 60k the first year guaranteed !!
Message-Id: <slrngnsckj.q56.tadmc@tadmc30.sbcglobal.net>

sln@netherlands.com <sln@netherlands.com> wrote:

> Subject: I need a job in C/C++/Perl immediately. 


I guess your fucked !!!
hahahahahahaaaaaaaaaaaaaaaaaaaaaaaa


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Mon, 26 Jan 2009 22:24:46 GMT
From: sln@netherlands.com
Subject: Re: I need a job in C/C++/Perl immediately. Telecomute only. Full-Time. Regex/XML/Database/Parsing(et all) Expert. Will work for 60k the first year guaranteed !!
Message-Id: <20esn4d2nuf52qgktad0hu60td2p7ks3pe@4ax.com>

On Mon, 26 Jan 2009 16:00:51 -0600, Tad J McClellan <tadmc@seesig.invalid> wrote:

>sln@netherlands.com <sln@netherlands.com> wrote:
>
>> Subject: I need a job in C/C++/Perl immediately. 
>
>
>I guess your fucked !!!
>hahahahahahaaaaaaaaaaaaaaaaaaaaaaaa

I wouldn't work for you if you were the last employer on earth !!!

sln



------------------------------

Date: Mon, 26 Jan 2009 15:43:35 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: inputting the ephemerides
Message-Id: <slrngnsbk7.pvs.tadmc@tadmc30.sbcglobal.net>

Larry Gates <larry@example.invalid> wrote:


>    my @s = split / /, $line;


> Can I make a better split to include fields with only digits or characters?


Yes. And the "better split" was already provided in a different thread.

Does this sound familiar?

   You are using the pattern / / which will not work correctly...

   will have *two* spaces in front of it.  You need to use the 
   special split pattern ' ' instead:

   perl -le'print for ( split " ", localtime 1231358400 )[1,2,4]'


ie.

   my @s = split ' ', $line;
or
   my @s = split / +/, $line;
or
   my @s = split /\s+/, $line;

as appropriate.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Mon, 26 Jan 2009 15:57:48 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: inputting the ephemerides
Message-Id: <slrngnsces.q56.tadmc@tadmc30.sbcglobal.net>

Jim Gibson <jimsgibson@gmail.com> wrote:
> In article <vxt888htljiu.so0hoyxtchkb$.dlg@40tude.net>, Larry Gates
><larry@example.invalid> wrote:


>> q2)  How do I write to $gh and replace thw entire file, even if there are
>> fewer characters in the replacer?
>
> Open another file for writing and write the modified lines to that
> file. When you are all done, you can rename the new file to the name of
> the old file, thereby deleting the old file, or you can just use the
> new file instead.


Or, probably best yet, let Perl's inplace editing feature handle all of
that administrivia for you.

See the -i switch in

    perldoc perlrun

and the $^I variable in

    perldoc perlvar


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Mon, 26 Jan 2009 15:07:07 -0700
From: Larry Gates <larry@example.invalid>
Subject: Re: inputting the ephemerides
Message-Id: <47zzbigltdib.vqcn6up708fj.dlg@40tude.net>

On Mon, 26 Jan 2009 12:35:38 -0800, Jürgen Exner wrote:

> Larry Gates <larry@example.invalid> wrote:
>>   while (my $line = <$fh>) {
>>   $line =~ s/\t/   /g;
>>   $line =~ s/ER/ /g;
>>   $line =~ s/°/ /g;
>>   }
> 
> What is the section above supposed to do?
> It reads a line from a file into memory, alters the line, and then
> happily throws it away by reading the next line without doing anything
> with that altered line. This is a giant NOOP. Why are you doing that?
> 

I've been doing this in bite-sixed chunks.  The problems that dogged me for
a long time were what to do with tabs, the ER that followed the moon's
distance from earth and no other body's,  and the degree sign, which is B0
hex and therefore not ascii.

I don't know what noop is, but I suspect it's a loop that does a whole lot
of nothing.  (Douglas Hofstadter had his own clever alterations along these
lines, but that's a different story.)

I *do* use the $line, because that's what I split on:

my @s = split /\s+/, $line;


>>Can I make a better split to include fields with only digits or characters?
> 
> Apparently your original string contains consecutive sequences of space
> characters. Your RE will split between each individual space, thus
> creating numerous empty result strings.
> If you don't want that then instead of splitting at a single space use
> the whole consecutive sequence of space characters as the item to split
> the original string at.
> 
> jue

Ok.  It sometimes takes me a while to use some of the suggestions that you
(plural) give me.  I was finally able to mimic the join syntax that you
(singular) posted at the top of this subthread, and I'm pleased to roll out
my first output that I can call a solution:

   use strict;
   use warnings;


   my $filename = 'eph6.txt';
   my $filename2 = 'outfile1.txt';
   open(my $fh, '<', $filename) or die "cannot open $filename: $!";
   open(my $gh, $filename2) or die "cannot open $filename2: $!";

   while (my $line = <$fh>) {
   $line =~ s/\t/   /g;
   $line =~ s/ER/ /g;
   $line =~ s/°/ /g;
   }
   close($fh);

  seek($gh,0,0);

   while (my $line = <$gh>) {
   my @s = split /\s+/, $line;

   $s[1] =~ s/h//;
   $s[2] =~ s/m//;
   $s[3] =~ s/s//;
   $s[5] =~ s/'//;
   for my $i (0..9) {
      print STDOUT  "s $i is $s[$i]\n";
   }
   $line = join(' ', @s[0..$#s]);
   print "$line\n";
   }
   close($gh);
# perl reg9.pl

C:\MinGW\source>perl reg9.pl
s 0 is Sun
s 1 is 19
s 2 is 43
s 3 is 51
s 4 is -21
s 5 is 17.8
s 6 is 0.984
s 7 is -35.020
s 8 is 87.148
s 9 is Set
Sun 19 43 51 -21 17.8 0.984 -35.020 87.148 Set
 ...
s 0 is Pluto
s 1 is 18
s 2 is 6
s 3 is 40
s 4 is -17
s 5 is 44.9
s 6 is 32.485
s 7 is -52.833
s 8 is 108.052
s 9 is Set
Pluto 18 6 40 -17 44.9 32.485 -52.833 108.052 Set

C:\MinGW\source>
-- 
larry gates

Are you going to bother to set up an unspoofable identity for every
shirt in your closet?
             -- Larry Wall, 8th State of the Onion


------------------------------

Date: Mon, 26 Jan 2009 22:23:04 GMT
From: sln@netherlands.com
Subject: Re: inputting the ephemerides
Message-Id: <dfdsn499t798ve97a754sm8qc27p2c6kou@4ax.com>

On Mon, 26 Jan 2009 15:07:07 -0700, Larry Gates <larry@example.invalid> wrote:

>On Mon, 26 Jan 2009 12:35:38 -0800, Jürgen Exner wrote:
>
>> Larry Gates <larry@example.invalid> wrote:
>>>   while (my $line = <$fh>) {
>>>   $line =~ s/\t/   /g;
>>>   $line =~ s/ER/ /g;
>>>   $line =~ s/°/ /g;
>>>   }
>> 
>> What is the section above supposed to do?
>> It reads a line from a file into memory, alters the line, and then
>> happily throws it away by reading the next line without doing anything
>> with that altered line. This is a giant NOOP. Why are you doing that?
>> 
>
>I've been doing this in bite-sixed chunks.  The problems that dogged me for
>a long time were what to do with tabs, the ER that followed the moon's
>distance from earth and no other body's,  and the degree sign, which is B0
>hex and therefore not ascii.
>
>I don't know what noop is, but I suspect it's a loop that does a whole lot
>of nothing.  (Douglas Hofstadter had his own clever alterations along these
>lines, but that's a different story.)
>
>I *do* use the $line, because that's what I split on:
>
>my @s = split /\s+/, $line;
>
>
>>>Can I make a better split to include fields with only digits or characters?
>> 
>> Apparently your original string contains consecutive sequences of space
>> characters. Your RE will split between each individual space, thus
>> creating numerous empty result strings.
>> If you don't want that then instead of splitting at a single space use
>> the whole consecutive sequence of space characters as the item to split
>> the original string at.
>> 
>> jue
>
>Ok.  It sometimes takes me a while to use some of the suggestions that you
>(plural) give me.  I was finally able to mimic the join syntax that you
>(singular) posted at the top of this subthread, and I'm pleased to roll out
>my first output that I can call a solution:
>
>   use strict;
>   use warnings;
>
>
>   my $filename = 'eph6.txt';
>   my $filename2 = 'outfile1.txt';
>   open(my $fh, '<', $filename) or die "cannot open $filename: $!";
>   open(my $gh, $filename2) or die "cannot open $filename2: $!";
>
>   while (my $line = <$fh>) {
>   $line =~ s/\t/   /g;
>   $line =~ s/ER/ /g;
>   $line =~ s/°/ /g;
>   }
>   close($fh);
>
>  seek($gh,0,0);
>
>   while (my $line = <$gh>) {
>   my @s = split /\s+/, $line;
>
>   $s[1] =~ s/h//;
>   $s[2] =~ s/m//;
>   $s[3] =~ s/s//;
>   $s[5] =~ s/'//;
>   for my $i (0..9) {
>      print STDOUT  "s $i is $s[$i]\n";
>   }
>   $line = join(' ', @s[0..$#s]);
>   print "$line\n";
>   }
>   close($gh);
># perl reg9.pl
>
>C:\MinGW\source>perl reg9.pl
>s 0 is Sun
>s 1 is 19
>s 2 is 43
>s 3 is 51
>s 4 is -21
>s 5 is 17.8
>s 6 is 0.984
>s 7 is -35.020
>s 8 is 87.148
>s 9 is Set
>Sun 19 43 51 -21 17.8 0.984 -35.020 87.148 Set
>...
>s 0 is Pluto
>s 1 is 18
>s 2 is 6
>s 3 is 40
>s 4 is -17
>s 5 is 44.9
>s 6 is 32.485
>s 7 is -52.833
>s 8 is 108.052
>s 9 is Set
>Pluto 18 6 40 -17 44.9 32.485 -52.833 108.052 Set
>
>C:\MinGW\source>

Fully quoted.

Nobody is giving you a proper solution to your original problem
representation, only because you won't take that solution, which is
the real solution.

Instead, whore attenition monger, you have to make a complete idiot out of
yourself and post sub problems, not even relative to the original problem,
blown way out of proportion to the nth degree, all because you can't find your
way around the documentation like everybody else.

Your entire problem is solved with a single 20 character regular expression,
but your a nut job that needs a book read to him before bedtime.

sln



------------------------------

Date: Mon, 26 Jan 2009 15:47:11 -0700
From: Larry Gates <larry@example.invalid>
Subject: Re: inputting the ephemerides
Message-Id: <ermz015vjfq2$.1n4icgp2kdcqf$.dlg@40tude.net>

On Mon, 26 Jan 2009 13:05:40 -0800, Jim Gibson wrote:

> In article <vxt888htljiu.so0hoyxtchkb$.dlg@40tude.net>, Larry Gates
> <larry@example.invalid> wrote:

>> q2)  How do I write to $gh and replace thw entire file, even if there are
>> fewer characters in the replacer?
> 
> Open another file for writing and write the modified lines to that
> file. When you are all done, you can rename the new file to the name of
> the old file, thereby deleting the old file, or you can just use the
> new file instead.

I sure made a mess of this:

   use strict;
   use warnings;


   my $filename = 'eph6.txt';
   my $filename2 = 'outfile1.txt';
   my $filename3 = 'temp.txt';
   open(my $fh, '<', $filename) or die "cannot open $filename: $!";
   open(my $gh, '+>', $filename2) or die "cannot open $filename2: $!";
   open(my $hh, '+>', $filename3) or die "cannot open $filename3: $!";

   while (my $line = <$fh>) {
   $line =~ s/\t/   /g;
   $line =~ s/ER/ /g;
   $line =~ s/°/ /g;
   }
   close($fh);

  seek($gh,0,0);

   while (my $line = <$gh>) {
   my @s = split /\s+/, $line;

   $s[1] =~ s/h//;
   $s[2] =~ s/m//;
   $s[3] =~ s/s//;
   $s[5] =~ s/'//;
   for my $i (0..9) {
      print STDOUT  "s$i is $s[$i]\n";
   }

   $line = join(' ',@s);
   print "$line\n";
   print $hh "$line\n";
   }
   close($fh);
   close($gh);
   close($hh);

#rename $filename3, $filename2;
   
# perl reg10.pl

I think I see what Jue was calling a noop and uri guttman was scratching
his head about.  Do I need a temp file at all for this?  I thought I was
reading and writing from $gh but apparently not.  I wonder how I ever got
output at all.??
-- 
larry gates

And besides, if Perl really takes off in the Windows space, I think the
rest of us would just as soon have a double-agent within ActiveState.  :-)
             -- Larry Wall in <199807172334.QAA18255@wall.org>


------------------------------

Date: Mon, 26 Jan 2009 23:00:24 GMT
From: sln@netherlands.com
Subject: Re: inputting the ephemerides
Message-Id: <o2gsn495bdhnnu73hsma2bpkch9kc9s1sr@4ax.com>

On Mon, 26 Jan 2009 15:47:11 -0700, Larry Gates <larry@example.invalid> wrote:

>On Mon, 26 Jan 2009 13:05:40 -0800, Jim Gibson wrote:
>
>> In article <vxt888htljiu.so0hoyxtchkb$.dlg@40tude.net>, Larry Gates
>> <larry@example.invalid> wrote:
>
>>> q2)  How do I write to $gh and replace thw entire file, even if there are
>>> fewer characters in the replacer?
>> 
>> Open another file for writing and write the modified lines to that
>> file. When you are all done, you can rename the new file to the name of
>> the old file, thereby deleting the old file, or you can just use the
>> new file instead.
>
>I sure made a mess of this:
>
>   use strict;
>   use warnings;
>
>
>   my $filename = 'eph6.txt';
>   my $filename2 = 'outfile1.txt';
>   my $filename3 = 'temp.txt';
>   open(my $fh, '<', $filename) or die "cannot open $filename: $!";
>   open(my $gh, '+>', $filename2) or die "cannot open $filename2: $!";
>   open(my $hh, '+>', $filename3) or die "cannot open $filename3: $!";
>
>   while (my $line = <$fh>) {
>   $line =~ s/\t/   /g;
>   $line =~ s/ER/ /g;
>   $line =~ s/°/ /g;
>   }
>   close($fh);
>
>  seek($gh,0,0);
>
>   while (my $line = <$gh>) {
>   my @s = split /\s+/, $line;
>
>   $s[1] =~ s/h//;
>   $s[2] =~ s/m//;
>   $s[3] =~ s/s//;
>   $s[5] =~ s/'//;
>   for my $i (0..9) {
>      print STDOUT  "s$i is $s[$i]\n";
>   }
>
>   $line = join(' ',@s);
>   print "$line\n";
>   print $hh "$line\n";
>   }
>   close($fh);
>   close($gh);
>   close($hh);
>
>#rename $filename3, $filename2;
>   
># perl reg10.pl
>
>I think I see what Jue was calling a noop and uri guttman was scratching
>his head about.  Do I need a temp file at all for this?  I thought I was
>reading and writing from $gh but apparently not.  I wonder how I ever got
>output at all.??

I'm sure your mother was shocked too...

sln


------------------------------

Date: Mon, 26 Jan 2009 16:46:18 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: inputting the ephemerides
Message-Id: <slrngnsf9q.qmf.tadmc@tadmc30.sbcglobal.net>

Larry Gates <larry@example.invalid> wrote:


>    $line = join(' ',@s);
>    print "$line\n";


You can make the same output as those 2 lines with:

   print "@s\n";


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Mon, 26 Jan 2009 16:51:51 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: inputting the ephemerides
Message-Id: <slrngnsfk7.qmf.tadmc@tadmc30.sbcglobal.net>

Larry Gates <larry@example.invalid> wrote:

>
>> Larry Gates <larry@example.invalid> wrote:
>>>   while (my $line = <$fh>) {
>>>   $line =~ s/\t/   /g;
>>>   $line =~ s/ER/ /g;
>>>   $line =~ s/°/ /g;
>>>   }

>> This is a giant NOOP. Why are you doing that?


You have not answered the question.

Why do you think you need those lines in your program?


> I'm pleased to roll out
> my first output that I can call a solution:


>    while (my $line = <$fh>) {
>    $line =~ s/\t/   /g;
>    $line =~ s/ER/ /g;
>    $line =~ s/°/ /g;
>    }
>    close($fh);


Delete those lines and compare the output to when those lines
are included.

There will be no differences.

ie. those lines do not do anything useful, so remove them.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: 26 Jan 2009 21:06:33 GMT
From: xhoster@gmail.com
Subject: Re: Which is faster - hash or array lookup
Message-Id: <20090126161005.527$Wf@newsreader.com>

Rasmus Villemoes <burner+usenet@imf.au.dk> wrote:
> Hi
>
> In a program I'm writing, I will need to access the 53130 different
> 5-element subsets of 0..24 many many times. So I thought I would
> generate each of these subsets once and for all, using a canonical
> enumeration scheme, and save the result in a global hash or array
> (Concretely, I have generated a file containing lines of the form
> "0:0,1,2,3,4", "1:0,1,2,3,5" etc., which I then read and parse at the
> start of the program, that is, I generate an anonymous array
> [0,1,2,3,4], and then I store a reference to this in $combs{0} or
> $combs[0].)
>
> Now the question is, should I store these in an array or a hash,
> if I want to access a random entry as fast as possible?

Assuming you want to access them randomly by index, rather than by
canonical representation, then the array will be faster (and cleaner).  But
if what you do between accesses is anything but trivial, that will probably
dominate your run time.


$ time perl -le 'srand(0); my %x; @x{0..50_000}=(0..50_000);
    foreach (1..1e7)
    { print $x{int rand scalar keys %x} }' > foo2
14.364u 0.144s 0:15.22 95.2%    0+0k 0+0io 0pf+0w

$ time perl -le 'srand(0); my @x=0..50_000; foreach (1..1e7)
    { print $x[rand @x] }' > foo1
10.960u 0.204s 0:11.43 97.6%    0+0k 0+0io 0pf+0w

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


------------------------------

Date: Mon, 26 Jan 2009 21:28:37 GMT
From: sln@netherlands.com
Subject: Re: Which is faster - hash or array lookup
Message-Id: <tjasn495isqdoaunldi8q63k4j7rqf1h9j@4ax.com>

On 26 Jan 2009 21:06:33 GMT, xhoster@gmail.com wrote:

{snip}
>
>Assuming you want to access them randomly by index, rather than by
>canonical representation, then the array will be faster (and cleaner).  But
>if what you do between accesses is anything but trivial, that will probably
>dominate your run time.

{snip}

Alot of fab Techno Twins verbage. Unfortunately, it doesen't clearly state
any meaning, if one was offered in the first place.

sln



------------------------------

Date: 26 Jan 2009 21:57:41 GMT
From: xhoster@gmail.com
Subject: Re: Which is faster - hash or array lookup
Message-Id: <20090126170114.120$iI@newsreader.com>

Rasmus Villemoes <burner+usenet@imf.au.dk> wrote:
> bugbear <bugbear@trim_papermule.co.uk_trim> writes:
>
> > Rasmus Villemoes wrote:
> >> Hi
> >> In a program I'm writing, I will need to access the 53130 different
> >> 5-element subsets of 0..24 many many times.
> >
> > Are you sure there isn't a better algorithm for your (unstated)
> > purpose?
>
> Well, that depends. I am suite sure that perl is not The Right Tool
> for my overall purpose, but what I am trying to do probably does
> involve accessing each of these combinations by number (or some other
> key). I have decided to use perl for this pet project to help me learn
> some more perl.

Well in that case, what I'd do (and have done) is implement them in several
different ways, run them, and compare the timings.  It will teach you a lot
of Perl, especially those ineffable things hard to put into documentation
or USENET posts.

> The project concerns a little game which is played on a 5x5
> board. Each player has 5 pieces, and additionally there is a common
> piece used by both players. Only one piece can occupy a square at any
> time, so the positions of either player's pieces at any time is
> exactly a 5-subset of 0..24. If I use a canonical numbering of these
> 5-subsets, I can describe the state of the game using 5 bytes (2*2
> bytes to describe numbers in the range 0..53129, and 1 byte to
> indicate the position of the common piece along with information on
> whose turn it is).

Your scheme allows impossible boards, because some combinations of the
two players combinations (or one of them and the common piece) will be
incompatible.  Couldn't you canonicalize at entire-board level, rather than
at each player individually?


> For any given state, a move from that state can be
> described by 3 bytes (encoding the new positions of the player's
> pieces and the common piece).

Why would you want to scrimp on space here?  Are you planning on storing
all possible moves from all possible boards in memory simultaneously?  I'd
probably just plan on recomputing possible moves on the fly, rather than
storing, and so wouldn't care about storage space for this.

> But in order to compute which moves are
> possible from a given state, I need the positions of the 11 pieces on
> the board. It may not be smart to store anonymous arrays containing
> the 5-subsets. Another possibility is to use a bitstring with exactly
> 5 1's. That would probably save a lot of memory, and may be faster to
> use (I will often need to ask "in state $x, is there a piece on square
> number $n". I guess vec() can answer that question if I use
> bitstrings, whereas traversing an array looking for $n is slow).

You can use a sparse array, checking defined $x[$n] rather than
grep $_==$n, @x, just like you can a sparse vector.  Although I'd usually
use a hash for that purpose instead of an array.  But if I'm understanding
this right, this choice is at a different level than the one you originally
asked.

> Of course, I could skip the huge constant table, but then I would
> either have to describe each state using more data, or compute the
> occupied/empty squares each time.

The CPU still has to compute it each time, it is just a matter of how you
go about getting it to do so.  It seems like you will have to go in both
directions rapidly, canonical->board->different board->canonical.  Unless
you have something especially clever in mind, I'd think it would be less
work to go from human-readable-string-representation of board to
array/hash-representation of the board, then from some abstruse canonical
number to an array/hash representation.   (And back)

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


------------------------------

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 V11 Issue 2160
***************************************


home help back first fref pref prev next nref lref last post