Re: Hashes from files. Unable to access values. Please, please help.

2010-11-23 Thread addie
> Where did $var come from? Sorry about that. That was a left over from the actual code that I tried to pare down to be a small example. Messed that up as badly as the copy/paste of the code made it really very ugly. Addie -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional

Re: Hashes from files. Unable to access values. Please, please help.

2010-11-21 Thread Uri Guttman
> "JWK" == John W Krahn writes: JWK> Uri Guttman wrote: >>> "a" == addie writes: >> a> %hash = split(/\s/, $locus_line); >> >> that assigns a single pair to the hash. a SINGLE PAIR to the WHOLE >> HASH. anything in the hash before that is wiped out. also the values >> w

Re: Hashes from files. Unable to access values. Please, please help.

2010-11-21 Thread Rob Dixon
On 21/11/2010 09:56, addie wrote: I have been fighting with this problem for over a week now he really aggravating thing is that I had it working for over a year without problem. have tried everything I can imagine. I've cut the code down to a toy version to isolate the problem and it is no help

Re: Hashes from files. Unable to access values. Please, please help.

2010-11-21 Thread John W. Krahn
Uri Guttman wrote: "a" == addie writes: a> %hash = split(/\s/, $locus_line); that assigns a single pair to the hash. a SINGLE PAIR to the WHOLE HASH. anything in the hash before that is wiped out. also the values will have newlines on them which isn't the main bug but is usually wrong

Re: Hashes from files. Unable to access values. Please, please help.

2010-11-21 Thread Uri Guttman
> "SHC" == Shawn H Corey writes: SHC> On 10-11-21 12:49 PM, Uri Guttman wrote: a> my %hash = (); >> >> no need to initialize a lexical hash with (). SHC> Sorry but you should initialize all your variables. At one time SHC> mod_perl did not initialize the data space; it simply r

Re: Hashes from files. Unable to access values. Please, please help.

2010-11-21 Thread Uri Guttman
> "a" == addie writes: a> #!/usr/bin/ a> perl a> \ that is VERY strange line wrapping. please be careful how you paste code so it doesn't do that. readers can't then paste the code and run it without cleaning up the wrapped lines. a> use strict; a> use warnings; a> my %hash =

Re: Hashes from files. Unable to access values. Please, please help.

2010-11-21 Thread Shawn H Corey
On 10-11-21 12:49 PM, Uri Guttman wrote: a> my %hash = (); no need to initialize a lexical hash with (). Sorry but you should initialize all your variables. At one time mod_perl did not initialize the data space; it simply re-used it. So your variables started with whatever was in them

Re: Hashes from files. Unable to access values. Please, please help.

2010-11-21 Thread Shawn H Corey
On 10-11-21 04:56 AM, addie wrote: #!/usr/bin/ perl \ use strict; use warnings; my %hash = (); my $key = ''; open ACCESSIONS, "fix.txt" or die "Can't open fix.txt: $!\n"; while (my $locus_line =){ #This is supposed to populate %hash. %hash = split(/\s/, $locus_line); foreach my $k (ke

Re: hashes + use constant - weird behavior

2010-05-14 Thread Dr.Ruud
Stanisław T. Findeisen wrote: use constant { SOME_CONSTANT => 'some value' }; $hash{SOME_CONSTANT} = 'value 1'; Not weird at all, just works as documented. So change to either: $hash{ +SOME_CONSTANT } = 'value 1'; or: $hash{ SOME_CONSTANT() } = 'value 1'; -- Ruud -- To uns

Re: hashes + use constant - weird behavior

2009-03-06 Thread Chas. Owens
On Fri, Mar 6, 2009 at 03:31, "Stanisław T. Findeisen" wrote: > Chas. Owens wrote: >> >> SOME_CONSTANT is being interpreted as the string "SOME_CONSTANT". > > Why is it so? This is crazy. Because it is nicer to say $hash{key} than $hash{"key"} and Perl is optimized for the common case. When you

Re: hashes + use constant - weird behavior

