Instantly share code, notes, and snippets.

@bimmerlabs /transmission.pm Secret
Last active Dec 9, 2017

Embed
What would you like to do?
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