Solved

Useless use of reference constructor in void context

Posted on 2004-09-06
6
1,806 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 250 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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

624 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