2009-03-06 Thread Jenda Krynicky
From: "Stanisław T. Findeisen" > Chas. Owens wrote: > > SOME_CONSTANT is being interpreted as the string "SOME_CONSTANT". > > Why is it so? This is crazy. Because most often you want it that way. Most often you do want the $hash{BLAHBLAH} to mean $hash{'BLAHBLAH'} and not have to put qu

Re: hashes + use constant - weird behavior

2009-03-06 Thread Paul Johnson
On Fri, Mar 06, 2009 at 09:31:44AM +0100, "Stanisław T. Findeisen" wrote: > Chas. Owens wrote: >> SOME_CONSTANT is being interpreted as the string "SOME_CONSTANT". > > Why is it so? This is crazy. Were it not so, every time you created a sub with the same name as one of your hash keys you would f

Re: hashes + use constant - weird behavior

2009-03-06 Thread Stanisław T. Findeisen
Chas. Owens wrote: SOME_CONSTANT is being interpreted as the string "SOME_CONSTANT". Why is it so? This is crazy. This is one of the drawbacks to the constant pragma. Change the code hash keys to one of these and it will work the way you want it to: $hash{+SOME_CONSTANT} #unary plus What

Re: hashes + use constant - weird behavior

2009-03-05 Thread Gunnar Hjalmarsson
Stanisław T. Findeisen wrote: #!/usr/bin/perl use warnings; use strict; use constant { SOME_CONSTANT => 'some value' }; my $index = 'some value'; my %hash = (); $hash{SOME_CONSTANT} = 'value 1'; $hash{$index} = 'value 2'; print("The value is: " . $hash{SOME_CONSTANT} . '/' . $hash{$index

Re: hashes + use constant - weird behavior

2009-03-05 Thread Chas. Owens
On Thu, Mar 5, 2009 at 12:23, "Stanisław T. Findeisen" wrote: > #!/usr/bin/perl > > use warnings; > use strict; > > use constant { >    SOME_CONSTANT => 'some value' > }; > snip > print("The value is: " . $hash{SOME_CONSTANT} . '/' . $hash{$index} . "\n"); snip SOME_CONSTANT is being interpreted

Re: Hashes

2008-02-05 Thread Omega -1911
On Feb 4, 2008 10:05 PM, <[EMAIL PROTECTED]> wrote: > Hi > > i am not able to declare hases > > first i tried this > > * > use strict > my %familyname; > $familyname{"mark"}="antony"; > > and i get an error "Global symbol

Re: Hashes of Hashes

2006-12-29 Thread John W. Krahn
Jason Malburg wrote: > Hi, Hello, > I'm working on a complex data structure with hashes of hashes and > hashes of arrays and I noticed a weird behavior I was hoping someone > could explain. Put these two lines at the beginning of your program: use warnings; use strict; and perl will tell you w

Re: Hashes of Hashes

2006-12-29 Thread Jen Spinney
On 12/28/06, Jason Malburg <[EMAIL PROTECTED]> wrote: Hi, I'm working on a complex data structure with hashes of hashes and hashes of arrays and I noticed a weird behavior I was hoping someone could explain. Here's a sample: $Data{US17}{1}{GROUP} = "STRING"; $Data{US17}{1}{GROUP}{.001} = 5; $Da

Re: Hashes and scope

2006-04-20 Thread Allister
On Thursday 20 April 2006 21:48, Tom Phoenix wrote: > On 4/20/06, Allister <[EMAIL PROTECTED]> wrote: > > %qnums_quests = ($quest_number, $quest_string); > > The assignment operator replaces the entire variable on the left with > the value on the right. If you wish to modify the hash, instead of >

Re: Hashes and scope

2006-04-20 Thread Tom Phoenix
On 4/20/06, Allister <[EMAIL PROTECTED]> wrote: > %qnums_quests = ($quest_number, $quest_string); The assignment operator replaces the entire variable on the left with the value on the right. If you wish to modify the hash, instead of replacing everything it contains, you probably want a stateme

Re: hashes and loops

