Possible bug?; keywords for sub idenifier?

Discussion in 'Perl Misc' started by Trent Curry, Sep 7, 2003.

  1. Trent Curry

    Trent Curry Guest

    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, Sep 7, 2003
    #1
    1. Advertising

  2. Trent Curry

    Trent Curry Guest

    "Trent Curry" <> wrote in message
    news:bjg4a1$c6j$...
    > 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:
    >

    [Snipped example code]

    Just FYI, I'm using Perl 5.6.1 (i386)
     
    Trent Curry, Sep 7, 2003
    #2
    1. Advertising

  3. Trent Curry

    Amir Kadic Guest

    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, Sep 8, 2003
    #3
  4. Trent Curry

    Trent Curry Guest

    "Amir Kadic" <> wrote in message
    news:bjgjav$ip512$-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, Sep 8, 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. THY
    Replies:
    1
    Views:
    398
    Steve C. Orr, MCSD
    Aug 19, 2003
  2. Kathy Burke
    Replies:
    3
    Views:
    398
    Kathy Burke
    Nov 24, 2003
  3. Tee
    Replies:
    2
    Views:
    816
  4. Ben
    Replies:
    2
    Views:
    901
  5. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,044
    Lawrence D'Oliveiro
    May 20, 2011
Loading...

Share This Page