6/23 perl open3 question: according to the manpage, both of these should
work. The first one does. Why does the second one produce an error
message? "open3: wtr should not be null at ./open3.cgi line 20"
open3(\*WTRFH, \*RDRFH, \*ERRFH, $command);
open3($wtr, $rdr, $err, $command);
\_ How did you assign $wtr?
\_ Do I need to assign a value to them?
the example just shows declaring them: my ($wtr, $rdr, $err);
\_ don't breed.
\_ ill assume for a moment youre not a new form of troll: yes,
you need to put something in a variable before passing it as
a parameter to a function or subroutine of some sort. not
just in perl but in _most_ languages. you scheme/lisp freaks
and other assorted nuts should count down slowly from 10
before replying.
\_ Okay, assigning some random value works, but not in
"use strict" mode. I'm not trolling. I'm serious.
'Can't use string ("one") as a symbol ref while
"strict refs" in use at ./bin/open3.cgi line 27.'
\_ Not true, but I'll assume that you're just uninformed.
Ever heard of autovivification? Try this on a system that
has a resonably recent perl installed:
perl -e 'open $foo,"</etc/passwd" or die "It didnt work!";print <$foo>'
(by the way this won't work on soda since the version
of perl on soda is fairly out of date)
(by the way this won't work on soda since perl5.00503
installed on soda is fairly out of date and doesn't support
this feature).
\_ Thank you. The machine I'm using open3 on is also
an older version of perl. Is there a way to use
$variable filehandles, or do I need to stick with
the glob notation?
\_ See the notes about IO::File in the "open" section
of the perlfunc man page. In summary, it's still
fairly simple, e.g.:
use IO::File;
my $handle = new IO::File;
open $handle ... blah blah
\_ It's a hack. "Install latest version of perl to
avoid sloppy coding" isn't a real answer.
\_ autovivification is not a hack. It's a widely
used and supported feature. Take a look at the
third edition of the Camel book and numerous
articles on the net. |