John Plum wrote:
HI Folk,

Hello,


May I introduce myself, John Plumridge, London, UK.

John W. Krahn, Vancouver, Canada.


      - I'm still in awe of this whole creation we're in.

Life?


Nice to meet you.

And very nice to meet you as well.


I have a reason of course, for approaching you, via my MTNews 'console'.
What a great application!

MY problem is obtaining and passing text/html from file to a scalar variable to be printed to mail, (using MIME::Creator).

Unfortunately I get: 'printFile(FileHandle=GLOB(0x84b66b8))'

The reference assigned to the scalar variable is from a FileHandle sub routine. However, with a similar reference to sub routines, i.e. OrderFromForm_html(), I get the output printed to mail without a problem. That sub routine is perl processed form data passed from a preceding visible page in browser - 'form.html')
With mixed success then, I'v worked hard at this. Take a look:

###----signature (html)from external file----###

my $signature_file = "/path_to/signature.html";

use FileHandle;

You would probably be better off using IO::Handle and the three argument open instead:

$ perl -MFileHandle -le'open my $FH, "<", ".perlsig3" or die $!; my $x = $FH->getline; print for keys %INC'
warnings/register.pm
XSLoader.pm
IO/Handle.pm
SelectSaver.pm
IO/Seekable.pm
warnings.pm
Fcntl.pm
IO.pm
Symbol.pm
Carp.pm
Exporter/Heavy.pm
File/Spec/Unix.pm
FileHandle.pm
strict.pm
Exporter.pm
vars.pm
File/Spec.pm
IO/File.pm

$ perl -MIO::Handle -le'open my $FH, "<", ".perlsig3" or die $!; my $x = $FH->getline; print for keys %INC'
XSLoader.pm
Carp.pm
IO/Handle.pm
Exporter.pm
strict.pm
SelectSaver.pm
warnings.pm
Symbol.pm
IO.pm

It looks like it imports a lot less stuff.


   my $signature = new FileHandle;
$signature->open("<$signature_file")or die "Could not open file\n";

use IO::Handle;

open my $signature, '<', $signature_file or die "Could not open '$signature_file' $!";


sub printFile($) {

You should not be using prototypes, they don't really do what you may think that they do: http://www.perl.com/language/misc/fmproto.html


 my $fileHandle = $_[0];
    while (<$fileHandle>) {
        my $line = $_;

That is usually written as:

    while ( my $line = <$fileHandle> ) {

Why assign to the $_ variable when you are not going to use it?


        chomp($line);
        print "$line\n";

Why remove the newline with chomp() just to add it back when you print?


$fileHandle->close(); # automatically closes file

Did you really want to close the filehandle after reading one line?


    }
}



#---Assemble/concatenate references in both ascii and html, to make full confirmatory message bodies with order details---

$scalar_sig = "\printFile($signature)";

You can not call a subroutine from inside a string. Just the $signature variable and the backslash get interpolated.

$scalar_sig = printFile( $signature );

But that won't work because printFile() does not return anything, it just prints to the STDOUT stream.

Perhaps you want something more like:

use IO::Handle;
open my $signature, '<', $signature_file or die "Could not open '$signature_file' $!";
my $scalar_sig = $signature->getline;  # read just one line
$signature->close;


Or perhaps:

use IO::Handle;
open my $signature, '<', $signature_file or die "Could not open '$signature_file' $!";
$signature->read( my $scalar_sig, -s $signature );  # read the whole file
$signature->close;


my $customer_msg_html = $customer_msgStart_html . OrderFromForm_html() . $customer_msgEnd_html . $scalar_sig;

#---- Create Message ---

    Email::MIME->create(
        attributes => {
            content_type => "text/html",
            charset      => "UTF-8",
            encoding     => "quoted-printable",
            format       => "flowed",
        },
        body => $customer_msg_html,
    ),


################
So, as I suggested, the message arrives with the body message all nicely concatenated , except for the $scalar_sig variable, which is moissing: and I have the 'printFile(FileHandle=GLOB(0x84b66b8))' as a nice fat error.

I would really appreciate your help, and outright suggestions, as I have struggled with is and tests for three days now, (but I have got a lot of the work done (: - though this problem has me stumped)!



John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to