On Sat, Feb 07, 2004 at 07:42:30PM -0000, Rob Dixon ([EMAIL PROTECTED]) wrote:
>> Kenton Brede wrote:
>> <snip>
> Hi Kenton.
Hi, thanks for the great code.
> How does this look?
Well ... complex :) Let me see if I can put this in English.
> sub get_uid {
> my %list;
> @list{map {(split /:/)[2]} <DATA>} = ();
map reads the UID variables from <DATA> into @list. What I don't
understand is "= ()" My understanding is assignments move from right to
left so it seems "()" is assigned to "@list{map {(split /:/)[2]} <DATA>}"
I'm guessing this is how the hash is populated but it looks like "()" is
undef?
> return (grep {not exists $list{$_}} 700 .. 799)[0];
From perldoc "grep BLOCK LIST."
So grep finds the first "[0]" UID in the hash that doesn't exist in the list
700 to 799.
> }
>
> More readably, this does almost the same thing:
>
> sub get_uid {
>
> my %list;
>
> while(<DATA>) {
> my $uid = (split /:/)[2];
> $list{$uid}++;
Looks like this increments the next instance of $uid into the hash.
> }
>
> foreach my $uid (700 .. 799) {
> return $uid unless exists $list{$uid};
> }
>
> return undef;
I've got a question about this line. I know it's there if all
available UIDs are taken, then the sub will return a value. You've
chosen to return "undef." Would it be in proper form to -
return "No available UIDs in the 700 range." ?
Maybe a better way of asking the question is, Are there "return"
guidelines? I've perldoc -f and -q and
searched in the archives and didn't find a whole lot.
Any doc pointers on this topic would be helpful. I've been making some
first attempts at 'C.' Maybe that's why this seems so confusing to me
ATM :)
Thanks,
Kent
--
"Efficiency is intelligent laziness."
-David Dunham
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>