in reply to An error message to understand

Does it mean that one of the @CHOICE array contents are empty?

Yes. You can avoid that warning by checking for definedness:

foreach (@CHOICE) { if (defined && m/2001\sCensus\sOutput\sArea/){
or
foreach (@CHOICE) { next if (!defined); if (m/2001\sCensus\sOutput\sArea/){

This uses $_ implicitly in both the definedness test and the pattern match. Often it's clearer to assign the value to a lexical variable:

for my $chosen (@CHOICE) { if (defined $chosen && $chosen =~ m/2001\sCensus\sOutput\sArea/){

As a further comment, usage of upper-case variable names is generally reserved for constants or perl private variables.


There are ten types of people: those that understand binary and those that don't.

Replies are listed 'Best First'.
Re^2: An error message to understand
by Perl Mouse (Chaplain) on Jan 06, 2006 at 12:14 UTC
    And since the pattern can never match the empty string, or 0, you could skip the define and write:
    foreach (@CHOICE) { if ($_ && /.../) { ... } }
    Or:
    foreach (@CHOICE) { $_ or next; if (/.../) { ... } }
    if all you have inside the foreach is the if statement.
    Perl --((8:>*

      I don't particularly want to argue about it but I would not approve of such a change. True, as the pattern match is now it does not make a difference, but if the pattern is ever changed it's easy to miss changing the test as well, which can introduce a subtle bug. Just checking for truth makes the code more brittle. IMO, YMMV, etc.


      There are ten types of people: those that understand binary and those that don't.