in reply to Unintialised value?

If you use strict; use warnings; whenever you try to compare an undefined value it will yelp. This is great to do, but if you want to fix that warning you should let perl know you expect the possibility of an undef value by testing for an undef value (and only performing concatanation, regular expressions, or anything else with it) if it's defined, i.e.:

# note that we have to check if its defined # because it's possible it could be 0, and false #62 exit 0 unless ((defined ($page)) and (defined($pages{$page})) and ($pages{$page} == '1'));

You should note that you are shifting from @_ to set $page == undef; especially on this little bit of test code. So if @_ is undefined then you'll get those warnings. You can turn off warnings for uninitialized values by using:

NOWHINING: { no warnings qw (uninitialized); my %pages = ("index" => '1', "me" => '1', "stuff" => '1', "links" => '1'); my $page = shift; exit 0 unless $pages{$page} == '1'; }

Just be careful with the above code because:

  1. The no warnings qw(uninitialized); is declared within the NOWHINING: block so as to keep its scope only for the offending code. You could extend this to your entire program by using no warnings qw(uninitialized); at the top of your script, but this becomes dangerous because you want to know when uninitialized values are being used.
  2. The %pages and the $page variables are only valid within the {}s. This may or may not be an issue. Adjust your scope accordingly.
  3. Is @_ supposed to contain undef values? If it isn't you've got bigger problems.
  4. because @_ is "magical" as soon as you use any function that modifies @_ it can on change you. I recommend you never use it unless where the @_ comes from is clear from the code.
  5. Use something like my @arguments = @_; at the beginning of wherever you get the @_ from so that any sub that is called doesn't modify @_ on you.
  6. perl -e 'use strict; use warnings; my $foo; print $foo;' and perl -e 'use strict; use warnings; undef =~ m/foo/;' will show you some ways you can get and reproduce that error.

Good luck!

Vautrin