Solved

Useless use of reference constructor in void context

Posted on 2004-09-06
6
1,706 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
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This video discusses moving either the default database or any database to a new volume.

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now