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!

chomp() in linux verses Win32

Status
Not open for further replies.

snookmz

Programmer
Apr 17, 2001
46
AU
G'day all

I've come accross a strange problem in my perl script.. Im trying to write a program that runs on both win32 systems and linux systems, but iv hit a little snag.. the chomp() function seems to behave very weirdly on my linux box, but when i run the same script on my win32 box it runs perfectly..

i.e. the chomp() function does work in that it strips the carriage return line feed off the end of the $_ variable, but then when i go to use it as a reference to a hash element

e.g. if(exists($hash{"$_"}))}

it doesn't return true, when $_ == the element in $hash.. but this works fine on my win32 box, and everything behaves the way it should...

Im really stumped on this one, and if anyone could shed some light on the matter i would be really gratefull :)

thanks in advance /-------------------------------------
| I always have been, and
| always will be, a newbie :)
\-------------------------------------
 
You need t have a setting to say if you are on a UNIX or NT system. If you are on a unix system, you need an if statement to decide whether you can use chomp. Im not sure what the NT equivelant is, but I'm sure some of the more advanced programmers will know :) I personally try and stand well clear of NT systems (or anything M$ related...lol)

Andy
 
Shortly:[ul][li]In
Code:
if(exists($hash{"$_"}))
you should write only
Code:
{$_}
I think.[/li]
[li] I think
Code:
s/[\r\n]+$//;
would do a nice chomp. Yes, I found chomp strange... [/li]
[/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top