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

Re: using strict and functions

by Desdinova (Friar)
on Jan 17, 2002 at 22:04 UTC ( [id://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>

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

    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://139569]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-25 23:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found