in reply to Re: Scope of variables
in thread Scope of variables

Ok Thanks. Could you please tell me the scope of ora_errstr variable here.

Replies are listed 'Best First'.
Re^3: Scope of variables
by wfsp (Abbot) on Apr 21, 2006 at 06:56 UTC
    Have a look at package for more info.

    main:: is the default. If there are no other packages that's the one your in and there is no need to include the prefix. If there is a package (e.g. a module) that has a variable of the same name then you would need the package prefix to distinguish between the two.

      Ok. That means both $main'ora_errstr & $ora_errstr belongs to the same package. Then $main'ora_errstr = $ora_errstr doesn't make any sense.
      Actually $main'ora_errstr = $ora_errstr this statement is defined in the subroutine of ora package. This package is being called by many other scripts. Some of the scripts use $ora'ora_errstr & some $main'ora_errstr. I am really confused. Please help me.
        I think you have it there. A variable of the same name exists in main and in ora. So you have to spell out which one you mean. Perhaps this will help:
        #!/usr/bin/perl use strict; use warnings; # package main (default); our $ora_errstr = 'main'; { package ora; our $ora_errstr = 'ora'; print "package ora\n"; print "\$ora_errstr: $ora_errstr\n"; print "\$main::ora_errstr: $main::ora_errstr\n"; print "\n\n"; } package main; print "package main\n"; print "\$ora_errstr: $ora_errstr\n"; print "\$ora::ora_errstr: $ora::ora_errstr\n"; __DATA__ ---------- Capture Output ---------- > "C:\Perl\bin\perl.exe" _new.pl package ora $ora_errstr: ora $main::ora_errstr: main package main $ora_errstr: main $ora::ora_errstr: ora > Terminated with exit code 0.