Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
    Usually I add an explicit exit statement to the end of the 'main' part of the code ..

I don't .. because I use braces for my 'mainline' code. Here's a recent script I wrote based on something I saw on Twitter:

#!/usr/bin/perl use strict; use warnings; # Base 24 question from https://twitter.com/pwnallthethings/status/13 +43590455511023621 my @digits = qw/B C D F G H J K M P Q R T V W X Y 2 3 4 6 7 8 9/; my %digit_value; my $string = 'FCKGW-RHQQ2-YXRKT-8TG6W-2B7Q8'; # Convert a base 24 number to decimal. This is a group of five # numbers, like a Windows key. { my $v = 0; foreach my $d ( @digits ) { $digit_value{ $d } = $v++; } my @units = split ( /-/, $string ); foreach my $u ( @units ) { my $value = decode ( $u ); print "$u -> $value\n"; } } sub decode { my ( $str ) = @_; my $val = 0; my @chars = split ( //, $str ); foreach my $c ( @chars ) { $val *= 24; $val += $digit_value{ $c }; } return $val; }

There's no exit required because the closing brace indicates "That's the end!" to Perl. I have seen code where the mainline is right up against the left margin -- I never code like that, because it obscures what's going on -- it's the same level as the use statements, so I don't know where the declarations end and the executable code starts.

And I don't put an exit anywhere, because that would indicate I was bailing out early, instead of allowing the syntax to naturally indicate where the end of the procedure is. To be clear, I'm *not* saying your way is wrong -- it's just not what I prefer. I like my way because it's clear and legible. For me, white space is my friend.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.


In reply to Re^4: why avoid & on function call by talexb
in thread why avoid & on function call by fireblood

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others chanting in the Monastery: (3)
    As of 2024-09-12 03:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The PerlMonks site front end has:





      Results (15 votes). Check out past polls.

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.