Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How to write macro in perl

by mihirjha (Novice)
on Jan 11, 2008 at 05:29 UTC ( #661801=perlquestion: print w/ replies, xml ) Need Help??
mihirjha has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks! I want know, how we can write macro in perl. If you can provide me an example to do the same, it will be really great. Thanks & regards, Mihir

Comment on How to write macro in perl
Re: How to write macro in perl
by CountZero (Bishop) on Jan 11, 2008 at 06:14 UTC
    Please define "macro". What do you want to use it for?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: How to write macro in perl
by McDarren (Abbot) on Jan 11, 2008 at 06:15 UTC
    A macro to do what?

    What are your inputs?

    What processing do you need to do?

    What is your expected output?

    What have you tried so far?

    Please read How (Not) To Ask A Question and then update your question with enough detail to enable us to help you.

      Hi Monks! Thanks for your questions. Please find the answers below. A macro to do what? -I want macro do following activity - To check whether the variable are define before using - Log the value passed to the variable entering/leaving a function i.e. to printing the trail of Input and output variable. - Memory statistic before entering and leaving the function to have idea about the memory status. I don't want that code to be part of the final product. I need those things for development/debugging purpose. What are your inputs? Input is .pl file What processing do you need to do? - To check whether the variable are define before using - Log the value passed to the variable entering/leaving a function i.e. to printing the trail of Input and output variable. - Memory statistic before entering and leaving the function to have idea about the memory status. What is your expected output? Expected output that all the above should be control with #ifdef , so that these things help in debugging but i don't want that to be part of the final product. What have you tried so far? I am trying to learn ExtUtils::PerlPP but i have not comprehand it properly. I hope, I have explained my situation. Please let me know , if you need more input from me. Regards, Mihir
        It sounds like you want to learn Perl. I'd suggest you go to the O'Reilly web-site and look at their offerrings.
        mihirjha,

        I'm afraid that I'm still not clear about what it is that you are trying to do. You mention checking whether or not a variable is defined. Well, Perl has an inbuilt function for this, called defined. A very simple example of its usage is as follows:

        #!/usr/bin/perl -l use strict; use warnings; my $foo = 1; my $bar; print '$foo is ', defined $foo ? "defined" : "not defined"; print '$bar is ', defined $bar ? "defined" : "not defined";
        Which prints:
        $foo is defined $bar is not defined

        You also mention that you want to track the value of a variable. The easiest way to do this is with print, or perhaps something like Data::Dumper.

        If, as apl suggests, you are new to Perl and want to learn, then I would suggest that a good place to start would be the Tutorials section of the Monastery.

        In any case, welcome to PerlMonks.

        Darren :)

        It looks to me like you are trying to do some profiling of your code as it runs in a test environment. Take a look at the Devel modules, you may be able to find a profiler that does what you want.

        If you want to inject code into subroutines for testing, you might find Hook::LexWrap useful.

        Update: I'd find it a lot easier to read your posts if you added some formatting to your nodes. When you have long lists of things, us an ordered or unordered list. Keep you paragraphs short. Whitespace helps improve readability.


        TGI says moo

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://661801]
Approved by BrowserUk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (15)
As of 2014-09-17 14:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (83 votes), past polls