2005-06-15 Thread John W. Krahn
Karyn Williams wrote: At 07:42 AM 6/15/05 -0700, you wrote: Karyn Williams wrote: Also, there are just a handful of files BUT they are ever changing, so I would like to not list the statically in the code. but this would work: chomp( my @lists = qx(ls /usr/local/dir) ); But this would

Re: hashes and loops

2005-06-15 Thread Karyn Williams
At 07:42 AM 6/15/05 -0700, you wrote: >Karyn Williams wrote: >> Also, >> there are just a handful of files BUT they are ever changing, so I would >> like to not list the statically in the code. >> >but this would work: > >chomp( my @lists = qx(ls /usr/local/dir) ); > >But this would work a lot

Re: hashes and loops

2005-06-15 Thread John W. Krahn
Karyn Williams wrote: [snip] So, first question is why is this happenning ? Then how do I fix it ? What is happening that you didn't want to happen? What is NOT happening that you did want to happen? http://www.catb.org/~esr/faqs/smart-questions.html Also, there are just a handful of

Re: hashes and loops

2005-06-15 Thread Dave Gray
On 6/14/05, Karyn Williams <[EMAIL PROTECTED]> wrote: > Below is code that I found on the web that I slightly modified. I am trying > to create a script to remove from a file (tlist) the items in another file > (tnames). This works but I have multiple files (tlist) I need to check > against. I'm no

RE: hashes and loops

2005-06-14 Thread Karyn Williams
At 04:37 PM 6/14/05 -0700, you wrote: >Karyn Williams wrote: >> Below is code that I found on the web that I slightly modified. I am >> trying to create a script to remove from a file (tlist) the items in >> another file (tnames). This works but I have multiple files (tlist) I >> need to check agai

Re: hashes and loops

2005-06-14 Thread Jeff 'japhy' Pinyan
On Jun 14, Karyn Williams said: Below is code that I found on the web that I slightly modified. I am trying to create a script to remove from a file (tlist) the items in another file (tnames). This works but I have multiple files (tlist) I need to check against. I'm not sure how/where to put the

RE: hashes and loops

2005-06-14 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Karyn Williams wrote: > Below is code that I found on the web that I slightly modified. I am > trying to create a script to remove from a file (tlist) the items in > another file (tnames). This works but I have multiple files (tlist) I > need to check against. I'm not sure how/where to put the loop

Re: hashes and arrarys

2005-06-03 Thread Xavier Noria
On Jun 3, 2005, at 23:56, The Ghost wrote: [EMAIL PROTECTED]; print "Answers:$surveyQuestions{answers}[$x]\n; # <--- Prints the number of answers instead My problem is that I always get the number of answers instead of the answers. What am I doing wrong? Perl struct

Re: hashes of arrays?

2005-01-26 Thread Ing. Branislav Gerzo
Andrianoelison Joël [AJ], on Tuesday, January 25, 2005 at 18:59 (+0100) has on mind: AJ> my %myhash; # you'd better declare it outside the while() I always initalize hashes and arrays like this: my %myhash = (); -- ...m8s, cu l8r, Brano. [I feel alephed out] -- To unsubscribe, e-mail: [E

Re: hashes of arrays?

2005-01-25 Thread Ankur Gupta
It is possible to store an array in a hash by using references #foreach $destination (@dest_users) { # NO NEED FOR THIS #print "==>$destination\n"; push( @{$aliases{$alias}}, @dest_users ); foreach $key ( keys %aliases ){ print "$key: @{$aliases{$key}}\n

RE: hashes of arrays?

2005-01-25 Thread Andrianoelison Joël
Hum, use hash like this : my %myhash; # you'd better declare it outside the while() foreach $destination (@dest_user) { if (/$destination/) { s/(\s+):*/defined($myhash{$destination})?$myhash{$destination}=$myhash{$dest ination}.",".$1:$myhash{$destination}=$1/e } } guess it'd work :-( not teste

Re: Hashes and memory consumption

2003-01-16 Thread Jenda Krynicky
From: Schoenwaelder Oliver <[EMAIL PROTECTED]> > I have some problems with a script using hashes. > I use hashes for years but never had this kind of problem before... I > have a ascii file with 6.5 MB of data. This file is tokenized by > Parse:Lex module. The tokens are then stored in a two level

