[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

Understanding of single ref constructor

I am trying to understand and fix the warning that I'm getting from my Perl Script MakePhase1a. The warning message is below:

Useless use of single ref constructor in void context at MakePhase1a line 134.

Part of the code from MakePhase1a which contains LINE 134 is below:

until ($answer eq 'y')
{
print "\n\nEnter name of Tube file to process (e.g. TUBE505.BIN): ";
$tubefl = <STDIN>;
chomp($tubefl);
print "\n\nTube file is $tubefl.";
print "\nIs $tubefl correct? (y or n):";
$answer=<STDIN>;
chomp($answer);
}
  open(PHASE, ">$phasefile");
  print PHASE "$site\n";                    \# Site Location\n";
  print PHASE "$pmnum\n";  <====== LINE 134 ==============================

#### Split $pmnum to get pm and number separated:
      while ($pmnum =~ m/(\d+)/g)
           {$buoy = $1;
         };
#      print "buoy = $buoy";

Any help on this would be greatly appreciated.
jakeyo
0
jakeyo
Asked:
jakeyo
  • 5
  • 4
1 Solution
 
wilcoxonCommented:
At a guess, you are not defining $pmnum anywhere prior to this (I can't say for sure not seeing the previous 100 lines).  Are you using strict and warnings in your code?  If not, you should.
0
 
jakeyoAuthor Commented:
I've cut out the 1st 150 or so lines of my program. I don't mean to bother you with all of the lines, but I wanted to show you where and how $pmnum is defined in the code. I've used the <====== symbol to highlight the lines using $pmnum. Thanks.
jakeyo

#!/usr/bin/perl   -w
#-w
use vars qw/ $BUOY_ID $buoy_number $caldir $log_fh
             $deployment_letter $VERSION
           /;

use strict;
use File::Basename;
use Cwd;
use Carp;
use FileHandle;
require VMS::Filespec if $^O eq 'VMS';
#"use" fails in compilation if not on VMS!
use RamData::Flags qw/%FLAG/;     #load flag values and threshold
use RamData::A2Module;
use AtlasData::Buoy;
use TAOPerl::JulianTime;
#use IPC::RUN;
# if working in windows comment the next line
eval("use RamData::DBInfo") unless ($^O =~ /win/i);

$VERSION = '1.291';

# Request Command file to process
my $phasefile;
my $answer = 'n';
my $site;
my $pmnum;                           <======================== $pmnum
my $deploy_letter;
my $tubefile;
my $tubefl;
my $sitepm;
my $pmdeploy;
my $workdir;
my $buoy;
my $buoydeploy;
my $extn;
my $extn1;

# Loop until command file name is correct
until ($answer eq 'y')
{
print "\n\nEnter name of Site file to make (e.g. NewSite1.cmd): ";
$phasefile = <STDIN>;
chomp($phasefile);
print "\n\nSite file is $phasefile\n\n";

print "Is $phasefile file the correct name? (y or n): ";
$answer=<STDIN>;
chomp($answer);
}

# Loop until correct Site is entered.
$answer = 'n';
until ($answer eq 'y')
{
print "\n\nEnter the Site Location (e.g. 2s125w): ";
$site = <STDIN>;
chomp($site);
print "\n\nSite file is $site\n\n";

print "Is $site file the correct name? (y or n): ";
$answer=<STDIN>;
chomp($answer);
}

#Loop untile correct PM number is given.
$answer = 'n';
until ($answer eq 'y')
{
print "\n\nEnter the PM number (e.g. pm946): ";
$pmnum = <STDIN>;                                       <================ $pmnum
chomp($pmnum);                                             <================ $pmnum
print "\n\nPM number is $pmnum";                  <================ $pmnum

print "\n\nIs PM number $pmnum correct? (y or n): "; <================ $pmnum
$answer=<STDIN>;
chomp($answer);
}

# Loop until correct deployment letter is given.
$answer = 'n';
until ($answer eq 'y')
{
print "\n\nEnter the deployment letter (e.g. a): ";
$deploy_letter       = <STDIN>;
chomp($deploy_letter);

print "\n\nIs deployment letter $deploy_letter correct? (y or n): ";
$answer=<STDIN>;
chomp($answer);
}


# Loop until correct extension is given.
$answer = 'n';
until ($answer eq 'y')
{
print "\n\nEnter file extension for printing (e.g. .ram (period needed) : ";
$extn       = <STDIN>;
chomp($extn);

print "\n\nIs extension $extn correct? (y or n): ";
$answer=<STDIN>;
chomp($answer);
}

$answer = 'n';
until ($answer eq 'y')
{
print "\n\nEnter Tube file name (e.g. Tube.ans): ";
$tubefile = <STDIN>;
chomp($tubefile);
print "\n\nTube file is $tubefile.";

print "\nIs $tubefile correct? (y or n):";
$answer=<STDIN>;
chomp($answer);
}

$answer = 'n';
until ($answer eq 'y')
{
print "\n\nEnter name of Tube file to process (e.g. TUBE505.BIN): ";
$tubefl = <STDIN>;
chomp($tubefl);
print "\n\nTube file is $tubefl.";
print "\nIs $tubefl correct? (y or n):";
$answer=<STDIN>;
chomp($answer);
}
  open(PHASE, ">$phasefile");
  print PHASE "$site\n";                    \# Site Location\n";
  print PHASE "$pmnum\n";             <================ $pmnum Line 134

#### Split $pmnum to get pm and number separated:
      while ($pmnum =~ m/(\d+)/g)       <================ $pmnum          
           {$buoy = $1;
         };
#      print "buoy = $buoy";

  print PHASE "$deploy_letter\n";
  print PHASE "$tubefile                \# Tube Processing File Name\n";
  print PHASE "1                        \# Batch flag: 1=yes, 2=no.\n";
  $sitepm = '/'.$site.'/'.$pmnum;      <================ $pmnum
  print PHASE "$sitepm                  \# dirs flag directory location.\n";
  $buoydeploy = $buoy.$deploy_letter;
  print PHASE "$buoydeploy              \# buoy flag, buoy number\n";
  print PHASE "y                       \# plots flag: y=all plots, n=specify\n";
  print PHASE "y                        \# temp flag.\n";
  print PHASE "y                        \# pres flag.\n";
  print PHASE "y                        \# sal flag.\n";
  print PHASE "y                        \# dens flag.\n";
  print PHASE "$extn                     \# extn flag-Extension of file to use\n";
  print PHASE "6                        \# sfreq flag - no. of samp/hr.\n";
  print PHASE "1                        \# Batch flag: 1=yes; 2=no plottube.\n";
  $workdir = $site.'/'.$pmnum.'/worked';             <================ $pmnum
  print PHASE "$workdir                 \# Working dir.\n";
0
 
wilcoxonCommented:
Very strange.  I don't see any cases where $pmnum would not be defined (unless STDIN gives EOF which is unlikely).  I also haven't seen that specific warning before (I'd expect something like "undefined").  I'm thinking it doesn't like PHASE on that line but it seemed to like it fine on the previous line and the open presumably succeeded.

Do you get the same warning if you do "perl -cw script.pl"?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jakeyoAuthor Commented:
Yes, I get the same warning. But I also get another line which says "MakePhase1a syntax OK."

The MakePhase1a script does not have the .pl extension. So I copied it and added the .pl extension. However, I got the same result as stated above.
jakeyo
0
 
wilcoxonCommented:
You could do "perl -cw MakePhase1a" - it doesn't matter if the script has the .pl extension or not.

I suspect it's a misplaced warning.  If you comment out line 134 and run perl -cw again, does the warning go away?  If not, keep trying commenting and uncommenting lines to try finding out exactly which line it is really complaining about.
0
 
jakeyoAuthor Commented:
Ok, I'll give it a try.
0
 
jakeyoAuthor Commented:
Found it.
Look at Line 134 carefully. You'll see the "print ....;" statement followed by
\#.....
The backslash is still part of the code and not part of the comment. Hence, the warning.
jakeyo
0
 
jakeyoAuthor Commented:
I'm sorry, it's line 133.
jakeyo
0
 
wilcoxonCommented:
Good catch.  I missed that when looking at line 133.
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.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now