On Tue, 30 Nov 2004 23:33:39 +0000, Jonathan Paton <[EMAIL PROTECTED]> wrote:
> Dave,
> 
> Yes, look up references in your books.
> 
> E.g.
> 
> sub example {
>     my @data = qw<Hello World>;
>     return [EMAIL PROTECTED];
> }
> 
> my $reference = example();
> 
> for my $word (@{ $reference }) {
>     print "$word\n";
> }
> 
> Jonathan Paton
> 

You do not *have* to use references at this point, and while I think
mastering their use is
important, it's not on my list of "things a beginner needs" (and
someone who does not know how to even use subs in list contexts is not
ready yet for them)...

#!/usr/bin/perl
use strict;
use warnings;

# flowers -- return a list of
sub flowers
{
  # let's suppose you got your flowers out of the database, but to make this
  # stand on it's own I will just return the list
  return ( 'Dafodil', 'Rose', 'Stench Blossom' );
}

#
# in the mainline code
#
foreach my $flower ( flowers() )  { #  flowers() is a subroutine call
 print "Have a dozen ${flower}s\n";
}

# note that I used the ${} notation with $flower in that string,
# beacuse I wanted the literal "s" to be attached

-- 
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