Siegfried Heintze wrote:
> Hey Perlers!
> 
> This code used to work and then I changed something and it no longer
> works! The problem is the output no longer includes "string 2a" and
> "string 2b". What am I doing wrong?
> 
> How do explicitly assign an array (not an array reference, but an
> array) to an array cell?
> 
> Thanks,
> Sieg
> 
> 
> sub concat {
>   # All arguments are assumed to be strings or nested arrays of
>   strings. # Concatenate all elements of all arguments.
>   return join "", map ref eq "ARRAY" ? concat( @$_ ) : $_, @_ }
> 
> my @sResult = ();
> push @sResult,  "string 1";
> push @sResult,  "string 2";
> 
> my $nMark = @sResult;
> 
> push @sResult, ();  # make an array of an array cell: does not work
> 
> push @sResult = "string 3";
        
> 
> [EMAIL PROTECTED] = "string 2a";
> [EMAIL PROTECTED] = "string 2b";
> 
        If you want the array, then change above two lines:

        $sResult[$nMark] = ["string 2a", "string 2b"] ;
        
        But the way this is, the 'string 3' will be replaced. if want to keep 
the string 3, then I did a 

        if ( defined $sResult[$nMark] ) {
           $sResult[$nMark] = [$sResult[$nMark], "string 2a", "string 2b"] ;

         }else {
            $sResult[$nMark] = ["string 2a", "string 2b"];
       }

The output with this last one is:
string 1string 2string 3string 2astring 2b

        But unsure is that what you are after.

Wags ;)
 }> print concat [EMAIL PROTECTED];



*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************


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