fork download
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. print "First approach: Pass a reference to the array",
  7. " using the backslash operator:\n";
  8. my @words = ("Practical", "Extraction and", "Reporting", "Language");
  9. print_words(\@words);
  10.  
  11. print "\nSecond approach: Pass a reference to an anonymous array:\n";
  12. my $words_ref = ["Practical", "Extraction and", "Reporting", "Language"];
  13. print_words($words_ref);
  14.  
  15. sub print_words {
  16. my ($words_ref) = @_;
  17. for (0 .. $#$words_ref) {
  18. print "$_. ", $words_ref->[$_], "\n";
  19. }
  20. }
  21.  
Success #stdin #stdout 0s 3696KB
stdin
Standard input is empty
stdout
First approach: Pass a reference to the array using the backslash operator:
0. Practical
1. Extraction and
2. Reporting
3. Language

Second approach: Pass a reference to an anonymous array:
0. Practical
1. Extraction and
2. Reporting
3. Language