rahul_lfo has asked for the wisdom of the Perl Monks concerning the following question:
Output of the File----#!/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);
{"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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bug in my perl script
by hdb (Monsignor) on Oct 17, 2013 at 07:40 UTC | |
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 | |
|
Re: Bug in my perl script (JSON @ARGV jsontidy)
by Anonymous Monk on Oct 17, 2013 at 07:34 UTC | |
|
Re: Perl Script to create jsons(Issue with comma)
by davido (Cardinal) on Oct 17, 2013 at 14:41 UTC |