#!/usr/bin/perl -w # Dato un array di interi ed un numero intero # letto da console dire se l'elemento e' # presente nell'array. Eseguire la ricerca due volte. use strict; my(@arrayInt, $el, $found); @arrayInt = (2, 4, 5, 1, 5, 6); sub chiedi { my ($elemento); print "Inserisci il numero da cercare: "; $elemento = ; chomp($elemento); return $elemento; } sub cerca { my ($elemento, @arInt); ($elemento, @arInt) = @_; my $trovato = 0; my $i = 0; while (($i < @arInt) && !$trovato) { print "Controllo l'elemento $i-esimo\n"; if ($elemento == $arInt[$i]) { $trovato = 1; # leggi: true! } $i++; } return $trovato; } $el = chiedi(); $found = cerca($el, @arrayInt); if ($found) { print "Trovato!\n"; } else { print "Non trovato!\n"; } $el = chiedi(); $found = cerca($el, @arrayInt); if ($found) { print "Trovato!\n"; } else { print "Non trovato!\n"; }