in reply to Pipe File contents into Perl Script

To put the file into an array:

my @file_lines = <>;

To read it line by line:

while ( my $line = <> ) { print "The line is: $line"; push @file_lines, $line; }

You might also want to look at chomp, if you don't want line endings on your lines.

Replies are listed 'Best First'.
Re^2: Pipe File contents into Perl Script
by smack (Beadle) on Sep 21, 2007 at 17:55 UTC
    This worked, Thanks!

    “There are no cats in America, and the streets are paved with cheese.” -Fievel Mousekewitz
      kyle@x:~$ cat perlmonks.pl #!/usr/bin/perl use strict; use warnings; my @file_lines; while ( my $line = <> ) { print "The line is: $line"; push @file_lines, $line; } kyle@x:~$ cat file.txt line one line two line three kyle@x:~$ perl perlmonks.pl < file.txt The line is: line one The line is: line two The line is: line three

      Show us the code that's not working, and maybe we can help.

      A reply falls below the community's threshold of quality. You may see it by logging in.