- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Problem in running perl script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2008 11:33 PM
тАО03-11-2008 11:33 PM
I have a problem in running the perl script. Its throwing these error.
"Use of uninitialized value in scalar chomp at"
and
Name "main::OUT" used only once: possible typo
can u pls help me resolve these errors.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2008 11:59 PM
тАО03-11-2008 11:59 PM
Solutionprobably you meant STDOUT where you have something like
print OUT "Warning\n";
> "Use of uninitialized value in scalar chomp at"
in your code you have either
chomp;
or
chomp $foo;
the default arg to chomp is $_. The variable that chomp is seeing has no value, or is undef, which causes the warning.
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 12:47 AM
тАО03-12-2008 12:47 AM
Re: Problem in running perl script
This is the part of the script. I have assigned the $value to chomp, and I am printing the value also , can u please tell me wht is wrong in this .
open(F,"$currentenvroot/load.config") or die "cannot open
$currentenvroot/load.config config file";
while($line =
($name,$value) = split("=",$line);
chomp ($value);
print "NAME $name VAL $value \n" ;
$nv{$name} = $value;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 12:58 AM
тАО03-12-2008 12:58 AM
Re: Problem in running perl script
Only if you go through the while loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 01:02 AM
тАО03-12-2008 01:02 AM
Re: Problem in running perl script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 01:28 AM
тАО03-12-2008 01:28 AM
Re: Problem in running perl script
my %nv;
my $fn = "$currentenvroot/load.config";
open my $fh, "<", $fn or die "cannot open config file '$fn': $!";
while (<$fh>) {
chomp;
my ($name, $value) = split m/=/;
print "NAME $name VAL $value \n" ;
$nv{$name} = $value;
}
Several issues addressed.
1. while ($line =
this will stop is the line consists of a single 0. If you want to assign to a variable, use something like
while (defined (my $line =
2. On modern perls, it is better to use lexical file handles. They have a better (more restricted) scope, and are way more easy to pass to functions and methods that take handles. Compare
$csv->getline ($fh);
to
$csv->getline (*FH);
3. split ("=", $line)
Does NOT do what you expect. Besides some exceptions, the first argument to split is a regex, not a string.
4. chomp on a variable
When needing to chomp lines, do that as soon as possible for readability. First reject the lines you don't want, then chomp, then parse.
5. use strict;
Use strict; Always. And thus also use lexical variables. When you now make a typo or use a variable out of it' scope, it'll warn.
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 01:50 AM
тАО03-12-2008 01:50 AM
Re: Problem in running perl script
I have modified the changes u have told me ...but still I am getting error. I have declared my %nv;
Global symbol "$nv" requires explicit package name at /opt_apps/comcat_itg/r_curr/be/loads/patsy_discount/driver/ftp_patsy.pl.
I am sending u the script.
#!usr/bin/perl
use warnings;
use strict;
my $var;
my $inpath;
my $value;
my $line;
my @line;
my $name;
#############################################################
# FTP Script to transfer data files from 649 to hpcc547
#Ramkumar Balasubramanian
#############################################################
my $currentenvroot=`/opt_apps/comcat_root/bin/getEnvRootPath.sh SH`;
$currentenvroot =~ s/[\n\r]//g;
my $currentftpenvroot=`/opt_apps/comcat_root/bin/getEnvRootPath.sh FTP`;
$currentftpenvroot =~ s/[\n\r]//g;
my $cmd;
my $cmdprd;
my $lcddir;
my $cdir;
my %nv;
my $fn = "$currentenvroot/r_curr/be/loads/load.config";
#Now Start FTP to Send the PATSY Data to htx6048 #
$lcddir="lcd $currentftpenvroot/data/output/patsy_discount\n";
open my $fh, "<", $fn or die "cannot open config file '$fn': $!";
while (<$fh>) {
chomp;
my ($name, $value) = split m/=/;
print "NAME $name VAL $value \n" ;
$nv{$name} = $value;
}
ANd this is the error I am getting
Global symbol "$nv" requires explicit package name at /opt_apps/comcat_itg/r_curr/be/loads/patsy_discount/driver/ftp_patsy.pl line 57.
Execution of /opt_apps/comcat_itg/r_curr/be/loads/patsy_discount/driver/ftp_patsy.pl aborted due to compilation errors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 02:28 AM
тАО03-12-2008 02:28 AM
Re: Problem in running perl script
Maybe, you could change the split criteria to include possible whitespace around the equals sign, as to have stripped it off from you key value pairs?
e.g.
my ($key, $val) = split /\s*=\s*/, $line;
$nv{$key} = $val if defined $key;
As this looks like parsing one of those notorious Win ini files,
there plenty of modules on CPAN for those
(probably too bewildering not to have it parsed by ones own parsing)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 02:38 AM
тАО03-12-2008 02:38 AM
Re: Problem in running perl script
Looks these are fewer than 57 lines.
There must be another occurrence of $nv.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 03:23 AM
тАО03-12-2008 03:23 AM
Re: Problem in running perl script
$nv{$key}
Look for occurances of $nv that are not followed by an opening brace.
And I bet the warning/error comes with a line numer. Should be clear enough.
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 03:54 AM
тАО03-12-2008 03:54 AM
Re: Problem in running perl script
Clearly that means that the 'split' line did not produce a $values, which probably means there was no '=' on the line.
>> my ($name, $value) = split m/=/;
A simply debugging for that suspected problem would be a print line like
print STDERR "Bad input line # $. : $_\n" unless defined($value);
And, as indicated the split uses a regular expression which you may want to exploit, for example to suck up whitespace around the '='
my ($name, $value) = split m/\s*=\s*/;
Depending on the exact parsing requirements You may also want to consider NOT to use a split but a match. For example, you may want to skip lines which start with a # or find new sections in the input, or skip leading whitespace
while (<$fh>) {
if (/\s*(\S+)\s*=\s*(.*)$/) {
$name = $l;
$values = $2;
:
} else {
if (other acceptable input) {
...
} else {
print STDERR "Bad input line # $. : $_\n";
}
}
}
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 04:32 AM
тАО03-12-2008 04:32 AM
Re: Problem in running perl script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2008 06:36 AM
тАО03-12-2008 06:36 AM
Re: Problem in running perl script
An anser the "solved" your problem is usually rated 9..10, and answer that helped greatle 5..8, an informative answer that didn't bring you closer but helped you understand things better 2..4 and all else 0..1
http://forums11.itrc.hp.com/service/forums/pageList.do?userId=CA1462614&listType=unassigned&forumId=1
Enjoy, Have FUN! H.Merijn