- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: perl query
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
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
тАО09-05-2006 08:00 AM
тАО09-05-2006 08:00 AM
I am trying to pass the the following into a sub routine
&insert_audit("$hostid successfully $hostname");
the subroutine is used to pass the data into a MySQL database via perl::DBD module. I appear to have a problem though when trying to create an array from the pass to the sub routine
sub insert_audit ()
{
my (@record)=shift (@_);
print "@record\n";
}
The above is ok, ie (1 line of output below)
48 successfully rs-demo8
If I try to print an element of the array. The statement is as follows
sub insert_audit ()
{
my (@record)=(@_);
print "@record\n";
print "$record[1]";
}
Use of uninitialized value in join or string at configUpload.pl line 49
Which suggests the attempt to create the array from the parameters passed to the sub routine fails ?
Am I doing something wrong ?
TIA
Steve
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2006 08:15 AM
тАО09-05-2006 08:15 AM
SolutionYes, one or more of the elements is the array passed is undefined. Consider:
#!/usr/bin/perl
use strict;
use warnings;
sub insert_audit
{
my (@record)=(@_);
print "@record\n";
print "$record[1]\n";
}
insert_audit ("a", "b" , "c");
print "------\n";
insert_audit ("a", undef, "c");
1;
If you run that you will see:
a b c
b
------
Use of uninitialized value in join or string at /tmp/subs line 8.
a c
Use of uninitialized value in concatenation (.) or string at /tmp/subs line 9.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2006 08:33 AM
тАО09-05-2006 08:33 AM
Re: perl query
I understand your description and why I would see this error. I can't however see why in this example I get the error. When I print the array as a whole
print "@record\n";
I get each element that I have passed, ie
&insert_audit("$hostid successfully $hostname");
gives
49 successfully rs-dev
Am I being a little thick here ?
TIA
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2006 08:39 AM
тАО09-05-2006 08:39 AM
Re: perl query
my $sum=@record;
print "$sum\n";
1
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2006 08:46 AM
тАО09-05-2006 08:46 AM
Re: perl query
OK, you passed a scalar, not an array or list when you said:
# insert_audit("$hostid successfully $hostname");
You should do:
# insert_audit (($hostid, "successfully",$hostname));
Thus:
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
sub insert_audit
{
my (@record)=(@_);
print "@record\n";
print "$record[1]\n";
}
my $hostid = 48;
my $hostname = "myhost";
insert_audit ( ($hostid, "successfully", $hostname) );
1;
...yields:
48 successfully myhost
successfully
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2006 08:53 AM
тАО09-05-2006 08:53 AM
Re: perl query
I get it,
Thanks James
In the meantime I came to this
my ($hostid, $exit, $hostname);
my ($record)=(@_);
($hostid, $exit, $hostname)=split(/ /, $record);
Will do it your way as that is correct
Thanks again
Steve