Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2008
    Posts
    8

    Unanswered: 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

  2. #2
    Join Date
    Feb 2008
    Posts
    8
    So no one!!!!!!!!

  3. #3
    Join Date
    Oct 2002
    Location
    Baghdad, Iraq
    Posts
    697
    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.

    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.

  4. #4
    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

  5. #5
    Join Date
    Oct 2002
    Location
    Baghdad, Iraq
    Posts
    697
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •