in reply to Re: Bareword vs. Indirect Filehandle behaviour
in thread Bareword vs. Indirect Filehandle behaviour

Perl can't figure out what you mean (and imho ought not, anyways) ...

I was sort of hoping that it could figure out what I mean because I think the while (<IN>) {print OUT;} construct is one of the neater features of the language. If I substitute an indirect filehande for a bareword one I still mean it to be a filehandle and give the same behaviour. Adding the $_ is no big deal but the new behaviour breaks an idiom that I would guess is familiar to most and widely used.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^3: Bareword vs. Indirect Filehandle behaviour
by rodion (Chaplain) on Sep 19, 2006 at 10:57 UTC
    Just one opinion, but I think your asking perl to extend an idiom rather than to not break one. The old idiom is still there.

    For me, it would be quite confusing if Perl extended the idiom so that "print $outFH;" was a write of "$_" to a specified filehandle, rather than a write of a variable to STDOUT. I have no doubt Perl could get it right, because it knows what variables are file handles and what aren't. I'd just have trouble reading it without my eyes getting caught in the wrong mode; I'd have to mentally back-track each time I read it.

      I have no doubt Perl could get it right, because it knows what variables are file handles and what aren't.

      In general, Perl actually can't know this. It's reasonably easy to make a Perl object that can act as a file handle as well as a string, depending on how you use it.

      Good point.

      I'm looking at this as the bloke writing the code so I know it's a filehandle. The poor devil maintaining my code once I've moved on will, as you say, keep having to backtrack. Three extra keystrokes it is, then :-)