in reply to Re^3: How to reference to array keys?
in thread How to reference to array keys?


Hey Marshal,

I've defiantly made some headway with the new simplified version that you gave me. But I just have one questions about it at the moment.

1. For the section in the code where it Dumps the raw records,
foreach my $line (@records) { (my $colnumber1, @rest) = split(' ',$line); printf "%-8s @rest\n", $colnumber1; }
how does the first line in the loop (one with the 'split' function) work?
I get that your creating and assigning 2 new variables, but how does it work setting one split function equal to 2 different variables (and 2 different types of variables)? By doing 2 print statements inside that loop, one fore each variable, I can see that:
$colnumber1 = either 'OWNER' -or- 'WAITING'
@rest = one whole line of data not including 'OWNER' or 'WAITING'


UPDATE
Came across one other question for the moment.
In the same file what does the line if (!$current_owner) check for if $current_owner has no value? Or does it?


Thanks,
Matt


Replies are listed 'Best First'.
Re^5: How to reference to array keys?
by jethro (Monsignor) on Jul 28, 2011 at 23:46 UTC

    The line with split works this way: First of all the left side of the equation is in parentheses, so it provides list context to the left side (many functions return different things in different contexts, see the first two paragraphs of split

    So the split in list context returns a list of strings that get distributed to the list on the left side of the equation. This list begins with a scalar, so the first item in the list is stored in the scalar. The second variable is an array and arrays just take everything they can get, so all the other strings are pushed into @rest. If there were another array or scalar at the end of the list on the left side, it would be empty. If another scalar were before @rest, it would hold the second item of the list of strings

    (!$current_owner) is true when $current_owner is false. $current_owner is false if it is undef, the empty string ("") or 0. Since $current_owner is initialized with the empty string, this condition is at least true the first time the subroutine process_owner_record is called.


      Jethro,

      Thanks for the reply. Good explanation, makes much more sense now!


      Thanks, Matt