in reply to Re^9: Is there a problem with using barewords as filehandles ?
in thread Is there a problem with using barewords as filehandles ?

> You mean something like this I guess:

Almost

use strict; use warnings; MAIN: { open my $fh,">","filename"; ... nose(); ... } sub nose {...;}

nose() won't have access to any lexical vars defined inside the main block.

> I can’t tell how often I’ve been blamed for it.

It's a variation of putting the main code into a main() sub and calling it from the start.

I think it's a pattern taken from C and I've seen some monks here advocating it.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^11: Is there a problem with using barewords as filehandles ?
by karlgoethebier (Abbot) on Jul 08, 2020 at 22:51 UTC

    Yes. This I meant. Creating a main() sub I always considered to be unperlish. The block is the way to go. And to be honest: Sometimes when I was unsure and/or in a hurry I’ve put another block into a block. With the nice «side-effect» of some nice indention. Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help