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

How to prevent concatenation?

Status
Not open for further replies.

DarinGowan

Technical User
Jul 15, 2002
8
US
How do I prevent perl from concatenating a value?

I am parsing out multiple variable=vaule from a long string (array). One of those variable=value pairs is something like this "origin=aaa.bbb.ccc.ddd" (yep, it's an IP address).

Here is a snipit of my program:
==========================================================
# for each element in the array
while ($data = shift @EVENTDATA) {

# look for specific items, then "set" the variable to it's value
elsif (index($data,'origin=') == 0) {
eval("\$" . "$data") ;
}
}

The eval statement (should) translate to the following:

$origin=aaa.bbb.ccc.ddd

However, when I print my line of data, the IP address comes out like this:

aaa.bbbccc.ddd

Ergo my question "How do I prevent perl from concatenating a value?"

Thank you.

Darin Gowan


 
Here's an update. I used a different method of setting the perl variable...

I used the split function rather than relying on eval. It worked!

elsif (index($data,'origin=') == 0) {
# eval("\$" . "$data") ;
($junk, $origin) = split(/=/, $data);
}


Sorry to bother you all with my problems...

Darin Gowan
 
Darin,

It's not a bother.... and thanks for posting your solution as well. Mike
________________________________________________________________

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top