I just spent longer than I care to admit on this one...

opendir(DIR,'/') || die "$!"; my @files=readdir(DIR) || die "$!"; closedir(DIR) || die "$!"; print join "\n", @files;
select this for answer:
|| has a higher precedence than =
(my @files=readdir(DIR)) || die “$!”;
.....works just fine

email: mandog

Replies are listed 'Best First'.
Re: Precedence (spot the bug)
by Chmrr (Vicar) on Oct 22, 2001 at 05:07 UTC

    Ayup. Note that or is identical to || but with a lower precence; thus, it's rather practical for things like this. Generally, || is used mainly to establish default values, because of its high predence.

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^+*`^ ve^#$&V"+@( NO CARRIER'

Re: Precedence (spot the bug)
by Arguile (Hermit) on Oct 22, 2001 at 05:16 UTC

    You might consider using the lower precedence "or" especially for error checking. The double pipe version is more useful for when you want to do short-circuit evaluation in conditional expressions.

    opendir DIR, '/' or die "Failure opening dir /: $!";

    Stylistically I find this much easier to read and you don't have to worry about precedence as 'or' and 'xor' are as low as you can get on the chart ;).

Re: Precedence (spot the bug)
by kschwab (Vicar) on Oct 22, 2001 at 05:09 UTC
    or perhaps you could look at or :) :
    my @files=readdir(DIR) or die “$!”;
    .....works just fine too.