Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Why don't file handles have sigils?

by trippledubs (Deacon)
on Jul 09, 2014 at 00:46 UTC ( [id://1092821] : note . print w/replies, xml ) Need Help??


in reply to Why don't file handles have sigils?

I wonder about this also. Annoying to kind of have to convert that in your head when reading older style instruction (Network Programming with Perl by Stein) that use barewords all over the place when the newer guidance is to use lexical filehandles. I think that the short answer is that the bareword is the old way to do it, and now you should use lexical variables because they limit the scope. This seems to confirm:
#!/usr/bin/env perl use strict; use warnings; { open (OUTPUT,"> out.txt") or die; } print OUTPUT "a"; # Works OUTPUT must still be in scope { open (my $new_out, ">","new_out.txt") or die $!; print $new_out "b"; } #print $new_out "c"; #this will not work

Replies are listed 'Best First'.
Re^2: Why don't file handles have sigils?
by perlfan (Vicar) on Jul 09, 2014 at 03:13 UTC
    The future is here.
    open my $output, ">", "out.txt"; print $output "derp"; close $output;