Loading ...
Sorry, an error occurred while loading the content.
 

RE: [PBML] Dereferencing an referenced array element in a subroutine

Expand Messages
  • Charles K. Clarkson
    ... Always use strict and warnings. Always! Theres is a contraction for there is and is spelled there s . The qw() operator does not need commas to
    Message 1 of 3 , Oct 7, 2005
      JC <> wrote:

      : I suppose this is a simple problem, however, I'm not
      : able to find the right incantation to make this work
      :
      : Code:

      Always use strict and warnings. Always!

      "Theres" is a contraction for "there is" and is spelled
      "there's". The qw() operator does not need commas to separate
      words.

      Perl assumes an array should be displayed in list context
      unless we indicate that it shouldn't. The "scalar" function forces
      scalar context, which returns the length of an array.


      : #!/usr/bin/perl

      use strict;
      use warnings;

      my $var1 = 'Perl is the Best';
      my @arr = qw(There's more than one way);
      try($var1, \@arr);


      sub try {
      foreach my $i ( @_ ) {
      if ( ref $i ) {
      print "Referenced Array Element 0: $i->[0] \n";
      print "The entire Array: @$i\n";
      print 'Total Elements in referenced array: ', scalar @$i, "\n";
      }
      }
      }


      __END__

      HTH,

      Charles K. Clarkson
      --
      Mobile Homes Specialist
      254 968-8328
    Your message has been successfully submitted and would be delivered to recipients shortly.