?? fig04_11.pl
字號:
#!/usr/bin/perl
# Fig. 4.11: fig04_11.pl
# Demonstrating function splice.
# create two arrays and display their initial contents
@array = ( 0 .. 20 );
@array2 = ( A .. F );
print "\@array: @array\n";
print "\@array2: @array2\n\n";
# replace part of @array with the elements from @array2
@replaced = splice( @array, 5, scalar( @array2 ), @array2 );
print "replaced: @replaced\n",
"with: @array2\n",
"resulting in: @array\n\n";
# remove 3 elements, beginning with element 15 of @array
@removed = splice( @array, 15, 3 );
print "removed: @removed\n",
"leaving: @array\n\n";
# remove all elements from element 8 to the end of @array
@chopped = splice( @array, 8 );
print "removed: @chopped\n",
"leaving: @array\n\n";
# delete all remaining elements
splice( @array );
unless ( @array ) {
print "\@array has no elements remaining\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. #
###########################################################################
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -