#!/usr/bin/perl -w use strict; my @numbers = (1, 2, 5, 7, 8, 9); my $pos = 0; for my $counter (1..10) { # Is this value of $counter the next value in @numbers? # If it is then display image number $counter and move onto the # next value in @numbers. # If it is not then display the error image and carry on looking # for the same value in @numbers. if (defined $numbers[$pos] and $numbers[$pos] == $counter) { print "Use image: $counter \n"; $pos++; } else { print "Use error image\n"; } } #### #!/usr/bin/perl -w use strict; my @numbers = (1, 2, 5, 7, 8, 9); for my $counter ( 1..10 ) { my $img; # Check whether this value of counter is in @numbers for my $i ( @numbers ) { if ($i == $counter) { $img = "image" . ($counter-1); last; } } # If $img is still undefined then this value is missing if (!defined $img) {$img = "error.bmp"} print "$counter $img\n"; }