raflach has asked for the wisdom of the Perl Monks concerning the following question:

My original code looked like this:
my $ContactID = somecontactid; my @rows=$db->select("select HTMLCheck from Contact where ContactID=$C +ontactID"); my $HTMLCheck = $rows[1]->{HTMLCheck}; # do something with $HTMLCheck
That works, but seems sloppy and wasteful of resources.

I would like to simplify this by simply obtaining the HTMLCheck element of the hash in the 1st element of the array of hashes returned by the $db->select procedures directly into the $HTMLCheck variable. I tried doing:
my $HTMLCheck = $db->select("select HTMLCheck from Contact where Conta +ctID=$ContactID")[1]->{HTMLCheck};
That does not seem to be working as expected. Can anyone advise of a way to simplify the above code?

Replies are listed 'Best First'.
Re: getting a single element from hash result
by Anonymous Monk on Jun 02, 2000 at 22:57 UTC
    Also note that the first row is index 0, not 1.
      It would be if the select weren't a company written function that starts at 1... idiots just wastin' space.
Re: getting a single element from hash result
by swiftone (Curate) on Jun 02, 2000 at 20:55 UTC
    my $HTMLCheck = $db->select("select HTMLCheck from Contact where Conta +ctID=$ContactID")[1]->{HTMLCheck};
    That looks basically right. My guess is that Perl got confused as to what was being subreferenced. Try:
    my $HTMLCheck = {$db->select("select HTMLCheck from Contact where Cont +actID=$ContactID")}[1]->{HTMLCheck};
      I think you meant: my $HTMLCheck = ($db->select("select HTMLCheck from Contact where ContactID=$ContactID"))[1]->{HTMLCheck};