1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
my @record_types = qw(100 200 300 400 500);
...
# Daten die reinkommen
$record_type_found = substr($file_content,$position+12,3);
foreach (@record_types) {
if ($record_type_found == $_)
{
$record_type_status = "ok";
last;
}
$record_type_status = "not ok"; #
}
print $record_type_found, ": ", $record_type_status, "\n";
1 2 3 4 5 6 7
my $found = 0; for my $item (@array) { if ($item eq 'something') { $found = 1; last; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/perl use strict; use warnings; my $record_type_status; my %record_types = ( 100 => 1 , 200 => 1 , 300 => 1 , 400 => 1 , 500 => 1 ); my $record_type_found = "101"; if ($record_types{$record_type_found}) { $record_type_status = "ok"; } else { $record_type_status = "not ok"; # } print $record_type_found, ": ", $record_type_status, "\n";
if (grep { $_ eq 'irgendwas' } @record_types)
2013-06-28T14:30:55 murphyWenn mich nicht alles täuscht gibt es in neueren Perlversionen sogar eine Optimierung für booleschen Kontext, in dem grep nach dem ersten Treffer abbricht und wahr zurückgibt anstatt die Eingabeliste komplett zu scannen.
print " => OK\n" if grep {print "$_, "} qw( a b c );
say "drin" if 3 ~~ [1,5,3,4];