Nyimi Jose wrote:
> 
> > From: Konrad Foerstner [mailto:[EMAIL PROTECTED]]
> >
> > My problem today ;) : I have a file with some unmeant empty
> > lines and I want to remove them, without writing a new file
> > and without storing all the content temporarily in an array.
> > I thought about the following lines of code, but they don't
> > do the job.
> >
> > open (FH, "+<$filename");
> >
> > foreach (<FH>){
> >     $_ =~ s/^\n//g;
> 
> Although you have opened the file in read/write mode,
> $_ =~ s/^\n//g changes only the content of $_ not the file.
> You need somehow to remove your empty lines from the file itself.
> 
> That's here the module Tie::File can elegantly do the job:
> 
> my @file;
> tie @file,'Tie::File', $filename or die ...
> map{ $file[$_]=~s/^\s*$// } (0 .. $#file);

Ick, map in a void context.  And the substitution isn't removing the
line, just the contents of the line.

tie my @file,'Tie::File', $filename or die $!;
@file = grep /\S/, @file;




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to