473,474 Members | 1,304 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trouble with $key to HASH when Numeric


It seems if I "Change" the $key going to if ""(exists($GREEN{$key}))""
at all It hoses. The keys look like "19973|3.1.A.4" without the quotes.
If I print like this "print GREEN{$key}\n"; to see what the Hash is
getting it looks like this:
}REEN{12483|3.1.B.2

That is odd? Is there a way to send my data to the hash without it
getting hosed???

Code below:
foreach (keys %HOT) {

# 6AE-23945: 4.1.B.6 # Fix this
# Make a Key for %GREEN from %HOT that works
my $i=$_;
$i=~/(\d{5}?)$/g;
$i=$1;

my $key="$i|$HOT{$_}";
#print "$GREEN{$key}\n";

if (exists($GREEN{$key})) {
# Remove from %GREEN
# remove $KEY and its value from %HASH
print "Removed $GREEN{$key}\n";
delete($GREEN{$key});
} else { # print "did not see\n";
}
}
Craig

Jul 19 '05 #1
2 3242
CowBoyCraig wrote:
It seems if I "Change" the $key going to if ""(exists($GREEN{$key}))""
at all It hoses. The keys look like "19973|3.1.A.4" without the quotes.
Based on your problem, I can see that they are not what you think.
If I print like this "print GREEN{$key}\n"; to see what the Hash is
getting it looks like this:
}REEN{12483|3.1.B.2


That is to be expected when you print a value like "12483|3.1.B.2\r\n".

You did not use chomp() or other means to get rid of the
unwanted carriage return at the end of the line.

Next time, post to comp.lang.perl.misc instead of comp.lang.perl .

-Joe
Jul 19 '05 #2
In article <11*********************@l41g2000cwc.googlegroups. com>,
CowBoyCraig <si******@us.ibm.com> wrote:
It seems if I "Change" the $key going to if ""(exists($GREEN{$key}))""
at all It hoses. The keys look like "19973|3.1.A.4" without the quotes.
Can you be more specific? "hoses" is not a good description of an error
condition.


If I print like this "print GREEN{$key}\n"; to see what the Hash is
getting it looks like this:
}REEN{12483|3.1.B.2
Looks like your key has a carriage return ('\r') at the end.

That is odd? Is there a way to send my data to the hash without it
getting hosed???
One does not "send data" to a hash. Can you be more specific about what
you are trying to do?

Code below:
use strict;
use warnings;

foreach (keys %HOT) {

# 6AE-23945: 4.1.B.6 # Fix this
# Make a Key for %GREEN from %HOT that works
my $i=$_;
$i=~/(\d{5}?)$/g;
What do you think this statement is doing? It has a couple of oddities:
1) the pattern /(\d{5}?)$/ will match zero or one group of 5 digits at
the end of a string -- in other words, this pattern will always match
and capture either 5 digits or nothing; 2) the pattern is anchored to
the end of the string, yet you are asking for all matches with the g
modifier (there can only be one end of string unless you specify the m
modifier, which you do not).
$i=$1;
You may have 5 digits in $1, or you may have nothing. You should check
to see which it is (or fix your regex).

my $key="$i|$HOT{$_}";
#print "$GREEN{$key}\n";

if (exists($GREEN{$key})) {
# Remove from %GREEN
# remove $KEY and its value from %HASH
print "Removed $GREEN{$key}\n";
delete($GREEN{$key});
} else { # print "did not see\n";
}
}


Please post a complete, working program and tell us what you think it
is doing that it is not. But post it to comp.lang.perl.misc, because
this newsgroup is defunct.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Joakim Storck | last post by:
Hello, Is there any way that I can find the hash value of a class from an instance? >>> class A: .... pass .... >>> a = A() >>> hash(A)
2
by: Mark | last post by:
I'm using an enumerator to iterate through a HashTable that contains all numeric keys. I'd like to iterarate through the HashTable based on the ordered keys. Is there a quick way to do this?...
2
by: Me | last post by:
I have a hash (of a hashes) that has data like this table1->table_name ->table_size table2->table_name ->table_size
26
by: JGH | last post by:
How can I check if a key is defined in an associative array? var users = new array(); users = "Joe Blow"; users = "John Doe"; users = "Jane Doe"; function isUser (userID) { if (?????)
21
by: scandal | last post by:
I am a javascript newbie working on a script that checks whether a "path" from one element in an array to another is "blocked." Currently, the script pushes an already processed cell index (hence...
6
by: Sahil Malik [MVP] | last post by:
Public Private Key Pairs - How do they work? ----------------------------------------------- I was looking at a presentation recently in which it was suggested that - User 1 Encrypts a message...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
4
by: webmaniac | last post by:
Hi, Does anyone knows How "JAVAScript Public Key Encryption" works? I am trying to secure my web page. The users are going to be log in to my website. I want to give them a 4 digit pin, that...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.