LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-13-2005, 05:12 AM   #1
stoney79
LQ Newbie
 
Registered: Jul 2003
Posts: 12

Rep: Reputation: 0
Perl: differences between Win2k & Linux?


Hi there,

I've been having problems with a Perl script I've been given. It falls over at the following segment:
Code:
	open (PRJLISTFILE, "<$ENV{'_TMROOT'}/project/prjlist.txt");
	LOOP: while (defined($PrjListLine=<PRJLISTFILE>)){
		chomp $PrjListLine;
		print STDOUT "$PrjListLine\n";
		next LOOP if ($PrjListLine =~ /^\#/);
		next LOOP if ($PrjListLine =~ /^\s*$/);
		$PrjListLine =~ s/\#.*//g;
		$RootLocations = $RootLocations." ".$PrjListLine;
		print STDOUT "Current RL: [$RootLocations]\n"; 
	}
	print STDOUT $RootLocations;
	close PRJLISTFILE;
This should read a list of directory locations and create a list of them in the variable $RootLocations, each delimited by a space. This works fine on Windows, but under Linux it overwrites the first one each time, resulting in a rather munged variable. Any thoughts as to the difference?

I've checked and the textfile looks fine on both, so it's not a CRLF prob. All suggestions gratefully received! Using ActiveState Perl v5.6.1 on both (originally using 5.8.1 in Linux, so have reverted back to 5.6.1)

Thanks,

Tony

Last edited by stoney79; 01-13-2005 at 05:14 AM.
 
Old 01-13-2005, 08:25 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
Do you mean that the file has a CRLF in both cases?

If so, then the Linux version will remove only the LF with chomp(), because Linux doesn't treat CR as a newline character.

This will also leave a CR at the end of each line, which the terminal will interpret as “go back to start of line”, hence why this would look the same on each line.

In this case, you could declare a local value for $/ to be CRLF to get around this problem, or (for instance) use a regexp to remove all whitespace (or all CRs and all LFs) from the end of the line.
 
Old 01-13-2005, 08:56 AM   #3
stoney79
LQ Newbie
 
Registered: Jul 2003
Posts: 12

Original Poster
Rep: Reputation: 0
Ah....

Yep - that's fixed it. I'm still a bit of a Linux newbie so haven't quite grasped the finer points of CR and LF! I thought it must have been that, but each time I loaded the file in an editor the customer ^Ms weren't there so I thought it wasn't that. But my friend showed me dos2unix and since then it's fixed! I've now hit another problem, but will investigate a bit more!

Thanks a lot rjlee!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Win2K DC & Linux logon SADANA Linux - Networking 1 02-06-2004 02:43 PM
DHCPD differences between Win2K and Win XP brundles Linux - Networking 2 12-05-2003 01:23 PM
Win2k & Linux install---plss help. prasadkowli Linux - Software 5 11-09-2003 05:23 AM
Triple Boot - Win2K, Suse Linux & my own linux pavkb Linux - General 2 09-29-2003 08:57 AM
email sharing across two os linux & win2k breadbin Linux - Software 1 09-16-2002 03:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration