H
Harpreet
Hi.
I am learning perl scripting and was reading an online tutorial where i
encountered this code(at the end of message). The first part of the
code (reading from file) has been pasted as-is and the second(reading
from standard input stream) was written by me. When I execute the
program, I get the correct result from the first one and then I type
into the stream some data but I don't know how to end it. I used the
conventional unix "dot-enter" scheme but it didn't work. Neither did
Ctrl-D. I found some examples which read from <STDIN> and worked with a
while loop. Can somebody explain me why reading from the standard input
doesn't work the way I have written ? If I am missing the escape
character to denote the end of stream, please mention it.
Any pointers will be appreciated.
Thanks and Regards,
Harpreet.
<CODE>
#!usr/local/bin/perl
#
$file = '/etc/passwd'; # Name the file
open(INFO, $file); # Open the file
@lines = <INFO>; # Read it into an array
close(INFO); # Close the file
print @lines; # Print the array
open(INFO, '-');
@lines2 = <INFO>; # Read it into an array
close(INFO);
print @lines2;
</CODE>
I am learning perl scripting and was reading an online tutorial where i
encountered this code(at the end of message). The first part of the
code (reading from file) has been pasted as-is and the second(reading
from standard input stream) was written by me. When I execute the
program, I get the correct result from the first one and then I type
into the stream some data but I don't know how to end it. I used the
conventional unix "dot-enter" scheme but it didn't work. Neither did
Ctrl-D. I found some examples which read from <STDIN> and worked with a
while loop. Can somebody explain me why reading from the standard input
doesn't work the way I have written ? If I am missing the escape
character to denote the end of stream, please mention it.
Any pointers will be appreciated.
Thanks and Regards,
Harpreet.
<CODE>
#!usr/local/bin/perl
#
$file = '/etc/passwd'; # Name the file
open(INFO, $file); # Open the file
@lines = <INFO>; # Read it into an array
close(INFO); # Close the file
print @lines; # Print the array
open(INFO, '-');
@lines2 = <INFO>; # Read it into an array
close(INFO);
print @lines2;
</CODE>