I'm printing the lines from a text file.
As I read the lines I would like to remove the linebreak but I can't seem to get it working.
I have tried this:
[HIGHLIGHT="Perl"]
$line =~ tr/\015//;
$line =~ tr/\n//;
$line =~ tr/\r//[/HIGHLIGHT]
But it doesn't seem to work. Any ideas?
tr/// has no concept of what you are trying to do, s/// would work (I think) but perl has the chomp() function which is specifically for removing the input record seperator (or line endings) which is by default a newline (\r\n on windows).
Code:chomp($line);
I was not aware of the chomp() function. This works fine for my purposes. thanks!
You could also use something like :
open(F,"<$ARGV[0]") or die("No file specified.\n");
my @data=<F>;
close(F);
my $blah=join("",@data);
# notice m
$blah =~ s/[\n\r]//mg;
print $blah;
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks