Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > uuencode file.csv | mailx

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-07-08, 10:54
kshtoperl kshtoperl is offline
Registered User
 
Join Date: Feb 2008
Posts: 8
uuencode file.csv | mailx

HI All,

i am writing a perl script. and my intersion is to mail the output of the subroutine
in a csv attached format. like

sub rout1 {
some commands;
some commands;
}

@data=rout1;

I tried the follwoing
qx { @data | uuencode file.csv | mailx -s "Reort" userid;

system ( @data | uuencode file.csv | mailx -s "Reort" userid);

but somehow it is not working.
Any kind of help will be appriciated

Best Regards
Reply With Quote
  #2 (permalink)  
Old 02-11-08, 08:51
kshtoperl kshtoperl is offline
Registered User
 
Join Date: Feb 2008
Posts: 8
So no one!!!!!!!!
Reply With Quote
  #3 (permalink)  
Old 02-23-08, 19:27
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Fort Polk, LA
Posts: 500
Quote:
Originally Posted by kshtoperl
So no one!!!!!!!!

Oh, waah. There aren't a lot of perl hackers (this is a database forum!), and I was away for a few weeks doing .50 cal gunnery at Fort Knox.

To answer your questions:

I think you could possibly do what you're trying to do with a simple open command. I don't have a mailer running on this 'puter, but let's say you're trying to do this: echo Stupid test | gzip -c | uuencode blah.gz

That's bash, here's what it looks like in Perl:

Code:
open FOO, "| gzip -c | uuencode blah.gz"; print FOO "Stupid test"; close FOO;

Since @data is an array, you might want to join it or something. I'll assume you mean to end each line with a newline.

Code:
open FOO, "| uuencode filename.csv | mailx --whatever"; print FOO "$_\n" for @data; close FOO;

Second, if you can, you should install Convert::UU from CPAN. You can then use this code:

Code:
use Convert::UU; $encoded_string = uuencode(join("\n", @data), "filename.csv"); open FOO, "| mailx --whatever"; print FOO $encoded_string; close FOO;

If you ever need to make your script more general and robust, you should look at Mail::Transport:end. They have a plugin for mailx.

Quote:
I tried the follwoing
qx { @data | uuencode file.csv | mailx -s "Reort" userid;

system ( @data | uuencode file.csv | mailx -s "Reort" userid);

As to why your code didn't work:

The qx stuff and system commands are only useful when you don't need to communicate with the program. If you do `@data | uuencode | ...`, what happens is that Perl expands @data and sends that to your shell. Your shell is expecting commands, not data, so it either crashes or tries to interpret them. (Good thing you didn't have rm -rf / in your data!)

Last edited by sco08y : 02-23-08 at 19:35.
Reply With Quote
  #4 (permalink)  
Old 03-18-08, 04:43
kshtoperl kshtoperl is offline
Registered User
 
Join Date: Feb 2008
Posts: 8
xls in unix

Now i have another situation over here.

I have multiple csv file created through uuencode.csv and mail them to the mailids.

cat test1 | uuencode test1.csv > tmpfile
cat test2 | uuencode test2.csv >> tmpfile
cat test3 | uuencode test3.csv >> tmpfile


cat tmpfile | mailx -s "Files" mailid

but i want to create one main csv file in which test1,test2,test3 will be in the tabed format( in windows it is function fnUpdateTabs() )
rather creating multiple attachment.

is it possible?

any kind of help will be appriciated.
Thanks
Reply With Quote
  #5 (permalink)  
Old 04-19-08, 13:46
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Fort Polk, LA
Posts: 500
but i want to create one main csv file in which test1,test2,test3 will be in the tabed format( in windows it is function fnUpdateTabs() )
rather creating multiple attachment.


The CSV file format doesn't allow for multiple tabs; you need a proper spreadsheet format for that.

Spreadsheet::WriteExcel helps here...

Code:
use Spreadsheet::WriteExcel; use strict; my $book = Spreadsheet::WriteExcel->new('tabs.xls'); for my $csv (@ARGV) { my $row = 0; my $sheet = $book->add_worksheet($csv); open(my $handle, "<", $csv); while(my $rowstr = <$handle>) { chomp $rowstr; #remove trailing newline my $col = 0; for my $cell (split /,/, $rowstr) { $sheet->write($row, $col++, $cell); } $row++; } close $handle; } $book->close();

That'll get you 90% there, generating a real Excel spreadsheet with multiple tabs, but naturally the last 10% is 90% of the work. Oh, and you can't use *.csv on the command line, just specify each file individually or use the glob function in the perl code.

Last edited by sco08y : 04-19-08 at 14:00.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On