http://qs321.pair.com?node_id=11119049


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

«...writing the main code after the subs are declared or putting a block around it.»

You mean something like this I guess:

#!/usr/bin/env perl use strict; use warnings; KARL: { nose(); } sub nose {...;} __END__

I wrote my code many years like this and I can’t tell how often I’ve been blamed for it.

«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

Replies are listed 'Best First'.
Re^10: Is there a problem with using barewords as filehandles ?
by LanX (Saint) on Jul 08, 2020 at 22:19 UTC
    > 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

      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