in reply to Re: Understanding -> function
in thread Understanding -> function

Many Thanks for this help,
Appreciate your further help..
** I understood that $bakjobs->{"$2"} takes value of $2 for hash %bakjobs and store it.
** I further understood that {"dbt"} becomes key of %{$bakjobs-> {"$2}.
Then
(1) what is the use of =$1 and =$3 at end of code?
(2) This means the %bakjobs will have two different keys one as "dbt" and other as "cbt"
$bakjobs->{"$2"}{"dbt"} = $1; Thanks in advance..

Replies are listed 'Best First'.
Re^3: Understanding -> function
by ysth (Canon) on Dec 28, 2008 at 20:43 UTC
    $bakjobs is a reference to the hash %bakjobs. The $bakjobs->{"$2"} part is accessing the "$2" key of that hash. The added {"dbt"} takes the value of the "$2" key and interprets it as a reference to another hash (creating one if necessary) and the = $1; stores $1 as the value for the "dbt" key in that inner hash. So if the line being parsed was BAKfoo bar, %bakjobs looks something like this (in addition to anything else already in it):
    %bakjobs = ( "foo" => { "dbt" => "bar", "cdt" => undef, } );
    (The value for cdt is undef from $3 because there are only two sets of capturing parentheses in your regex.)