coldmiser has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to write a quick perl script on Windows Activestate 5.6.0 and it doesn't look like my syntax is correct.

I'm trying to get my code to (add one to $filename AND rename a file AND run my Logging routine) OR run my Logging routine.

($filename++ && rename ("E:\\IFMXBKUP\\IFMXBKUP.BAK","E:\\IFMXBKUP\\IF +MXBKUP.$filename.BAK") && &Logging("renaming E:\\IFMXBKUP\\IFMXBKUP.B +AK to E:\\IFMXBKUP\\IFMXBKUP.$filename.BAK")) || &Logging("Cannot ren +ame E:\\IFMXBKUP\\IFMXBKUP.BAK: $!");

So, it has to do all three commands OR just one. Here is the code I have. I'm sure I have to be close, I just can't figure out what I'm doing wrong.

Can someone look at it for me and please tell me the stupid mistake I made (besides writing code for Activestate 5.6.0 or Windows which I have no control over)

Thanks for your assistance.

Replies are listed 'Best First'.
Re: ANDs and ORs
by Fletch (Bishop) on Apr 04, 2007 at 18:13 UTC

    What you're doing wrong is attempting to exclusively use boolean operators for flow control rather than sanely using conditionals (i.e. if).

Re: ANDs and ORs
by ikegami (Patriarch) on Apr 04, 2007 at 18:14 UTC

    You'll have a problem is $filename is initially zero, undefined or otherwise false. Fix:

    ($filename++, rename(...) && Logging(...)) || Logging(...);

    or

    do { $filename++; rename(...) && Logging(...) } || Logging(...);

    or

    (++$filename && rename(...) && Logging(...)) || Logging(...);

    I hope you're using that style because it's a one liner, because it's ugly (i.e. unreadable and unmaintainable)!

Re: ANDs and ORs
by Joost (Canon) on Apr 04, 2007 at 18:18 UTC
    So, it has to do all three commands OR just one. Here is the code I have. I'm sure I have to be close, I just can't figure out what I'm doing wrong.
    Then you shouldn't use && and || update: like that:
    ( a() && b() && c() ) || e();
    does:
    execute a() if a() returns false execute e() and end. if a() returns true execute b() if b() returns false execute e() and end. if b() returns true exece c() and end.
    so it executes either a() and e(), a() b() and e() or a() b() and c().
Re: ANDs and ORs
by Anno (Deacon) on Apr 04, 2007 at 18:41 UTC
    Does your Logging() always return a true value?

    Anno