Home > Blockchain >  File::Copy: Can I use next if failed and also print?
File::Copy: Can I use next if failed and also print?

Time:09-20

I am creating a system which, as a part of it's process, should copy many files. I want that if a copy fails, the system will print an error and move to the next iteration (using the Perl next statement).

How can I create a one-liner, 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.

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