#!/usr/bin/perl use strict; use warnings; #charset below would be 1 and in future 1 for bookmark and 0 for hist +ory item my @charset = ('1','0'); my @charset2 =(''); my @charset3 =(''); my @charset4 = (('A'..'Z'), ('a'..'z')); my @charset5 = (('A'..'Z'), ('a'..'z')); my @charset6 = ('1' .. '1000'); my @charset7 =('http://www.','https://www.'); my @charset8=('.com','.co','.in','.info','.org','.net','.biz','.us','. +me','.mobi','.co.in','.firm.in','.gen.in','.ind.in','.net.in','.org.i +n','.tv','.ag','.am','.asia','.at','.be','.bz','.ca','.cc','.co.nz',' +.co.uk','.com.ag','.com.au','.com.br','.com.bz','.com.co','.com.es',' +.com.mx','.com.pe','.com.so','.com.tw','.cz','.de','.es','.eu','.fm', +'.fr','.gs','.idv.tw','.it','.jobs','.jp','.la','.me.uk','.ms','.mx', +'.net.ag','.net.au','.net.br','.net.bz','.net.co','.net.nz','.net.pe' +,'.net.so','.nl','.nom.co','.nom.es','.nom.pe','.org.ag','.org.au','. +org.es','.org.nz','.org.pe','.org.so','.org.tw','.org.uk','.pe','.se' +,'.so','.tk','.tw','.ws','.xxx'); my @charset9 = ('":"'); my @charset40=('"'); my @charset41=(','); my @charset42=('{"browserBookMarksData":['); my @charset43=(']}'); my @charset51=('{'); my $i=0; my $prefix ; my $suffix ; print "Enter the limit : "; chomp(my $lim = <STDIN>); { $prefix .=$charset42[rand(@charset42) ]; } { $suffix .=$charset43[rand(@charset43) ]; } open(FILE, ">>bookmarkmirror.json"); print FILE ("$prefix"); while ( $lim-- ) { my $bookMark; my $created; my $date; my $title; my $url; my $www; my $com; my $visits; my $quotes; my $comma; my $start; my $end; my $curly ; my $extra; { $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) ]; } #if ($EmailType == '0'){ #$m_emailLabel .="test";} #else {$m_emailLabel .="";} { $quotes .=$charset40[rand(@charset40) ]; } { $comma .=$charset41[rand(@charset41) ]; } { $curly .=$charset51[rand(@charset51)]; } { $www .=$charset7[rand(@charset7)]; } { $com .=$charset8[rand(@charset8)]; } { $extra .=$charset9[rand(@charset9)]; } print FILE ( "$curly"."\"bookMark\"\:"."$quotes"."$bookMark"."$quo +tes"."$comma","\"created\"\:"."$quotes".int(rand(10000000000000))."$q +uotes"."$comma","\"date\"\:"."$quotes".int(rand(10000000000000))."$qu +otes"."$comma","\"title"."\"\:\"$title\""."$comma","\"url"."$extra"." +$www"."$url"."$com\""."$comma","\"visits"."\"\:\"$visits\"\}\ ". if ( +$lim != $i){"$comma"}); if($lim == '1') { print FILE (","); } $i++; } print FILE ("$suffix"); close(FILE);
Output of the File----
{"browserBookMarksData":[{"bookMark":"0","created":"5663146972656","da +te":"6965942382812","title":"QQjVYxgf","url":"https://www.ySLjEGzo.or +g","visits":"783"} ,,{"bookMark":"1","created":"3386840820312","date" +:"4520874023437","title":"GTHCiPLs","url":"http://www.cmBoOQmy.pe","v +isits":"946"} ,]}

The problem is that I am getting two unwanted comma's,which is at the end of the json created and the last bean. Please help how to eliminate these unwanted comma's.


In reply to 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.