- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Use of uninitialized value $_ in split
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
Forums
Discussions
Discussions
Discussions
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
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
07-26-2010 03:20 PM
07-26-2010 03:20 PM
I have created the attached script to check to see if a connection to a port can be made.
Basically the script runs like this -
script1.pl -f filename.conf
where filename.conf has the following content -
host:port
but when I am running the script I am getting "Use of uninitialized value $_ in split".
Can you help here?
Thanks,
Allan
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2010 03:49 PM
07-26-2010 03:49 PM
Solution----------------------
Yours:
open (FILE, $filename) or die "Unable to open $filename";
until (eof FILE){
$FS = ':';
($Fld1,$Fld2) = split($FS, $_);
my $hostname = $Fld1;
my $portnumber = $Fld2;
}
close (FILE);
-----------------
Untested, but I suggest something like the following, which always seems to get $_ working with a foreach loop.
open (FILE, $filename) or die "Unable to open $filename";
@array=
close (FILE);
$FS = ':';
foreach (@array) {
($hostname,$portnumber) = split($FS, $_);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2010 04:09 PM
07-26-2010 04:09 PM
Re: Use of uninitialized value $_ in split
Allan :
You never read the configuration file, and hence '$_' is undefined. Try:
#!/usr/bin/perl
use strict;
use warnings;
use Socket;
use Getopt::Std;
# set time until connection attempt times out
my $timeout = 3;
if ($#ARGV != 1) {
print "usage: script.pl -f filename.conf \n";
exit 2;
}
our $opt_f;
getopts("f:");
my $filename = $opt_f;
open (FILE, $filename) or die "Unable to open $filename";
my ($hostname, $portnumber) = split(/:/,
close (FILE);
my $host = shift || $hostname;
my $port = shift || $portnumber;
my $proto = getprotobyname('tcp');
my $iaddr = inet_aton($host);
my $paddr = sockaddr_in($port, $iaddr);
socket(SOCKET, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
# socket opened
eval {
local $SIG{ALRM} = sub { die "timeout" };
alarm($timeout);
connect(SOCKET, $paddr) || error();
alarm(0);
};
if ($@) {
close SOCKET || die "close: $!";
print "$hostname is NOT listening on tcp port $portnumber.\n";
exit 1;
}
else {
close SOCKET || die "close: $!";
print "$hostname is listening on tcp port $portnumber.\n";
exit 0;
}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2010 03:48 AM
07-27-2010 03:48 AM
Re: Use of uninitialized value $_ in split
You have a large number of questions with unassigned points (159 of 278 responses). It would be appreciated if you could evaluate the help you received.
http://forums.itrc.hp.com/service/forums/pageList.do?userId=CA1505975&listType=unassigned&forumId=1
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2010 07:56 PM
08-12-2010 07:56 PM
Re: Use of uninitialized value $_ in split
Thanks,
Allan