#!/usr/bin/perl -w # Dati due array di interi dire se il primo e' sottoinsieme # del secondo use strict; my(@primoArrayInt, @secondoArrayInt, @terzoArrayInt); @primoArrayInt = (1, 3); @terzoArrayInt = (1, 2); @secondoArrayInt = (2, 4, 5, 1, 5, 6); print "Elementi del primo array: @primoArrayInt\n"; print "Lunghezza del primo array: ".@primoArrayInt."\n"; print "Elementi del secondo array: @secondoArrayInt\n"; print "Lunghezza del secondo array: ".@secondoArrayInt."\n"; print "Elementi del terzo array: @terzoArrayInt\n"; print "Lunghezza del terzo array: ".@terzoArrayInt."\n"; 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; } sub incluso { my ($pAI, $sAI); ($pAI, $sAI) = @_; my $incluso = 1; my $i = 0; while (($i < @$pAI) && $incluso) { $incluso = $incluso && cerca(@$pAI[$i], @$sAI); $i++; } return $incluso; } sub stampa { if ($_[0]) { print "Incluso!\n"; } else { print "Non incluso!\n"; } } stampa(incluso(\@primoArrayInt, \@secondoArrayInt)); stampa(incluso(\@terzoArrayInt, \@secondoArrayInt));