Perl Experts - Need your help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Perl Experts - Need your help
# 1  
Old 11-16-2009
Perl Experts - Need your help

Hi All,

I need to take a dump of a table and load into excel and send as an attachment and for this am using a Perl script.
I know the usual way of doing this by writing all the fields next to 'select' query and similarly writing into an excel as shown below
$worksheet->write($row,$col++,$row_hash->{abc},$vmergeformat);
.....
...
....
$worksheet->write($row,$col++,$row_hash->{xyz},$vmergeformat);

where 'abc' and 'xyz' are fields.

Now say If there are 70 fields in a table and I want these fields into an excel without writing their names explicitly.

Much thanks in advance

Thanks,
RN
# 2  
Old 11-16-2009
Would this work for you:
Code:
foreach my $row_key ( keys %{$row_hash} ) {
    $worksheet->write($row,$col++,$row_hash->{$row_key},$vmergeformat);
}

Or, if you need the columns in a certain order, save that ordering to an array, and use that:
Code:
my @order = qw/abc def ghi/;
foreach my $row_key ( @order ) {
    $worksheet->write($row,$col++,$row_hash->{$row_key},$vmergeformat);
}

# 3  
Old 11-16-2009
Hi Pludi,

Thanks for your reply .....

So I need to use

Code:
my $sth= $dbh->prepare( qq{select * from www});

$worksheet->set_column("A:A", 8);
$worksheet->write($row,$col++,"abc",$mergeformat);
...
...
...
$worksheet->set_column("Z:Z", 8);
$worksheet->write($row,$col++,"xyz",$mergeformat);
my $row_hash;
while($row_hash = $sth->fetchrow_hashref) {
foreach my $row_key ( keys %{$row_hash} ) {
    $worksheet->write($row,$col++,$row_hash->{$row_key},$vmergeformat);
}


Kindly correct me if am wrong

Last edited by pludi; 11-16-2009 at 01:32 PM.. Reason: code tags, please...
# 4  
Old 11-16-2009
Depending on what you want to do (which I don't know) this should work. Just don't forget to advance the $row variable and to close the while block (it's currently still open).
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To all the awk experts out there!

Hello All, I recently encountered this difficulty in processing a File. Input File has millions of records with fields like below ID1,ID2,DATE,FLAG,VAL 123,432,0604,1,-0.5 123,432,0604,22,0.5 123,433,0604,1,-0.54 123,433,0604,22,6.77 123,543,0605,22,0.94 To put this simply, I will have... (8 Replies)
Discussion started by: PikK45
8 Replies

2. IP Networking

Experts - Need suggestion

I'm searching to learn linux coding for a month but no clear about the where to start . Right now i'm in networking but not much interested in this maintenance jobs . I'm looking to create my own product in wireless network and also having idea about gadget that can be useful for students . But i... (1 Reply)
Discussion started by: Cholasivam
1 Replies

3. Shell Programming and Scripting

awk experts please help

I have a log file of 60 MB with 20k records which contains data like below. this contains some data so removed 2891358271000020, 2012-12-02 23:16:17 , 2012-12-02 23:16:17 , 378015123, 2012-12-02 23:16:19 , 2012-12-02 23:16:19 , (15 Replies)
Discussion started by: mirwasim
15 Replies

4. UNIX for Advanced & Expert Users

Experts!! please help me

Hi experts, Please help me on the below: how to write a shell script to search and delete files on windows server. -script runs on unix box -it should search for specific files on windows server and delete them periodically. (1 Reply)
Discussion started by: chpradeepch
1 Replies

5. UNIX for Advanced & Expert Users

for experts

Hi i'm working with mpi programs every thing ok but i need after i compile the mpi to calc the area of the rectangle for example (not my program) accept two arguments from the command line: mpirun -n 4 myprog 24 100 here 24 and 100 two arguments i'll pass them to the program how can... (1 Reply)
Discussion started by: Scotch
1 Replies

6. Solaris

Experts !!! Please advise

Hi, I work on sun Solaris. Am hosting few web services on my server which are accessed over the internet. Now to check whether the web service is responding or not, i first have to log in to the web service URL. If it doesn't respond there, i come back to my server box and restart the service... (4 Replies)
Discussion started by: sting672744
4 Replies

7. UNIX for Dummies Questions & Answers

Perl Experts - Need your help

Hi All, I am using ingres in perl select count(*) rec from user_tables where table_name = 'abc'; I want to use the alias variable 'rec' and check the value if >0 insert values else create table. How can I do this without using hash variables in perl. Kindly help me in this regard. Much... (1 Reply)
Discussion started by: karthickrn
1 Replies

8. UNIX for Dummies Questions & Answers

Looking for Advice from Experts

Where to start... I am a system administrator who didn't think he would ever be one. My first work was on Window 2000 as a tech(hardware, installs, stuff like that). Then we got Macs (I work in photography and Videography). The I was sent to Mac cert school. Set up a Mac Xserve and about 100... (2 Replies)
Discussion started by: Squidy P
2 Replies

9. Shell Programming and Scripting

perl module installation problems... experts advice needed,...

---------- This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) ----------in win 2000 advanced server,.. i am somewhat comfortable with perl but i am new to perl modules.. when i tried to install xml::simple and xml::parser there... (4 Replies)
Discussion started by: sekar sundaram
4 Replies
Login or Register to Ask a Question