in reply to Re: reading files
in thread reading files

thanks but if i then print  @file it prints the array fine but removes all the whitespace I wanted to preserve! How can I get around this?

Replies are listed 'Best First'.
Re: Re: Re: reading files
by Mr. Muskrat (Canon) on Dec 13, 2002 at 15:31 UTC

    Either the file you are reading doesn't contain the whitespace you think it does or you just can't see it when it prints. ;)

    Perhaps you are printing extra newlines?

    my @file = <DATA>; foreach (@file) { print $_,"."; } __DATA__ 2 spaces at the front and 2 spaces at the end one tab at the front and one tab at the end no spaces at the front or end but 5 spaces before the second 5

    Prints:
    2 spaces at the front and 2 spaces at the end . one tab at the front and one tab at the end .no spaces at the front or end but 5 spaces before the second 5 .
Re^3: reading files
by Ionizor (Pilgrim) on Dec 13, 2002 at 15:27 UTC

    When printing try:

    foreach $line (@file) { print $line."\n"; }

    Alternatively, you could change Mr. Muskrat's code as follows:

    my @file; while (<$file>) { push(@file, "$_\n"); }