PREE HW#8 - 1/usr/local/bin/perl die"$0 requires an argument\n if$#ARGV < 0#must have at least one argument print@ARGV\n#print all arguments

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1. #!/usr/local/bin/perl die"$0 requires an argument.\n" if$#ARGV < 0; #must have at least one argument. print"@ARGV\n"; #print all arguments print"@ARGV[0]\n"; #print first arguments print"@ARGV[1]\n"; #print second arguments print"There are", $#ARGV + 1,"arguments.\n"; # $#ARGV is the last subscript print"$ARGV[$#ARGV] is the last one.\n"; #print last arg #end 2. #!/usr/local/bin/perl -w #This program uses a subroutine to find the smallest of a list of numbers. print("Please enter file name: "); $name = <STDIN>; open (F1, "<$name") || die("Can't open $name"); chomp(@numbers = <F1>); $smallest = smallest(@numbers); print("The smallest is: $smallest\n"); #end of main program #start of function
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
{ my ($sm) = 100000; #use my to declear a private variable foreach $_ (@_) { if($_ < $sm) { $sm = $_; } } return $sm; } #end of function # end of program 3. #!/usr/local/bin/perl #This program shows that @_ is an alias for the argument list. @numbers = (1 .
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/11/2010 for the course MSEE 1 taught by Professor Alex during the Spring '10 term at Northwestern Polytechnic University.

Page1 / 7

PREE HW#8 - 1/usr/local/bin/perl die"$0 requires an argument\n if$#ARGV < 0#must have at least one argument print@ARGV\n#print all arguments

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online