Why don't you use JSON to create your output. Instead of struggling with complicated strings, you would only have to create some hashes and let the module do the work for you. For example:

use strict; use warnings; use JSON; my %bookmarks; for (1..3) { push @{$bookmarks{browserBookMarksData}}, { bookmark => "0", c +reated => "01/12/2012" }; } print to_json \%bookmarks;

would create

{"browserBookMarksData":[{"created":"01/12/2012","bookmark":"0"},{"cre +ated":"01/12/2012","bookmark":"0"},{"created":"01/12/2012","bookmark" +:"0"}]}

No need to worry about commata...

Update: The last part of your script could look similar to this:

print "Enter the limit : "; chomp(my $lim = <STDIN>); my %bookmarks; while ( $lim-- ) { push @{$bookmarks{browserBookMarksData}}, { bookMark => $charset[ rand(@charset) ], created => $charset2[ rand(@charset2) ], date => $charset3[ rand(@charset3) ], title => join '', @charset4[map {int rand @charset4} (1..8) +], url => join '', @charset5[map {int rand @charset5} (1..8) +], visits => $charset6[rand(@charset6) ], }; } print to_json \%bookmarks;

In reply to Re: Bug in my perl script by hdb
in thread Perl Script to create jsons(Issue with comma) by rahul_lfo

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.