Solved

Useless use of reference constructor in void context

Posted on 2004-09-06
6
1,768 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

740 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