Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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
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, ++!

    dmm

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-09-19 02:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (129 votes), past polls