Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help get wrong Variable

Status
Not open for further replies.

Troniac

Technical User
Mar 4, 2003
4
0
0
US
My doings are:

Read about 600 IP's from a MySQL Database put them in a socket array and proof the sockets.
Thats work pretty fine!!!

But there are some problems putting the collected data back to the database.

I use an array to collect the data here is an example:

foreach(@somedata)
{
$container[$read_set->peerhost()] = $somedata;
}
# Now i want to show the collected data from the last operation. to the screen. Later put this in the database.

my $i = 0;
foreach(@ip)
{
print $ip[$i].$container[$ip[$i]]
$i++;
}

# Screen output
80.132.212.155=|XXXXXXXXXXXX
62.143.17.160 =|XXXXXXXXXXXX
80.145.179.151=|XXXXXXXXXXXX
242.63.170.85 =|XXXXXXXXXXXX
217.81.57.164 =|XXXXXXXXXXXX

# There are someproblems!!!
This row is defenetly correct:
217.81.57.164=|XXXXXXXXXXXX

but look at the others here are the real values.
80.132.212.155=|HHHHHHHHHHHH
62.143.17.160 =|CCCCCCCCCCCC
80.145.179.151=|242.63.170.85 =|ZZZZZZZZZZZZ

I looked back to this
$container[$read_set->peerhost()] = $somedata;
and noticed that there is a problem with $read_set->peerhost() when i use print $read_set->peerhost(); i get the correct ip from any server. But when i do this
my $dummy = $read_set->peerhost();
print split($dummy,".");
i get this
Screen output:
1
1
1
1
1

I do not understand this because there have to be the ip addresses withous doted seperators :(

could someone may help me please
 
couple of problems

you have the arguments to split() the wrong way around - it should be

split(PATTERN, EXPR);

and -- if you're looking for a . in a string, you have to tell Perl to ignore the fact that the . is a special regular expression character

so -- like this

($first, $second, $third, fourth) =
split(/\./, '192.168.100.2');

so your code could be written as
split(/\./, $dummy);

Why, though,do you want the IP addresses with the dots? And how, without the dots, are you going to tell the difference between

192.168.101.2
and
192.168.10.12

?

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Also, an IP address (or anything that is anything but an integer) is not a valid array index. You can use an IP address as a hash key, so store your $somedata in a hash:
[tt]
$container{$read_set->peerhost()} = $somedata;
[/tt]
jaa
 
I am very thankfull for your Help,
that's what i'm looking for.

best wishes
Troniac
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top