Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Thanks bitingduck (Pilgrim) for you input. As you suggested i used Text::CSV module to read csv file.

Main pl file :
#!/usr/bin/perl use warnings; use strict; use warnings; use Text::CSV; my $file1 = 'C:\TR_Vijay\Automation\serverinput.csv'; my $csv = Text::CSV->new(); my @columns; open (CSV, "<", $file1) or die $!; while (<CSV>) { next if ($. == 0); if ($csv->parse($_)) { @columns = $csv->fields(); print "$columns[0] \n"; print "$columns[1] \n"; print "$columns[2] \n"; print "$columns[3] \n"; } else { my $err = $csv->error_input; print "Failed to parse line: $err"; } open my $file, '>>', 'result.xml' or die "Can't open file: $!"; print $file <<EOF <?xml version="1.0" encoding="UTF-8"?> <!-- <!*************************************************************** +*> --> <!-- <!* + *> --> <!-- <!* PuTTY Configuration Manager save file - All right reserved. +*> --> <!-- <!* +*> --> <!-- <!*************************************************************** +*> --> <!-- <!The following lines can be modified at your own risks.> --> <configuration version=$columns[0] savepassword="True"> <root type="database" name=$columns[1] expanded="True"> <container type="folder" name=$columns[2] expanded="True"> <container type="folder" name=$columns[3] expanded="True"> <connection type="PuTTY" name=$columns[4]> <connection_info> <name>$columns[4]</name> <protocol>SSH</protocol> <host>$columns[7]</host> <port>$columns[8]</port> <session>Default Settings</session> <commandline>$columns[10]</commandline> <description /> </connection_info> <login> </login> <timeout> <connectiontimeout>1000</connectiontimeout> <logintimeout>750</logintimeout> <passwordtimeout>750</passwordtimeout> <commandtimeout>750</commandtimeout> </timeout> <command> </command> <options> <loginmacro>False</loginmacro> <postcommands>False</postcommands> <endlinechar>10</endlinechar> </options> </connection> </root> </configuration> EOF ; } close CSV;
I was able to achive almost expect for few things. Anyhelp would be much appreciated. Achieved so far : 1. able to read data from csv file 2. ouput the xml file with data read from csv file. Now Issues are : 1. Don't want to print first 7 lines of the xml format everytime. It should be printed only once at top of the file.
<?xml version="1.0" encoding="UTF-8"?> <!-- <!*************************************************************** +*> --> <!-- <!* + *> --> <!-- <!* PuTTY Configuration Manager save file - All right reserved. +*> --> <!-- <!* +*> --> <!-- <!*************************************************************** +*> --> <!-- <!The following lines can be modified at your own risks.> -->
2. Don't want to print last 2 line everytime. it just need to be printed only once at bottom of the file
</root> </configuration>
3. Not sure where i made mistake, but when ever i try to open the result.xml, it doesn't open. even program doesn't give any error thou.

In reply to Re^2: how to update an xml file by read data from csv file by Vijay81
in thread how to update an xml file by read data from csv file by Vijay81

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (10)
    As of 2014-07-31 21:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (253 votes), past polls