Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any criterias when $0 of a Perl script becomes null?

Tags:

process

perl

I am having a Perl script which internally uses dependent Perl modules from CPAN and my own project. I am using the $0 (process script name) attribute value in my script. Strangely, this value suddently becomes NULL after some dependent API calls. I am not using eval() or system() in my process. Just a regular top-down running script. Any idea what could be the reason for the vanishing of $0 value?

like image 745
Nirmal Singh Raja Reegan Avatar asked Aug 02 '13 11:08

Nirmal Singh Raja Reegan


1 Answers

Tie::StdScalar to find out who changed $0.

{
   package Tie::Scalar::Croaker;
   use Tie::Scalar qw( );
   use Carp qw( confess );
   our @ISA = qw( Tie::StdScalar );
   sub FETCH { $0 }
   sub STORE { confess('$0 changed'); }
   tie($0, Tie::Scalar::Croaker::);
}
like image 196
daxim Avatar answered Sep 30 '22 18:09

daxim