#!/usr/bin/perl # ----- $myinputfile = 'palindromes.txt'; # The '<' indicates input open MY_IN, "<", $myinputfile; # 3 argument version # same as: open(MY_IN, $myinputfile); chomp(@lines = ); close(MY_IN); print "@lines"; # ----- # The '>' indicates output open MY_OUT, ">temp.txt"; # 2 argument version # select the output filehandle select MY_OUT; print "this is going to temp.txt\n"; # return output to screen: select STDOUT; print "this is going to the screen\n"; close MY_OUT; # ----- sub simple_print { print "This is my special global variable \$n: $n\n"; } sub arg_print { print "I believe your value is: $_[0]\n"; } # declare a global variable: $n = 'epstein'; # invoke the function with &: &simple_print; # and provide an argument: &arg_print('barbarino'); # ----- sub minimum { # @_ is the incoming array of arguments # set the minimum to be the first element $min = shift @_; foreach (@_) { if ($_ < $min) { $min = $_; } } # equivalent to: return $min; $min; } my $the_min = &minimum(7,4,5,6); # $the_min = 4 print "Minimum is: $the_min\n";