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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |