By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,541 Members | 1,525 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,541 IT Pros & Developers. It's quick & easy.

Perl with Json

P: 4
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
Share this Question
Share on Google+
3 Replies

Expert Mod 2.5K+
P: 3,503
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 100+
P: 971
Config::JSON may be do what you want.

Jul 17 '08 #3

P: 4
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.