Using the example below (partially taken from Learning PERL Objects), I
can't seem to figure out how to take a reference to an array in-line.
See the last 2 lines:

#!/usr/bin/perl

use Data::Dumper;

sub check_required_items {
  my $who = shift;
  my $items = shift;

  my @required = qw(preserver sunscreen water_bottle jacket);
  print "\n\n";
  print Dumper $items;
  for my $item (@required) {
    print "Checking $item:";
    unless (grep $item eq $_, @{$items}) { # not found in list?
      print "$who is missing $item.\n";
    } else {
      print "OK!\n";
    }
  }  
}

my $arrayPointer;

# This works:
@{$arrayPointer}=qw(Money preserver sunscreen);
check_required_items("Mr. Howell", $arrayPointer);

# These don't work:
check_required_items("Mr. Howell", @{$arrayPointer}=qw(Money preserver 
sunscreen));
check_required_items("Mr. Howell", qw(Money preserver sunscreen));


How do I tell Perl to give me a reference to an array in the last 2
statements? There's got to be a way to pass a reference without having
to explicitly name a variable. Right?

Thank You


-- 
Bill Gradwohl



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to