Thanks Shlomi, your "untested" code worked first time. :-)
________________________________ From: Shlomi Fish <shlo...@iglu.org.il> To: beginners@perl.org Cc: Brian <brian5432...@yahoo.co.uk> Sent: Sun, October 31, 2010 4:23:52 PM Subject: Re: Removing leading whitespace and removing alternate newlines On Sunday 31 October 2010 17:01:24 Brian wrote: > Hi guys, long time no working with PERL :-) > > 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 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/