Input data of a file from perl into HTML table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Input data of a file from perl into HTML table
# 1  
Old 03-07-2014
Input data of a file from perl into HTML table

Hi ,
I need an help in perl scripting.
I have an perl script written and i have an for loop in that ,where as it writes some data to a file and it has details like below.
Code:
 cat out.txt
This is the first line 
this is the second line.
.....

Now, this file needs to be send in mail in HTML format.

so far ,i have done

Code:
sub blah
{
        my $message = shift;
        open    blah, ">>", $data_file or die "Unable to write to $data_file";
        print   blah "$message\n";
        close   blah
}
foreach $e ()
{
blah("<tr><td bgcolor=#B2CAF6><b>Data:</b></td><td>`cat out.txt`</td></tr>");
}

with this code am not able get what i am expecting, it give the output in the mail as

Data: `cat out.txt` in the table.

Please help me out here.
# 2  
Old 03-07-2014
You can open() out.txt and read it, assign it's input into a variable. After that you write the content into the new file with your html stuff surrounding. Basically the same like you already open the file for appending, just add it before that step.
It would be good not to use the same name for the file handle like the name of the sub routine.
If you use die(), you might want to add $! to print the original error message too.

Last edited by zaxxon; 03-07-2014 at 11:46 AM.. Reason: added info
# 3  
Old 03-07-2014
thanks zaxxon for your reply.

But sorry am afraid ,i didnt get quite clear.

But i have tried something similar of what you are trying to say ? please correct me if this is not your perception.

Code:
$value=(open my $output, ">","out.txt" );
blah("<tr><td bgcolor=#B2CAF6><b>Data:</b></td><td>$value</td></tr>");

but not sure... what is the issue in that.. its giving the output in the mail as
Data: $value


to add more here, am generating the html mail from unix shell script from the file created from the sub routine.
and i have called the shell script inside the perl.

---------- Post updated at 12:25 PM ---------- Previous update was at 10:44 AM ----------

Could someone please help me here ?

Last edited by scott_cog; 03-07-2014 at 12:03 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Parsing - export html table data as .csv file?

Hi all, Is there any out there have a brilliant idea on how to export html table data as .csv or write to txt file with separated comma and also get the filename of link from every table and put one line per rows each table. Please see the attached html and PNG of what it looks like. ... (7 Replies)
Discussion started by: lxdorney
7 Replies

2. UNIX for Dummies Questions & Answers

Extract table from an HTML file

I want to extract a table from an HTML file. the table starts with <table class="tableinfo" and ends with next closing table tag </table> how can I do this with awk/sed... ---------- Post updated at 04:34 PM ---------- Previous update was at 04:28 PM ---------- also I want to... (4 Replies)
Discussion started by: koutroul
4 Replies

3. Shell Programming and Scripting

Creating html table from data in file

Hi. I need to create html table from file which contains data. No awk please :) In example, ->cat file num1 num2 num3 23 3 5 2 3 4 (between numbers and words single TAB). after running mycode i need to get (heading is the first line): <table>... (2 Replies)
Discussion started by: Manu1234567
2 Replies

4. Shell Programming and Scripting

extract complex data from html table rows

I have bash, awk, and sed available on my portable device. I need to extract 10 fields from each table row from a web page that looks like this: </tr> <tr> <td>28 Apr</td> <td><a... (6 Replies)
Discussion started by: rickgtx
6 Replies

5. Shell Programming and Scripting

Perl Script for reading table format data from file.

Hi, i need a perl script which reads the file, content is given below. and output in new file. TARGET DRIVE IO1 IO2 IO3 IO4 IO5 ------------ --------- --------- --------- --------- --------- 0a.1.8 266 236 ... (3 Replies)
Discussion started by: asak
3 Replies

6. Shell Programming and Scripting

Bash shell script that inserts a text data file into an HTML table

hi , i need to create a bash shell script that insert a text data file into an html made table, this table output has to mailed.I am new to shell scripting and have a very minimum idea of shell scripting. please help. (9 Replies)
Discussion started by: intern123
9 Replies

7. UNIX for Dummies Questions & Answers

Bash script to insert data into an html table

hi, I need to create a bash shell script which picks up data from a text file and in the output file puts it into an html made table. I have to use sed and awk utilties to do this the input text file will contain data in the format: job name para1 para2 para3 para4 para4 1 ... (1 Reply)
Discussion started by: intern123
1 Replies

8. Shell Programming and Scripting

Converting html table data into multiple variables.

Hi, Basically what I am trying to do is the following. I have created a shell script to grab timetabling information from a website using curl then I crop out only the data I need which is a table based on the current date. It leaves me with a file that has the table I want plus a small amount... (2 Replies)
Discussion started by: domsmith
2 Replies

9. Shell Programming and Scripting

Is it possible to convert text file to html table using perl

Hi, I have a text file say file1 having data like ABC c:/hm/new1 Dir DEF d:/ner/d sd ...... So i want to make a table from this text file, is it possible to do it using perl. Thanks in advance Sarbjit (1 Reply)
Discussion started by: sarbjit
1 Replies

10. Shell Programming and Scripting

Perl: Variable input via HTML

I am completely new to perl and am just going over the tutorials right now. What I am trying to attempt is to take the input from the HTML (in a form) and use those variables in a perl script. I've looked everywhere for a simple example on how to do this and cannot find it or do not understand... (5 Replies)
Discussion started by: douknownam
5 Replies
Login or Register to Ask a Question