Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

There is no way for Perl to find "uninitialized variables" before they are used. will give you a warning if you use a variable before initializing it.

Your problem seems to be not "uninitialized" but unused variables - from your description, I think you have code like this:

my ($foo,$bar,$baz,$i); for $i (0..10) { print "$i\n"; };

and you want to eliminate $foo,$bar,$baz from your code. The only way to do that is to remove them all and add only the necessary declarations back in.

There can be no automated way to do that which works every time because of the following program:

my $i; if (rand > 0.5) { $i = 1; };

You could create a special object which registers itself with a central authority and deregisters itself when it gets overwritten and at program end check if the object was not overwritten. That way you could find out all variables that have not been used throughout one run of the program. But it is likely much easier to do this manually.

Update: Roy Johnson spotted an embarassing typo - I forgot the parentheses around a my declaration

In reply to Re: finding Un-Initialised variables from the perl code by Corion
in thread finding Un-Initialised variables from the perl code by jesuashok

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2022-05-24 00:44 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (82 votes). Check out past polls.