Skip to content

Instantly share code, notes, and snippets.

@bimmerlabs
Last active December 9, 2017 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bimmerlabs/69296da070dbeb10c94acc73eeb3bef0 to your computer and use it in GitHub Desktop.
Save bimmerlabs/69296da070dbeb10c94acc73eeb3bef0 to your computer and use it in GitHub Desktop.
There are two possibilities ('A' for automatic and 'M' for manual) in the database that are selected from a form entry. But for some database entries, there is only one, and I can't know that until I query the database. In case the user selects one that doesn't exist, how do I iterate through the results more than once?
# this is functioning now
# get $results from Mojo::Pg
my $results = $db->select('w_fuellmengen', undef, {fuellmengen_typ => $car->{'fztyp_typschl'}});
my $hash;
# process rows with Mojo::Pg::Results
while (my $next = $results->hash) {
# try form value
if ($next->{fuellmengen_getriebe} eq $self->param('trans')) {
$hash = $next;
}
# try auto
elsif ($next->{fuellmengen_getriebe} eq 'A') {
$hash = $next unless($hash);
}
# try manual
elsif ($next->{fuellmengen_getriebe} eq 'M') {
$hash = $next unless($hash);
}
}
return ($hash);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment