in reply to How is this Perl?

See the attributes pragma.

Update: Thanks to GrandFather I found the link I was after.

I tried to link to it but perldoc doesn't seem to know about it.)


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: How is this Perl?
by GrandFather (Saint) on Aug 11, 2007 at 07:06 UTC

    [doc://perlsub#Subroutine-Attributes-attribute-subroutine,-attribute-attrs|Subroutine attributes] gives the link: Subroutine attributes.

    The easiest way to "discover" the link is to point your browser to perlsub, then click the TOC entry for the section you want to link to. The link can then be copied from the browser and the encoded characters cleaned up (maybe one day PM will handle the encoded chars so cleaning up's not needed).


    DWIM is Perl's answer to Gödel
Re^2: How is this Perl?
by dogz007 (Scribe) on Aug 11, 2007 at 06:22 UTC
    Well I've learned something new today. Never heard of attributes before. I read the perldoc, but I'm still confused about the benefit (or real function, for that matter) of attributes. Can somebody 'splain?

      Attributes is a convenient way to add additional semantics (meaning) to a subroutine or variable.

      For instance if you wanted to add function signatures to Perl subroutines you could do something like this.

      #subroutinge must always be called with to args: #a username and a password sub login_user : Signature( username, password ) { #do something to login a user. }

      At compile-time the subroutine Signature will be automatically called. This subroutine could basically do anything, but in the example it would probably parse the function signature and if it is valid, manipulate the symbol table by insertering a subrouting that does argument validation before calling login_user in place of the original login_user subroutine.

      A more thorough explanation of how to use attributes can be found here