Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: using strict and functions

by Desdinova (Friar)
on Jan 17, 2002 at 22:04 UTC ( #139569=note: print w/ replies, xml ) Need Help??

in reply to using strict and functions

One way would be to add

use vars qw($var1 @array2};
That will give you the effect of a global var (actually a package var.) Without strict complaining too much. There is a great discussion of this here

Another option would be to pass the functions a reference to the variable. See perlref for details on using references. In my opinion this is a better way because it makes your functions more usable in other programs.
Also if they are small vars you can just pass them to the function in your call. If it is a huge list you will get better performance with the reference though.

UPDATE: Removed the comma per the comment below btw- you are bieng no more 'picky' than perl itself <g>

Comment on Re: using strict and functions
Download Code
Replies are listed 'Best First'.
Re(2): using strict and functions
by dmmiller2k (Chaplain) on Jan 18, 2002 at 08:57 UTC

    Sorry to nitpick but you can do either this:

        use vars qw($var1 @array2);

    or this:

        use vars ( '$var1', '@array2' );

    but using a comma within a qw() list includes the comma in whatever word(s) it touches.

    Other than that, ++!


    If you GIVE a man a fish you feed him for a day
    TEACH him to fish and you feed him for a lifetime

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2015-11-29 07:17 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (748 votes), past polls