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

Hi, I've created a CGI script, that produces output that looks fine, but creates tons of error messages like these in the Apache error log:

Fri Dec 16 17:23:46 2011 -e: Use of uninitialized value $ModPerl::ROOT::ModPerl::Registry::home_rianne_Documents_workspace_Wordclouds_perl_wordclouds_2ecgi::word in pattern match (m//) at /home/rianne/Documents/workspace/Wordclouds/perl/wordclouds.cgi line 2139, <GEN1> line 4463. Fri Dec 16 17:23:46 2011 -e: Use of uninitialized value $ModPerl::ROOT::ModPerl::Registry::home_rianne_Documents_workspace_Wordclouds_perl_wordclouds_2ecgi::word in pattern match (m//) at /home/rianne/Documents/workspace/Wordclouds/perl/wordclouds.cgi line 2141, <GEN1> line 4463. Fri Dec 16 17:23:46 2011 -e: Use of uninitialized value $ModPerl::ROOT::ModPerl::Registry::home_rianne_Documents_workspace_Wordclouds_perl_wordclouds_2ecgi::word in concatenation (.) or string at /home/rianne/Documents/workspace/Wordclouds/perl/wordclouds.cgi line 1627, <GEN1> line 4463.

Anyone has an idea how to fix this ?

This is my code: (partly)
#!/usr/bin/perl -w # #wordclouds.cgi #create wordclouds for different categories from an ultimate data set use strict; use bytes; use warnings qw(redefine); require Encode; use Unicode::Normalize; use CGI qw/:standard -private_tempfiles/; use CGI::Carp qw/fatalsToBrowser/; use Text::Unaccent; use Text::CSV_XS; use Fcntl qw( :DEFAULT :flock ); use constant UPLOAD_DIR => "/tmp"; use constant BUFFER_SIZE => 16_384; use constant MAX_FILE_SIZE => 250*1_048_576; # Limit each uploa +d to 50 MB use constant MAX_DIR_SIZE => 300 * 1_048_576; # Limit total uploads +to 100 MB use constant MAX_OPEN_TRIES => 100; $CGI::DISABLE_UPLOADS = 0; $CGI::POST_MAX = MAX_FILE_SIZE; local our $q = new CGI; $q->cgi_error and error( $q, "Error transferring file: " . $q->cgi_err +or ); local our $filename = $q->param( "file" ) || error( $q, "No f +ile received." ); local our $infile = $q->upload( "file") || error( $q, "No file + uploaded."); local our $textcolumn = $q->param( "textcolumn" ) || error( $q, "No t +extcolumn entered." ); local our $catcolumn = $q->param( "categorycolumn" ) || error( $q, "N +o categorycolumn entered." ); local our $size = $q->param( "size" ) || error( $q, "No size entered." + ); local our $brands = $q->param( "brands" ) ; local our $stop = $q->param( "stop" ) ; local our $language = $q->param( "lang" ) || error( $q, "No language +entered." ); local our $colour = $q->param( "colour" ) || error( $q, "No colour en +tered." ); local our $twitterselect = $q->param( "twitterselect" ) || error( $q, +"No Twitter selection entered." ) ; local our $stem = $q->param( "stem" ) || error( $q, "No stemming prefe +rence entered." ); local our $bigrams = $q->param( "bigrams" ) || error( $q, "No preferen +ce for bigrams entered." ); $textcolumn--; $catcolumn--; local our $onlyhashtags = 0; local our $onlyusernames = 0; if($twitterselect eq "hashtags"){ $onlyhashtags =1 ; } elsif($twitterselect eq "usernames"){ $onlyusernames = 1; } local our @fontsizes =("xx-small", "x-small", "small", "normal", "larg +e", "x-large", "xx-large"); local our %stat_tf; local our %stat_df; local our $max_tf; local our %prob; local our %stat_2tf; local our %count_2tf; local our %prob2; local our %p; local our %count_tf; local our %count_df; local our $term_count; local our $doc_count; local our $lambdap = 0.1; local our $mu = 0.4; local our $prune = 0.001; local our $minnrquotes = 10; local our $minbigrams = 5; local our $cloudsize = $size; local our %length; local our $total_length; local our %cloud; local our @brandsarray; local our %tablestring; local our %languages = ( "en" => 'English', "de" => 'German', "nl" => 'Dutch', "fr" => 'French', ); local our %colours = ( "black" => ':000000', "none" => '', "red" => ':FF0000', "green" => ':006600' ); $stop =~ s/ //g; my @addstop = split(/\,/, $stop); for(@addstop){ $stophash{"all"}{$_} = 1; } print $q->header( "text/html", -expires => "-1s" ), + $q->start_html( -title => "Wordcloud Generator Version 0.02", -b +gcolor => "#ffffff", -head=>$q->meta({-http_equiv => 'Pragma', -content => 'no-cache'}) +), $q->h2( "Wordcloud Generator" ), $q->hr, $q->p("Processed file:", $filename), #$q->p("Removing ", $languages{$language}, " stopwords"); #$q->p("Text column:", $textcolumn+1), #$q->p("Category column:", $catcolumn+1); process_file($infile); show_word_stat(); print $q->end_html; exit;

Replies are listed 'Best First'.
Re: ModPerl::Registry error
by zwon (Abbot) on Dec 17, 2011 at 06:41 UTC

    mod_perl analyses shebang line and adds use warnings if it contains -w switch, so yours

    use warnings qw(redefine);
    doesn't really make much sense, all warnings are enabled.

    As a side note, passing arguments to the functions via global variables is not a good idea. All these local our ... look terrible and just asking for trouble. Even if they were not global, it's just to many of them, I'd recommend you to group some of them together into nice data structures.

      Hi, I posted the wrong code accidentally, I just wanted to turn on the warnings, to see if I could get some clue about the error message. I put back no warnings qw(redefine); but it still gives me the same errors. Any other ideas ?

      Apart from looking terrible, what is wrong with using local our variables?

Re: ModPerl::Registry error
by Anonymous Monk on Dec 16, 2011 at 17:06 UTC

    Anyone has an idea how to fix this ?

    Sure, as documented :)

    $ perl -we " m// " Use of uninitialized value $_ in pattern match (m//) at -e line 1. $ perl -Mdiagnostics -we " m// " Use of uninitialized value $_ in pattern match (m//) at -e line 1 (#1) (W uninitialized) An undefined value was used as if it were alread +y defined. It was interpreted as a "" or a 0, but maybe it was a mi +stake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl will try to tell y +ou the name of the variable (if any) that was undefined. In some cases it + cannot do this, so it also tells you what operation you used the undefine +d value in. Note, however, that perl optimizes your program and the opera +tion displayed in the warning may not necessarily appear literally in y +our program. For example, "that $foo" is usually optimized into "that + " . $foo, and the warning will refer to the concatenation (.) operat +or, even though there is no . in your program.

    you can either make sure whatever variable you're matching against is defined, or silence those warnings, your choice

    See also

    http://perl.apache.org/docs/1.0/guide/porting.html

    CGI::Application/ http://cgi-app.org/ can help you organize your program , as could mojo / dancer / catalyst