my in the perl syntax

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default my in the perl syntax

    Well I am very new to Perl. I have read Oreily's
    Camel book, but haven't found any thing about
    my that is used in any of the code.

    e.g
    my $var

    What is my supposed to be over here?

    __________________________________________________ ______________________
    Yahoo! India Mobile: Download the latest polyphonic ringtones.
    Go to [url]http://in.mobile.yahoo.com[/url]
    Harshal borade Guest

  2. Similar Questions and Discussions

    1. Perl Syntax Highlighting
      Greetings fellow members, I am in search for Perl/CGI definitions for use within CodeColoring.xml and Colors.xml. Perl syntax highlighting would...
    2. [ANNOUNCE] Apache::Syntax::Highlight::Perl 1.00
      The uploaded file Apache-Syntax-Highlight-Perl-1.00.tar.gz has entered CPAN as file:...
    3. How to Implement a BNF syntax in perl?
      Hi, I have a long BNF (Backus-naur form) for parsing a protocol message. Suppose I want to implement a BNF like this Response = Status-line...
    4. Simple Perl code/syntax question
      > Hallo everyone and thank you for your previous help Well there is the FAQ about case statements: perldoc -q 'switch or case' In your case...
    5. Perl Math Syntax
      Hello peoples, Needs some help getting a ... well ... pretty basic math script working but the solution eludes me .... I have a text file called...
  3. #2

    Default Re: my in the perl syntax

    Harshal borade wrote:
    > Well I am very new to Perl. I have read Oreily's
    > Camel book, but haven't found any thing about
    > my that is used in any of the code.
    >
    > e.g
    > my $var
    >
    > What is my supposed to be over here?
    I am new as well and by lurking in the groups I can tell you with great
    certainty to use "perldoc". It is wonderful. In your case you would type
    the following: perldoc -f my

    perldoc -f my

    my EXPR
    my TYPE EXPR
    my EXPR : ATTRS
    my TYPE EXPR : ATTRS
    A "my" declares the listed variables to be local (lexically) to
    the enclosing block, file, or "eval". If more than one value is
    listed, the list must be placed in parentheses.

    The exact semantics and interface of TYPE and ATTRS are still
    evolving. TYPE is currently bound to the use of "fields" pragma,
    and attributes are handled using the "attributes" pragma, or
    starting from Perl 5.8.0 also via the "Attribute::Handlers"
    module. See "Private Variables via my()" in perlsub for details,
    and fields, attributes, and Attribute::Handlers.

    HTH

    Robert
    Robert Guest

  4. #3

    Default Re: my in the perl syntax

    There is definitely an explanation in the Camel (Chapter 4.8.1, Scoped variable declarations).

    my $var declares a lexical variable, i.e. a variable with limited scope (where the scope is limited by an enclosing block, such as a subroutine, a conditional loop etc.).

    HTH,

    Jan

    Harshal Borade wrote:
    >Well I am very new to Perl. I have read Oreily's
    >Camel book, but haven't found any thing about
    >my that is used in any of the code.
    >
    >e.g
    >my $var
    >
    >What is my supposed to be over here?
    --
    Common sense is what tells you that the world is flat.
    Jan Eden Guest

  5. #4

    Default Re: my in the perl syntax

    From: Robert <bobx@linuxmail.org>
    Subject: Re: my in the perl syntax
    Date: Fri, 06 Feb 2004 07:57:39 -0500

    Hi the best to understand is like in the next code snippet:

    sub SubA
    {
    my $var1 ;

    }

    In this function the var $var will be local and so can not be accessed
    from outside. (Or if you have a global variable $var, it's actual
    value will be totally different.)

    Gurus will explain better..
    > Harshal borade wrote:
    >
    > > Well I am very new to Perl. I have read Oreily's
    > > Camel book, but haven't found any thing about
    > > my that is used in any of the code.
    > >
    > > e.g
    > > my $var
    > >
    > > What is my supposed to be over here?
    > I am new as well and by lurking in the groups I can tell you with great
    > certainty to use "perldoc". It is wonderful. In your case you would type
    > the following: perldoc -f my
    >
    > perldoc -f my
    >
    > my EXPR
    > my TYPE EXPR
    > my EXPR : ATTRS
    > my TYPE EXPR : ATTRS
    > A "my" declares the listed variables to be local (lexically) to
    > the enclosing block, file, or "eval". If more than one value is
    > listed, the list must be placed in parentheses.
    >
    > The exact semantics and interface of TYPE and ATTRS are still
    > evolving. TYPE is currently bound to the use of "fields" pragma,
    > and attributes are handled using the "attributes" pragma, or
    > starting from Perl 5.8.0 also via the "Attribute::Handlers"
    > module. See "Private Variables via my()" in perlsub for details,
    > and fields, attributes, and Attribute::Handlers.
    >
    > HTH
    >
    > Robert
    >
    > --
    > To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    > For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    > <http://learn.perl.org/> <http://learn.perl.org/first-response>
    Gabor Urban Guest

  6. #5

    Default Re: my in the perl syntax

    > Well I am very new to Perl. I have read Oreily's
    > Camel book, but haven't found any thing about
    > my that is used in any of the code.
    >
    > e.g
    > my $var
    >
    > What is my supposed to be over here?
    >
    >
    Since the Camel is a reference more than a tutorial and because it is
    already a pretty thick tome many of the examples in it will not include
    'my' as that is really a best practice not an absolute necessity to
    demonstrating code in a reference setting, so to make example code
    shorter and easier to understand. Having said that, it *is* a best
    practice and you *should* be doing,

    use strict;
    use warnings;

    In all of your code, which will necessitate the use of 'my' very often.

    [url]http://perl.plover.com/FAQs/Namespaces.html[/url]

    Is an excellent article on scoping in Perl, and should clear things up
    with regards to 'my'.... come back if you have further questions,

    [url]http://danconia.org[/url]
    Wiggins D Anconia Guest

  7. #6

    Default Re: my in the perl syntax

    Harshal borade wrote:
    >
    > Well I am very new to Perl. I have read Oreily's
    > Camel book, but haven't found any thing about
    > my that is used in any of the code.
    >
    > e.g
    > my $var
    >
    > What is my supposed to be over here?
    Perhaps this article will help you understand:
    [url]http://perl.plover.com/FAQs/Namespaces.html[/url]


    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn Guest

  8. #7

    Default Re: my in the perl syntax

    I certainly appreciate the pain you have gone through
    in writing that mail, but I haven't understood about
    "perldoc -f my". I went through a book , How to Perl
    5, last night. And it says that every variable
    declared gets into main, a default package. To avoid
    the namespace pollution it says that, its a good way
    to hide names from collision.
    Tell me if I have misunderstood it.
    Well infact if u could send me a a small code which
    uses the perl -f doc or the later thing mentioned by
    you, would help me a lot.


    --- Gabor Urban <gabaux@rubin.hu> wrote: > From:
    Robert <bobx@linuxmail.org>
    > Subject: Re: my in the perl syntax
    > Date: Fri, 06 Feb 2004 07:57:39 -0500
    >
    > Hi the best to understand is like in the next code
    > snippet:
    >
    > sub SubA
    > {
    > my $var1 ;
    >
    > }
    >
    > In this function the var $var will be local and so
    > can not be accessed
    > from outside. (Or if you have a global variable
    > $var, it's actual
    > value will be totally different.)
    >
    > Gurus will explain better..
    >
    > > Harshal borade wrote:
    > >
    > > > Well I am very new to Perl. I have read
    > Oreily's
    > > > Camel book, but haven't found any thing about
    > > > my that is used in any of the code.
    > > >
    > > > e.g
    > > > my $var
    > > >
    > > > What is my supposed to be over here?
    > > I am new as well and by lurking in the groups I
    > can tell you with great
    > > certainty to use "perldoc". It is wonderful. In
    > your case you would type
    > > the following: perldoc -f my
    > >
    > > perldoc -f my
    > >
    > > my EXPR
    > > my TYPE EXPR
    > > my EXPR : ATTRS
    > > my TYPE EXPR : ATTRS
    > > A "my" declares the listed variables to
    > be local (lexically) to
    > > the enclosing block, file, or "eval". If
    > more than one value is
    > > listed, the list must be placed in
    > parentheses.
    > >
    > > The exact semantics and interface of TYPE
    > and ATTRS are still
    > > evolving. TYPE is currently bound to the
    > use of "fields" pragma,
    > > and attributes are handled using the
    > "attributes" pragma, or
    > > starting from Perl 5.8.0 also via the
    > "Attribute::Handlers"
    > > module. See "Private Variables via my()"
    > in perlsub for details,
    > > and fields, attributes, and
    > Attribute::Handlers.
    > >
    > > HTH
    > >
    > > Robert
    > >
    > > --
    > > To unsubscribe, e-mail:
    > [email]beginners-unsubscribe@perl.org[/email]
    > > For additional commands, e-mail:
    > [email]beginners-help@perl.org[/email]
    > > <http://learn.perl.org/>
    > <http://learn.perl.org/first-response>
    >
    > --
    > To unsubscribe, e-mail:
    > [email]beginners-unsubscribe@perl.org[/email]
    > For additional commands, e-mail:
    > [email]beginners-help@perl.org[/email]
    > <http://learn.perl.org/>
    > <http://learn.perl.org/first-response>
    >
    >
    __________________________________________________ ______________________
    Yahoo! India Education Special: Study in the UK now.
    Go to [url]http://in.specials.yahoo.com/index1.html[/url]
    Harshal borade Guest

  9. #8

    Default Re: my in the perl syntax

    Harshal Borade wrote:
    >I certainly appreciate the pain you have gone through
    >in writing that mail, but I haven't understood about
    >"perldoc -f my". I went through a book , How to Perl
    >5, last night. And it says that every variable
    >declared gets into main, a default package. To avoid
    >the namespace pollution it says that, its a good way
    >to hide names from collision.
    >Tell me if I have misunderstood it.
    >Well infact if u could send me a a small code which
    >uses the perl -f doc or the later thing mentioned by
    >you, would help me a lot.
    "perldoc -f my" refers to Perl's built-in documentation. You can enter thiscommand at your prompt to get a description of my ("perldoc -f grep" givesa description of grep etc).

    But you already got several descriptions (as well as the output of perldoc -f my on this list), including mine.

    I do not see your problem.

    - Jan
    --
    If all else fails read the instructions. - Donald Knuth
    Jan Eden Guest

  10. #9

    Default Re: my in the perl syntax

    Harshal Borade wrote:
    > I certainly appreciate the pain you have gone through
    > in writing that mail, but I haven't understood about
    > "perldoc -f my".
    It is meant to be entered exactly as written on the command-line. It is the
    same way we call Perl programs:
    >perldoc -f my
    is a call to the perldoc program or [in Windows, batch file/program]. This
    program searches for information
    relating to the keywords offered. Since the call in question used the -f
    switch, it searches for information
    about built-in Perl functions by the name "my". Then it displays the
    information found in formatted text.
    Use perldoc first to find out about perl keyword, functions, general
    question, modules, etc.

    > I went through a book , How to Perl
    > 5, last night. And it says that every variable
    > declared gets into main, a default package. To avoid
    > the namespace pollution it says that, its a good way
    > to hide names from collision.
    > Tell me if I have misunderstood it.
    There is no way to tell, really. It sounds like you are almost quoting the
    text. Try restating this in your
    own words. What you say here does seem to make sense, but what does it mean
    to you? Can you
    see the connection between scoping and the process of breaking programs into
    manageable chunks?

    As you work with these concepts, we will be happy to point you along the
    way.
    >
    > Well infact if u could send me a a small code which
    > uses the perl -f doc
    No. This is something you have to get in the habit of doing for yourself.
    You should get used to
    working at the command-line. It will be critical as you start writing and
    testing your code.

    Joseph



    R. Joseph Newton Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139