On Dec 12, 2007 12:04 AM, Sayed, Irfan (Irfan) <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I have some string stored in array as follows.
>
> @array=(dadsad,assasd) Now if i print this array then it is printing as
> dadsad,assasd

I certainly hope you are not using barewords like this.  This will
work (for certain definitions of work) with the strict pragma turned
off, but it is a very bad idea.  Please tell me the real code looks
like this

my @array = ('dadsad', 'assasd');

or

my @array = qw(dadsad assasd);

snip
>
> Now i want output like
>
> dadsad
> assasd
>
> so i did
>
> for (@array) {
>
> print $_,"\n";
>
> }
snip

Besides needing indentation, this is okay.  A better loop would name
the temporary variable (only use the default variable with functions
and operators that use it by default like chomp and regexes).

for my $item (@array) {
    print "$item\n";
}

snip
> My query is that can i store the output of this for loop in variable or
> list. so that if i print the content of that variable or array then it
> should print as
>
> dadsad
> assasd
>
> Please guide
snip

Well, yes, you can create a new array or scalar holding the
information, but it would just be a duplicate plus the newlines which
would be a waste of space.  Why do you want this?

my @array_plus_newlines = map { "$_\n" } @array;
my $flattened_array_plus_newlines = join '', map { "$_\n" } @array;

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


Reply via email to