Possible bug?; keywords for sub idenifier?

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

  1. #1

    Default Possible bug?; keywords for sub idenifier?

    I just wondering, why does Perl allow you to use supposedly reserved words
    for a sub (function) identifier?

    An example that illustrates this is as follows:

    test.pl
    ----------
    #!/usr/bin/perl

    package test;
    use strict;

    $test::Config = new Test_Config;

    print $test::Config->my;
    print "\n";
    ----------

    Test_Config.pm
    ----------
    package RMS_Config;
    use strict;

    sub new {
    my $this = shift;
    my $obj = {
    'TEST1' => 1,
    'TEST2' => 2
    };

    bless $obj, $this;
    return $obj;
    }

    sub my {
    my $this = shift;

    return "test123";
    }

    1;

    ----------

    Output
    ----------
    [SR@SRLNX test]$ perl -W test.cgi
    test123
    [SR@SRLNX test]$
    ----------

    Why on earth does it allow reserved names to be used as identifiers? I also
    works if tried like this:

    test_2.pl
    ----------
    #!/usr/bin/perl

    package test;
    use strict;

    sub my {
    print "f o o\n";
    }
    ----------

    I get no errors nor warning.

    Thanks for any info.


    Trent Curry Guest

  2. Similar Questions and Discussions

    1. Searching on keywords
      Hello, I have a table setup as: +---------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra |...
    2. Keywords & Description
      Hello, I recently built a Contribute enabled site for one of my clients using Dreamweaver templates. My client wants to edit the page keywords...
    3. keywords and .swf
      I have a couple of questions - can more keywords be somehow added into a website? The keyword field only allows 256 characters. I've got about...
    4. Keywords
      Help - I think I am gong mad. In Publisher 2000 I click Web Properties and put some words in Keywords - separated by , - save and upload. When I...
    5. Need docs on mso- keywords
      In web pages created by Publisher, there are these keywords: mso-ignore mso-font-charset mso-paper-source and many others. Where can I find...
  3. #2

    Default Re: Possible bug?; keywords for sub idenifier?

    Trent Curry wrote:
    > I just wondering, why does Perl allow you to use supposedly reserved words
    > for a sub (function) identifier?
    Why not?
    Can you imagine any trouble resulting from it
    (except for human-unreadable code)
    ?

    The interpreter knows what you mean when you call
    a method on a blessed reference, doesn't it?

    It also has no trouble with main::my, &my, or &my(),
    but it will give up when you say just my(), so everything
    is just perfect, IMHO.

    Amir

    Amir Kadic Guest

  4. #3

    Default Re: Possible bug?; keywords for sub idenifier?

    "Amir Kadic" <zoooz@gmx.de> wrote in message
    news:bjgjav$ip512$1@ID-142982.news.uni-berlin.de...
    > Trent Curry wrote:
    >
    > > I just wondering, why does Perl allow you to use supposedly reserved
    words
    > > for a sub (function) identifier?
    >
    > Why not?
    > Can you imagine any trouble resulting from it
    > (except for human-unreadable code)
    > ?
    >
    > The interpreter knows what you mean when you call
    > a method on a blessed reference, doesn't it?
    >
    > It also has no trouble with main::my, &my, or &my(),
    > but it will give up when you say just my(), so everything
    > is just perfect, IMHO.
    >
    > Amir
    So its actually a feature then? Just seems rather odd when you've been
    through so many other langs (c/c++/java/cobol/PL-SQL/and the likes). Its an
    interesting feature though. Perl is a lang that never ceases to amaze me :-)


    Trent Curry 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