Re: Hashes and memory consumption

2003-01-16 Thread david
Schoenwaelder Oliver wrote: > Hi list members, > > I have some problems with a script using hashes. > I use hashes for years but never had this kind of problem before... > I have a ascii file with 6.5 MB of data. This file is tokenized by > Parse:Lex module. i never use this module before so i d

Re: hashes and string

2002-12-01 Thread Rob Dixon
Simas Sorry if I'm too late, but: my $hours; my $hours_flags = "0000"; @$hours{'00' .. '23'} = split '', $hours_flags; Cheers, Rob - Original Message - From: "Simas Mockevicius" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, December 01, 2

Re: hashes and string

2002-12-01 Thread Simas Mockevicius
Thanx, but i have writen my code (maybe huge, but :)... for (my $a = 0; $a < 24; $a++) { my $value = substr $hours_flags, $a, $a; $Hours->{$a} = $value; } :-) Symka. > $_ = "0000"; > @h{grep~s/^.$/0$&/,0..23} = /./g; > > I hope that works > > -- > To unsubscribe

Re: hashes and string

2002-12-01 Thread badchoice
$_ = "0000"; @h{grep~s/^.$/0$&/,0..23} = /./g; I hope that works -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: hashes and string

2002-12-01 Thread badchoice
$_ = "0000"; @h{0..23} = /./g; (no '00' keys) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Hashes Question : Thank you

2002-11-27 Thread Sudarshan Raghavan
On Wed, 27 Nov 2002, Ben Crane wrote: > Cheers, > > I was going to think about using a hash for a text > file that contains information from a > file::find...there are thousands and thousands of > files I want to x-check and update it the modified > date differs...at the moment, arrays work fine

Re: Hashes Question : Thank you

2002-11-27 Thread Ben Crane
Cheers, I was going to think about using a hash for a text file that contains information from a file::find...there are thousands and thousands of files I want to x-check and update it the modified date differs...at the moment, arrays work fine, but I was hoping a hash would mean a slightly quick

Re: Hashes Question!

2002-11-27 Thread Sudarshan Raghavan
On Wed, 27 Nov 2002, Ben Crane wrote: > Hi all, > > One quick Q about hashes: > > they contain a key and data? > e.g: %stuff=(A => 'one', > B => 'two'); > > where A and B are keys to data one and two...but what > happens if you have a massive text file wher you had > one key, but 2

Re: Hashes Question!

2002-11-27 Thread Jenda Krynicky
From: Ben Crane <[EMAIL PROTECTED]> > Hi all, > > One quick Q about hashes: > > they contain a key and data? > e.g: %stuff=(A => 'one', > B => 'two'); > > where A and B are keys to data one and two...but what > happens if you have a massive text file wher you had > one key, but 20 o

Re: Hashes

2002-10-13 Thread John W. Krahn
Colin Johnstone wrote: > > Gidday from Downunder, Hello, > Im writing the script to read the the contetns of a text file into a hash, > the text file has two records > > [EMAIL PROTECTED]|html > [EMAIL PROTECTED]|txt Hash keys have to be unique so the key "[EMAIL PROTECTED]" can either have t

RE: Hashes

2002-10-13 Thread Johnstone, Colin
Hi All, Yes silly me, I found the problem the second record replaced the first as the key was the same. Thank You Colin Johnstone Website Project Officer Corporate Website Unit Public Affairs Directorate ph 9561 8643 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e

RE: Hashes and loops

2001-09-19 Thread Daniel Falkenberg
> List, > > I have the following while loop that goes and pings a whole heap of servers around our company. If one is broken or doesn't respond to the ping my code e-mails me the results of which server isn't responding. This all works well but I really need it to be able to keep pinging all the

RE: Hashes with multiple values per key

