On 8/24/07, Yoyoyo Yoyoyoyo <[EMAIL PROTECTED]> wrote: > Hi all, > > I am using the diamond operator to redirect input to my perl script. I want > to copy all of the input on to a single variable using the following > subroutine: > > sub getfile # Copies the file redirected to this perl script to the varialbe > $x > { > my $x; > local $/ = undef; > $x = <>; > return $x; > } > > The problem is that when I try to print what the above subroutine returns, > the program kindof hangs. That is, it doesn't just print the output and then > send me back to the command line, instead I have to press Ctrl-c to break out > of it, like it is expecting input from the keyboard. > > Any help is appreciated, > > Robert
The Perl operator, <>, reads from STDIN. To pipe a file to STDIN, you need to run the script like so: script.pl < file_to_pipe Please note the '<' If you do this: script.pl file_to_read the filename gets put onto $ARGV[0]. You can open the file inside Perl like so (untested code): die "Please run like: $0 filename\n" if (not -f $ARGV[0]); open $filehandle, "< $ARGV[0]"; my $x; local $/ = undef; $x = <$filehandle>; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/