[EMAIL PROTECTED] wrote:
> Hi all,
Hello,
> I used to do this on UNIX scripts ...
>
> #!/usr/bin/ksh
> vowels="a e i o u"
> for letter in $vowels
> do
> echo $letter
> done
>
> How do I do the same in Perl?
#!/usr/bin/perl
use warnings;
use strict;
my @vowels = qw/ a e i o u /;
for my $letter ( @vowels ) {
print "$letter\n";
}
> Is it possible to do this in Perl without having to put vowels into an array
> and
> use foreach, i.e., using only a FOR-LOOP, but not necessarily having to
> hardcode
> the ending number as for($start=1;$start<=5;$start++)? vowels may change into
> letters="a b c d e f g h" in which case for($start=1;$start<=5;$start++) may
> not be valid anymore.
>
> Any feedback will be very much appreciated .... Thanks in advance ...
my $vowels = q/aeiou/;
my $index;
while ( length( my $letter = substr $vowels, $index++, 1 ) ) {
print "$letter\n";
}
my $vowels = q/aeiou/;
for my $letter ( map substr( $vowels, $_, 1 ), 0 .. length( $vowels ) - 1 ) {
print "$letter\n";
}
my $vowels = q/aeiou/;
while ( $vowels =~ /(.)/sg ) {
print "$1\n";
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>