2001-08-08 Thread Bob Showalter
> -Original Message- > From: Casey West [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, August 07, 2001 5:23 PM > To: Bob Showalter > Cc: '[EMAIL PROTECTED]' > Subject: Re: Hashes with multiple values per key > > ... > That's not very nice dude. I d

Re: Hashes with multiple values per key

2001-08-07 Thread Sophia Corwell
--- Casey West <[EMAIL PROTECTED]> wrote: > On Tue, Aug 07, 2001 at 05:42:55PM -0400, Bob > Showalter wrote: > : > -Original Message- > : > From: Sophia Corwell > [mailto:[EMAIL PROTECTED]] > : > Sent: Tuesday, August 07, 2001 5:24 PM > : > To: Casey W

Re: Hashes with multiple values per key

2001-08-07 Thread Casey West
On Tue, Aug 07, 2001 at 05:42:55PM -0400, Bob Showalter wrote: : > -Original Message- : > From: Sophia Corwell [mailto:[EMAIL PROTECTED]] : > Sent: Tuesday, August 07, 2001 5:24 PM : > To: Casey West : > Cc: [EMAIL PROTECTED] : > Subject: Re: Hashes with multi

RE: Hashes with multiple values per key

2001-08-07 Thread Bob Showalter
> -Original Message- > From: Sophia Corwell [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, August 07, 2001 5:24 PM > To: Casey West > Cc: [EMAIL PROTECTED] > Subject: Re: Hashes with multiple values per key > > > Thanks for the reply eventhough my question w

Re: Hashes with multiple values per key

2001-08-07 Thread Sophia Corwell
Thanks for the reply eventhough my question was not clear. Let me explain what I am trying to do. I have a hash named %orgjobs whose keys have multiple values. The keys are department numbers and the values are job_titles. There is a also a text file that has a list of departments, users, and

RE: Hashes with multiple values per key

2001-08-07 Thread RArul
@{$hash{'jmj'}}; }; close(INP); timethis(100, $expressiveCode); timethis(100, $idiomaticCode); Please refer attachment for the stats(small file). -- Rex -Original Message- From: Luke Bakken [mailto:[EMAIL PROTECTED]] Sen

RE: Hashes with multiple values per key

2001-08-07 Thread Luke Bakken
> #Mode Idiomatic Way and is more efficient too! > map { print "Take working vacation bud\n"; } grep{$_ eq 'george'} > @{$hash{'jmj'}}; > > I would prefer the second way -- the idiomatic way of doing it in Perl. I > have read, somewhere that the second approach is more efficient. Actually discard

RE: Hashes with multiple values per key

2001-08-07 Thread RArul
ere that the second approach is more efficient. -- Rex -Original Message- From: Luke Bakken [ mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> ] Sent: Tuesday, August 07, 2001 3:59 PM To: Sophia Corwell Cc: [EMAIL PROTECTED] Subject: Re: Hashes with multiple values per key > D

Re: Hashes with multiple values per key

2001-08-07 Thread Luke Bakken
> Does anyone have any ideas on what is a good way to > check the existance of a value for a key that has > multiple values? I'll assume that your hash table has the following structure: $hash{$key} = [ ]; that is, the value of each hash element is an array reference. Let's say you're looking

Re: Hashes with multiple values per key

2001-08-07 Thread Casey West
On Tue, Aug 07, 2001 at 12:14:55PM -0700, Sophia Corwell wrote: : Hello Perl Help, : : Does anyone have any ideas on what is a good way to : check the existance of a value for a key that has : multiple values? I'm not quite sure what you're asking for so I'm going to try and rephrase your questi

re: hashes

2001-06-15 Thread Paul
--- Oliver Glass <[EMAIL PROTECTED]> wrote: > Paul, thanks so much for all this information! You're welcome. I'm glad somebody appreciated it. =o) > As well as helping me learn your kindness really brightened up a > dreary day at the office :) lol -- worth the time, also. > Well, I've been w

re: hashes

2001-06-15 Thread Oliver Glass
Paul, thanks so much for all this information! As well as helping me learn your kindness really brightened up a dreary day at the office :) Well, I've been working on hashes for the last few weeks and have some more questions now. I've dropped them into our original correspondence. Best wishes,