Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
}#! /usr/local/bin/perl -w use strict; my $num_of_params; $num_of_params = @ARGV; if ($num_of_params < 2) { die ("\n You haven't entered enough parameters f\n\n"); } open (FILE, $ARGV[0]) or die "unable to open file"; open (OUTFILE, ">$ARGV[1]"); my $line; my @array; my $tv=0; my $computers=0; my $exercise; my $food; my $choice; print STDOUT "\nPlease select the catergory of results that you wish t +o see;\n\n\t1. tv \n\t2. computers \n\t3. exercise \n\t4. food\n\n"; $choice = <STDIN>; # remove the newline character from the chosen option. chomp $choice; # when the results are printed to the screen, ensure the user understa +nds what # the data is - this print statement does this. print "\nchoice \t\t value \n\n"; while (<FILE>) { $line = $_; chomp ($line); @array = (); @array = split (/\s+/, $line); if ((($array[1] =~ m{/any\|\w+\|\w+}) || ($array[1] =~ m{/:other\| +\w+\|\w+})) && ( $array[8] > 95) && ($choice eq 1)) { $tv = "$array[1]\t$array[8]\n"; print $tv; print OUTFILE $tv; } if ((($array[1] =~ m{/any2\|\w+\|\w+}) || ($array[1] =~ m{/:other2\ +|\w+\|\w+})) && ($array[8] > 95) && ($choice eq 2)) { $computers = "$array[1]\t$array[8]\n"; print $computers; print OUTFILE $computers; } + if ((($array[1] =~ m{/any\|\w+\|\w+}) || ($array[1] =~ m{/:other3\|\w ++\|\w+})) && ($array[8] < 95) && ($choice eq 3)) { $exercise = "$array[1]\t$array[8]\n"; print $exercise; print OUTFILE $exercise; } if ((($array[1] =~ m{/any\|\w+\|\w+}) || ($array[1] =~ m{/:other4\| +\w+\|\w+})) && ($array[8] < 95) && ($choice eq 4)) { $food = "$array[1]\t$array[8]\n"; print $food; print OUTFILE $food; } print "\nWould you like to go back to the main menu? (y/n/q)"; $choice2 = <STDIN>; if ($choice2 eq 'y') { print "\nPlease select the catergory of results that you wish to see;\ +n\n\t1. tv \n\t2. computers \n\t3. exercise \n\t4. food \n\n"; } if ($choice2 eq 'n') { exit; } if ($choice2 eq 'q') { exit; } close OUTFILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: nested loops problem
by r0b (Pilgrim) on Jun 11, 2002 at 16:03 UTC | |
by Anonymous Monk on Jun 11, 2002 at 16:21 UTC | |
by r0b (Pilgrim) on Jun 11, 2002 at 16:28 UTC |