[Israel.pm] boolean statment as sub parameter

sawyer x xsawyerx at gmail.com
Mon Feb 23 22:54:11 PST 2009


That would work. But then you have to do:
if (@dir) { # better named @files
    # do somthing
} else {
    # wasn't able to open the folder
    die "open folder failed: $!\n";
    # or return
}

A few comments:
1. better written: opendir my $difh (dont use barewords)
2. since you could run things only if it worked, it's shorter to
return or die if it fails and run the rest of the code instead of
having a few more lines of if(){}else{}
3. you risk the $! ($ERRNO, $OS_ERROR on English) being hijacked by
something else, like a file open or even a print. A print could fail
(without you knowing if you don't check the return of it) and override
the $!.

Just my 2 cents.

On Mon, Feb 23, 2009 at 6:38 PM, Levenglick Dov-RM07994
<dov at freescale.com> wrote:
>
> Without actually running, how about
> opendir (DIR, $dir) and @dir = readdir DIR;
> Instead of
> opendir (DIR, $dir) or die;
>
> Best Regards,
> Dov Levenglick
> SmartDSP OS Development Leader
>
> -----Original Message-----
> From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On
> Behalf Of Yitzchak Scott-Thoennes
> Sent: Monday, February 23, 2009 18:32
> To: Perl in Israel
> Subject: Re: [Israel.pm] boolean statment as sub parameter
>
> On Sun, February 22, 2009 11:15 pm, Avishalom Shalit wrote:
> > well an example for "and" is like a conditional (upon success)
> >
> > so do_this() and do_that() and do_the_other_thing() will only
> > do_the_other_thing if the first two were successful
>
> I meant it's hard to find a real example where it would be obviously
> better to say
>
> if (do_this() && do_that()) { do_the_other_thing() }
>
> or
>
> do_the_other_thing() if do_this() && do_that();
>
>
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl



More information about the Perl mailing list