perl - Lines not executed in the good order while dying in foreach loop -
i have strange behavior understand.
here perl script, check if folders present :
#!/usr/bin/env perl use warnings; $root = "c:\\data\\tests"; @check = ("folder1", "folder2", "folder3"); foreach $check (@check){ print $check; print -d "$root\\$check" ? " ok\n" : die " nok : not accessible"; }
now, assume folder3 missing, should have output:
folder1 ok folder2 ok folder3 nok : not accessible @ c:\data\tests\strange.pl line 8.
instead have :
folder1 ok folder2 ok nok : not accessible @ c:\data\tests\strange.pl line 8. folder3
so looks in last loop, second line executed before first..
someone knows why ?
so looks in last loop, second line executed before first..
someone knows why ?
die ".."
unlike print
goes stderr
furthermore output buffered might want disable in order wanted output,
stdout->autoflush(); stderr->autoflush();
Comments
Post a Comment