Professional Web Applications Themes

My if statement doesn't fit my needs - PERL Miscellaneous

Hi all , I wrote something like below > 58 if ( chown 102, 200, $DirtoCreate or warn "Unable to > chown $DirtoCreate: $!\n" ) { > 59 print "Rights for $DirtoCreate successfully > changed.\n"; > 60 } but it doesn't fit my needs. What i'd like would be: if the chown command succeeds it prints Rights for $DirtoCreate successfully changed. BUT if it fails, i want it to only print the warn text and NOT the print text. The first case works OK, but in the second one i've got both the warn AND the print. Where did i ...

  1. #1

    Default My if statement doesn't fit my needs

    Hi all ,

    I wrote something like below
    > 58 if ( chown 102, 200, $DirtoCreate or warn "Unable to
    > chown $DirtoCreate: $!\n" ) {
    > 59 print "Rights for $DirtoCreate successfully
    > changed.\n";
    > 60 }
    but it doesn't fit my needs.

    What i'd like would be:
    if the chown command succeeds it prints Rights for $DirtoCreate
    successfully changed.
    BUT if it fails, i want it to only print the warn text and NOT the print
    text.

    The first case works OK, but in the second one i've got both the warn
    AND the print.

    Where did i fail ?

    Thx for any help.

    Jean-Luc B :O)

    Jean-Luc BEAUDET Guest

  2. #2

    Default Re: My if statement doesn't fit my needs

    On Wed, 09 Jul 2003 11:16:58 +0200, Jean-Luc BEAUDET <beaudetcyber.kodak.com> wrote:
    > Hi all ,
    >
    > I wrote something like below
    >
    >> 58 if ( chown 102, 200, $DirtoCreate or warn "Unable to
    >> chown $DirtoCreate: $!\n" ) {
    >> 59 print "Rights for $DirtoCreate successfully
    >> changed.\n";
    >> 60 }
    >
    > but it doesn't fit my needs.
    >
    > What i'd like would be:
    > if the chown command succeeds it prints Rights for $DirtoCreate
    > successfully changed.
    > BUT if it fails, i want it to only print the warn text and NOT the print
    > text.
    >
    > The first case works OK, but in the second one i've got both the warn
    > AND the print.
    >
    > Where did i fail ?
    Not realizing that warn returns a true status if it was able to
    warn. 8-)

    You could just add an else branch:

    my $verbose;
    my $uid = 102;
    my $gid = 200;

    if ( chown $uid, $gid, $DirtoCreate ) {
    print "Rights for $DirtoCreate successfully changed.\n"
    if $verbose;
    }
    else {
    warn "Unable to chown $DirtoCreate: $!\n";
    }

    --
    Perusion Hostmaster

    "Being against torture ought to be sort of a bipartisan thing."
    -- Karl Lehenbauer
    Perusion hostmaster Guest

Similar Threads

  1. Replies: 0
    Last Post: September 8th, 10:15 PM
  2. Replies: 0
    Last Post: September 8th, 10:15 PM
  3. Replies: 0
    Last Post: September 8th, 08:59 PM
  4. Please help! My SQL statement doesn't work..
    By alecken in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: March 3rd, 09:54 PM
  5. Having problems with an IF statement, just doesn't make sense
    By Nadim Attari in forum PHP Development
    Replies: 0
    Last Post: July 7th, 12:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139