Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Still, at least it's not the worst mistake I made in PBP. ;-)

Uh-oh. Whats next? Have a list? ;-)

I stand by the overall recommendation though. Error messages that point users to the right place are definitely worth the (tiny) overhead of passing named args in a hash.

Definitely. The recommendation of passing named args in a hash is fine, the one of the MTOW you promote TDI is, if not wrong, then sub-optimal.

my %hash = ( foo => 1, bar => quux($blorf), ); my $result = frobnitz(\%hash); # ok my $result = frobnitz( %hash); # also ok # --- my $hashref = ( foo => 1, bar => quux($blorf), ); my $result = frobnitz( $hashref); # ok # --- frobnitz( { foo => 1, bar => scalar bar($quux) } ); # not ok

In the above examples, both of the costly structures for %hash and $hashref are allocated at the pad of the current scope and populated at run time. In the last example, that structures are set up and teared down at every call to frobnitz() :

use Devel::Peek; sub f{ Dump $_[0] }; f( {o=>1} ) for 1..3; __END__ SV = RV(0x8c17080) at 0x8c17074 REFCNT = 1 FLAGS = (ROK) RV = 0x8bfd7a4 SV = PVHV(0x8c02d04) at 0x8bfd7a4 REFCNT = 1 FLAGS = (SHAREKEYS) ARRAY = 0x8c1bb0c (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "o" HASH = 0xc74f0e7f SV = IV(0x8c17060) at 0x8c17064 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 SV = RV(0x8c17070) at 0x8c17064 REFCNT = 1 FLAGS = (ROK) RV = 0x8c17074 SV = PVHV(0x8c02d04) at 0x8c17074 REFCNT = 1 FLAGS = (SHAREKEYS) ARRAY = 0x8c1bb0c (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "o" HASH = 0xc74f0e7f SV = IV(0x8bfd7a0) at 0x8bfd7a4 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 SV = RV(0x8bfd7b0) at 0x8bfd7a4 REFCNT = 1 FLAGS = (ROK) RV = 0x8c17064 SV = PVHV(0x8c02d04) at 0x8c17064 REFCNT = 1 FLAGS = (SHAREKEYS) ARRAY = 0x8c1bb0c (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "o" HASH = 0xc74f0e7f SV = IV(0x8c17070) at 0x8c17074 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1

Some of the above pointer being equal is just an artefact of the subsequent call of the same sub (I guess here).


In reply to Re^3: Named Subroutine Parameters: Compile-time errors vs. Run-time warnings by shmem
in thread Named Subroutine Parameters: Compile-time errors vs. Run-time warnings by AnomalousMonk

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (6)
    As of 2014-04-19 08:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (478 votes), past polls