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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |