in reply to reading files

Easiest:
my @file = <$file>;

Another option:

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

Replies are listed 'Best First'.
Re: Re: reading files
by Anonymous Monk on Dec 13, 2002 at 15:18 UTC
    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?

      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 .

      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"); }