[plug] perl program to strip blank lines from a file

Sol Hanna sol at autonomon.net
Mon May 17 18:10:46 WST 2004


I expect at least 10 replies from Perl hackers (which I'm not) to this
question, but I think really all you need is a regular expression,
something like 
$_ =~ /^$//;

I think that you don't just want to match, but to substitute the blank
line with nothing (thereby removing the line).

No doubt Bernard or Matt or Ryan will set you straight. ;)

/sol

On Mon, 2004-05-17 at 15:36, David Buddrige wrote:
> Hi all, 
> 
> I am tryin to put together a program which will strip blank lines out of a 
> text file.  To this end, I have written the following perl program; but it 
> doesn't seem to work... can anyone see why?  To my mind, the regex ^$ should 
> match lines that have no content, but this does not seem to be so... 
> 
> any help greatly appreciated... 
> 
> #!/usr/bin/perl 
> 
> while(<>)
> {
>    if(/^$/)
>    {
>    }
>    else
>    {
> 	print;
>    }
> } 
> 
> thanks 
> 
> David.
> _______________________________________________
> PLUG discussion list: plug at plug.linux.org.au
> http://mail.plug.linux.org.au/cgi-bin/mailman/listinfo/plug
> Committee e-mail: committee at plug.linux.org.au
-- 
------------------------
Sol Hanna
sol at autonomon dot net
------------------------




More information about the plug mailing list