List Info

Thread: Single assignment to a mixture of data types




Single assignment to a mixture of data types
country flaguser name
United States
2007-08-30 05:03:50

I know this must be easy but Perl's syntax has confounded me again... I
would expect the code
below to assigthe value of $string as 'C' b
ut instead all values are assigned to the array
.

How can I assign to both a string and array in one line - ideally
without using references.

Thanks
NJH

#!c:/perl/bin/perl.exe

use warnings;
use strict;
use diagnostics;

my (array,$string) = (('A','B'),'C');
print "My array is: arraynMy $string is: $stringn";

Produces:
My array is: A B C
My $string is:

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: Single assignment to a mixture of data types
country flaguser name
United States
2007-08-30 05:43:43

Hi!

In my knowledge it is so that you have to turn it around. So don't use
:>; my (array,$string) = (('A','B'),'C');
Because it will always be ABC, but use it so:
> my ($string, array) = ('C', ('A','B'));

Perl flushes everything at one times. This also goes for passing
parameters.

Gergely.

--- In perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com, "hooyar66" <pcbcad...> wrote:
&gt;
> I know this must be easy but Perl's syntax has confounded me again... I
> would expect the code
>; below to assign the value of $string as 'C' b
> ut instead all values are assigned to the array
&gt; .
>
> How can I assign to both a string and array in one line - ideally
> without using references.
>
> Thanks
&gt; NJH
>
> #!c:/perl/bin/perl.exe
>
> use warnings;
> use strict;
> use diagnostics;
>
> my (array,$string) = (('A','B'),'C');
&gt; print "My array is: arraynMy $string is: $stringn&quot;;
>;
> Produces:
> My array is: A B C
> My $string is:
>
>
>
>
> [Non-text portions of this message have been removed]
>

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )