I am new to perl & below is my problem statement: 1.Need to create an xml file (parent($a)/child($b) in code) taking user input.Need to check if number of lines exceeds 4000.If so, close the file checking if proper parent -child are created ,close the xml file with proper tag & write the content in new file until $a times.Below is my code ========================================================================================================================
#!/usr/bin/perl use strict; use Fcntl; use File::Basename; print "Deploy adaptations (y/n)?\n"; $s=<STDIN>; chomp ($s); if ($s eq 'y'){ print "Please enter apadtation path\n"; $path=<>; chomp($path); @files = <$path/*.zip>; foreach $file (@files) { $base=basename($file); print "$base\n"; } } my @user; do{ print "Select adaptations to be deployed\n"; $userinput = <STDIN>; chomp($userinput); push(@user ,"$userinput"); print "Select more adaptations ? (y/n)\n"; $result=<STDIN>; chomp ($result); }while ($result eq 'y'); #print "@user\n"; foreach (@user){ print "Hello\n"; } print "Enter number of objects to be created\n"; $a =<STDIN>; chomp ($a); print "Enter the name of Managed object\n"; $m =<STDIN>; chomp ($m); print "Do you want child objects to be created?(y/n)\n"; $r=<STDIN>; chomp ($r); if ($r eq 'y') { print "Enter number of child objects present under par +ent DN\n"; $b =<STDIN>;#children hiearchy chomp ($b); } my ($ext)=0; #$file_count=0; while ($a >=1) { sysopen (FILE,"/opt/robot/testcases/gep/tools/sample_$file_count++.xml +", O_RDWR|O_EXCL|O_CREAT,0755); printf FILE qq(<?xml version="1.0" encoding="UTF-8"?>\n); printf FILE qq(<!--DOCTYPE raml SYSTEM "ocos20.dtd"-->\n); printf FILE qq (<ocos version="2.0" xmlns:xsi="http://www.w3.org/2001/ +XMLSchema-instance" xsi:noNamespaceSchemaLocation='ocos20.xsd'>\n); printf FILE qq (<!--ocos version="2.0" xmlns="ocos20.xsd"-->\n); printf FILE qq(<cmData type="actual" scope="changes">\n); #printf FILE qq (<managedObject class="PLMN" version="1" operation="cr +eate" distName="PLMN-$a"/>\n); #printf FILE qq (</managedObject>\n); $linecount=0; do { if ($b==1) { printf FILE qq (<managedObject class="$m +" version="1" operation="create" distName="$m-$a"/>\n); printf FILE qq (<managedObject class="PL +MN" version="1" operation="create" distName="PLMN-$a"/>\n); printf FILE qq (</managedObject>\n); printf FILE qq (<managedObject class="GPBB" version= +"1" operation="create" distName="$m-$m/GPBB-$a">\n); printf FILE qq (</managedObject>\n); } elsif($b==2){ printf FILE qq (<mana +gedObject class="$m" version="1" operation="create" distName="$m-$a"/ +>\n); printf FILE qq (<managedObject class="GPBB +" version="1" operation="create" distName="$m-$a/GPBB-$a">\n); printf FILE qq (</managedObject>\n); printf FILE qq (<managedObject class="GPST +" version="1" operation="create" distName="$m-$a/GPBB-$a/GPST-$a">\n) +; printf FILE qq (</managedObject>\n); } elsif($b==3){ +printf FILE qq (<managedObject class="$m" version="1" operation="crea +te" distName="$m-$a"/>\n); printf FILE qq (<managedObject + class="GPBB" version="1" operation="create" distName="$m-$a/GPBB-$a" +>\n); printf FILE qq (</managedObjec +t>\n); printf FILE qq (<managedObject + class="GPST" version="1" operation="create" distName="$m-$a/GPBB-$a/ +GPST-$a">\n); printf FILE qq (</managedObjec +t>\n); printf FILE qq (<managedObject + class="GGSN" version="6.0" operation="create" distName="$m-$a/GPBB-$ +a/GPST-$a/GGSN-$a">\n); printf FILE qq (</managedObjec +t>\n); } $linecount= system ("wc -l < sample_$file_count++.xml"); }while ($linecount <=100); printf FILE qq (</cmData>\n); printf FILE qq (</ocos>\n); close (FILE); $a--; }

In reply to open a new xml file if line count exceeds 4000 lines by charan1717

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.