JE> I haven't tried it, but if the first element of the array is the mode
JE> and the second the file name, then I don't see why there should be a
JE> problem. At least I would assume that the function call semantics for
JE> Perl's build-in functions are the same as for user-defined functions,
JE> i.e. both flatten the argument list.
And? Noone actually tried?
$ perl -wle '@xy = qw( > /dev/null ); open $fh, @xy or die $!'
Name "main::fh" used only once: possible typo at -e line 1.
No such file or directory at -e line 1.
$ perl -wle '@xy = qw( > ); open $fh, @xy or die $!'
Name "main::fh" used only once: possible typo at -e line 1.
No such file or directory at -e line 1.
$ perl -wle 'open $fh, ">" or die $!'
Name "main::fh" used only once: possible typo at -e line 1.
No such file or directory at -e line 1.
nope. remember many functions can take an array as the first arg so they
actually parse things with prototypes. you can find out the prototype of
any builtin with the function prototype. only those funcs that take a
final list do any slurping (splice, push, etc.) from the args list.
perl -le 'print prototype "CORE:
pen"'
*;$@
so that means open takes a handle and then an optional scalar (the mode
or file name) and then slurps a list.
Not exactly. That C<(*)> represents typeglob. And looking in
assuming i interpret the prototype correctly which could be wrong
since i rarely use them.
Only perl can parse Perl.
*CUT*
Looking at code above I've got to crazy conclusion that there are some
(at least 2) implementations of B<open>. And that's the compiler what
decides what route to go. And since it can't get it, it falls back at
first one, which is C<open FILEHANDLE,EXPR>. Then this B<open> tries to
open empty filename. And obviously fails.
Maybe someone with deeper insight could comment?
p.s. Actually that idea is really crazy, because it's wrong
$ perl -wle '@xy = qw( /dev/null ); open $fh, @xy or die $!'
Name "main::fh" used only once: possible typo at -e line 1.
No such file or directory at -e line 1.