in reply to Understanding -> function

Hi. (I would) Appreciate (it) if you would use <code> tags. Otherwise your code might be interpreted as markup.

$bakjobs->{$2}{dbt} = $1; $bakjobs->{$2}{cdt} = $3;

This is simply inserting into a hash of hashes based on the last matched regex. However, based on the regex provided, I suspect $3 will be undefined.

Aside from that this code has numerous things wrong (or at least questionable) with it:

Replies are listed 'Best First'.
Re^2: Understanding -> function
by John007 (Acolyte) on Dec 28, 2008 at 20:02 UTC
    Thanks Monks.. The formatting code will be below where there will be $1, $2 and $3 values.
    ( /^BAK(\w+)\s+(\d+)\s+([\w\_]+)\s*/i )
    But I still do not understand the use of =$1; and $3; at end of code for below two lines.
    $bakjobs->{"$2"}{"dbt"} = $1; $bakjobs->{"$2"}{"cdt"} =$3;
    Please explain.. Appreciate your help..

      That's an assignment. It puts the value of $1 into $backjobs->{$2}{dbt}. Likewise, it puts the value of $3 into $bakjobs->{$2}{cdt}.

      Also note that \w matches underscores, so the character class in the regex is redundant. See perlretut.

      $1, $2, $3 and so on are capture variables.

      Specifically, in the regex
          /^BAK(\w+)\s+(\d+)\s+([\w\_]+)\s*/i
      the sub-expressions (\w+), (\d+) and ([\w\_]+) (which, as already noted, is the same as (\w+) since \w is [a-zA-Z0-9_], but under the control of locale) are capturing groups, and whatever these groups match, if anything, is available through the capture variables. See perlre, perlretut (especially Extracting matches) and perlrequick for further discussion of capturing groups and capture variables; in particular, how the number of the variable ($1, $2, $3, etc.) relates to the order of the capture group in the regex.