Hi folks,
I've been dead-ending on this issue, and I'm dusting off my brain to re-engage with Perl, so pls bear with me.
Here's an example of what I'm trying to accomplish, have tried several variants to resolve; but am getting error mssgs to the effect of: Global symbol "@site" requires explicit package name at csvconvert-BETA.pl line 16.
Overview is I'm uploading a .CSV file to a tmp directory on a solaris box, and then running the script to read the data and convert to an XML format. I've had success with that portion, so now I'm trying to find a way to read line 4, column 4 (for example) and apply that to name the XML file. (previously I had statically assigned the directory and name and that worked fine, but want the script to be able to dynamically base it on a value in the .CSV file as there will need to be many uniquely named XML files in the same directory) -
-
use strict;
-
-
# Open the exchange-script.csv file for input
-
open(CSV_FILE, "/tmp/exchange-script.csv") ||
-
die "Can't open file: $!";
-
-
#set variable
-
my $count=0;
-
-
while(<CSV_FILE>) {
-
-
#only want to take data from line 4
-
if ($count==4) {
-
-
# Split each field, on the comma delimiter, into an array
-
my @fields = split(/,/, $_);
-
}
-
# Open a new xml file for output and name according to column 4 on line 4
-
open(XML_FILE, ">/exdir/dir2/ems/$fields[3].xml") ||
-
die "Can't open file: $!";
-
}
-
# Print the initial XML header and the root element
-
print XML_FILE "<?xml version=\"1.0\"?>\n";
-
print XML_FILE "<CEV>\n";
-
print XML_FILE " <Management_Item_File>/somewhere.xml</Management_Item_File>\n";
-
print XML_FILE " <Icon_Groups>\n";
-
print XML_FILE " <Icon_Group>\n";
-
print XML_FILE " <Name>Digital_IP_1_27</Name>\n";
-
print XML_FILE " <Symbol_Type>Cards:Card</Symbol_Type>\n";
-
print XML_FILE "\n";
-
print XML_FILE " <Background_Image>/something.gif</Background_Image>\n";
-
print XML_FILE "\n";
-
-
# The while loop to traverse through each line in exchange-script.csv
-
while(<CSV_FILE>) {
-
chomp; # Delete the new line char for each line
-
-
# Split each field, on the comma delimiter, into an array
-
my @fields = split(/,/, $_);
-
-
print XML_FILE<<"EOF";
-
<icon>
-
<Alarm_Status_ID>$fields[8]</Alarm_Status_ID>
-
<Label>$fields[2]</Label>
-
<X_Coordinate>$fields[7]</X_Coordinate>
-
<Y_Coordinate>$fields[0]</Y_Coordinate>
-
<Width>$fields[6]</Width>
-
<Height>$fields[7]</Height>
-
<Symbol_Type>EnvMSIcon:Generic</Symbol_Type>
-
<Optional>$fields[9]</Optional>
-
</icon>
-
EOF
-
}
-
-
# Close the root element
-
print XML_FILE " </Icon_Group>\n";
-
print XML_FILE " </Icon_Groups>\n";
-
print XML_FILE "</CEV>";
-
-
# Close all open files
-
close CSV_FILE;
-
close XML_FILE
-
-
Thanks for any assist!
Cheers, Hutch
2 1469 KevinADC 4,059
Recognized Expert Specialist
It's not clear what you want to do with lines 1, 2 and 3, but if you just want to skip them (untested code): - use strict;
-
use warnings;
-
-
# Open the exchange-script.csv file for input
-
open(CSV_FILE, "/tmp/exchange-script.csv") or
-
die "Can't open file: $!";
-
-
while (<CSV_FILE>) {
-
next if $. < 4;
-
# only want to take data from line 4
-
# $. stores the value of the current line
-
# being read from the file
-
if ($. == 4) {
-
# Split each field, on the comma delimiter, into an array
-
my $filename = (split(/,/, $_))[3];
-
-
# Open a new xml file for output and name according to column 4 on line 4
-
open(XML_FILE, ">/exdir/dir2/ems/$filename.xml") or
-
die "Can't open file: $!";
-
-
# Print the initial XML header and the root element
-
print XML_FILE qq{<?xml version=\"1.0\"?>
-
<CEV>
-
<Management_Item_File>/somewhere.xml</Management_Item_File>
-
<Icon_Groups>
-
<Icon_Group>
-
<Name>Digital_IP_1_27</Name>
-
<Symbol_Type>Cards:Card</Symbol_Type>
-
-
<Background_Image>/something.gif</Background_Image>
-
};
-
next;
-
}
-
-
chomp; # Delete the new line char for each line
-
-
# Split each field, on the comma delimiter, into an array
-
my @fields = split(/,/);
-
-
print XML_FILE<<"EOF";
-
<icon>
-
<Alarm_Status_ID>$fields[8]</Alarm_Status_ID>
-
<Label>$fields[2]</Label>
-
<X_Coordinate>$fields[7]</X_Coordinate>
-
<Y_Coordinate>$fields[0]</Y_Coordinate>
-
<Width>$fields[6]</Width>
-
<Height>$fields[7]</Height>
-
<Symbol_Type>EnvMSIcon:Generic</Symbol_Type>
-
<Optional>$fields[9]</Optional>
-
</icon>
-
EOF
-
-
# Close the root element
-
print XML_FILE " </Icon_Group>\n";
-
print XML_FILE " </Icon_Groups>\n";
-
print XML_FILE "</CEV>";
-
-
close XML_FILE;
-
}
-
close CSV_FILE;
Many thanks, the input twas not ignored despite my latency in responding.
Helped a great deal... I will in turn follow up with posting the complete script when complete. Which, i trust, may help others along the way!
The present enhancement I'm trying to integrate is a means to ping (query) a remote host before SNMPSET commands are issued to it. Have already integrated a mechanism to time-out based on number of attempts -- yet I would like to use something that pings the remote network element to verify the IP address passed along through the CLI ARGV is both reachable and valid before it goes into a cycle of attempts.
Trying to shy away from using any external modules if possible. which i'm supposing net::ping is one of them?
granted my understanding, as previously stated, is limited
Promise to post script(s) -- yes, there are a total of 3 + 1 to sequentially execute them ....when complete..
and i will do so in a mostly cogent manner :-)
Cheers,
hutch
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Luklrc |
last post by:
Hi,
I'm having to create a querysting with javascript. My problem is that
javscript turns the "&" characher into "&" when it gets used as a
querystring in the url EG:
/mypage.asp?value1=1&value2=4& ...
which of course means nothing to asp.
|
by: don |
last post by:
I have two existing interfaces having methods with same names. Now I have to
implement both intrfaces in one class. Is there any way I could implement
methods with same names in both interfaces without getting errors from the
compiler?
|
by: |
last post by:
I have an application that I'm converting from traditional ASP to asp.net,
using visual basic to code with.
the line it doesn't like is: "If (sData(rownumber, lcnt) =
sData(rownumber - 1, lcnt)) AND (WhatCol.Type <> 5 AND WhatCol.Type <> 6)
Then "
The error message is:
|
by: suzee_q00 |
last post by:
I will admit that lots of times the obvious eludes me and this is most likely one of those times but if anyone has any ideas on what I can do to make this code work, I would greatly appreciate it. Here's the code:
while ( ( fgets ( buf, BUFLEN, fin ) ) != NULL ) /* pulls a line from "fin" up to the length of BUFLEN and stores it in "buf" */
{
rmNl ( buf ); /* remove new line */
if ( !lineWithBlanks ( buf ) )
{
for (i = 0; buf !=...
|
by: goober |
last post by:
Ladies & Gentlemen:
I have built a form that client-side validates and posts data to a CRM
beautifully in Internet Explorer (IE) 6. The problem comes in FireFox
(FF) 1.5 when everything works except the validation. In FF it posts
fine to my CRM but with no validation!
Here are snippets of my code together after taking out as much as I can
for brevity sake.
| |
by: JyotiC |
last post by:
hi,
i am making a GUI using Tkinter,
I have a button and a checkbutton.
i want the button to be enable when checkbutton is on and disble when
the checkbutton is off.
thanx
|
by: andrewanderson |
last post by:
hi can anyone help me with this prog. cant find the prob why it cant display
cout<<"This is the display of your transaction"<<endl;
ifstream fobj; //declare input file stream
fobj.open("trans.txt"); //open file
if(!fobj) //File not opened
|
by: Savage |
last post by:
I'm making for fun a simple program which format a input file.Input file sustain of
person name,lastname and date of birth.Output file si supposed to be forammted as following:
NAME LASTNAME DATE OF BIRTH
And i finished it but there is little prob: it don't output date of birth!
I thinkt about the prob and can't figure out why is that happening.
To output data i used function: void output(void),i have...
|
by: sabby |
last post by:
I want to use the getline() so that i can enter a entire name in on line. (with spaces)
The prob is that i am initializing the variable as "N/A" and saving it to a text file. it is declared as a string. look at the code:
#include <iostream.h>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
//Account data structure
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |