[EMAIL PROTECTED] wrote:

> This works.... but does anyone have any ideas on the previous question?
>  while(<passwd_file> )
>        {
>        $line=$_;
>        chomp($line);
>        @list=split(/:/,$line);
>        $account_key=$list[0];
>        $account=join ":",@list;
>        $record{$account_key}=$account;
>        }
>
> I am trying to split off the user name and the password record in one pass
> through however what I am getting is only the first record is being
> populated into my user array.
>
> Can someone tell me am I going about this the right way?
>
> Thanks,
> Royce
>
> my @user=(split(/:/,(@passwd=(split(/\n/,`cat /etc/passwd`)))[0]));
> for($i=0;$i <= $#passwd ; $i++)
> {
> print "$user[$i]\n";
> print "$passwd[$i]\n";
> }

In brief, the one that works is ismple and direct, and therefore likely to
work, if only because it is simpler to understand.  The earlier version twists
in upon itself in unnecessary complication, and such complication in itself is
likely to induce errors/.  Specifically here, the inner split probably
generates onelist, and calling split on that list will operate only on the
first item, since split is used to split scalars into lists, and does not
operate on lists.

The principle of KISS operates in the programming field more than in any other
science IMHO.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to