ultimate n00b question re: my / our

Discussion in 'Perl' started by Koncept, Dec 5, 2003.

  1. Koncept

    Koncept Guest

    I hope this is not too silly...

    What is the difference between setting a var with my or our? When would
    I know to distingish between the two? Also, is this necessary to always
    define when setting a var?

    Thanks!

    --
    Koncept <<
    "Contrary to popular belief, the most dangerous animal is not the lion or
    tiger or even the elephant. The most dangerous animal is a shark riding
    on an elephant, just trampling and eating everything they see." - Jack Handey
     
    Koncept, Dec 5, 2003
    #1
    1. Advertising

  2. Koncept

    Nick Santos Guest

    "Koncept" <> wrote in message
    news:051220031452137698%...
    >
    > I hope this is not too silly...
    >
    > What is the difference between setting a var with my or our? When would
    > I know to distingish between the two? Also, is this necessary to always
    > define when setting a var?
    >
    > Thanks!



    It is not necessary to define your variables as mine or our. You can simple
    declare them like so

    $foo;
    #or
    $foo=12;

    the first of which isn't necessary. One of the great things about perl is
    that scalar variables are pretty much all your basic types in one, so you
    don't even NEED to declare them at all, you can just start using them. As
    for the case of my and our, I've seen people use my because it defines that
    it comes from a local source(though I may be wrong). I think the programmers
    that put my are using it as much for their knowledge as for the compilers. I
    personally have never heard of using an "our" defiinition." That'll have to
    come from someone else's knowledge
    -Nick
     
    Nick Santos, Dec 6, 2003
    #2
    1. Advertising

  3. Koncept

    Koncept Guest

    In article <EGfAb.36369$_M.167792@attbi_s54>, Nick Santos
    <> wrote:

    > As
    > for the case of my and our, I've seen people use my because it defines that
    > it comes from a local source(though I may be wrong). I think the programmers
    > that put my are using it as much for their knowledge as for the compilers.


    I figured this much. Thanks for your help.

    As for "our" this is what I found:

    "An our declares the listed variables to be valid globals within the
    enclosing block, file, or eval. That is, it has the same scoping rules
    as a ``my'' declaration, but does not create a local variable. If more
    than one value is listed, the list must be placed in parentheses. The
    our declaration has no semantic effect unless ``use strict vars'' is in
    effect, in which case it lets you use the declared global variable
    without qualifying it with a package name."

    http://aspn.activestate.com/ASPN/docs/ActivePerl/lib/Pod/perlfunc.html#i
    tem_our

    --
    Koncept <<
    "Contrary to popular belief, the most dangerous animal is not the lion or
    tiger or even the elephant. The most dangerous animal is a shark riding
    on an elephant, just trampling and eating everything they see." - Jack Handey
     
    Koncept, Dec 6, 2003
    #3
  4. Koncept

    Nick Santos Guest

    "Koncept" <> wrote in message
    news:061220031455130889%...
    > In article <EGfAb.36369$_M.167792@attbi_s54>, Nick Santos
    > <> wrote:
    >
    > > As
    > > for the case of my and our, I've seen people use my because it defines

    that
    > > it comes from a local source(though I may be wrong). I think the

    programmers
    > > that put my are using it as much for their knowledge as for the

    compilers.
    >
    > I figured this much. Thanks for your help.
    >
    > As for "our" this is what I found:
    >
    > "An our declares the listed variables to be valid globals within the
    > enclosing block, file, or eval. That is, it has the same scoping rules
    > as a ``my'' declaration, but does not create a local variable. If more
    > than one value is listed, the list must be placed in parentheses. The
    > our declaration has no semantic effect unless ``use strict vars'' is in
    > effect, in which case it lets you use the declared global variable
    > without qualifying it with a package name."
    >
    > http://aspn.activestate.com/ASPN/docs/ActivePerl/lib/Pod/perlfunc.html#i
    > tem_our
    >
    > --
    > Koncept


    Cool, looks like I learned as much from your post as you did. Thanks
    -Nick
     
    Nick Santos, Dec 6, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWFyY28gQWx2ZXM=?=

    eCompany!!! The ultimate idea for the software development!!!

    =?Utf-8?B?TWFyY28gQWx2ZXM=?=, Aug 13, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    337
    M. Posseth
    Aug 21, 2004
  2. Andoni

    [OT] Ultimate Interface.

    Andoni, Sep 30, 2004, in forum: Java
    Replies:
    4
    Views:
    318
    ~misfit~
    Sep 30, 2004
  3. SivaSankar.Battula

    what is the ultimate difference?

    SivaSankar.Battula, Aug 27, 2005, in forum: Java
    Replies:
    6
    Views:
    401
    Thomas G. Marshall
    Aug 29, 2005
  4. Steve Horrillo
    Replies:
    3
    Views:
    443
    Roy Schestowitz
    Jun 28, 2005
  5. Zombie
    Replies:
    0
    Views:
    363
    Zombie
    Oct 8, 2004
Loading...

Share This Page