/    Sign up×
Community /Pin to ProfileBookmark

Can PERL read a JS data only file?

This may be a stupid question, but I need to ask.

Is there a way that PERL can read a javascript data file?

I have a script that reads a 2-D data from an external file with the .js extension.

Is there a way to read the data and use it in a PERL script?

Could I treat it as a simple text file and split the information as needed?

Any other concepts I should consider?

Example 2-D data file:

[code]
// Externship Site Description
var Sites = [
[“Key”,”Externship Site”,””,”Location”,”O.Dz.<br>Site”,”Number of Students<br> Per Rotation”],
[“1″,”Aker-Kasten Eye Center”,””,”Boca Raton, FL”,”Y”,”3″],
[“2″,”Advanced Eye Clinic”,””,”Cheyenne, WY”,”Y”,”1″],
[“3″,”Aran Eye Associates”,””,”North Miami Beach, FL”,”Y”,”5″],
[“4″,”Atlantic Avenue Eye Care”,””,”Delray Beach, FL”,”N”,”1″],
[“5″,”Bascom Palmer Eye Institute”,””,”Miami, FL”,”Y”,”3 <br>(6 month rotation)”],
[“6″,”Braverman Eye Center”,””,”Hallandale, FL”,”Y”,”5″],
[“7″,”Brevard Eye Center”,”(Dr. David Hendrix)”,”Melbourne, FL”,”Y”,”1″],
[“8″,”Brevard Vision Care”,”(Dr. Kenneth Boyle)”,”Melbourne, FL”,”N”,”1″],
[“9″,”Center for Sight”,””,”Sarasota, FL”,”Y”,”3″],
[“10″,”Clayton Eye Center”,””,”Morrow, GA”,”Y”,”2″]
];
[/code]

Example 1-D data file:

[code]
// Class of 2013
var Students = [
“Last Name,First Name,N#,Email,GPA”,
“Boop,Betty,N0101,la51,2.5”,
“Oop,Ally,N0090,alsa,”,
“Fudd,Elmer,N0062,alsa,”,
“Bunny,Bugs,N0068,la52,”,
“Mouse,Mighty,N0108,aa10,”,
“Mouse,Mickey,N0072,ashk,”,
“Yosemite,Sam,N0105,fb27,”,
“Kid,Katzenjammer,N0027,brij,”,
“Duck,Donald,N0089,tb78,”
];
[/code]

to post a comment

2 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterMar 23.2011 — You can try Perl's [url=http://search.cpan.org/~makamaka/JSON-2.51/lib/JSON.pm]JSON[/url] module. Although the module is very strict about the syntax of the incoming JavaScript Object.

<i>
</i>#!/Perl/bin/perl -w
print "Content-Type: text/htmlnn";
use CGI::Carp qw(fatalsToBrowser);
use JSON;
use Data::Dumper;
my $js_string='[
["Key","Externship Site","","Location","O.Dz.&lt;br&gt;Site","Number of Students&lt;br&gt; Per Rotation"],
["1","Aker-Kasten Eye Center","","Boca Raton, FL","Y","3"],
["2","Advanced Eye Clinic","","Cheyenne, WY","Y","1"],
["3","Aran Eye Associates","","North Miami Beach, FL","Y","5"],
["4","Atlantic Avenue Eye Care","","Delray Beach, FL","N","1"],
["5","Bascom Palmer Eye Institute","","Miami, FL","Y","3 &lt;br&gt;(6 month rotation)"],
["6","Braverman Eye Center","","Hallandale, FL","Y","5"],
["7","Brevard Eye Center","(Dr. David Hendrix)","Melbourne, FL","Y","1"],
["8","Brevard Vision Care","(Dr. Kenneth Boyle)","Melbourne, FL","N","1"],
["9","Center for Sight","","Sarasota, FL","Y","3"],
["10","Clayton Eye Center","","Morrow, GA","Y","2"]
]';
my $result = decode_json($js_string);
print Dumper($result);
Copy linkTweet thisAlerts:
@JMRKERauthorMar 23.2011 — Thank you. I'll look into that solution.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...