On Sunday 31 October 2010 17:01:24 Brian wrote: > Hi guys, long time no working with PERL :-) >
See: http://perl.org.il/misc.html#pl_vs_pl > I have just installed 5.2.12 > You probably mean perl-5.12.2 . A few more comments on your code: > First, I am trying to remove leading tabs & spaces but the following leaves > a few blanks at the beginning of each line, could someone be kind enough > to point out the error of my ways please? :-) > > #!/usr/bin/perl > Add strict and warnings. See: http://perl-begin.org/tutorials/bad-elements/ > local $/=undef; You probably don't want to read the entire file to memory at once, as it may be very large. > open(FILE, "smith3.txt") || die ("Error\n"); Use three-args-open, lexical filehandles, and use a more descriptive error than "Error.". > $string = <FILE>; > $string =~ s/\s//; #remove leading spaces > This will remove only the first whitespace character (and in your case, from the entire file). > print "$string"; > > > > 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? Use something like this (untested): [code] #!/usr/bin/perl use strict; use warnings; my $filename = shift(@ARGV) or die "No filename specified in command-line"; open my $fh, "<", $filename or die "Cannot open '$filename' for reading - $!"; my $line_num = 1; while (my $line = <$fh>) { chomp ($line); $line =~ s{\A\s+}{}; print $line; if ($line_num % 2 == 0) { print "\n"; } } continue { $line_num++; } close($fh); [/code] Regards, Shlomi Fish > > Thanks muchly > Brian -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Best Introductory Programming Language - http://shlom.in/intro-lang <rindolf> She's a hot chick. But she smokes. <go|dfish> She can smoke as long as she's smokin'. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/