📄 fig06_08.pl
字号:
#!usr/bin/perl
# Fig 6.8: fig06_08.pl
# Syntax for calling a subroutine.
# subroutine with no arguments defined before it is used
sub definedBeforeWithoutArguments
{
print "definedBeforeWithoutArguments\n";
}
# subroutine with arguments defined before it is used
sub definedBeforeWithArguments
{
print "definedBeforeWithArguments: @_\n";
}
# calling subroutines that are defined before use
print "------------------------------\n";
print "Subroutines defined before use\n";
print "------------------------------\n";
print "Using & and ():\n";
&definedBeforeWithoutArguments();
&definedBeforeWithArguments( 1, 2, 3 );
print "\nUsing only ():\n";
definedBeforeWithoutArguments();
definedBeforeWithArguments( 1, 2, 3 );
print "\nUsing only &:\n";
&definedBeforeWithoutArguments;
print "\"&definedBeforeWithArguments 1, 2, 3\"",
" generates a syntax error\n";
print "\nUsing bareword:\n";
definedBeforeWithoutArguments;
definedBeforeWithArguments 1, 2, 3;
# calling subroutines that are not defined before use
print "\n-----------------------------\n";
print "Subroutines defined after use\n";
print "-----------------------------\n";
print "Using & and ():\n";
&definedAfterWithoutArguments();
&definedAfterWithArguments( 1, 2, 3 );
print "\nUsing only ():\n";
definedAfterWithoutArguments();
definedAfterWithArguments( 1, 2, 3 );
print "\nUsing only &:\n";
&definedAfterWithoutArguments;
print "\"&definedAfterWithArguments 1, 2, 3\"",
" generates a syntax error\n";
print "\nUsing bareword:\n";
definedAfterWithoutArguments;
print "\"definedAfterWithoutArguments\" causes no action\n";
print "\"definedAfterWithArguments 1, 2, 3\"",
" generates a syntax error\n";
# subroutine with no arguments defined after it is used
sub definedAfterWithoutArguments
{
print "definedAfterWithoutArguments\n";
}
# subroutine with arguments defined after it is used
sub definedAfterWithArguments
{
print "definedAfterWithArguments: @_\n";
}
###########################################################################
# (C) Copyright 2001 by Deitel & Associates, Inc. and Prentice Hall. #
# All Rights Reserved. #
# #
# DISCLAIMER: The authors and publisher of this book have used their #
# best efforts in preparing the book. These efforts include the #
# development, research, and testing of the theories and programs #
# to determine their effectiveness. The authors and publisher make #
# no warranty of any kind, expressed or implied, with regard to these #
# programs or to the documentation contained in these books. The authors #
# and publisher shall not be liable in any event for incidental or #
# consequential damages in connection with, or arising out of, the #
# furnishing, performance, or use of these programs. #
###########################################################################
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -