At 11:46 AM -0800 12/1/11, flebber wrote:
Hi

I can get the standard list slicing to work. But what about getting
the result of a list slice to an interpolated string or a range
interpolated.

In beginning perl Simon uses this example

#!/usr/bin/perl
# multilist.plx
use warnings;
use strict;
my $mone; my $mtwo;
($mone, $mtwo) = (1, 3);
print (("heads ", "shoulders ", "knees ", "toes ")[$mone, $mtwo]);
print "\n";


which is fine but say I wanted the print result to be: " I am touching
my shoulders and toes" rather than (shoulders toes)

Use printf:

printf(
  "I am touching my %s and %s\n",
  (("heads ", "shoulders ", "knees ", "toes ")[$mone, $mtwo])
);


I tried to create a list variable and then return the output of the
list interpolated but not getting expected result.

For example using months

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

#my $summer = (0,1,2);
#my $winter = (5,6,7);

qw|
        January         February        March
        April           May                     June
        July            August          September
        October         November        December
        |[(my @summer = (0,1,2)), (my @winter = (5,6,7))];
print "My Summer months @summer and my winter months @winter \n";

This returns the array 0,1,2 not the slice from the list.

This works:

my @months = qw(January February March April May June July
  August September October November December );
my @summer = @months[0,1,2];
my @winter = @months[5,6,7];


--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to