On Jul 22, Dave Adams said:

The following code looks too rigid, how can I achieve the same result
using one of the control structure (foreach, for, etc)?

my @today = Today();
my $year_now = $today[0];
my $month_now = $today[1];
my $day_now = $today[2];

Well, first of all, that could just be:

  my ($year_now, $month_now, $day_now) = Today();

print ($year_now);
print ("===\n");
print ($month_now);
print ("===\n");
print ($day_now);
print ("===\n");

And those could be:

  print "$_===\n" for $year_now, $month_now, $day_now;

And if Today() only returns those three values, you could do:

  print "$_===\n" for Today();

If Today() returns more than three values, then you could do:

  print "$_===\n" for (Today())[0..2];

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart

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