Re: fun with hashes!

2007-11-25 Thread John Douglas Porter
Uri wrote: isa is a key valid? (not same as in a set). isa usually works on fixed sets of keys Well, in a strict sense it IS the same, as it is just one of many possible set operations. I suppose you could say it's a subset of sets. :-) I think you're trying to focus on the

Re: fun with hashes!

2007-11-25 Thread Uri Guttman
JDP == John Douglas Porter [EMAIL PROTECTED] writes: JDP Uri wrote: isa is a key valid? (not same as in a set). isa usually works on fixed sets of keys JDP Well, in a strict sense it IS the same, as it is just one JDP of many possible set operations. I suppose you could say

Re: fun with hashes!

2007-11-25 Thread Keith Ivey
Jerrad Pierce wrote: How about using a hash to keep track of which things you've already handled? That's just the afore-mentioned count True, I guess, but lots of these uses are the same. In Uri's original post, isa could be considered the same as sets, and records the same as data

Re: fun with hashes!

2007-11-25 Thread Brian Duggan
Don't know if this falls into categories already covered (set of active objects in a class? counting?), but I often find a hash of open filehandles useful. e.g. to divide a big file into several smaller ones, using the distinct values of one of the fields as filenames : perl -MIO::File -ane

Re: fun with hashes!

2007-11-25 Thread Uri Guttman
s == shmem [EMAIL PROTECTED] writes: s You forgot an obscure corner of hashes: hashes in scalar context. s Here's a a use - calculate the next power of 2 of a given number: s sub next_power_of_two { s my %s; s @s{1..shift} = (); s %s =~ '/'; s return $'; s }

Re: fun with hashes!

2007-11-25 Thread Uri Guttman
KI == Keith Ivey [EMAIL PROTECTED] writes: KI Jerrad Pierce wrote: How about using a hash to keep track of which things you've already handled? That's just the afore-mentioned count KI True, I guess, but lots of these uses are the same. In Uri's original KI post, isa could be

Re: fun with hashes!

2007-11-25 Thread John Douglas Porter
Uri wrote: i still think isa is a (sic) concept that is important enough to cover on its own. sure it is a set but a very specific type with its own name. the names of these concepts are important (almost like design patterns which i despise :). If names are that important to you, then you

Re: fun with hashes!

2007-11-24 Thread David Landgren
Uri Guttman writes: AP == A Pagaltzis [EMAIL PROTECTED] writes: AP * Jerrad Pierce [EMAIL PROTECTED] [2007-11-23 22:50]: exists( $dispatch{$sub} ) ? $dispatch{$sub}-() : warn Key $sub does not exist in the dispatch table; AP ( $dispatch{$sub} || sub { warn no such action '$sub'

Re: fun with hashes!

2007-11-24 Thread Bernie Cosell
On 23 Nov 2007 at 23:54, Uri Guttman wrote: SHC == Shawn H Corey [EMAIL PROTECTED] writes: SHC Vladi Belperchinov-Shabanski wrote: On Fri, 23 Nov 2007 23:18:20 +0100 A. Pagaltzis [EMAIL PROTECTED] wrote: * Jerrad Pierce [EMAIL PROTECTED] [2007-11-23 22:50]: exists(

Re: fun with hashes!

2007-11-24 Thread A. Pagaltzis
* David Landgren [EMAIL PROTECTED] [2007-11-24 10:45]: Uri Guttman writes: AP == A Pagaltzis [EMAIL PROTECTED] writes: AP * Jerrad Pierce [EMAIL PROTECTED] [2007-11-23 22:50]: exists( $dispatch{$sub} ) ? $dispatch{$sub}-() : warn Key $sub does not exist in the dispatch table; AP

Re: fun with hashes!

2007-11-24 Thread Vladi Belperchinov-Shabanski
On Sat, 24 Nov 2007 10:43:58 +0100 David Landgren [EMAIL PROTECTED] wrote: Uri Guttman writes: AP == A Pagaltzis [EMAIL PROTECTED] writes: AP * Jerrad Pierce [EMAIL PROTECTED] [2007-11-23 22:50]: exists( $dispatch{$sub} ) ? $dispatch{$sub}-() : warn Key $sub does not exist in

Re: fun with hashes!

2007-11-24 Thread Uri Guttman
DL == David Landgren [EMAIL PROTECTED] writes: DL Uri Guttman writes: AP == A Pagaltzis [EMAIL PROTECTED] writes: AP * Jerrad Pierce [EMAIL PROTECTED] [2007-11-23 22:50]: exists( $dispatch{$sub} ) ? $dispatch{$sub}-() : warn Key $sub does not exist in the dispatch table; AP (

Re: fun with hashes!

2007-11-24 Thread David Landgren
Uri Guttman writes: DL Why stop there? Assuming $key never evaluates to 0: DLmy $sub = $dispatch{ $key || 'default' }; and what if $key is true but not found?? that is a different problem. your code doesn't handle that, it only handles a false or missing key DL If it does, wait

Re: fun with hashes!

2007-11-24 Thread Uri Guttman
DL == David Landgren [EMAIL PROTECTED] writes: DL Although there really is little point stuffing the coderef into a DL scalar, it's not like there's anything you can do to it. It's clearer to DL not draw attention to it and just run the damned thing: DL $dispatch{ $key || 'default' }-();

Re: fun with hashes!

2007-11-24 Thread Uri Guttman
SF == Steve Fink [EMAIL PROTECTED] writes: SF I don't think this has been mentioned, although it's really just a SF combination of two existing ones: I often have a table of sets. SF for my $user (@filenames) { SF open(my $fh, , $user) { SF while($fh) { SF

Re: fun with hashes!

2007-11-24 Thread Keith Ivey
How about using a hash to keep track of which things you've already handled? my %seen; for my $value (@values) { next if $seen{$value}++; # Do processing with $value here. } -- Keith C. Ivey [EMAIL PROTECTED] Washington, DC

Re: fun with hashes!

2007-11-24 Thread Jerrad Pierce
How about using a hash to keep track of which things you've already handled? That's just the afore-mentioned count -- Free map of local environmental resources: http://CambridgeMA.GreenMap.org -- MOTD on Pungenday, the 36th of The Aftermath, in the YOLD 3173: Wibble.

Re: fun with hashes!

2007-11-23 Thread Steven W. Orr
On Friday, Nov 23rd 2007 at 14:53 -, quoth Jerrad Pierce: =I admit I'm better with python these days than I am with perl, but one of =the caveats that the dispatch table should be taught with is that =selecting the correct code ref is different from calling through it. = =You might want to

Re: fun with hashes!

2007-11-23 Thread Uri Guttman
AP == A Pagaltzis [EMAIL PROTECTED] writes: AP * Jerrad Pierce [EMAIL PROTECTED] [2007-11-23 22:50]: exists( $dispatch{$sub} ) ? $dispatch{$sub}-() : warn Key $sub does not exist in the dispatch table; AP ( $dispatch{$sub} || sub { warn no such action '$sub' } )-(); some

Re: fun with hashes!

2007-11-23 Thread Mr. Shawn H. Corey
A. Pagaltzis wrote: * Mr. Shawn H. Corey [EMAIL PROTECTED] [2007-11-24 00:50]: my $sub = ( exists $dispatch{ $key } ref( $dispatch{ $key } ) eq 'CODE' ) ? $dispatch{ $key } : $dispatch{ 'default' }; Just because you're not paranoid doesn't mean computers don't hate you :)

Re: fun with hashes!

2007-11-23 Thread Danny Brian
Tied hashes a la Regexp::Common.

Re: fun with hashes!

2007-11-23 Thread Vladi Belperchinov-Shabanski
On Fri, 23 Nov 2007 23:18:20 +0100 A. Pagaltzis [EMAIL PROTECTED] wrote: * Jerrad Pierce [EMAIL PROTECTED] [2007-11-23 22:50]: exists( $dispatch{$sub} ) ? $dispatch{$sub}-() : warn Key $sub does not exist in the dispatch table; ( $dispatch{$sub} || sub { warn no such action

Re: fun with hashes!

2007-11-23 Thread Uri Guttman
SHC == Shawn H Corey [EMAIL PROTECTED] writes: SHC Vladi Belperchinov-Shabanski wrote: On Fri, 23 Nov 2007 23:18:20 +0100 A. Pagaltzis [EMAIL PROTECTED] wrote: * Jerrad Pierce [EMAIL PROTECTED] [2007-11-23 22:50]: exists( $dispatch{$sub} ) ? $dispatch{$sub}-() : warn Key

Re: fun with hashes!

2007-11-23 Thread A. Pagaltzis
* Mr. Shawn H. Corey [EMAIL PROTECTED] [2007-11-24 00:50]: my $sub = ( exists $dispatch{ $key } ref( $dispatch{ $key } ) eq 'CODE' ) ? $dispatch{ $key } : $dispatch{ 'default' }; Just because you're not paranoid doesn't mean computers don't hate you :) So why did you skip

Re: fun with hashes!

2007-11-23 Thread Mr. Shawn H. Corey
Steven W. Orr wrote: On Friday, Nov 23rd 2007 at 14:53 -, quoth Jerrad Pierce: =I admit I'm better with python these days than I am with perl, but one of =the caveats that the dispatch table should be taught with is that =selecting the correct code ref is different from calling through it.

Re: fun with hashes!

2007-11-23 Thread Steven W. Orr
on Friday, Nov 23rd 2007 at 13:12 -, quoth Uri Guttman: = =too long has this list been quiet. but i have a fun question. i am =writing up slides for an all about hashes class. one goal i have is to =list and explain as many different uses for hashes as reasonably =possible. i have a short

Re: fun with hashes!

2007-11-23 Thread Mr. Shawn H. Corey
Uri Guttman wrote: too long has this list been quiet. but i have a fun question. i am writing up slides for an all about hashes class. one goal i have is to list and explain as many different uses for hashes as reasonably possible. i have a short list to start with but i am sure the hive mind of

Re: fun with hashes!

2007-11-23 Thread Scott Wiersdorf
On Fri, Nov 23, 2007 at 01:12:37PM -0500, Uri Guttman wrote: isa is a key valid? (not same as in a set). isa usually works on fixed sets of keys my @foos = qw( axxj djdj whwh ) ; my %is_a_foo = map { $_ = 1 } @foos I don't have

Re: fun with hashes!

2007-11-23 Thread A. Pagaltzis
* Jerrad Pierce [EMAIL PROTECTED] [2007-11-23 22:50]: exists( $dispatch{$sub} ) ? $dispatch{$sub}-() : warn Key $sub does not exist in the dispatch table; ( $dispatch{$sub} || sub { warn no such action '$sub' } )-(); -- *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(,$\/, )[defined

Re: fun with hashes!

2007-11-23 Thread Uri Guttman
SW == Scott Wiersdorf [EMAIL PROTECTED] writes: SW I don't have any additional uses for hashes to add, but I do have a SW great hash initializer I picked up from Damian when he was in town a SW few years ago (borrowing from your example): SW my @foos = qw( axxj djdj whwh ) ; SW my

Re: fun with hashes!

2007-11-23 Thread Mr. Shawn H. Corey
Uri Guttman wrote: AP == A Pagaltzis [EMAIL PROTECTED] writes: AP * Jerrad Pierce [EMAIL PROTECTED] [2007-11-23 22:50]: exists( $dispatch{$sub} ) ? $dispatch{$sub}-() : warn Key $sub does not exist in the dispatch table; AP ( $dispatch{$sub} || sub { warn no such action '$sub' }