It's true that lack of "strict function-argument specification" or its "signature-less" subroutines could be annoying at times.

It's useful however when you need high level of abstraction. Consider the following pseudo self contained code excerpt:

#! /usr/local/bin/perl -w use strict ; # ################################################################# # Schema: Survey Database my %Survey = ( tblq => { primID => ['q_id'], cols => ['anstmpl_id', 'short_label', 'question' +, 'updated'] }, tblqtmpl => { primID => ['qtmpl_id'], cols => ['name', 'descr', 'updated'] }, tblqtmpl_q => { primID => ['qtmpl_id', 'q_id'], cols => ['seq', 'notes', 'updated'] }, ); # ################################################################# # Package: Survey Database {package Survey ; # assume %Survey defined somewhere # = = = = = = = = = = = = = = = = Contructor = = = = = = = = = = = + = = = = = = # sub dbconnect { } # = = = = = = = = = = = = = = = Public Methods = = = = = = = = = = + = = = = = = # foreach my $tbl (keys %Survey){ # define subroutines <action>_<tab +le> at runtime eval qq/sub insert_$tbl {return (shift)->_insert_table(_tblnam +e(),\@_)}/ ; eval qq/sub update_$tbl {return (shift)->_update_table(_tblnam +e(),\@_)}/ ; eval qq/sub delete_$tbl {return (shift)->_delete_table(_tblnam +e(),\@_)}/ ; } # = = = = = = = = = = = = = = = Private Methods = = = = = = = = = += = = = = = =# sub _insert_table { my ($self, $tbl, $values) = (shift, shift, shift) ; # ... and more... } sub _update_table { my ($self, $tbl, $values) = (shift, shift, shift) ; # ... and more... } sub _delete_table { my ($self, $tbl, $values) = (shift, shift, shift) ; # ... and more... } # -------------------------------------------------------------- sub _tblname{ # return <tbl>, if called by <action>_<tbl> e.g. s +how_tblanstype ( my $sub = (caller(1))[3] ) =~ s/.*::.*?_(.*)/$1/ ; return $sub ; } } # ################################################################# # Test Script: Survey Database Package # tblq $Survey->insert_tblq(\%data) ; $Survey->update_tblq(\%data) ; $Survey->delete_tblq(\%data) ; # tblqtmpl $Survey->insert_tblqtmpl(\%data) ; $Survey->update_tblqtmpl(\%data) ; $Survey->delete_tblqtmpl(\%data) ; # tblqtmpl_q $Survey->insert_tblqtmpl_q(\%data) ; $Survey->update_tblqtmpl_q(\%data) ; $Survey->delete_tblqtmpl_q(\%data) ;

The focus is such lines as eval qq/sub insert_$tbl {return (shift)->_insert_table(_tblname(),\@_)}/;. It generates subroutines at compile time. Having strict function argument specification may not allow you such a coding. Not necessarily good or bad, just another way to do things.


______________________
Footnote: As a side question, why not something likeinsert($table, $data) instead of insert_thistable($data)? Well, if you're refactoring existing code and some other scripts have been using insert_thistable($data), you have no choice but keep the interface.


In reply to Re: Considering Prototypes by chunlou
in thread Considering Prototypes by Anonymous Monk

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, details, 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, summary, 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.