Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Bug or inconsitency? FQN of Package and sub name identical

by swampyankee (Parson)
on Nov 22, 2007 at 15:28 UTC ( [id://652390]=note: print w/replies, xml ) Need Help??


in reply to Bug or inconsitency? FQN of Package and sub name identical

Odd behavior when package and sub names are identical? My first suggestion is "don't do that." Perl is probably resolving its subs based, at least partly, on which ones it sees first, so it will use the first one it finds. I don't think this is either a bug or an inconsistency; it's a design decision. It does mean that the order subs are defined matters, which is not a concern unique to Perl: quite a few linkers do the same thing.


emc

Information about American English usage here and here.

Any Northeastern US area jobs? I'm currently unemployed.

  • Comment on Re: Bug or inconsitency? FQN of Package and sub name identical

Replies are listed 'Best First'.
Re^2: Bug or inconsitency? FQN of Package and sub name identical
by ysth (Canon) on Nov 22, 2007 at 16:32 UTC
    Yes, Foo-> compiles to (&Foo())-> if a sub Foo already exists; otherwise it's ("Foo")->:
    $ perl -wl sub Foo::new{"new in Foo"} sub Bar::new{"new in Bar"} print "before sub Foo: ", Foo->new; sub Foo {"Bar"} print "after sub Foo: ", Foo->new __END__ before sub Foo: new in Foo after sub Foo: new in Bar
    You can disambiguate by saying Foo::->new or "Foo"->new. I prefer the former.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://652390]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2024-04-23 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found