467,113 Members | 1,374 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,113 developers. It's quick & easy.

Perl with Json

Hi there,

File manupulation is difficult in Perl.
I'd like to modify a file with JSON format.
For example, test.conf is:

Expand|Select|Wrap|Line Numbers
  1. {
  2.      "tests" : [
  3.           "test1",
  4.           "test2",
  5.           "temp1"
  6.      ],
  7.      ... (and so on)
  8. }
And, I'd like to add or delete an item to or from "tests" field.
So I wrote a Perl program:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  3. use JSON
  5. open TEST, ">test.conf"
  6. #  I have no idea how to get the json data from test.conf to this perl program.
  7. # Also, I have no idea how to add or delete an item (e.g. "temp2") to or from "tests" field.
  8. # And, I'd like to write the modified filed to test.conf file.
Help please!

Thanks in advance.
Jul 17 '08 #1
  • viewed: 3690
3 Replies
Expert Mod 2GB
Considering that Perl's bread and butter is text (that's what Larry Wall designed it to be used on), I would think it would be easier here than elsewhere.

Also, JSON is a "Java Script Object Notation" module. Isn't it a feature of javascript that it isn't able to access the filesystem? (correct me if I am wrong) If that's the case, would that limitation apply?

Back to the issue, why not present the data in the file, tell us what you are trying to do and show us the code you are trying to modify it with so we can help you.


Jul 17 '08 #2
Expert 512MB
Config::JSON may be do what you want.

Jul 17 '08 #3
Thanks a lot!

Config::JSON is exactly what I wanted!

Let me ask it If I have some problem after reading that and programming.
Jul 17 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

16 posts views Thread by G Matthew J | last post: by
20 posts views Thread by Luke Matuszewski | last post: by
2 posts views Thread by Kevin Newman | last post: by
2 posts views Thread by arkascha | last post: by
23 posts views Thread by dhtmlkitchen@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.