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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split IP address. 3

Status
Not open for further replies.

roycrom

Programmer
Aug 2, 2002
184
GB
I have this simple piece of code
Code:
#!/usr/bin/perl -W
print "Content-type: text/plain\n\n";
my ($a,$b,$c,$d) = split(/./, $ENV{'REMOTE_ADDR'});
print "A is $a\nB is $b\nC is $c\nB is $d\n";
print "$ENV{'REMOTE_ADDR'}";

This gives the ouptut in web page
A =
B =
C =
D =
192.168.0.2

Why aren't the variables being set?
Is there another line with an array I need to use, with an @ARRAY?

Thanks for any help you can give.

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
try /\./ instead of /./

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

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

 
Thanks alot,

I thought I had it right but didn't realise I had to escape the full stop.

Greatly appreciated



------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
No problem :) gets me every time.

We should just say for other people reading this thread that.... (should have done this originally)

split - splits up a variable into chunks based upon the pattern between the / characters

/\./ - this pattern means split up the variable between the . characters in it.

and finally - the thing that didn't work /./ had a problem because the . character has a special meaning inside a pattern (it matches any single character) so it needs to be "escaped" with a \ so that split knows you really do mean a . character.

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

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

 
* from me to mike

(should have done this originally)

it's hard to remember that resources like this are for people who aren't involved in the current conversation/transaction

--Paul


Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
Yeah - and the equal, and opposite, evil is to document and explain so much and so clearly that the actual answer is hidden in the explanations :) Not that I'd ever do that, obviously.

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top