lingoes has asked for the wisdom of the Perl Monks concerning the following question:

Hi,all. I'm new to perl ...

I copid a example from <Advanced perl programming>, and made some change.
How to make it work when "use strict" is on ?
Thanks a lot!
#!/usr/bin/perl #use warnings; use strict; our $spud="Wow!"; our @spud=qw(idaho russet); *potato=*spud; print $potato; print "@potato"

Replies are listed 'Best First'.
Re: How to make it work when "use strict;" is on?
by Corion (Patriarch) on Nov 19, 2014 at 12:56 UTC

    It helps us help you better if you show the error message you get.

    In your case, you want to make it known to Perl that you want to be using the variable names @potato and $potato as well as @spud and $spud.

    This can be done by using:

    use vars qw($spud @spud);

    ... or, as you're using our already by declaring:

    our $spud; our @spud;
      Thanks for your REP
      I got these error message:
      Variable "$potato" is not imported at E:\perl_script\chp3\typeglob.pl +line 8. Possible unintended interpolation of @potato in string at E:\perl_scri +pt\chp3\typeglob.pl line 9. Variable "@potato" is not imported at E:\perl_script\chp3\typeglob.pl +line 9. Global symbol "$potato" requires explicit package name at E:\perl_scri +pt\chp3\typeglob.pl line 8. Global symbol "@potato" requires explicit package name at E:\perl_scri +pt\chp3\typeglob.pl line 9. Execution of E:\perl_script\chp3\typeglob.pl aborted due to compilatio +n errors.
      when I turned off the "use strict;", it worked well...

        Whoops - in my reply, I gave you the wrong variable names to declare to Perl. You already declare $spud and @spud, but if you want to also use $potato and @potato, you need to also declare theses as global variables. You're using our, so you should declare:

        our $potato; our @potato;

        This will allow the two names to be used.