in reply to Re: Re: Re: Software Error: Close.pm
in thread Software Error: Close.pm

Hey bob thanks for your previous response as it helped HEAPS!! I am now recieving this error which I am not sure why??
syntax error at enquiry02.pl line 25, near "$mailer open"


It doesn't like that line were you open the headers. Here is my code so far. I reckon it looks ok but I only a newbie so it properly aint. Can you or anyone see what I did or am doing wrong in a simple terms as you can??? Thanks fellas
#!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use Mail::Mailer; my $query = CGI->new(); my @param = qw( Title Name Position School Address Suburb State PCode Email Tel Fax Comments ); my $mailer = new Mail::Mailer; my %headers = ( To => 'test@tester.com', From => 'test', Subject => 'test send stuff', ); $mailer open(\%headers); my $body = ( print $mailer $query->param('Title'), print $mailer $query->param('Name'), print $mailer $query->param('Position'), print $mailer $query->param('School'), print $mailer $query->param('Address'), print $mailer $query->param('Suburb'), print $mailer $query->param('State'), print $mailer $query->param('PCode'), print $mailer $query->param('Email'), print $mailer $query->param('Tel'), print $mailer $query->param('Fax'), print $mailer $query->param('Comments'), ); print $mailer $body; $mailer->close; print $query->redirect('http://www.travancoresch.vic.edu.au/developmen +t/reply02.html');

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Software Error: Close.pm
by bobn (Chaplain) on Aug 22, 2003 at 04:49 UTC

    syntax error at enquiry02.pl line 25, near "$mailer open"

    This happened because you said:

    $mailer open(\%headers);
    when what was needed was:
    $mailer->open(\%headers);

    open, by itself, is a function defined in the core of perl, used for 'opening' files for reading, writing, etcetera. It wants a file handle, a filename, and possibly a mode, but you gave it a hashref. (And preceded it with $mailer by itself, which is puzzling at best or a syntax error at worst). But $mailer->open() is something else entirely. Because you said my $mailer = new Mail::Mailer;, $mailer is now an object of type Mail::Mailer. The module Mail::Mailer actually defines a routine named open() - same name, seemingly as the core function open() - but if you say $mailer->open(), perl looks at the type of $mailer, sees that it's Mail::Mailer, and uses the open() function defined in that module instead.

    You should check out some doc, like:

    perldoc perlboot
    perldoc perltoot
    
    Look elsewher on this site for tutorials on this subject as well.

    Also, your code still has a problem. Specifically,

    my $body = ( print $mailer $query->param('Title'), print $mailer $query->param('Name'), print $mailer $query->param('Position'), print $mailer $query->param('School'), print $mailer $query->param('Address'), print $mailer $query->param('Suburb'), print $mailer $query->param('State'), print $mailer $query->param('PCode'), print $mailer $query->param('Email'), print $mailer $query->param('Tel'), print $mailer $query->param('Fax'), print $mailer $query->param('Comments'), ); print $mailer $body;
    is wrong. I suggest you go to your command line, issue:
    perldoc Mail::Mailer
    
    and read what comes up,

    (All code given here is UNTESTED unless otherwise stated.)

    --Bob Niederman, http://bob-n.com