Problem accessing filehandles (Perl).
Hi guys,
I've been reading / trying to learn some Perl lately. I've found the free book, "Learning Perl", quite good and easy to follow most of the times. However, today I was testing one of the scripts in the book and it would only run partly. Code:
#!/usr/bin/perl This row is supposed to give option, either to use an additional script as pipe (sort.plx), or STDOUT if the extra script is not found. It works with the other script present, however, with the sort.plx being absent it simply wont use STDOUT instead but whines to me: Can't open perl script "sort.plx": No such file or directory Has the author of the original script done some error writing it? Since I'm a beginner and found most of the stuff confusing in Perl either way (having previously only experience in Bash and some in PHP) - I can't really tell for sure :), but from what I can read in documentation - it doesn't appear to be wrong. As it looks now, the only way for me to use STDOUT is only by removing: open (SORT, "| perl sort.plx") or *SORT = *STDOUT; select *SORT; rows. But then, I lose the piping in to that other script as an option. Any ideas? Thanks in advance. |
use warnings;
Can comment out and try. |
Hi,
No effect after I did what you suggested. |
Quote:
Code:
my $sort_fh; |
After applying your suggestion, the script did actually manage to print output, correctly too, but the error message still persists (even without use strict / use warnings).
Also, this is the first time I read that lexical variables should be used as standard file handles. Any other ideas? |
Quote:
... If you read 'perldoc -f open', you'll see a number of examples with lexical variable as file handle. |
I've seen few lexical variables in the doc file, yes.
But two books are telling me so far that it's not the standard way to go. And since I'm trying to learn Perl here, I'm asking the question that teachers hear many times - 'why?' - so I know this for the future reference. Because, you seem to be encouraging the usage. |
Quote:
So, have you come to a conclusion about the error message ? |
You may want to bookmark the official Perl docs here http://perldoc.perl.org/ See also the extra tutorials http://www.perlmonks.org/?node=Tutorials
|
All times are GMT -5. The time now is 09:01 AM. |