Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^9: Is there a problem with using barewords as filehandles ?

by karlgoethebier (Abbot)
on Jul 08, 2020 at 22:12 UTC ( #11119049=note: print w/replies, xml ) Need Help??


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 (Cardinal) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11119049]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2020-10-01 13:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (13 votes). Check out past polls.

    Notices?