E
erik
I am ultimately trying to print out the @link array in the
db_print_report sub-routine. I can print out each scalar element of the
array in seperate sub-routines but I cannot print the entire array set.
I tried to initialize the array in the beginning of script with "my
@link;" and that did not help. I am sure this is a scope issue but why
can I print the scalar elements of the array but not the entire array?
Can someone help me out?
p.s. everything else is working as expected, except for the piece I
mentioned.
#!/usr/local/bin/perl
#########################################################
# Global Variables #
#########################################################
use DBI;
use CGI(":standard");
my $date=`date +%x_%r`;
my $device = param("device");
my $datetemp = `date +%x_%r`;
my @dateStamp = split('\n',$datetemp);
my $green = "#33CC33";
my $red = "#FF0000";
my $OK = " ............................. OK";
my $FAIL = " ............................. FAIL";
my @link;
#DNS check for host
my $temp = gethostbyname($device);
my $deviceip = join(".",unpack('C4',$temp));
#########################################################
# Connect to Database and run SQL query #
#########################################################
sub db_connect
{
$ENV{'ORACLE_SID'} = 'xxxxx';
$ENV{'ORACLE_HOME'} = '/oracle/';
# Connect to the Database
$dbh = DBI->connect("dbi:Oracle:host=xxxx;sid=xxxx", "xxxxx", "xxxxx",
{ AutoCommit => 0 } );
# check connect to DB
$dbh or (print <<EOD
Error: Can't connect to database
EOD
and die $DBI::errstr);
}
################################################################
# SERIAL and OE NUMBER QUERY #
################################################################
#I GRAB CUST_ID HERE FOR QUERIES LATER
sub db_serial_query{
my $serial_sql = qq( SELECT SERIAL_NO, ADDRESS_449,CUST_ID,OE_NUMBER
from DEVICE where DEVICE_ID= '$device');
my $sth = $dbh->prepare($serial_sql);
#Execute SQL Statement
$sth->execute or die "DBI::execute : $!";
while (@serial = $sth->fetchrow_array) {
($SERIAL_NO,$ADDRESS_449,$CUST_ID,$OE_NUMBER) = @serial;
}
$sth->finish();
}
################################################################
# CONTACT NAME QUERY #
################################################################
sub db_contact_query{
my $contact_sql = qq( select PRIORITY,FIRSTNAME,LASTNAME from CONTACT
where CONTACT_ID='$device');
my $sth = $dbh->prepare($contact_sql);
#Execute SQL Statement
$sth->execute or die "DBI::execute : $!";
while (@contact = $sth->fetchrow_array) {
($PRIORITY,$FIRSTNAME,$LASTNAME) = @contact;
}
$sth->finish();
}
################################################################
# LINK QUERY #
################################################################
sub db_link_query{
my $link_sql = qq( select
STATUS,SERVICE_TYPE,FR_NET_TYPE,BANDWIDTH,CKT_ID,FMS_NO,LINK_DESC,LINK_TYPE,LINK_ENCAPS,FMS_CKT_STUS_CD,T1_FRAME_LINE_ENCODING
from link where router_id_a='$device');
my $sth = $dbh->prepare($link_sql);
#Execute SQL Statement
$sth->execute or die "DBI::execute : $!";
while (@link = $sth->fetchrow_array) {
($STATUS,$SERVICE_TYPE,$FR_NET_TYPE,$BANDWIDTH,$CKT_ID,$FMS_NO,$LINK_DESC,$LINK_TYPE,$LINK_ENCAPS,$FMS_CKT_STUS_CD,$T1_FRAME_LINE_ENCODING
)= @link; #<--THIS IS WHAT I WANT PRINT IN LAST SUB-ROUTINE!!
}
$sth->finish();
}
#################################################################
# Ensure Device is found in DNS #
#################################################################
sub check_dns
{
( $deviceip ? ( $DNS_RESULTS = "OK" ) : ( $DNS_RESULTS = "FAIL" ));
}#end sub
###############################################################
# PRINT ALL RESULTS #
###############################################################
sub db_print_report{
print "Content-type: text/html\n\n";
print "<html><head><title>ODIE QA REPORT</title></head>";
print "<body bgcolor=#343434 text=$green>";
print "<p align=center><b><font color=#FFFFFF size=6>ODIE QA
REPORT</font></b>";
print "<br>";
print "<p align=center><font color=#FFFFFF>Submitted on $dateStamp[0]
EST</font></p>";
print "<p align=center><font color=#0099FF>REMINDERS:</font>";
print "<br>";
print "<p align=center><b><font color=#FFFFFF size=3>ODIE NAME:
$device</font></p></b>";
print "<br>";
###PRINT SERIAL
if ($SERIAL_NO eq ""){
$SERIAL_NO = "NULL";
print "<body><font color=$red>YOUR SERIAL NUMBER IS <b> $SERIAL_NO
$FAIL</b></font></body>";
}
elsif ($SERIAL_NO =~ "111"){
print "<body><font color=$red>YOUR SERIAL NUMBER IS 11111111...<b>
$FAIL</b></font></body>";
}
else{
print "<body>YOUR SERIAL NUMBER IS: <b> $SERIAL_NO
$OK</b></font></body>";
}
print "<br>";
###PRINT 449
if ($ADDRESS_449 eq ""){
$ADDRESS_449 = "NULL";
print "<body><font color=$red>YOUR 449 ADDRESS IS <b>$ADDRESS_449
$FAIL</b></font></body>";
}
else{
print "<body>YOUR 449 ADDRESS IS <b>$ADDRESS_449
$OK</b></font></body>";
}
print "<br>";
###PRINT OE
if ($OE_NUMBER eq ""){
$OE_NUMBER = "NULL";
print "<body><font color=$red>YOUR MNS OE IS <b>$OE_NUMBER
$FAIL</b></font></body>";
}
else{
print "<body>YOUR MNS OE IS <b>$OE_NUMBER $OK</b></font></body>";
}
print "<br>";
###PRINT FOR DNS
if ($DNS_RESULTS eq "FAIL"){
print "<body><font color=$red>YOUR ODIE NAME IS NOT IN DNS<b>
$FAIL</b></font></body>";
}
else{
print "<body>YOUR ODIE NAME IS IN DNS <b>$OK</b></font></body>";
}
print "<br>";
###PRINT Contact Info
if ($FIRSTNAME eq "" or $LASTNAME eq ""){
$FIRSTNAME = "NULL";
$LASTNAME = "NULL";
print "<body><font color=$red>YOUR PRIMARY CUSTOMER CONTACT NAME IS:
<b>$FIRSTNAME $LASTNAME $FAIL</b></font></body>";
}
else{
print "<body>YOUR PRIMARY CUSTOMER CONTACT NAME IS: <b> $FIRSTNAME
$LASTNAME $OK</b></font></body>";
}
print "<br>";
print "<br>";
######################PRINT CONTACT TABLE######################
#I USED A HERE DOCUMENT IN THIS SECTION TO PRESERVE THE SPACES IN HTML
print <<phy_addr_text;
<body><b>PHYSICAL SITE ADDRESS INFORMATION</b></font></body>
<table width="50%" border="1" height="171">
<tr>
<td>BUILDING: $BUILDING</td>
<td> </td>
</tr>
<tr>
<td>ROOM: $ROOM</td>
<td>FLOOR: $FLOOR</td>
</tr>
<tr>
<td>STREET: $STREET</td>
<td> </td>
</tr>
<tr>
<td>CITY: $CITY</td>
<td> </td>
</tr>
<tr>
<td>STATE: $STATE</td>
<td> </td>
</tr>
<tr>
<td>ZIPCODE: $ZIPCODE</td>
<td> </td>
</tr>
<tr>
<td>COUNTRY: $COUNTRY</td>
<td> </td>
</tr>
</table>
phy_addr_text
print "<br>";
print "<br>";
print "<body><b>LINK INFORMATION</b></font></body>";
print "<br>";
print "<body>link info: @link </body>";
print "</html>";
}#end sub
#########################################################
# Database Disconnect #
#########################################################
sub db_disconnect{
$dbh->disconnect();
}
#########################################################
# Main Driver #
#########################################################
db_connect();
db_serial_query();
db_contact_query();
db_link_query();
check_dns();
db_print_report();
db_disconnect();
db_print_report sub-routine. I can print out each scalar element of the
array in seperate sub-routines but I cannot print the entire array set.
I tried to initialize the array in the beginning of script with "my
@link;" and that did not help. I am sure this is a scope issue but why
can I print the scalar elements of the array but not the entire array?
Can someone help me out?
p.s. everything else is working as expected, except for the piece I
mentioned.
#!/usr/local/bin/perl
#########################################################
# Global Variables #
#########################################################
use DBI;
use CGI(":standard");
my $date=`date +%x_%r`;
my $device = param("device");
my $datetemp = `date +%x_%r`;
my @dateStamp = split('\n',$datetemp);
my $green = "#33CC33";
my $red = "#FF0000";
my $OK = " ............................. OK";
my $FAIL = " ............................. FAIL";
my @link;
#DNS check for host
my $temp = gethostbyname($device);
my $deviceip = join(".",unpack('C4',$temp));
#########################################################
# Connect to Database and run SQL query #
#########################################################
sub db_connect
{
$ENV{'ORACLE_SID'} = 'xxxxx';
$ENV{'ORACLE_HOME'} = '/oracle/';
# Connect to the Database
$dbh = DBI->connect("dbi:Oracle:host=xxxx;sid=xxxx", "xxxxx", "xxxxx",
{ AutoCommit => 0 } );
# check connect to DB
$dbh or (print <<EOD
Error: Can't connect to database
EOD
and die $DBI::errstr);
}
################################################################
# SERIAL and OE NUMBER QUERY #
################################################################
#I GRAB CUST_ID HERE FOR QUERIES LATER
sub db_serial_query{
my $serial_sql = qq( SELECT SERIAL_NO, ADDRESS_449,CUST_ID,OE_NUMBER
from DEVICE where DEVICE_ID= '$device');
my $sth = $dbh->prepare($serial_sql);
#Execute SQL Statement
$sth->execute or die "DBI::execute : $!";
while (@serial = $sth->fetchrow_array) {
($SERIAL_NO,$ADDRESS_449,$CUST_ID,$OE_NUMBER) = @serial;
}
$sth->finish();
}
################################################################
# CONTACT NAME QUERY #
################################################################
sub db_contact_query{
my $contact_sql = qq( select PRIORITY,FIRSTNAME,LASTNAME from CONTACT
where CONTACT_ID='$device');
my $sth = $dbh->prepare($contact_sql);
#Execute SQL Statement
$sth->execute or die "DBI::execute : $!";
while (@contact = $sth->fetchrow_array) {
($PRIORITY,$FIRSTNAME,$LASTNAME) = @contact;
}
$sth->finish();
}
################################################################
# LINK QUERY #
################################################################
sub db_link_query{
my $link_sql = qq( select
STATUS,SERVICE_TYPE,FR_NET_TYPE,BANDWIDTH,CKT_ID,FMS_NO,LINK_DESC,LINK_TYPE,LINK_ENCAPS,FMS_CKT_STUS_CD,T1_FRAME_LINE_ENCODING
from link where router_id_a='$device');
my $sth = $dbh->prepare($link_sql);
#Execute SQL Statement
$sth->execute or die "DBI::execute : $!";
while (@link = $sth->fetchrow_array) {
($STATUS,$SERVICE_TYPE,$FR_NET_TYPE,$BANDWIDTH,$CKT_ID,$FMS_NO,$LINK_DESC,$LINK_TYPE,$LINK_ENCAPS,$FMS_CKT_STUS_CD,$T1_FRAME_LINE_ENCODING
)= @link; #<--THIS IS WHAT I WANT PRINT IN LAST SUB-ROUTINE!!
}
$sth->finish();
}
#################################################################
# Ensure Device is found in DNS #
#################################################################
sub check_dns
{
( $deviceip ? ( $DNS_RESULTS = "OK" ) : ( $DNS_RESULTS = "FAIL" ));
}#end sub
###############################################################
# PRINT ALL RESULTS #
###############################################################
sub db_print_report{
print "Content-type: text/html\n\n";
print "<html><head><title>ODIE QA REPORT</title></head>";
print "<body bgcolor=#343434 text=$green>";
print "<p align=center><b><font color=#FFFFFF size=6>ODIE QA
REPORT</font></b>";
print "<br>";
print "<p align=center><font color=#FFFFFF>Submitted on $dateStamp[0]
EST</font></p>";
print "<p align=center><font color=#0099FF>REMINDERS:</font>";
print "<br>";
print "<p align=center><b><font color=#FFFFFF size=3>ODIE NAME:
$device</font></p></b>";
print "<br>";
###PRINT SERIAL
if ($SERIAL_NO eq ""){
$SERIAL_NO = "NULL";
print "<body><font color=$red>YOUR SERIAL NUMBER IS <b> $SERIAL_NO
$FAIL</b></font></body>";
}
elsif ($SERIAL_NO =~ "111"){
print "<body><font color=$red>YOUR SERIAL NUMBER IS 11111111...<b>
$FAIL</b></font></body>";
}
else{
print "<body>YOUR SERIAL NUMBER IS: <b> $SERIAL_NO
$OK</b></font></body>";
}
print "<br>";
###PRINT 449
if ($ADDRESS_449 eq ""){
$ADDRESS_449 = "NULL";
print "<body><font color=$red>YOUR 449 ADDRESS IS <b>$ADDRESS_449
$FAIL</b></font></body>";
}
else{
print "<body>YOUR 449 ADDRESS IS <b>$ADDRESS_449
$OK</b></font></body>";
}
print "<br>";
###PRINT OE
if ($OE_NUMBER eq ""){
$OE_NUMBER = "NULL";
print "<body><font color=$red>YOUR MNS OE IS <b>$OE_NUMBER
$FAIL</b></font></body>";
}
else{
print "<body>YOUR MNS OE IS <b>$OE_NUMBER $OK</b></font></body>";
}
print "<br>";
###PRINT FOR DNS
if ($DNS_RESULTS eq "FAIL"){
print "<body><font color=$red>YOUR ODIE NAME IS NOT IN DNS<b>
$FAIL</b></font></body>";
}
else{
print "<body>YOUR ODIE NAME IS IN DNS <b>$OK</b></font></body>";
}
print "<br>";
###PRINT Contact Info
if ($FIRSTNAME eq "" or $LASTNAME eq ""){
$FIRSTNAME = "NULL";
$LASTNAME = "NULL";
print "<body><font color=$red>YOUR PRIMARY CUSTOMER CONTACT NAME IS:
<b>$FIRSTNAME $LASTNAME $FAIL</b></font></body>";
}
else{
print "<body>YOUR PRIMARY CUSTOMER CONTACT NAME IS: <b> $FIRSTNAME
$LASTNAME $OK</b></font></body>";
}
print "<br>";
print "<br>";
######################PRINT CONTACT TABLE######################
#I USED A HERE DOCUMENT IN THIS SECTION TO PRESERVE THE SPACES IN HTML
print <<phy_addr_text;
<body><b>PHYSICAL SITE ADDRESS INFORMATION</b></font></body>
<table width="50%" border="1" height="171">
<tr>
<td>BUILDING: $BUILDING</td>
<td> </td>
</tr>
<tr>
<td>ROOM: $ROOM</td>
<td>FLOOR: $FLOOR</td>
</tr>
<tr>
<td>STREET: $STREET</td>
<td> </td>
</tr>
<tr>
<td>CITY: $CITY</td>
<td> </td>
</tr>
<tr>
<td>STATE: $STATE</td>
<td> </td>
</tr>
<tr>
<td>ZIPCODE: $ZIPCODE</td>
<td> </td>
</tr>
<tr>
<td>COUNTRY: $COUNTRY</td>
<td> </td>
</tr>
</table>
phy_addr_text
print "<br>";
print "<br>";
print "<body><b>LINK INFORMATION</b></font></body>";
print "<br>";
print "<body>link info: @link </body>";
print "</html>";
}#end sub
#########################################################
# Database Disconnect #
#########################################################
sub db_disconnect{
$dbh->disconnect();
}
#########################################################
# Main Driver #
#########################################################
db_connect();
db_serial_query();
db_contact_query();
db_link_query();
check_dns();
db_print_report();
db_disconnect();