My if statement doesn't fit my needs

  • Thread starter Jean-Luc BEAUDET
  • Start date
J

Jean-Luc BEAUDET

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)
 
P

Perusion hostmaster

Hi all ,

I wrote something like below


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. :cool:

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";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top