rgb96 has asked for the wisdom of the Perl Monks concerning the following question:
Hey Monks,
I'm taking a file that was written in notepad, importing it to my linux machine, and trying to chomp the lines and display them in a tree view. As I quickly found out, chomp won't work with it's default value because windows format uses crlf and not \n. Quick question, is it best to just change the value of $/ ? And if so, is this the way i would do it?
local $/ = "\r\n"; open(FILE, "environments.txt); my @temp = <FILE>; foreach my $line (@temp){ chomp($line); print $line; }
print used instead of treeview just for illustration
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: crlf to \n
by moritz (Cardinal) on Apr 02, 2009 at 14:36 UTC | |
by rgb96 (Acolyte) on Apr 02, 2009 at 14:51 UTC | |
Re: crlf to \n
by planetscape (Chancellor) on Apr 02, 2009 at 15:21 UTC | |
Re: crlf to \n
by kennethk (Abbot) on Apr 02, 2009 at 14:41 UTC | |
by codeacrobat (Chaplain) on Apr 02, 2009 at 23:10 UTC | |
Re: crlf to \n
by dwm042 (Priest) on Apr 02, 2009 at 18:26 UTC | |
by zwon (Abbot) on Apr 02, 2009 at 19:09 UTC | |
by Intrepid (Curate) on Apr 03, 2009 at 03:41 UTC |