Link to home
Start Free TrialLog in
Avatar of shragi
shragiFlag for India

asked on

Read and write File

Hi - I want to read and write a CSV File thru HTML or Java script or Perl or Jquery.
What is the best way to do it.

I want to read the csv file and should be able to edit a value and save it or add a new line to the csv.
Sample CSV:
1,2,3
2,3,4
3,4,5

I should be able to edit any value in the csv thru html.
how can I accomplish that.

Thanks
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

You can parse it with papaparse, editing will be trickier

http://papaparse.com/demo
You are mixing technologies here. Perl, JSP are server side technologies. Jquery / Javascript are client side.

Where do you want the file to be written?

There are restrictions with reading and writing files in the browser (JavaScript / JQuery) - due to security constraints. If you need to read write the CSV on the server then the task is trivial - but we need to know more about what it is you are trying to do.
Avatar of shragi

ASKER

Hi Julian - this is what I am trying to achieve

I have a file (currently saved as testfile.csv but can also be saved as testfile.txt) and the contents are like below

John, 2,3,C:/user/user/inputfile1.txt, C:/user/desktop/inputfile2.txt, myscript.pl, myscript1.pl, myscript2.pl
Randy,0,1,myscript1.pl
Robert,1,2,C:/user/desktop/inputfile3.txt, myscript.pl, myscript1.pl

If you look at the file each line starts with a name and then numbers and then file path or script path based on numbers.
Example:
John, 2,3,C:/user/user/inputfile1.txt, C:/user/desktop/inputfile2.txt, myscript.pl, myscript1.pl, myscript2.pl

means this line name is John and it has 2 input files and 3 scripts and two input file locations and 3 script location are provided next.

I wrote another script to call those scripts based on file availability but i want to provide a UI so that users can enter this data in browser instead of testfile.csv or testfile.txt

Now if I want to change the path for the input file in the below line
Robert,1,2,C:/user/desktop/inputfile3.txt, myscript.pl, myscript1.pl
i am currently opening the file and changing the path but it became difficult when you have more lines (like 200 -300) to find such a line.
So i am thinking of creating a UI where users can update the values in the file with out opening the file.

Here is what i am thinking

provide a drop down to select first value in the file
John, randy, robert
upon selecting robert provide text boxes for all the other values for robert  (Robert,1,2,C:/user/desktop/inputfile3.txt, myscript.pl, myscript1.pl)
one text box to edit value "1"
one text box to edit value "2"
one text box to edit value "C:/user/desktop/inputfile3.txt"
one text box to edit value "myscript.pl"
one text box to edit value "myscript1.pl"

Also ability to add new line to the file.

if i have a server i can easily do it using MVC, but there are no servers installed its a linux machine and i dont want to install server for this.

SO is there any way to accomplish this.

Thanks
Any particular reason you are working off a file and not a database?
Avatar of shragi

ASKER

No database is installed in server - and can't install DB for this one time task.
Are you asking us to write the script for you, or to help you troubleshoot your script?

To modify the file, I'd load it into a HoH or HoA so that you can easily locate/edit the specific record.

You could use the Text::CSV module to handle the reading/writing of the file.

You need to post your code so that we can see what you're doing and direct you on how to fix it.
In your duplicate question, which appears that you've abandoned, you state:
I know how to do this in Java using MVC pattern.
Given that you want to do this in perl instead of java, I suggest that you use one of Perl's MVC frameworks, such as Dancer2 or Mojolicious.
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I believe Slick812's comment is the best answer. I did change the grade because OP did not respond