Y
Yogi
Hi,
I am trying to understand how arrays work in scalar context. Here is
the question:
@a = (10,20,30,40,50);
@b = @a[0..3];
print "[@b] \n";
when I run this script, I am getting proper result i.e. o/p is: [10 20
30 40]
But when I do this change:
@a = (10,20,30,40,50);
@b = $a[0..3]; # THIS LINE IS CHANGED
print "[@b] \n";
I get o/p as: [20]. why? why first element of the range operator is
ignored and 2nd element is assigned to @b. I am trying this just to
satisfy my curiosity.
Regards,
I am trying to understand how arrays work in scalar context. Here is
the question:
@a = (10,20,30,40,50);
@b = @a[0..3];
print "[@b] \n";
when I run this script, I am getting proper result i.e. o/p is: [10 20
30 40]
But when I do this change:
@a = (10,20,30,40,50);
@b = $a[0..3]; # THIS LINE IS CHANGED
print "[@b] \n";
I get o/p as: [20]. why? why first element of the range operator is
ignored and 2nd element is assigned to @b. I am trying this just to
satisfy my curiosity.
Regards,