On Wed, Jun 24, 2009 at 03:25:57PM +0200, Jenda Krynicky wrote: > From: Roman Makurin <dro...@gmail.com> > > here is complite perl script which produces such results without > > any warning: > > > > #!/usr/bin/perl > > > > use strict; > > use warnings; > > > > use constant { > > A => 0, > > B => 1, > > C => 2 }; > > > > my @a = (A, B, C); > > my @b = (1, 2, 3); > > > > while(my $i = shift @a) { > > print $i, $/ > > } > > But of course this does not print anything. The shift(@a) returns the > first element of @a which is zero, assigns that to $i and then checks > whether it's true. And of course it's not. So it skips the body and > leaves the loop. Keep in mind that the value of > > my $i = shift @a > > is NOT a true/false whether there was something shifted from the > array. It's the value that was removed from the array and assigned to > the $i. And if that value it false (undef, 0, 0.0, "0", "0.0", "" - > if I remember rigth) then the whole expression evaluates to false in > boolean context. > > Whether you use constants or not is irrelevant. You'd see the same > behaviour with > > my @a = (0, 1, 2);
big thanks for explanation :) PS: My stupid head :D > > HTH, Jenda > ===== je...@krynicky.cz === http://Jenda.Krynicky.cz ===== > When it comes to wine, women and song, wizards are allowed > to get drunk and croon as much as they like. > -- Terry Pratchett in Sourcery > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > -- If you think of MS-DOS as mono, and Windows as stereo, then Linux is Dolby Digital and all the music is free... -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/