Thursday 5 September 2019

How many ways to verify Perl scalar variable is initialized or defined?


 Method1:

          if !(defined $a)
         {

         }       

Method2:

         $a = defined $a? $a : {  };

Method3:
     
          $a = "Hi" unless defined $a;          

Method4: 
         
          $a = $a || "Hi";   
          
Method5:
     
           $a ||= "Hi";     

Method6:

            if ( length( $a || '' ))
            {

             }

kaavannan perl blogspot

Labels: , , , , , ,

0 Comments:

Post a Comment

Note: only a member of this blog may post a comment.

<< Home