in reply to replacing blank lines

Try something like this.
#!/usr/local/bin/perl open (FILE, "/home/robert/Print/foo") || die "Cant open /home/robert/f +oo\n\n"; # Create a file array of lines while ($line = <FILE>) { push (@array, $line); } # Then control the output foreach $index (@array) { # if the line is completely blank dont print it. if ($index !~ /^\s*\n\s*$/) { print "$index"; } }

Replies are listed 'Best First'.
Re: Re: replacing blank lines
by KM (Priest) on Mar 06, 2001 at 05:36 UTC
    # Create a file array of lines while ($line = <FILE>){ push (@array, $line); }

    ew.... just do:

    my @array = <FILE>;

    # Then control the output foreach $index (@array){ # if the line is completely blank dont print it. if ($index !~ /^\s*\n\s*$/) { print "$index"; } }

    ewwwww... use something more like:

    for (@array) { print unless /^(\n|\s+)$/; }

    Even better, do it from the command line (see another node in this same thread)

    Cheers,
    KM