[17068] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4480 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 1 00:10:58 2000

Date: Sat, 30 Sep 2000 21:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <970373414-v9-i4480@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 30 Sep 2000     Volume: 9 Number: 4480

Today's topics:
    Re: finding the structure of a hash (Logan Shaw)
    Re: finding the structure of a hash (Logan Shaw)
    Re: finding the structure of a hash <godzilla@stomp.stomp.tokyo>
    Re: finding the structure of a hash (Logan Shaw)
    Re: finding the structure of a hash <godzilla@stomp.stomp.tokyo>
        flocking while using the diamond operator? tmdryden@my-deja.com
    Re: flocking while using the diamond operator? (Gwyn Judd)
    Re: flocking while using the diamond operator? (Garry Williams)
    Re: Levels of Perl Programmer <muskrat@mindless.com>
        macros (was Re: why it's called a "hash" (and a whole l <elijah@workspot.net>
        macros (was Re: why it's called a "hash" (and a whole l <elijah@workspot.net>
    Re: Perl Regex vlad_the_impaler24@my-deja.com
    Re: redirect script <webmaster@digital-espresso.com>
    Re: temporary file names <elijah@workspot.net>
        What happened to __DIE__ and __WARN__ signal handers??? <reedfish@ix.netcom.com>
        why it's called a "hash" (and a whole lot more) <jeffp@crusoe.net>
    Re: why it's called a "hash" (and a whole lot more) <anmcguire@ce.mediaone.net>
    Re: why it's called a "hash" (and a whole lot more) (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 30 Sep 2000 18:03:35 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: finding the structure of a hash
Message-Id: <8r5rg7$5h0$1@provolone.cs.utexas.edu>

In article <39D65C29.F7446478@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>Logan Shaw wrote:
>> Godzilla! wrote:
>> Anonymous Godzilla! wrote:
>> > Is that so? How would a script distinquish
>> > between elements, regardless of dimension,
>> > if there are no delimiters?
>(snippage not indicated by Shaw)

I didn't indicate snippage because I didn't quote two sections of your
text but not quote the intervening text.  You don't quote Einstein
like this:

	[ everything Einstein said prior to this in his life deleted ]
	Everything should be made as simple as possible, but no simpler.
	[ everything Einstein said after this in his life deleted ]
					- Albert Einstein

>> Well, here are five ways off the top of my head:
> 
>Those 'ways' are all very nice, very imaginative and,
>all are delimiters.

The Merriam-Webster dictionary (http://www.m-w.com/) has this:

	Main Entry: de*lim*it*er
	Pronunciation: di-'li-m&-t&r
	Function: noun
	Date: 1960
	: a character that marks the beginning or end of a unit of data 

And The Free On-line Dictionary of Computing has this:

	delimiter
	  
		  A character or string used to separate, or
		  mark the start and end of, items of data in, e.g., a
		  database, source code or text file.

		  (1997-12-23)

Call me crazy, but to me this implies that:

1.  A delimiter is a character,

2.  It occurs in a string and by its position in the string marks
    the end or beginning of a portion of that string.

None of my examples conform to that definition.  Yes, they all provide
information as to where each portion of the string starts and ends, but
they don't qualify as delimiters under any definition I was able to find.

And to quote Muffy Barkocy,

	using words in ways that no one else uses them generally
	impedes communication, which I consider to be undesirable.

  - Logan


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

Date: 30 Sep 2000 18:05:47 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: finding the structure of a hash
Message-Id: <8r5rkb$5hn$1@provolone.cs.utexas.edu>

In article <cmtB5.15622$td5.2771828@news1.rdc2.pa.home.com>,
Ben Kennedy <bkennedy99@home.com> wrote:
>"Logan Shaw" <logan@cs.utexas.edu> wrote in message
  ^^^^^^^^^^
>news:8r5lft$54v$1@provolone.cs.utexas.edu...
>> In article <39D6322A.B08B4D8E@stomp.stomp.tokyo>,
>> Anonymous  <anonymous@anonymous.anonymous> wrote:
>> >Is that so? How would a script distinquish
>> >between elements, regardless of dimension,
>> >if there are no delimiters?
>
>I had to go to deja to get the anonymous post, looks like my news server
>filtered it out.  Here is the original post:

Just FYI and FEI[1], although my name appears on this message, it's a
bit of a misattribution, since I didn't actually write anything in
that message.

  - Logan

[1]  For everyone's information.


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

Date: Sat, 30 Sep 2000 16:34:28 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: finding the structure of a hash
Message-Id: <39D67884.66AE3FB6@stomp.stomp.tokyo>

Logan Shaw wrote:
 
> Godzilla! wrote:
> > Logan Shaw wrote:
> > > Godzilla! wrote:
> > > > Anonymous Godzilla! wrote:

> > > > Is that so? How would a script distinquish
> > > > between elements, regardless of dimension,
> > > > if there are no delimiters?

> >(snippage not indicated by Shaw)


> > Those 'ways' are all very nice, very imaginative and,
> > all are delimiters.
 
> The Merriam-Webster dictionary (http://www.m-w.com/) has this:
 
>         Main Entry: de*lim*it*er
>         Pronunciation: di-'li-m&-t&r


Before I am tempted to launch into a discussion
about mental blindness of Language Lawyers, define
for yourself, this delimiter between our atmosphere
and space, in terms of gravity, with a relative
tangent of travel, a vector direction, as any radii
of our Earth as a sphere. When finished, reverse 
your direction of travel and define this delimiter
between our atmosphere and space, in terms of mass
per cubic centimeter, mass being simply molecules,
any and all.

If you can do this and if you can understand this,
you will have lightly touched upon a notion of
what is, a delimiter.

A puzzle for you mule blinder wearing Language Lawyers
whom are incapable of seeing past the end of your nose,
what is a delimiter in one dimensional space?

Problem here is you boys are Language Lawyers who have
"use strict" tattooed on your brains. I am programmer
who knows a delimiter is what you define it to be.


* draws a line in sand *

This is your delimiter.


* makes hand motions encompassing our universe *

This is my delimiter.



Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


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

Date: 30 Sep 2000 19:20:35 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: finding the structure of a hash
Message-Id: <8r600j$5mo$1@provolone.cs.utexas.edu>

In article <39D67884.66AE3FB6@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>If you can do this and if you can understand this,
>you will have lightly touched upon a notion of
>what is, a delimiter.

That may be an interesting definition of delimiter, but I'd submit that
the most useful definition of a delimiter in the context of computing
would imply that the delimiter appears as a non-terminal in the
production rules for a grammar.  (Or at least it would imply that you
can validly think of it that way.)

>A puzzle for you mule blinder wearing Language Lawyers
>whom are incapable of seeing past the end of your nose,
>what is a delimiter in one dimensional space?

I think delimiters makes sense in the context of a strings.  I don't
think a one-dimensional space is a very good model for a string, since
a one-dimensional space probably isn't composed of discrete elements.

>Problem here is you boys are Language Lawyers who have
>"use strict" tattooed on your brains. I am programmer
>who knows a delimiter is what you define it to be.

Yes, as Muffy Barkocy said in that quote I gave, we can define terms
however we want, but it is only when we start to define terms in
similar or equivalent ways that those terms start to actually be useful
for the purposes of communication.  (Defining terms differently and
then trying to have any meaning isn't a great way to communicate,
although it can be useful for amusement and even for thinking of new
things and new ways to think of things.)

You, as an English professor (from what I understand), should know
enough about postmodernism to appreciate that.  (Or maybe you
appreciate it too well...)

  - Logan


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

Date: Sat, 30 Sep 2000 18:00:34 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: finding the structure of a hash
Message-Id: <39D68CB2.6A039AEC@stomp.stomp.tokyo>

Logan Shaw wrote:
 
> Godzilla! wrote:

(snippage)

> That may be an interesting definition of delimiter, but I'd submit that
> the most useful definition of a delimiter in the context of computing
> would imply that the delimiter appears as a non-terminal in the
> production rules for a grammar.  (Or at least it would imply that you
> can validly think of it that way.)

So, you are finally coming around to useful dialog.

Previously, you cited five examples of 'delimiterless'
case examples. However, in each case, a delimiter is
defined. In one case, a numerical quantity, such as
'five characters'. Another case, a parity bit, which
is very clearly, a delimiter. In all cases, a very clear
delimiter is defined with strict rules. A delimiter is
not a line in the sand. A delimiter is what you 'set'
it to be.

 
> >A puzzle for you mule blinder wearing Language Lawyers
> >whom are incapable of seeing past the end of your nose,
> >what is a delimiter in one dimensional space?
 
> I think delimiters makes sense in the context of a strings.  I don't
> think a one-dimensional space is a very good model for a string, since
> a one-dimensional space probably isn't composed of discrete elements.

It's a trick question. One dimensional space is a delimiter
itself. Cannot be anything else. Best notion we have, as
humans, of one dimensional space, is the Big Bang, just before
God pointed Her finger and yelled with glee,

"Let there be Psychedelic Light! Let's Rock N Roll!"

 
> >Problem here is you boys are Language Lawyers who have
> >"use strict" tattooed on your brains. I am programmer
> >who knows a delimiter is what you define it to be.
 
> Yes, as Muffy Barkocy said in that quote I gave, we can define terms
> however we want, but it is only when we start to define terms in
> similar or equivalent ways that those terms start to actually be useful
> for the purposes of communication.  (Defining terms differently and
> then trying to have any meaning isn't a great way to communicate,
> although it can be useful for amusement and even for thinking of new
> things and new ways to think of things.)

Well, yes, an important, very important component of science, is
widely accepted definitions of terms to enhance communication. All
concur certain words or phrases have selected strict definitions.

Where these boys in this thread went wrong, as usual, is claiming
there are no delimiters within an Associative Array, or your Hash,
fancy dog food for humans. There are most certainly delimiters in
any hash. Wouldn't be a hash without delimiters. Duh?

You mule brained boys think not having to reference those delimiters
means there are no delimiters. Mule Manure. You reference those
delimiters by inference. Based on this stupefying logic displayed
by these boys claiming to be Perl Know-It-Alls, a hash would be,

keyvaluekeyvaluekeyvaluekeyvaluekeyvaluekeyvalue

I see a string. You boys see a hash.

This is a hash, using a space and an equal sign to symbolically
represent whatever the Hades perl core uses for delimiters,

key=value key=value key=value key=value key=value key=value 

So you see, by claiming there are no delimiters in a hash,
or claiming there are no delimiters when referencing a hash,
well, you boys are full of mule manure. You don't have a clue
on what you are spewing. You are referencing those delimiters
no matter what you ignorantly claim.

Don't know why I bother. This type of stupidity displayed
by some, not all, but most, is such an extreme degree of
ignorance there is no way to even begin to explain how 
absolutely dead wrong are these ignorant Language Lawyers.
Might as well be shucking and jiving in Swahili.

 
> You, as an English professor (from what I understand), should know
> enough about postmodernism to appreciate that.  (Or maybe you
> appreciate it too well...)

Next millennium, will our postmodernism still be just that?
My concept is twentieth century postmoderism, within a small
handful of centuries, will be referred to as,

"postmodern dark ages"

As collective whole, we humans are not very bright creatures
and we have a strong propensity to hate and destroy, all 
things, including ourselves, especially our minds.


Perhaps I use language to my best advantage and
to your greatest annoyance. 


Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


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

Date: Sat, 30 Sep 2000 23:19:37 GMT
From: tmdryden@my-deja.com
Subject: flocking while using the diamond operator?
Message-Id: <8r5se5$jaj$1@nnrp1.deja.com>

Howdy:

I'm trying to lock a file I'm using the diamond operator (<>) on, but
can't figure out how to make it work.

Here's my basic concept:

use Fcntl qw(:flock);

@ARGV = ("file");
flock(ARGV,LOCK_EX); # <== doesnt work
$^I = ".bak";
while (<>) {
 do something;
}

Any suggestions?

Ted
tedNOSPAM@dynamos.com


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 01 Oct 2000 01:58:25 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: flocking while using the diamond operator?
Message-Id: <slrn8td6hu.33s.tjla@thislove.dyndns.org>

I was shocked! How could tmdryden@my-deja.com <tmdryden@my-deja.com>
say such a terrible thing:
>Howdy:
>
>I'm trying to lock a file I'm using the diamond operator (<>) on, but
>can't figure out how to make it work.
>
>Here's my basic concept:
>
>use Fcntl qw(:flock);
>
>@ARGV = ("file");
>flock(ARGV,LOCK_EX); # <== doesnt work

Try this:

 open FILE, 'file' or die "Cannot open the file: $!";

 flock FILE, LOCK_EX or die "Cannot lock the file: $!";

 while (<FILE>)
 {
 blah blah
 }

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Fortune's real live weird band names #699:

The The


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

Date: Sun, 01 Oct 2000 03:15:13 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: flocking while using the diamond operator?
Message-Id: <5%xB5.52$b7.5897@eagle.america.net>

On Sun, 01 Oct 2000 01:58:25 GMT, Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
>Try this:
>
> open FILE, 'file' or die "Cannot open the file: $!";
>
> flock FILE, LOCK_EX or die "Cannot lock the file: $!";
>
> while (<FILE>)
> {
> blah blah
> }

Did you try this?  

    $ touch file
    $ cat flock_test
    #!/usr/local/bin/perl -w
    use strict;
    open FILE, 'file' or die "Cannot open the file: $!";
    flock FILE, LOCK_EX or die "Cannot lock the file: $!";
    $ perl -c flock_test
    Bareword "LOCK_EX" not allowed while "strict subs" in use at 
	flock_test line 4.
    flock_test had compilation errors.
    $

Or, even if we fix the compile problem: 

    $ cat flock_test
    #!/usr/local/bin/perl -w
    use strict;
    use Fcntl ':flock';
    open FILE, 'file' or die "Cannot open the file: $!";
    flock FILE, LOCK_EX or die "Cannot lock the file: $!";
    $ perl flock_test
    Cannot lock the file: Bad file number at flock_test line 5.
    $ 

You cannot obtain an exclusive lock on a file that is not opened for
updating.  You cannot obtain a shared lock on a file that *is* opened
for updating.  

-- 
Garry Williams


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

Date: Sun, 01 Oct 2000 03:42:47 GMT
From: "Matthew Musgrove" <muskrat@mindless.com>
Subject: Re: Levels of Perl Programmer
Message-Id: <XoyB5.13274$K46.41899@typhoon.kc.rr.com>

I love it.

4pts  from User, 5pts from Expert, 1pt from Wizard

I'm a User.

--
Matthew Musgrove
muskrat@mindless.com
http://free.prohosting.com/~musgrove/





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

Date: 1 Oct 2000 02:55:55 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: macros (was Re: why it's called a "hash" (and a whole lot more))
Message-Id: <eli$0009302253@qz.little-neck.ny.us>

In comp.lang.perl.misc, Andrew N. McGuire  <anmcguire@ce.mediaone.net> wrote:
> On Sat, 30 Sep 2000, Jeff Pinyan quoth:
> JP> The macro is not a function.  It's more like this code is plopped in
> JP> where PERL_HASH(...) is.  If we wrote this in Perl, we'd have to use
> JP> a function, because Perl doesn't have the concept of macros.
> That is not entirely true...
> 
> #!/usr/bin/perl -wP
> use strict;
> #define P print
> 
> P "hello, world\n";
> __END__

That can be generalized with source filters (Filter::*) to include
perl or shell scripts to find and expand macros, thus removing the
need for a C preprocessor on the system.

Elijah
------
perl <<'JAPH'
use Filter::sh 'perl -pey:*-r:A-~:+s/.*/print\"\$\&\"/s';
3^\] *WX]QN[ 9N[U 1JLTN[
JAPH


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

Date: 1 Oct 2000 03:26:21 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: macros (was Re: why it's called a "hash" (and a whole lot more))
Message-Id: <eli$0009302256@qz.little-neck.ny.us>

In comp.lang.perl.misc, Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> 	Andrew N. McGuire  <anmcguire@ce.mediaone.net> wrote:
> > That is not entirely true...
 ...
> > But that is generally considered not so good a practice,
> > primarily, I surmise, because it is not very Perlish/
> > flexible.
> And because it uses an external program that isn't part of the Perl
> distribution, and isn't available by default on many systems (cpp).

Yes, which is why Filter::* is much better.

> It's a leftover, yet another one, from times when it _could_ be handy to
> do this sort of stuff. Perl has outgrown this time. There is very little
> that can be done with preprocessing that can't be done with Perl
> directly anymore (does anyone have an example? I can't think of one).

Well, I find macros handy for puting oft-run code inline in several
places without maintaining several copies or enduring the overhead
of a subroutine.

If speed counts, I usually end up just keeping two copies. (I don't
get along well with perl OO, since I shun unneeded function calls.)

Elijah
------
perl -Mcharnames=latin -le'print"\N{J}\N{u}\N{s}\N{t} \N{A}\N{n}\N{o}\N{t}".
"\N{t}\N{h}\N{e}\N{r} \N{P}\N{e}\N{r}\N{l} \N{H}\N{a}\N{c}\N{k}\N{e}\N{r}\n"


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

Date: Sun, 01 Oct 2000 00:20:15 GMT
From: vlad_the_impaler24@my-deja.com
Subject: Re: Perl Regex
Message-Id: <8r5vvs$lr6$1@nnrp1.deja.com>

Acually it is a log file from a game, Quake 3. Basically when someone
gets killed it writes this line to the logfile
3 2 6: Robb killed EyEless by MOD_ROCKET

At first I just wanted the first three numbers, the 3 2 6, 3\2\6\, so
that I could make it one scalar variable, and then turn it into an
array in another perl program, so there will only be three numbers,
thanks everyone for all your help, and I will try those other examples,
but at this point, I am just hpayy it works... lol.

Vlad


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sat, 30 Sep 2000 13:59:57 -0800
From: Digital Espresso <webmaster@digital-espresso.com>
Subject: Re: redirect script
Message-Id: <39D6625D.39F2846F@digital-espresso.com>

Hello, Keat, You cannot accomplish this with a CGI/Perl.
This kind of function is done by JavaScript.

Keat wrote:

> I'm looking for a perl script that will automatically open up another url
> when exiting the original,  I know its possible as I've seen it done on the
> xxx sites, but I cant seem to find a script anywhere. Does anyone have any
> ideas where I can find such a script....????
>
> Please reply to keat@beal.org.uk
> Keaton Roebuck

--
Regards

Digital Espresso
________________

WEB:> http://www.digital-espresso.com
PHONE:> 907.337.3201; CELL: 907.441.9649; PAGER/V-MAIL: 907.275.9448
ADDRESS:> PO BOX 240414 Midtown Station Anchorage, AK 99524-0414




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

Date: 1 Oct 2000 00:58:00 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: temporary file names
Message-Id: <eli$0009302053@qz.little-neck.ny.us>

In comp.lang.perl.misc,
Francis Litterio  <franl-removethis@world.omitthis.std.com> wrote:
> Nick Wilson <wilson@world.std.com> writes:
> > Does Perl have a built-in mechanism for generating temporary file names
> > (something like tmpnam() in C)?
> 	use POSIX qw(tmpnam);
> 	my $tmpfile = POSIX::tmpnam();
> 
> Of course, by the time you use that filename, some other process may
> already be using it, but that's a different problem altogether.

Which is why persons seeking a temporary file should read the
FAQ question: How do I make a temporary file name?

The number of security holes introduced by seemingly innocent
programs just because they make predicatable temporary filenames
and then don't open them safely (ie, by not following symlinks)
is staggering.

Elijah
------
regular BUGTRAQ and VULN-DEV reader


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

Date: Sat, 30 Sep 2000 20:58:53 -0400
From: "Brian Kelly" <reedfish@ix.netcom.com>
Subject: What happened to __DIE__ and __WARN__ signal handers????????
Message-Id: <8r62gj$fto$1@slb0.atl.mindspring.net>

Where in the world is the documentation for the "__DIE__" and "__WARN__"
signal handlers
in the 3rd Edition of Perl Programming? It's in the 2nd Edition and the
Cookbook. I tested the
handlers in 5.6 and they're still there and work fine. So what gives?? Why
were they left out?
Has a decision been made to remove these handlers in a future version?? I
personally use them
and think they are a GREAT feature. Does anyone "out there" have a clue??

Brian

reedfish@ix.netcom.com




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

Date: Sat, 30 Sep 2000 20:22:39 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: why it's called a "hash" (and a whole lot more)
Message-Id: <Pine.GSO.4.21.0009301830000.12979-100000@crusoe.crusoe.net>

Perl has a data type called an associative array.  However, you can spell
it with 1/4 of the characters, and say it in 1/7 of the time with the word
"hash".

Why is a Perl data type named after a fancy word for dog food for humans
(q.v. Godzilla's posts)?  Because the method in which this data structure
is created is by employing a hashing function [1].

A hash, in C, is an array of linked lists.  Each key, which must be a
string [2], is converted to a number using a hashing algorithm.  In Perl,
this function is documented in perlguts, "Working with HVs":

       The hash algorithm is defined in the `PERL_HASH(hash, key,
       klen)' macro:

           hash = 0;
           while (klen--)
               hash = (hash * 33) + *key++;
           hash = hash + (hash >> 5);                  /* after 5.6 */

The macro is not a function.  It's more like this code is plopped in where
PERL_HASH(...) is.  If we wrote this in Perl, we'd have to use a function,
because Perl doesn't have the concept of macros.

  # $hash = PERL_HASH($key)
  sub PERL_HASH {
    my $key = reverse shift;  # "jeff" => "ffej"
    my $hash = 0;
    my $c;
    while (defined($c = chop($key))) {
      $hash = ($hash * 33) + ord($c);
    }
    return $hash + ($hash >> 5);
  }

The hash value for a given string is constant for the same hashing
algorithm.  So, once it's been calculated, there's no need to calculate it
again.  It'd be a good idea if the data structure remembers the hash value
for a key (it does).

Once a hash value has been determined for a key, this value is taken,
modulus some number.  This base is called the bucket number -- how many
containers (linked lists) of keys there are.  The hash value, modulus the
number of buckets, determines in which bucket a key-value pair is placed.

The key 'jeff', for instance, has a hash value of 4045365.  In a hash with
8 buckets, it would be placed in bucket 5.  (Perl's hash tables have
buckets in powers of 2.)

When one key is sent to a bucket where a key already exists, it is placed
at the head (front) of the bucket:

  (hash keys contain their name, hash value, and associated value)

  hash   [bucket]
   |
   +----+--[0]
        |
        :
        |
        +--[4] [ 'jill', 4050068, 'girl' ]
        |
        +--[5] [ 'jeff', 4045365, 'boy' ],
        |      [ 'rover', 143669573, 'dog' ]
        |
        :

From this diagram, we can see that 'rover' was added to the hash first,
and THEN 'jeff' was added, since 'jeff' comes before 'rover' in the hash
table.

When you iterate through a hash, the seemingly unordered list of keys
returned is the order as the keys appear, starting in the first bucket,
and working to the last bucket.  The Perl hash

  %names = qw(
    jeff      boy
    fire      cat
    jill      girl
    rover     dog
    tony      tiger
    geoffrey  giraffe
  );

has the internal structure (in Perl 5.6) of:

  [bucket]  [data]
  0         [ 'tony', 4427488, 'tiger' ]
  1         [ 'fire', 3902025, 'cat' ]
  2
  3
  4         [ 'jill', 4050068, 'girl' ]
  5         [ 'rover', 143669573, 'dog' ]
            [ 'jeff', 4045365, 'boy' ]
  6         [ 'geoffrey', 4524740894966, 'giraffe' ]
  7

If you call keys(), you'll get the keys in the following order [3]:

  tony, fire, jill, rover, jeff, geoffrey

Notice that if 'jeff' and been inserted after 'rover', it would appear
BEFORE 'rover' in the return list, since they map to the same bucket.

There might be some discrepancies (I've seen some, at least) that I am not
capable of explaining, but I've already explained more than what needs to
be known -- this implementation could all change radically.

They are also known as associative arrays because they associate a string
to another string, instead of an integer to a string.

=========================================================================

Footnotes:

[1] from the Free On-Line Dictionary of Computing (FOLDOC):
    http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=hashing
[2] which is why hash keys in Perl can't be references -- they get
    stringified
[3] remember, this is perl 5.6 -- perl 5.005 will behave slightly
    differently

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Sat, 30 Sep 2000 21:12:24 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: why it's called a "hash" (and a whole lot more)
Message-Id: <Pine.LNX.4.21.0009302107340.25621-100000@hawk.ce.mediaone.net>

On Sat, 30 Sep 2000, Jeff Pinyan quoth:

[ snip ]

JP> The macro is not a function.  It's more like this code is plopped in where
JP> PERL_HASH(...) is.  If we wrote this in Perl, we'd have to use a function,
JP> because Perl doesn't have the concept of macros.

[ snip ]

That is not entirely true...

#!/usr/bin/perl -wP
use strict;
#define P print

P "hello, world\n";
__END__

But that is generally considered not so good a practice,
primarily, I surmise, because it is not very Perlish/
flexible.

anm
-- 
$ENV{PAGER} = 'perl -wpe0';
system perldoc => '-t', '-F', $0;

=head1 
Just another Perl Hacker



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

Date: Sun, 1 Oct 2000 13:39:15 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: why it's called a "hash" (and a whole lot more)
Message-Id: <slrn8td8uj.jr6.mgjv@martien.heliotrope.home>

On Sat, 30 Sep 2000 21:12:24 -0500,
	Andrew N. McGuire  <anmcguire@ce.mediaone.net> wrote:
> On Sat, 30 Sep 2000, Jeff Pinyan quoth:
> 
> [ snip ]
> 
> JP> The macro is not a function.  It's more like this code is plopped in where
> JP> PERL_HASH(...) is.  If we wrote this in Perl, we'd have to use a function,
> JP> because Perl doesn't have the concept of macros.
> 
> [ snip ]
> 
> That is not entirely true...
> 
> #!/usr/bin/perl -wP
> use strict;
> #define P print
> 
> P "hello, world\n";
> __END__
> 
> But that is generally considered not so good a practice,
> primarily, I surmise, because it is not very Perlish/
> flexible.

And because it uses an external program that isn't part of the Perl
distribution, and isn't available by default on many systems (cpp).

And because it is dangerous, since both preprocessor directives and Perl
comments start with a hash (#). Any comment starting with a sequence of
characters that the preprocessor you have installed thinks is a
directive gets parsed. Since many preprocessors have different ideas
about what's allowed, it becomes hard to even write portable comments in
perl programs.

It's a leftover, yet another one, from times when it _could_ be handy to
do this sort of stuff. Perl has outgrown this time. There is very little
that can be done with preprocessing that can't be done with Perl
directly anymore (does anyone have an example? I can't think of one).

As a personal experience note: I've had to port a few hundred thousand
lines of code from Perl 4 to Perl 5, which was not hard, until we had to
run some of it on a machine where there was no cpp available. Since the
previous developers came from the C world, they had decided that to
avoid the abovementioned problem with Perl comments, they would only use
C comments, and rely on the cpp to strip them out. 

It took a bit fo time to reliably clean that up.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd.   | make up 3/4 of the population.
NSW, Australia                  | 


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4480
**************************************


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