Home > Software engineering >  Perl File::copy- Can i use next if failed and also print?
Perl File::copy- Can i use next if failed and also print?

Time:09-18

I am creating a system which , as a part of it's process, should copy many files. I want that if a copy fail, the system will print an error and move to the next iteration (perl next statement). how can i one line it if at all? currently I have:

    copy($source,$dest) or print "-E- Copy failed: $partition fusion SDC wasn't found\n "; 

I want to add next besides the print. Thanks!

CodePudding user response:

EXPR
   or print( ... ), next;
EXPR
   or do {
      print( ... );
      next;
   };
if ( !EXPR ) {
   print( ... );
   next;
}

You can remove any/all of the line breaks, but hiding a next deep into a line is something I try to avoid.


Tip: warn( ... ) (or print( STDERR ... )) should be used in favour of print( ... ) for error messages.

  • Related