Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

blazar (7356)

  (email not shown publicly)
Yahoo! ID: bik.mido (Add User, Send Message)

Journal of blazar (7356)

Monday April 02, 2007
09:51 AM

open my $f, '<:raw', \'foo'

[ #32881 ]

This is the second mention of a PerlMonks entry from last week I wanted to do...

Putting it briefly, I expected that a command like the one in the subject would open() a file "in memory" with the appropriate layer. Simply, it's not so: if you specify a layer, then the reference will be stringified and interpreted as a file name. Not too much of a problem: you can still use an explicit binmode() on the handle. Only, it's by all means a confusing behaviour, and I don't see how anyone could contradict me. Point is, the docs never say "if the third argument is a scalar reference, then it is opened as in memory file." Actually the feature is only described by two examples, both referring to '>' mode. Indeed other ones work too, but not if layers are specified. All in all I would say that the documentation could be clearer. But more importantly, although I am aware that Perl (5) deviates often enough from orthogonality, I don't see much usefulness in it doing so in this case and I would prefer it to be consistent by behaving as (I) expected.

Incidentally, Anno mentioned another situation in which it would be nice to have a scalar reference implicitly refer to a file "in memory", namely in connection with the magical ARGV filehandle, that is if you put one such reference in @ARGV. Indeed if such a beast did exist than that handle would be even more magic!

Now that I think of it, it would also be nice if @ARGV supported typeglob references to be interpreted as filehandles too, for even more magic. Not something for which I feel a compelling need, but not bad to have, I guess... (I can imagine a few situations in which it would be useful.) Of course this has not much to do anymore with the subject of this post...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.