Brian wrote:
Hi guys, long time no working with PERL :-)
Hello,
I have just installed 5.2.12 First, I am trying to remove leading tabs& spaces
Just tabs and spaces? Your code says all whitespace.
but the following leaves a few blanks at the beginning of each line,
You code only removes one whitespace character.
could someone be kind enough to point out the error of my ways please? :-) #!/usr/bin/perl
use warnings; use strict;
local $/=undef;
Or just: local $/;
open(FILE, "smith3.txt") || die ("Error\n");
Better as: open FILE, '<', 'smith3.txt' or die "Cannot open 'smith3.txt' $!";
$string =<FILE>;
my $string = <FILE>;
$string =~ s/\s//; #remove leading spaces
$string =~ s/^[ \t]+//mg; #remove leading spaces and tabs from every line
print "$string";
No need to stringify something that is alraedy a string: print $string; perldoc -q quoting
Secondly, I would like to remove newline from alternate lines, ie I would like to remove from lines 1,3,5,7 etc. What would be the simplest way of getting even line numbers to print on the same line as odds?
my $count; $string =~ s/(\n)/ $count++ % 2 ? $1 : '' /eg; John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/