Re: hash question

2009-09-29 Thread Shawn H Corey
Johnson, Reginald (GTS) wrote: Thanks to all that assisted in this thread. I think I am now getting where I want to go with using hashes. One comment that I could use clarification on is: JR(> for ( $i=0; $i <= $number_of_elements-1; $i++ ) { don't loop over indices, loop over

RE: hash question

2009-09-29 Thread Johnson, Reginald (GTS)
mber 25, 2009 1:58 PM To: Johnson, Reginald (GTS) Cc: beginners@perl.org Subject: Re: hash question >>>>> "JR(" == Johnson, Reginald (GTS) writes: JR(> Sample input file "test2,MS-Windows-NT,Silver,NPRO30DINCR,Client JR(> JXWGTI7R5CHD1 WINDOWS NT,Schedule test2_f

Re: hash question

2009-09-25 Thread Jim Gibson
On 9/25/09 Fri Sep 25, 2009 12:48 PM, "Johnson, Reginald (GTS)" scribbled: > Uri, > Thank you for the assistance. I have incorporated data dumper and the " > " into the code. What I find odd is that data dumper shows the values of > the hash as I expect them to be. Yet still when I print I get

Re: hash question

2009-09-25 Thread Steve Bertrand
Johnson, Reginald (GTS) wrote: > Uri, > Thank you for the assistance. I have incorporated data dumper and the " > " into the code. What I find odd is that data dumper shows the values of > the hash as I expect them to be. Yet still when I print I get a hex > number. > > My output > > Enter the f

RE: hash question

2009-09-25 Thread Johnson, Reginald (GTS)
} print Dumper( \%policy_Hash); while ( my ($key,$value)= each %policy_Hash ) { print "$key => $value \n"; } } #end while close(INFILE); -Original Message- From: Uri Guttman [mailto

Re: hash question

2009-09-25 Thread Uri Guttman
> "JR(" == Johnson, Reginald (GTS) writes: JR(> Sample input file "test2,MS-Windows-NT,Silver,NPRO30DINCR,Client JR(> JXWGTI7R5CHD1 WINDOWS NT,Schedule test2_full_1700 FULL 604800" JR(> print "Enter the filename of input file with full path\n"; JR(> my $input_file = <>;

Re: hash question

2009-09-25 Thread Jim Gibson
On 9/25/09 Fri Sep 25, 2009 10:05 AM, "Johnson, Reginald (GTS)" scribbled: > I don't see what I am doing wrong in printing out the values in the > hash. I am inputting a file with records of varying number of fields and > want to put them in a hash. My output says Use of uninitialized value in

Re: hash question

2005-09-06 Thread Gergely Buday
Thank you all for your answers. - Gergely -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: hash question

2005-09-06 Thread Jeff 'japhy' Pinyan
On Sep 6, Gergely Buday said: do you have a clue why is this not working? The interpreter complains about a syntax error in line 7 near $myhash. You have written '$myhash($ky)' when you meant to write '$myhash{$ky}'. You have also written '%myhash = { ... }' when you meant to write '%myhash

Re: hash question

2005-09-06 Thread Ankur Gupta
On 9/6/2005 4:50 PM Gergely Buday wrote: Hi there, do you have a clue why is this not working? The interpreter complains about a syntax error in line 7 near $myhash. Seems like you are confused with the brackets... #!/usr/bin/perl %myhash = { "alma" => "apple", "korte" => "pear" }; Shou

Re: hash question

2005-09-06 Thread Shobha Deepthi
Its should be , print $ky, ":" , $myhash{$ky}, "\n"; Shobha Deepthi V The statement below is true. The statement above is false. Gergely Buday wrote: Hi there, do you have a clue why is this not working? The interpreter complains about a syntax error in line 7 near $myhash. #!/usr/bin

RE: hash question

2003-07-23 Thread Mike Bernhardt
Hashes don't keep your data in any knowable order- they keep it however works best for them. That's why you have to reference a value by it's key, not by it's location in the hash. -Original Message- From: awarsd [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 23, 2003 4:52 AM To: [EMAIL P

Re: hash question

2003-07-23 Thread Todd W.
"Awarsd" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > for(1..99){ > $result{$_}=$_; > } > ##saved it in a dbm file and reopen to the file > ##when i open the file i just read all the keys and display > ## the key > . > foreach (keys %dbm){ > print "$_,"; > } > ## now the int

RE: hash question

2003-07-23 Thread Kipp, James
> > maybe someone can enlighten me(if it is possible). > I did a very simple loop/save/open/display to test hash. > > ... > ... > for(1..99){ > $result{$_}=$_; > } > ##saved it in a dbm file and reopen to the file > ##when i open the file i just read all the keys and display > ## the k

Re: Hash Question

2002-12-06 Thread Jan Gruber
Hi, Sean && List >$Hash{"$User"}{"$Page"}{"$NumTimesVisited"} = $ANumber; > Is this possible? Sure, this will work. I would decrease the hash depth a bit: $Hash{$User}{$Page} = $NumTimesVisited; > If so, how would I traverse this, as I will not know > before hand the values in the hash; I wi

RE: Hash Question

2002-12-06 Thread simran
To interate over something like: $abc{'a1'}{'b1'} = $number1 $abc{'a2'}{'b2'} = $number2 $abc{'a3'}{'b3'} = $number3 $abc{'a4'}{'b4'} = $number4 ... You can use: foreach my $key1 (keys %abc) { foreach my $key2 (keys %{$abc{$key1}}) { my $value = $abc{$key1}{$key2} pri

RE: Hash Question

2002-12-06 Thread Sean Rowe
Thank you! -Original Message- From: Bob Showalter [mailto:[EMAIL PROTECTED]] Sent: Friday, December 06, 2002 9:45 AM To: '[EMAIL PROTECTED]'; Beginners@perl. org (E-mail) Subject: RE: Hash Question > -Original Message- > From: Sean Rowe [mailto:[EMAIL PROTECTED]

RE: Hash Question

2002-12-06 Thread Sean Rowe
That sounds more like what I want to do. I have a question, though: Since I'm not going to know before hand what my hash values are (as I create them on the fly), how can I iterate through each hash to get each value? -Original Message- From: Igor Sutton Lopes [mailto:[EMAIL PROTECTED]]

RE: Hash Question

2002-12-06 Thread Bob Showalter
> -Original Message- > From: Sean Rowe [mailto:[EMAIL PROTECTED]] > Sent: Friday, December 06, 2002 9:30 AM > To: Beginners@perl. org (E-mail) > Subject: Hash Question > > > I need to keep track of a user, all the web pages a user has > visited, and > the number of times the user visited

Re: Hash Question

2002-12-06 Thread Mystik Gotan
I'm not very sure if it works. I'd rather concentate the whole thing. $Hash{"User"} = $ANumber; $Hash{"Page"} .= $ANumber; $Hash{"NumTimesVisited"} .= $ANumber; Also note that you should be using $ in your HashKey calls! -- Bob Erinkveld (Webmaster Insane Hosts) www.insane-hosts.net

RE: Hash Question

2002-02-07 Thread Chas Owens
On Thu, 2002-02-07 at 14:27, Balint, Jess wrote: > After hours of pondering and sitting in wonder of simple it is, I have come > up with something. I do believe that this: > > for my $i (0..$#keys) { > > Quite possibly should be > > foreach ( @keys ) { > > Otherwise, why would yo

RE: Hash Question

2002-02-07 Thread Balint, Jess
After hours of pondering and sitting in wonder of simple it is, I have come up with something. I do believe that this: for my $i (0..$#keys) { Quite possibly should be foreach ( @keys ) { Otherwise, why would you have my @keys = (0, 1, 2, 3); Instead of just $keys = 3 and the

RE: Hash Question

2002-02-04 Thread Chas Owens
the values of '-f' > arguments? If so, it may be easier. Thanks for all your help. > > --Jess > > -Original Message- > From: Chas Owens [mailto:[EMAIL PROTECTED]] > Sent: Monday, February 04, 2002 2:56 PM > To: Balint, Jess > Subject: RE: Hash Question

RE: Hash Question

2002-02-04 Thread Balint, Jess
for a single argument, '-f' here and store an array reference in the hash for all the values of '-f' arguments? If so, it may be easier. Thanks for all your help. --Jess -Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED]] Sent: Monday, February 04, 2002

RE: Hash Question

2002-02-04 Thread Balint, Jess
That seems like the best way to do it, but if I enter -f 3, $tables[n] = " " and not 3 like it should. I think that $1 is defined as " " in this argument. What can I do about this? -Original Message- On Fri, 2002-02-01 at 15:23, Balint, Jess wrote: > A scalar value based on the number of

Re: Hash Question

2002-02-02 Thread Dave Benware
7;tutorial'? > > -Original Message- > From: Dave Benware [mailto:[EMAIL PROTECTED]] > Sent: Friday, February 01, 2002 2:44 PM > To: Beginners perl > Subject: Re: Hash Question > > "Balint, Jess" wrote: > > > > Since this is a beginners list

RE: Hash Question

2002-02-02 Thread Chas Owens
Okay, I came up with two solutions. The first is to use eval to build the hash and recursive functions to deal with it. The second takes up more space, but is easier to deal with: cat the keys together. The first is better when you have many things that are going to be the same and the key size

RE: Hash Question

2002-02-01 Thread Balint, Jess
The way I have the argument parsing set up is for ( 0..$#ARGV ) { . . . When a -f n is presented on the command line, n will be the field number for the first hash. So if I use -f 1 -f 2 -f 3, there will be three levels of hashes. The top level will contain all unique values in the first field of

RE: Hash Question

2002-02-01 Thread Chas Owens
On Fri, 2002-02-01 at 15:23, Balint, Jess wrote: > A scalar value based on the number of command line arguments put into an > array. > > if( $ARGV[$_] =~ /^-f/ ) { > # PARSE TABULATION VALUES > if( $table ) { > $table = $ARGV[$_]; >

RE: Hash Question

2002-02-01 Thread Chas Owens
how will you know how many keys are needed? On Fri, 2002-02-01 at 14:42, Balint, Jess wrote: > I think I will go ahead and use something like the multi-dimensional hash > example below. What I need to do is create hashes dynamically based on how > many are needed for this particular instance of t

RE: Hash Question

2002-02-01 Thread McCollum, Frank
Where might one find this 'tutorial'? -Original Message- From: Dave Benware [mailto:[EMAIL PROTECTED]] Sent: Friday, February 01, 2002 2:44 PM To: Beginners perl Subject: Re: Hash Question "Balint, Jess" wrote: > > Since this is a beginners list, I thought

RE: Hash Question

2002-02-01 Thread Balint, Jess
I think I will go ahead and use something like the multi-dimensional hash example below. What I need to do is create hashes dynamically based on how many are needed for this particular instance of the program. Any ideas on dynamic hash creation multi-dimensionally? Thanks -jess -Origina

Re: Hash Question

2002-02-01 Thread Dave Benware
"Balint, Jess" wrote: > > Since this is a beginners list, I thought I would be allowed to ask this > question. Can there be multiple values for hash keys, or just one? The > reason I am asking is that I am working on a statistical program and would > need to use multiple hashes as values of ano

RE: Hash Question

2002-02-01 Thread Hanson, Robert
Better yet you could use 'tie' and create your own hash implementation like the code below. You will be able to set and retreive values normally except for the fact that if you want a single value to be linked to two keys you will need to store the value in one key and reference that key in anoth

Re: Hash Question

2002-02-01 Thread Chas Owens
On Fri, 2002-02-01 at 12:42, Balint, Jess wrote: > Since this is a beginners list, I thought I would be allowed to ask this > question. Can there be multiple values for hash keys, or just one? The > reason I am asking is that I am working on a statistical program and would > need to use multiple h

RE: Hash Question

2002-02-01 Thread Hanson, Robert
n $hash->{$key}; } } Rob -Original Message- From: Hanson, Robert Sent: Friday, February 01, 2002 1:04 PM To: 'Balint, Jess'; '[EMAIL PROTECTED]' Subject: RE: Hash Question Just one unless you use references. Here is an example with references... %hash =

Re: Hash Question

2002-02-01 Thread Deen Hameed
Keys are unique in a hash; what you put in them is up to you. the new value will overwrite the old value, unless you append it during assignment, using the . operator. Yes, you can store a hash in a hash in a hash... :) try perldoc perldsc for stuff on data structures. deen On Fri, 1 Feb 200

Re: Hash Question

2002-02-01 Thread Terry Dignon
Hashes cannot store multiple values (to the best of my knowledge), although they can store arrays or additional hashes which can of course, contain more values. "Balint, Jess" wrote > > Since this is a beginners list, I thought I would be allowed to ask this > question. Can there be multiple va

RE: Hash Question

2002-02-01 Thread Hanson, Robert
Just one unless you use references. Here is an example with references... %hash = ( one => 1, two => 2 ); $hash{oneagain} = \$hash{one}; foreach my $key ( keys %hash ) { my $value = (ref $hash{$key}) ? ${$hash{$key}} : $hash{$key}; print "$key => $value\n"; } And when you

Re: Hash question

2001-12-28 Thread Andrea Holstein
Wim De Hul wrote: > > Hashes are hard to understand (regarding on the questions in this > list...). I have also a question: > Why doesn't this work? I get a synthax error? > > foreach $index (sort keys %IfType{$router}) { > print " Interface: $IfType{$router}{$index

Re: Hash question...

2001-12-17 Thread Andrea Holstein
Ahmed Moustafa wrote: > > Hi Dan, > > Try this: > > # -- > %flags=(); > foreach $user ( keys (%popusers) ) { > if (-e "/home/$user/test.pl") { > $flags{$user} = "YES"; > } else { > $flags{$user} = "NO"; > } > } > # -- > Or quite a little

Re: Hash question...

2001-12-17 Thread Ahmed Moustafa
Hi Dan, Try this: # -- %flags=(); foreach $user ( keys (%popusers) ) { if (-e "/home/$user/test.pl") { $flags{$user} = "YES"; } else { $flags{$user} = "NO"; } } # -- I hope that helps, Ahmed Daniel Falkenberg wrote: > Hi All, > > Just

Re: hash question- solved

2001-11-25 Thread [EMAIL PROTECTED]
On Sun, 25 Nov 2001, [EMAIL PROTECTED] wrote: > Date: Sun, 25 Nov 2001 15:18:19 +0200 (IST) > From: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED] > Subject: hash question > > hi all, > can someone point me in the right direction. i dont understand the > following line of c

Re: Hash Question

2001-08-16 Thread Neeraj Arora
Hello Jose, i think u can use $hashref = $dbh->selectall_hashref("select.); perdoc dbi to find more :) neeraj Friday, August 17, 2001, 12:02:14 AM, you wrote: TJCFS> How do I populate a Hash array with 3 fields from the result of an sql statement. TJCFS> (i.e. SELECT ORIGIN, DEPT,