understanding subroutines in perl -


sub bat {    ($abc) = @_;    @gcol ;    {       $rec = {};       $rec->{name}        = "batid";       $rec->{type}        = "varchar2";       $rec->{length}      = "14";       $rec->{scale}       = "0";       $rec->{label}       = "id";       $rec->{ref_comment} = "shows bat type";       $rec->{ref_link} ="$appl_home/bat.cgioptions=status&options=mfgdate&options=details&options=refreshauto";       $rec->{ref_col}     = [ ("bat_id") ];       $rec->{nullable}    = "y";       $rec->{pk}          = "n";       $rec->{print}       = undef;       $rec->{visible}     = "yes";       push (@gcol, $rec);    } } 

can explain subroutine being done in each line ? , hash used in or not? $rec= {};? happens using push?

you ask explanation of happening on every line , don't think you've got yet.

sub bat {    # take first parameter passed subroutine , store    # in variable called $abc.    # value ignored rest of subroutine,    # line of code pointless.    ($abc) = @_;     # declare array variable called @gcol.    @gcol ;     # start new block of code.    {        # declare scalar variable called $rec.       # initialise reference empty, anonymous hash       $rec = {};        # next dozen lines pretty same.       # each of them inserts key/value pair $rec hash.       $rec->{name}        = "batid";       $rec->{type}        = "varchar2";       $rec->{length}      = "14";       $rec->{scale}       = "0";       $rec->{label}       = "id";       $rec->{ref_comment} = "shows bat type";       # line interesting uses value       # of global variable called $appl_home.       # using global variables inside subroutine       # bad idea limits portability of subroutine.       $rec->{ref_link} ="$appl_home/bat.cgioptions=status&options=mfgdate&options=details&options=refreshauto";       # line interesting instead of setting       # value scalar value, sets reference       # anonymouse array.       $rec->{ref_col}     = [ ("bat_id") ];       $rec->{nullable}    = "y";       $rec->{pk}          = "n";       $rec->{print}       = undef;       $rec->{visible}     = "yes";        # having set hash twelve key/value pairs,       # push hash reference onto (currently empty)       # array, @gcol.       push (@gcol, $rec);        # next line marks end of block of code.       # because $rec variable declared inside block,       # go out of scope , ceases exist.       # however, because reference still stored in @gcol,       # memory not recovered, hash still exists.    }     # line marks end of subroutine.    # end of scope variables declared within subroutine.    # includes @gcol array ceases exist @    # point. unfortunately, means our constructed    # hash ceases exist @ point , our work    # wasted. } 

to summarise, code lot of work, work wasted variables uses thrown away subroutine ends. net effect of calling subroutine absolutely nothing.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -