The definition of empty {} after the If () statement in the eval {} statement

I am currently trying to document a Perl script to prepare it for .NET. I had no previous experience in Perl before, but I managed to get through it with a lot of google fu. I came across one line of code that stopped me because I am not sure what it does. I was able to figure out most of them, but I missed the part, and I do not know if this is really important. Here is the line of code:

eval { if(defined $timeEnd && defined $timeStart){}; 1 } or next;

I know that definedchecks the variables $timeEndand $timeStartto see if they are null/ nothing/ undef. I also believe that the block is evalused as a Try / Catch block to catch any exceptions. The line of code is in the loop foreach, so I believe that the keyword nextwill continue with the next iteration of the loop foreach.

The part that I come across is decrypted as a bit {};1. I understand that it ;is the operator separator in Perl, and since it did not escape with a backslash, I have no idea what it is doing there. I also do not know what it means {}. I suppose this has something to do with the array, but it will be an empty array, and I don't know if that means anything special when it comes immediately after the block if(). Finally, I do not know what such an integer 1means and does it at the end of the block eval.

If someone could break this line of code into separate parts and their definitions, I would really appreciate it.

: .NET Perl , , , . VB.NET , :

For each element in xmlList    'This isn't in the Perl code I posted, but it the `foreach` loop that the code resides in.
    Try
        If Not IsNothing(timeEnd) AND Not IsNothing(timeStart) then 
        End If
    Catch ex as Exception
        Continue For
    End Try
Next
+4
2

elsif else, if :

if (EXPR) BLOCK

, EXPR - . . {} if.

, ( ). ,

while (s/\s//) { }

s/\s//g;

, , :

if(defined $timeEnd && defined $timeStart){}

! [1] So

eval { if(defined $timeEnd && defined $timeStart){}; 1 } or next;

eval { 1 } or next;

[2]

1 or next;

# Nothing to see here...

  • , .

    $ perl -MTie::Scalar -e'
       our @ISA = "Tie::StdScalar";
       tie(my $x, __PACKAGE__);
       sub FETCH { die }
       defined($x)
    '
    Died at -e line 4.
    

    , .

  • , $@.

+7

eval{} expresion (1 ) undef, . ,

my $ok = eval {
  if (defined $timeEnd && defined $timeStart){};
  1 
};
$ok or next;

perldoc -f eval

.. - , -; return , .

die, eval undef , $@

+2

All Articles