On Jul 22, jdavis said: > I would like to pass subs vars to work on. right now I,m >using globals to pass messages to the subs.Is this the right >way to do this?
Globals are bad. The main mechanism is: sub plus_minus { my ($this, $that) = @_; # arguments arrive in the @_ array return ($this + $that, $this - $that); } my $x = 10; # my() variables are NOT globals my $y = 14; # globals are bad, these are lexicals my ($plus, $minus) = plus_minus($x, $y); Notice that by passing values to a function, the FUNCTION can have its own names for the things to work on? So you don't need to worry about what name the function's using, since they're my()d (so they're lexically scoped), and you can name your variables whatever you want. Contrast that to: sub ugly { return ($x + $y, $x - $y); } which requires you to call your variables $x and $y on the outside. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]