Hi Parag, first of all, a few comments on your code.
On Sat, 5 Nov 2011 00:16:29 -0700 Parag Kalra <paragka...@gmail.com> wrote: > Hi, > > I have a function which looks something like: > > sub foo_bar { > ${$_[0]} = new foo_bar ( > address => $_[1], > sudo => $_[3]', > id => $_[0] . '_' . $_[2], > ); > sleep 8; > > } 1. Don't do $_[0], $_[1], etc. See: http://perl-begin.org/tutorials/bad-elements/#subroutine-arguments 2. Don't call your classes with names starting in lowercase: http://perl-begin.org/tutorials/bad-elements/#lowercase_modules_and_pkgs 3. Don't use indirect-object notation: http://www.modernperlbooks.com/mt/2009/08/the-problems-with-indirect-object-notation.html 4. You're using $_[0] both as a string and as a reference. What are you trying to do? > > When the code is executed, I get an error > > *Can't use string ("some") as a SCALAR ref while "strict refs" * > > This is resolved using - *no strict 'refs*'; > > Do we need to always use the above while using Perl variable indirection > - ${$_[0]} No you don't. If $_[0] is a hard reference to a scalar, then it will work fine: my $scalar_var; function_call(\$scalar, @other_args); See: http://perl-begin.org/topics/references/ strict refs warns (and rightfully so) when you try to use a string as a reference because this is: 1. A symbolic reference. 2. Will always be for a package-scope variable - not for a lexical variable. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/ Larry Wall dreams in Perl. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/