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

why isn't this chomp working?

Status
Not open for further replies.

m4trix

Vendor
Jul 31, 2002
84
CA
I have a text file with a name and IP on each line, sepparated by double bars (||) like this for example:
[tt]
userone||22.51.32.32
usertwo||192.32.32.*
userthree||32.35.*.*
userfour||24.32.62.323
[/tt]

For example. Anyway, when I read in the file, I use the code:
[tt]
my ($users,$ips);
while(<USRS>){
chomp $_;
($users,$ips) = split(/\|\|/, $_);
push(@Users, $users);
push(@IPs, $ips);
}
[/tt]
That would work fine - except the chomp doesn't remove the newline. I don't know why. It's as though there's a new line line there that is not recognised as one. The only way I can get it to &quot;chomp&quot; properly is to chop TWICE.

I figured it was something wrong with the file, but I've tried redoing it, I even used a separate script to save it with JUST \n's after each line, but it still won't work.

Any ideas? I'm kind of iffy about leaving two chops next to eachother like that. If for some reason the first one starts working right, then I'll lose a character I don't want to.

I've also tried s/\n// but it didn't work either. same result as chomp.
 
Hmmmn, seems a pesky control char has got into your file. At this point I would open the file up in a hex editor to see what it was and then explicitly get rid of it with a regexp.

Hope that helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top