in reply to Can't print data from the input file in Command Line processing.
Method 2open (IN, "< $file") or warn ("Can't open $file: $!\n"), die; while (<IN>) { # loop through the file, print ("$file ==> $_"); # read one line at a time } close(IN);
Method 3open (IN, "< $file") or warn ("Can't open $file: $!\n"), die; chomp(my @data = <IN>); # read all lines into array of lines # and get rid of trailing \n's print "$_\n" for @data; close(IN);
open (IN, "< $file") or warn ("Can't open $file: $!\n"), die; my $data = do { local $/; <IN> }; # file slurping print ("$file ==> $data\n"); close(IN);
|
|---|