text html from file to a scalar and mail

2009-09-12 Thread John Plum
HI Folk,

May I introduce myself, John Plumridge, London, UK. 
  - I'm still in awe of this whole creation we're in.

Nice to meet you.


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;
   my $signature = new FileHandle;
  $signature-open($signature_file)or die Could not open 
file\n;   


sub printFile($) {
 my $fileHandle = $_[0];
while ($fileHandle) {
my $line = $_;
chomp($line);
print $line\n;
$fileHandle-close(); # automatically closes file
}
}



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

$scalar_sig = \printFile($signature);

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 P.

-- 
--
http://jakbop.nfshost.com


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




text-html from file to a message body

2009-09-12 Thread John Plum
HI Folk,

May I introduce myself, John Plumridge, London, UK. 
  - I'm still in awe of this whole creation we're in.

Nice to meet you.


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;
   my $signature = new FileHandle;
  $signature-open($signature_file)or die Could not open 
file\n;   


sub printFile($) {
 my $fileHandle = $_[0];
while ($fileHandle) {
my $line = $_;
chomp($line);
print $line\n;
$fileHandle-close(); # automatically closes file
}
}



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

$scalar_sig = \printFile($signature);

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 P.

-- 
--
http://jakbop.nfshost.com


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




Re: text html from file to a scalar and mail

2009-09-12 Thread Shlomi Fish
Hi John!

Nice to meet you, and welcome to Perl. I'll try to answer as well as I can. 
Note that I will also give you some general Perl best practices and links that 
may not be a cause of the problems you are having.

On Saturday 12 September 2009 11:32:20 John Plum wrote:
 HI Folk,
 
 May I introduce myself, John Plumridge, London, UK.
   - I'm still in awe of this whole creation we're in.
 
 Nice to meet you.
 

:-)

 
 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))'
 

This means it is a typeglob (a generic entry in the Perl 5 packages (= 
namespaces)) that is blessed into the FileHandle class. Generally, 
FileHandle is deprecated and you should use IO::Handle and friends instead.

  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;
 

It's nice that you're declaring your variables using my, but why don't you 
have the use strict; and use warnings; pragmata? See:

* http://www.perlmonks.org/?node_id=111088

* http://perl-begin.org/tutorials/perl-for-newbies/part2/#page--my--DIR

In case, they were included, you should have placed them here, so we won't be 
led into believing they were omitted from the original program.

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

You should use IO::Handle instead of File::Handle (or IO::File in your case), 
and use the three args open. It's nice you've used die.

$signature is not a good name for a filehandle - better call it $signature_fh.

 
 
 sub printFile($) {

Don't use prototypes.

  my $fileHandle = $_[0];

Accessing $_[$idx] is not very robust - you should do:


my $fileHandle = shift;


Or:


my ($fileHandle) = @_;


 while ($fileHandle) {
 my $line = $_;

Just do: 


while (my $line = $fileHandle) {


 chomp($line);
 print $line\n;
 $fileHandle-close(); # automatically closes file

You shouldn't close the fileHandle inside the line reading loop, as you won't 
be able to read from it further.

 }
 }
 
 
 
 #---Assemble/concatenate references in both ascii and html, to make full
 confirmatory message bodies with order details---
 
 $scalar_sig = \printFile($signature);

Perl won't call printFile for you from within the string. Neither will the 
print be returned to the string. 

Please do:


my $scalar_sig = slurpFile($signature);


Look at http://search.cpan.org/dist/File-Slurp/ , and there are some other 
modules on the CPAN that can do it. (like http://search.cpan.org/dist/IO-All/ 
).

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

Your style is inconsistent between camelCase, and 
underscore_separated_identifiers. 

 
 # 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)!
 

For more information see:

1. http://perl.net.au/wiki/Freenode_Sharp_Perl_FAQ

2. http://faq.perl.org/

3. http://perl-begin.org/

4. http://www.perl.org/books/beginning-perl/

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: text html from file to a scalar and mail

2009-09-12 Thread Jenda Krynicky
From: Shlomi Fish shlo...@iglu.org.il
  use FileHandle;
 my $signature = new FileHandle;
$signature-open($signature_file)or die Could not open
  file\n;
 
 You should use IO::Handle instead of File::Handle (or IO::File in your case), 
 and use the three args open. It's nice you've used die.

Nope. You should not be bothering with thatever class is at the 
moment behind the Perl filehandles and just use open() as a function. 
Not everything has to be an object

  open my $SIGNATURE, '', $signature_file
or die Could not open '$signature_file': $^E\n;

 $signature is not a good name for a filehandle - better call it $signature_fh.

I use all capitals for filehandles. Both oldstyle and lexical.

   my $fileHandle = $_[0];
 
 Accessing $_[$idx] is not very robust - you should do:
 
 
 my $fileHandle = shift;
 
 
 Or:
 
 
 my ($fileHandle) = @_;

Nope. Accessing $_[$idx] all over the place within the subroutine 
would be prone to errors and inconvenient (though sometimes 
necessary), what syntax do you use to copy the parameters into 
lexical variables is largely unimportant. And sometimes you can't 
just shift() off parameters from @_, you need to keep them there.

  my $customer_msg_html = $customer_msgStart_html  . OrderFromForm_html()
  . $customer_msgEnd_html . $scalar_sig;
 
 Your style is inconsistent between camelCase, and 
 underscore_separated_identifiers. 

Maybe there is a meaning to the underscores on some places and case 
change in others. Don't be so quick. The fact that you do not see a 
pattern from a very short example doesn't necessarily mean there 
isn't one. It may very well be too big to fit in the small cut hole 
that you see.

Jenda
= je...@krynicky.cz === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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