On Mon, 1 Oct 2001, Gareth Londt wrote:

> i need to know where to put a new line in.........i keep getting errors......?
> here is what the code looks like, if anyone can help with the newline....i
> would much appreciate it.
>
> #!/usr/bin/perl -w
>
> $file = 'dnsbills.06-09-2001';
>
> open FILE, $file;
> @lines = <FILE>;
> close (FILE);
>
> for ($line=0;$line <=$#lines;$line++){
>         if ($lines[$line] =~ /^Reg Date/) {
>                 print STDERR $lines[$line+2];
>                 @columns = split " ", $lines[$line+2];
>                 print $columns[1];
>                 }
>         }

Dumping a file into an array is not always a good idea.  If that file is
huge, you are going to eat up memory.  Where do you need a newline and
what errors are you getting?

Here's how I would code this, guessing that you need a new line after you
print your column.  I also tidied the code up a little bit (don't use
C-style loops if you don't need to, and definitely not for an array!), and
made use of the default variable.

#!/usr/bin/perl -w

use strict;

open FILE, 'dnsbills.06-09-2001' or die "Could not open file: $!\n";

while(<FILE>) {

        if(/^Reg Date/ {
                print STDERR;
                @columns = split /\s/;
                print "$columns[1]\n";
        }
}

close FILE;

-- Brett
                                          http://www.chapelperilous.net/
------------------------------------------------------------------------
"No job too big; no fee too big!"
                -- Dr. Peter Venkman, "Ghost-busters"


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

Reply via email to