Re: How to take a reference in line

2006-01-19 Thread RangerRickCA
 
Please remove me from this list!  Thank you!
 
RRCA



Re: How to take a reference in line

2006-01-18 Thread Todd W

Bill Gradwohl [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 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.

snip /

 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?


You bet:

check_required_items(Mr. Howell, [qw(Money preserver sunscreen)] );

a generic construct looks like this:

my $array_ref = [ 'foo', 'bar', 'bazz' ];

perldoc perlref

Todd W.




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




How to take a reference in line

2006-01-16 Thread Bill Gradwohl
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




Re: How to take a reference in line

2006-01-16 Thread Shawn Corey

Bill Gradwohl wrote:

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?


Try:
  check_required_items(Mr. Howell, $arrayPointer=[qw(Money preserver 
sunscreen)] );

  check_required_items(Mr. Howell, [qw(Money preserver sunscreen)] );


--

Just my 0.0002 million dollars worth,
   --- Shawn

Probability is now one. Any problems that are left are your own.
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is available at http://perldoc.perl.org/

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