difference between my and our ? (declared in the same file)
perl
Solution
As you see, both `my` and `our` have lexical effect.
`my` creates a lexically scoped variable.
`our` creates a lexically scoped alias to a package variable.
Just because you say `package` in no fashion changes the lexical scope, so your `$val` is still an alias to `$one::val` even after having seen the `package two` statement.
If you don’t see a close curly, you haven’t finished your scope. (Or EOF or end of string in a string `eval`).
Problem
Before writing this program,I thought that `our` is a package scope variable and `my` is a file scope variable.But,After did that program,I am get confused. My program is, ``` #!/usr/bin/perl use strict; use warnings; package one; our $val = "sat"; my $new = "hello"; print "ONE:val =>$val \n"; print "ONE:new =>$new \n\n"; package two; print "TWO:val =>$val \n"; print "TWO:new =>$new \n"; ``` which outputs ``` ONE:val =>sat ONE:new =>hello TWO:val =>sat TWO:new =>hello ``` So,what is the difference between `my` and `our`.Whether the both are the same or it having any difference?