Palaniappan <> wrote:
> I am a newbie,
Please see the Posting Guidelines that are posted here frequently.
It will help you get answers to your Perl questions.
> sorry if my doubt is very basic..
There is no need to apologize for basic questions.
(There _is_ a need to apologize for questions answered in the
std docs though, but you didn't do that.)
> i am having a hash %abc with keys as
>
> $abc{'a0'}, $abc{'a1'}, .... $abc{'a9'}
Sequentially numbered hash keys may indicate that you've chosen
the wrong data structure. An array is often better in such cases...
> and i wrote a for loop to print all 10 values..
>
> for($i=0;$i<10;$i++)
That is an error-prone way of indexing, see below for a Better Way.
Space characters are not a scarse resource, feel free to use as
many of them as you need to make your code easier to read and understand.
for( $i=0; $i<10; $i++ )
> { print "$i - $abc{"a$i"} "; }
>
> i got the problem of using "" in between the string...
Here are 4 ways doing what you want, and one way that suggests
you try to want something else
---------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my %abc = qw/ a0 zero a1 one a2 two a3 three a4 four a5 five a6 six
a7 seven a8 eight a9 nine /;
foreach my $i ( 0 .. 9 ) {
print "$i - $abc{'a' . $i}\n"; # concatenation
print "$i - ", $abc{"a$i"}, "\n"; # list of args to print()
print qq/$i - $abc{"a$i"}\n/; # alternate delimiters
print "$i - $abc{ qq/a$i/ }\n"; # other alternate delimiters
}
print "-----\n";
foreach my $i ( 'a0' .. 'a9' ) { # range using magic auto-increment
print "$i - $abc{$i}\n";
}
print "-----\n";
---------------------------------
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas