Dan Muey wrote: > Howdy list! > > I was wondering if it's possible to run a funtion and have it set a > bunch of variables. > > As in variables I didn't declare before.
Yes, but don't do it. > > #/usr/bin/perl -w > > use strict; > > makevars(); # declares, and gives a value to $one $two $three > > print "$one $two $three"; Just return a list and assign to variables if you need to have separate variables: ($one, $two, $three) = myfunction(); > > I could have it return a refrence to a hash and just use > > $v->{'one'} $v->{'two'} etc but It'd be nice to just have the > vars ready to go after running makevars(); > > Is this possible? Something like: > > sub makevars { > my $c; > @vars = qw(one two three); > for(@vars) { ${$_} = $c++; } > return ???; > } > > makevars() > > print "$one $two $three"; You have to use "no strict" since you're using soft references. You can also use caller() to get get calling package name. But again, don't do this. There is rarely any good reason to create distinct symbol table variables in this manner, and many risks/pitfalls in doing so. Either assign a returned list like I showed above, or store the data in a hash. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]