in reply to Perl Script to create jsons(Issue with comma)
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Bug in my perl script
by rahul_lfo (Initiate) on Oct 17, 2013 at 09:30 UTC | |
by hdb (Monsignor) on Oct 17, 2013 at 09:36 UTC | |
by rahul_lfo (Initiate) on Oct 17, 2013 at 09:49 UTC | |
by rahul_lfo (Initiate) on Oct 17, 2013 at 11:27 UTC | |
by hdb (Monsignor) on Oct 17, 2013 at 11:57 UTC |