Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Useless use of reference constructor in void context

Posted on 2004-09-06
6
Medium Priority
?
1,863 Views
Last Modified: 2010-07-27
I am getting the following error messages or warnings when trying to run my program:

Any clues?


Useless use of reference constructor in void context at /usr/local/sbin/Alert line 238.
Useless use of reference constructor in void context at /usr/local/sbin/Alert line 48.
 
# Try to find a configuration file, complain and die on fail.
if ( -e "./$me.conf" ) { $config_file = "./$me.conf"; }
elsif ( -e "/usr/local/etc/$me.conf" ) { $config_file = "/usr/local/etc/$me.conf"; }
elsif ( -e "/etc/$me.conf" ) { $config_file = "/etc/$me.conf"; }
else {
    sub
    {
        openlog( "$me", "pid,nowait", "$me" );
        syslog( "info", "Could not find a configuration file!" );
        closelog();
       die( "Could not find a configuration file!: /usr/local/etc/$me.conf, /etc/$me.conf, or ./$me.conf" );
    }  #Line 48
}


sub openDB
{
    my $dbh = DBI->connect( "DBI:mysql:$config{'dbname'}", $config{'dbuser'}, $config{'dbpass'},
        { RaiseError => 1, AutoCommit => 1 } );
    return $dbh;
} #line 248
0
Comment
Question by:bat_mop
  • 3
6 Comments
 
LVL 1

Expert Comment

by:JustinPincar
ID: 11993003
the sub { blah } bit would return a reference to a subroutine. You aren't actually doing the stuff inside there. You're just making a closure that contains it. If this is what you wanted, you should do $rs = sub {blah}; (with the seimcolon) and call it later with &$rs();  If its not, and you just wanted to execute that code right then, just leave out the sub and the {}'s.
~Justin
0
 
LVL 1

Accepted Solution

by:
JustinPincar earned 1000 total points
ID: 11993015
i forgot to do the second one...
That looks right to me. I would suggest that:
1) The sub is in the wrong context, or
2) Its just a warning that strict refs gives you, and is nothing to worry about.
~Justin.
0
 

Author Comment

by:bat_mop
ID: 11993018
so the program will run just fine even though i got the 2 warnings?

if possible I would like to send you an email with the code to see if you can clear those 2 erros and I can give you the  points :)) my email is {{email addr removed by jmcg -- EE Page Editor for Perl}}.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11993029
Justin has explained about the void sub, so I'll offer another way of writing that block that's a bit easier to read

foreach my $dir qw(. /usr/local/etc /etc) {
  $config_file = "$dir/$me.conf" if -e "$dir/$me.conf";
}

unless ($config_file) {
  openlog( "$me", "pid,nowait", "$me" );
  syslog( "info", "Could not find a configuration file!" );
  closelog();

  die "Could not find a configuration file: /usr/local/etc/$me.conf, /etc/$me.conf or ./$me.conf\n";
}
0
 
LVL 1

Expert Comment

by:JustinPincar
ID: 11993033
I think that it will run fine if you take out the sub and the {} surrounding your code in the first one.
My email is {{email addr removed by jmcg -- EE Page Editor for Perl}}, not sure if you're allowed to help fix stuff via email here though...
`justin
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question