Solved

Useless use of reference constructor in void context

Posted on 2004-09-06
6
1,779 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

738 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