[22259] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4480 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 29 06:05:47 2003

Date: Wed, 29 Jan 2003 03:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 29 Jan 2003     Volume: 10 Number: 4480

Today's topics:
    Re: array slicing <thens@nospam.com>
    Re: array slicing <bart.lateur@pandora.be>
    Re: array slicing <thens@nospam.com>
    Re: array slicing (Anno Siegel)
    Re: array slicing <thens@nospam.com>
    Re: array slicing (Anno Siegel)
    Re: cgi-lib to cgi.pm conversion (Jay Tilton)
    Re: cgi-lib to cgi.pm conversion <bart.lateur@pandora.be>
    Re: Email address RE <mbear@uq.net.au>
    Re: exec in windows question <jurgenex@hotmail.com>
    Re: exec in windows question (Sisyphus)
    Re: exec in windows question <bart.lateur@pandora.be>
        ftp and telnet: 3 months old to PERL <b_rangananathan@hotmail.com>
    Re: ftp and telnet: 3 months old to PERL <tassilo.parseval@localhost.localhost>
    Re: How to close all ports ??? <dwayne@hotmail.com>
        How to search a file (newbie) <dmuren@start.no>
    Re: How to search a file (newbie) <bernard.el-hagin@DODGE_THISlido-tech.net>
        Need help with sendmail routine <file attachments> (Tara)
    Re: Need help with sendmail routine <file attachments> <bigj@kamelfreund.de>
    Re: Need help with sendmail routine <file attachments> <bigj@kamelfreund.de>
    Re: Need Perl Web-based email script <dalehend@softhome.net>
    Re: Newbie looking for direction <bongie@gmx.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 29 Jan 2003 09:58:06 +0530
From: Thens <thens@nospam.com>
Subject: Re: array slicing
Message-Id: <20030129095806.4834fb35.thens@nospam.com>

On 28 Jan 2003 19:34:11 GMT
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

> Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> > Thens (thens@nospam.com) wrote on MMMCDXXXVII September MCMXCIII in
> > <URL:news:20030128193145.38a3ac7c.thens@nospam.com>:
> > []  Hi,  
> > []      I want a simplistic solution to a problem that i have in slicing
> > []  array.
> > []  
> > []  #! /usr/local/bin/perl -w
> > []  
> > []  use strict;
> > []  
> > []  # NUMBERS in order
> > []  my @numbers = ( 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE' ) 
> > []  
> > []  # I want to print numbers greater than or equal to three
> > []  # I expect a magical operation to return me the elements in the list after T
> > []  
> > []  print join(' ', <your code operating on @numbers>);
> > 
> > 
> > print "@{[do {my $c; grep {$c || $_ eq 'THREE' && ++ $c} @numbers}]}\n";
> 
>   print "@{[grep { $_ eq 'THREE' .. !defined }  @numbers]}\n";

    Thanks a bunch. This was what i was looking for ..

Regards
Thens.


------------------------------

Date: Wed, 29 Jan 2003 08:17:08 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: array slicing
Message-Id: <6f3f3v4dtfitismp6tcukgls4jfrcq5dk6@4ax.com>

Thens wrote:

>But i was looking for
>something that will just take the element and find out the offset by
>itself.

Eh? You want a script that understands English? "THREE" is not a number.

-- 
	Bart.


------------------------------

Date: Wed, 29 Jan 2003 13:56:02 +0530
From: Thens <thens@nospam.com>
Subject: Re: array slicing
Message-Id: <20030129135602.09efba24.thens@nospam.com>

On Wed, 29 Jan 2003 08:17:08 GMT
Bart Lateur <bart.lateur@pandora.be> wrote:

> Thens wrote:
> 
> >But i was looking for
> >something that will just take the element and find out the offset by
> >itself.
> 
> Eh? You want a script that understands English? "THREE" is not a number.


  Not exactly! That was a simple example to make things clear. My point
was 'i have the element but not the offset'. 

> -- 
> 	Bart.


------------------------------

Date: 29 Jan 2003 08:44:39 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: array slicing
Message-Id: <b1849n$9hl$1@mamenchi.zrz.TU-Berlin.DE>

Thens  <thens@nospam.com> wrote in comp.lang.perl.misc:
> On 28 Jan 2003 19:34:11 GMT
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> 
> > Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> > > Thens (thens@nospam.com) wrote on MMMCDXXXVII September MCMXCIII in
> > > <URL:news:20030128193145.38a3ac7c.thens@nospam.com>:
> > > []  Hi,  
> > > []      I want a simplistic solution to a problem that i have in slicing
> > > []  array.
> > > []  
> > > []  #! /usr/local/bin/perl -w
> > > []  
> > > []  use strict;
> > > []  
> > > []  # NUMBERS in order
> > > []  my @numbers = ( 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE' ) 
> > > []  
> > > []  # I want to print numbers greater than or equal to three
> > > []  # I expect a magical operation to return me the elements in the
> list after T
> > > []  
> > > []  print join(' ', <your code operating on @numbers>);
> > > 
> > > 
> > > print "@{[do {my $c; grep {$c || $_ eq 'THREE' && ++ $c} @numbers}]}\n";
> > 
> >   print "@{[grep { $_ eq 'THREE' .. !defined }  @numbers]}\n";
> 
>     Thanks a bunch. This was what i was looking for ..

Oh dear.  Please consider using something slightly less obscure, even
it may be longer.

Anno


------------------------------

Date: Wed, 29 Jan 2003 15:19:55 +0530
From: Thens <thens@nospam.com>
Subject: Re: array slicing
Message-Id: <20030129151955.240c0937.thens@nospam.com>

On 29 Jan 2003 08:44:39 GMT
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

> Thens  <thens@nospam.com> wrote in comp.lang.perl.misc:
> > On 28 Jan 2003 19:34:11 GMT
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> > 
> > > Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> > > > Thens (thens@nospam.com) wrote on MMMCDXXXVII September MCMXCIII in
> > > > <URL:news:20030128193145.38a3ac7c.thens@nospam.com>:
> > > > []  Hi,  
> > > > []      I want a simplistic solution to a problem that i have in slicing
> > > > []  array.
> > > > []  
> > > > []  #! /usr/local/bin/perl -w
> > > > []  
> > > > []  use strict;
> > > > []  
> > > > []  # NUMBERS in order
> > > > []  my @numbers = ( 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE' ) 
> > > > []  
> > > > []  # I want to print numbers greater than or equal to three
> > > > []  # I expect a magical operation to return me the elements in the
> > list after T
> > > > []  
> > > > []  print join(' ', <your code operating on @numbers>);
> > > > 
> > > > 
> > > > print "@{[do {my $c; grep {$c || $_ eq 'THREE' && ++ $c} @numbers}]}\n";
> > > 
> > >   print "@{[grep { $_ eq 'THREE' .. !defined }  @numbers]}\n";
> > 
> >     Thanks a bunch. This was what i was looking for ..
> 
> Oh dear.  Please consider using something slightly less obscure, even
> it may be longer.
   

   Basically, Iam learning perlish way of doing things and this one will
never be used in my 'production worthy code'.



> Anno


------------------------------

Date: 29 Jan 2003 10:26:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: array slicing
Message-Id: <b18a8d$duv$1@mamenchi.zrz.TU-Berlin.DE>

Thens  <thens@nospam.com> wrote in comp.lang.perl.misc:
> On 29 Jan 2003 08:44:39 GMT
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> 
> > Thens  <thens@nospam.com> wrote in comp.lang.perl.misc:
> > > On 28 Jan 2003 19:34:11 GMT
> > > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> > > 
> > > > Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> > > > > Thens (thens@nospam.com) wrote on MMMCDXXXVII September MCMXCIII in
> > > > > <URL:news:20030128193145.38a3ac7c.thens@nospam.com>:
> > > > > []  Hi,  
> > > > > []      I want a simplistic solution to a problem that i have in slicing
> > > > > []  array.
> > > > > []  
> > > > > []  #! /usr/local/bin/perl -w
> > > > > []  
> > > > > []  use strict;
> > > > > []  
> > > > > []  # NUMBERS in order
> > > > > []  my @numbers = ( 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE' ) 
> > > > > []  
> > > > > []  # I want to print numbers greater than or equal to three
> > > > > []  # I expect a magical operation to return me the elements in the
> > > list after T
> > > > > []  
> > > > > []  print join(' ', <your code operating on @numbers>);
> > > > > 
> > > > > 
> > > > > print "@{[do {my $c; grep {$c || $_ eq 'THREE' && ++ $c} @numbers}]}\n";
> > > > 
> > > >   print "@{[grep { $_ eq 'THREE' .. !defined }  @numbers]}\n";
> > > 
> > >     Thanks a bunch. This was what i was looking for ..
> > 
> > Oh dear.  Please consider using something slightly less obscure, even
> > it may be longer.
>    
> 
>    Basically, Iam learning perlish way of doing things and this one will
> never be used in my 'production worthy code'.

Well, it isn't quite correct either.  If @numbers contains undefined
elements, it will stop listing there.  It may be utterly perlish, but
it is not the perlish way of doing things.

Anno


------------------------------

Date: Wed, 29 Jan 2003 03:49:50 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: cgi-lib to cgi.pm conversion
Message-Id: <3e374e96.230728581@news.erols.com>

"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote:

: Have you heard of indenting?

Or perltidy?



------------------------------

Date: Wed, 29 Jan 2003 08:25:59 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: cgi-lib to cgi.pm conversion
Message-Id: <ps3f3vsrp37u516jfdv31jo1ad3j1eb38j@4ax.com>

Todd Anderson wrote:

>The search routine below was written using cgi-lib.pl. I am trying to
>convert it to use cgi.pm. It is not returning any found items as is.
>Even with no search parameters.
>Any help is appreciated and thanks in advance.

Converting from cgi-lib.pl to CGI.pm is the easy part: CGI.pm has a
compatibility mode. See the docs for CGI.pm, section "COMPATIBILITY WITH
CGI-LIB.PL".

-- 
	Bart.


------------------------------

Date: Wed, 29 Jan 2003 16:25:22 +1000
From: Matthew Braid <mbear@uq.net.au>
Subject: Re: Email address RE
Message-Id: <b17s4i$b6v$1@bunyip.cc.uq.edu.au>

Gee, fleeble is a perfectly valid email address. Maybe on your local 
server (in which case fleeble@localhost would be better), but that 
doesn't help at all if you're trying to parse and verify, say, the From 
field of a message. (In fact, try to find a single word in the last 2 
sentences that _isn't_ a 'perfectly valid email address', other than 
"doesn't" and "you're"). I'm sorry, but if Mail::Address is just going 
to return words its of no use. I might as well just do a split.

I've managed to find Email::Find on CPAN which hopefully will be more 
useful (as soon as I read the caveat I knew at least the author of that 
particular package knew what the difference between a word and an email 
address is).

Thanks Helgi for pointing out the FAQ.

MB



------------------------------

Date: Wed, 29 Jan 2003 02:17:57 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: exec in windows question
Message-Id: <pRGZ9.20784$uR.9507@nwrddc01.gnilink.net>

Don wrote:
> The commands shown below are running, however, I have to close the
> first calc window before the second notepad command will run. example
> system (calc);
> system (notepad);

That's the expected behaviour. 'system' calls the external command and waits
until it is finished before continuing with the rest of the Perl script.

> If I use exec, the script exits after the first line is run.  example
>
> exec "calc";
> exec "notepad";

Not exactly. The first "exec" replaces the Perl script with the calc
program. When calc finishes there is nothing the control flow could return
to.

> There was mention of using the back ticks or wacks `` - but I was
> unable to make use of those as well.

Those are used if you want to capture the output of an external program.

> Any ideas would be greatly appreciated.  Essenially, I'd like to get
> the first command (calc) to execute and then the second command
> (notepad) to execute without having to close the calc window.  I
> actually have about five .exe commands I need to run from the script.
> Yeah, I'm new at this. Thanks for any help.

Actually you problem is not so much a Perl issue as more a lack of knowledge
about processes and how to invoke them.

There are two common ways to approach this:
- either use "system" and simply start the external program in the
background, jsut as you would do from the command line. In a normal (UNIX)
shell this would be done by appending a simple "&" to the end of the
command. On Windows use the command "start" to start the program:
    system ("start foo.exe");

- Or "fork" a new process before "exec"-ing the external command in the
child process. Then parent continues the main program and is ready to fork
and exec more children.

jue




------------------------------

Date: 28 Jan 2003 21:32:43 -0800
From: kalinabears@hdc.com.au (Sisyphus)
Subject: Re: exec in windows question
Message-Id: <e615828f.0301282132.ad5de70@posting.google.com>

dgnaismith@yahoo.com (Don) wrote in message news:<e0f580c3.0301281541.73a0e76@posting.google.com>...
> I've looked in the FAQ and perldocs and am having a difficult time
> finding the answer to the following problem.  Also searched the
> newsgroups.
> 
> 
> I'm trying to run a perl script in windows using wperl.exe thus
> keeping the user from seeing a DOS type window.  That part seems to
> works well.
> 
> The commands shown below are running, however, I have to close the
> first calc window before the second notepad command will run. example
> 
> system (calc);
> system (notepad);
> 
> If I use exec, the script exits after the first line is run.  example
> 
> exec "calc";
> exec "notepad";
> 
> In the above example notepad does not run and this is the norm from
> what I've read.
> 
> There was mention of using the back ticks or wacks `` - but I was
> unable to make use of those as well.
> 
> Any ideas would be greatly appreciated.  Essenially, I'd like to get
> the first command (calc) to execute and then the second command
> (notepad) to execute without having to close the calc window.  I
> actually have about five .exe commands I need to run from the script. 
> Yeah, I'm new at this. Thanks for any help.
> 
> Don

If I've got it right, you want to run:

system("start calc");
system("start notepad");

If that's not what you're after, then you might also take a look at
the Spawn() function (from Win32.pm) and the Win32::Process module -
its Create() function in particular.

Cheers,
Rob


------------------------------

Date: Wed, 29 Jan 2003 08:38:59 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: exec in windows question
Message-Id: <v24f3vg973l1qv7de586lc4ckajainj69u@4ax.com>

Don wrote:

>Any ideas would be greatly appreciated.  Essenially, I'd like to get
>the first command (calc) to execute and then the second command
>(notepad) to execute without having to close the calc window.  I
>actually have about five .exe commands I need to run from the script. 

Use an API call to start up the programs. See the docs for the module
"Win32::Process".

<http://aspn.activestate.com/ASPN/Reference/Products/ActivePerl/site/lib/Win32/Process.html>

You may have to install this module first. You're new at this, huh? Go
to the command line (DOS window), type "PPM install Win32-Process", and
if you're in luck, it'll just fetch the module from the internet
(provided your computer has a live connection) and install it.

There is also other sample code available on internet, if the synopsis
isn't too clear (and IMO it isn't).

One thing to keep in mind is that Win32::Process::Create() creates a
process object and *returns* it in the first parameter, which must be an
LValue (say, a scalar variable) which doesn't need to be set before the
call -- it'll be set afterwards. Why this unintuitive syntax was chosen,
I have no idea. It should have been a function call. But maybe that's
just my opinion.

-- 
	Bart.


------------------------------

Date: Wed, 29 Jan 2003 08:15:30 GMT
From: "Bharathi" <b_rangananathan@hotmail.com>
Subject: ftp and telnet: 3 months old to PERL
Message-Id: <C4MZ9.11118$to3.9881@rwcrnsc51.ops.asp.att.net>

All,
Any idea of  how to do automatic ftp in PERL.  I am PC at office.  I have a
bunch of files in th unix systetm that needs to  send to a  ftp server . Is
there anway way I can write a PERL script run it on my  PC ( Have PERL
installed) its over. Any help is appeciated.


1.myfile.txt (UNIX system)
2.Use PERL to move it to the ftp server  ( Any help here. Have no clue how
to do)
3. Crypt the file( myfile.txt->myfile.txt.gpg) on the ftp server by doing a
telnet using PERL ( Any help?)

TIA
Bharath









------------------------------

Date: 29 Jan 2003 08:45:43 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@localhost.localhost>
Subject: Re: ftp and telnet: 3 months old to PERL
Message-Id: <slrnb3f55i.18b.tassilo.parseval@localhost.localhost>

Also sprach Bharathi:

> Any idea of  how to do automatic ftp in PERL.  I am PC at office.  I have a
> bunch of files in th unix systetm that needs to  send to a  ftp server . Is
> there anway way I can write a PERL script run it on my  PC ( Have PERL
> installed) its over. Any help is appeciated.

It's either Perl (the language) or perl (the actual interpreter), but
never PERL.

> 1.myfile.txt (UNIX system)
> 2.Use PERL to move it to the ftp server  ( Any help here. Have no clue how
> to do)

    perldoc Net::FTP

Since it appears to be a text file, be sure to set transfer mode to
ascii (might not be necessary when transferring the file between two
systems with the same newline semantics).

> 3. Crypt the file( myfile.txt->myfile.txt.gpg) on the ftp server by doing a
> telnet using PERL ( Any help?)

    perldoc Net::Telnet

Use it to connect to the remote host and issue the commands necessary to
encrypt the file.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


------------------------------

Date: Wed, 29 Jan 2003 06:13:53 GMT
From: David Wayne <dwayne@hotmail.com>
Subject: Re: How to close all ports ???
Message-Id: <43se3v42klqmdqskpj0hnbjjgf77k1cee0@4ax.com>


I did read what I could fins at perldoc, and I set reuse to 1 when
starting the socket because that seemed to be the best choice.

But I ran it and it sat there listening but I could not get my
client-side program to connect, eventually I aborted the script and
now get an internal error when trying to re-run it (with no changes),
so I assume it is because it is still "open and I need to know how to
close it.



David Wayne wrote:
| I am currently writing a script which opens ports using IO::socket,
| but if the script is aborted, I cannot run the script again because
| the port I used is still open.
|
| Any suggestions ?
|

Check IO::Socket's documentation for the "Reuse" setting.


-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+Ny+aeS99pGMif6wRAtCjAJoDAFpMtOTINGb2PiLZM6qRttoiUACgnEo2
APh0BYQ9ZkRDIvuZlQUbPG0=
=bpfA
-----END PGP SIGNATURE-----



------------------------------

Date: Wed, 29 Jan 2003 10:00:57 +0100
From: "Djm" <dmuren@start.no>
Subject: How to search a file (newbie)
Message-Id: <dLMZ9.21372$Rc7.298367@news2.e.nsc.no>

hey...

I need some help to make a perl-script to search a big file.
Consider the text below. The utv2:3 and utv2:4 are unike. I want to be able
to search the file for these unike utvs that I put into the script. I also
want to print the all text between f.eks. utv2:3 and utv2:4.
Anyone care to give me a hand?
Thanks
---
the file contains text in this format
---

ajsdlf

dsgga lasdgj gasg

utv2:3 asldf fasdløfk asldøgi ds
lsdkg
slg
s
utv2:4 sldfj sdlfkj  laksdj

----

Dave




------------------------------

Date: Wed, 29 Jan 2003 10:17:31 +0100
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: How to search a file (newbie)
Message-Id: <4r6f3vk1lrjujf06t4oj4fhcl7mi03mjhl@4ax.com>

On Wed, 29 Jan 2003 10:00:57 +0100, "Djm" <dmuren@start.no> wrote:

>hey...
>
>I need some help to make a perl-script to search a big file.
>Consider the text below. The utv2:3 and utv2:4 are unike. I want to be able
>to search the file for these unike utvs that I put into the script.


You're not very clear on what you want. Do you just want to find the
strings 'utv2:3' and 'utv2:4' in the file? If so then use the match
operator 'm//'. Find out how in the docs:


  perldoc perlop


>I also want to print the all text between f.eks. utv2:3 and utv2:4.


This is a task well suited for the range operator '..'. Read about it
in the same place:


  perldoc perlop


>Anyone care to give me a hand?


Read the perlop manpage and try to whip up something yourself. If it
doesn't work the way you want let us know what the problem is and
we'll help you fix it.

[snipped example data]



Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


------------------------------

Date: 29 Jan 2003 00:52:35 -0800
From: tararse@hotmail.com (Tara)
Subject: Need help with sendmail routine <file attachments>
Message-Id: <27eb673f.0301290052.c026466@posting.google.com>

Hello, I have this simple script that is submitted from a form that I
want to add file attachments too.  How can I work in this process
under the sub SendSubmission routine?  I know it has something to do
with encode_base64, but I have no idea on how to implement this.  Can
someone please help?

Thank you. 

Tara Rose



#!/usr/bin/perl

$ErrorPage = "http://www.mydomain.com/error.htm";

$ThankPage = "http://www.mydomain.com/send.htm";

$Referer = "http://www.mydomain.com/";

$Subject = "Message Header One";
$Subject1 = "Message Header Two";

# E-mail address to send intake form to (your address)
# If not using PERL 5, escape the @ thus: \@ instead of @ 
$YourEmail = 'myemail@test.com';

# Script works only on your server(s) - ('URL1','URL2')
@referers = ('www.mydomain.com','mydomain.com');

# Location of mail program - check your doc or ask admin
$MailProgram = '/usr/sbin/sendmail -i -t';

# Brief message for body of e-mail autoreply
$Message = "This is a test.";

# Your signature lines the end of the autoreply e-mail
$Message1 = "Thank you.";

$Signature2 = "";

&CheckReferingURL;
&ReadParse;
$first_name = $in{'first_name'};
$last_name = $in{'last_name'};
$phone_number = $in{'phone_number'};
$city = $in{'city'};
$state = $in{'state'};
$province = $in{'province'};
$country_name = $in{'country_name'};
$Email = $in{'Email'};
$Message = $in{'Message'};
&CheckEmailAddressFormat;
&CheckFields;
&GetDate;
&SendSubmission;
&SendAutoReply;
print "Location: $ThankPage\n\n";
exit;

# _________________________________________________________

sub SendSubmission {
open (MAIL,"|$MailProgram -t");
print MAIL "To: $YourEmail\n";
print MAIL "From: $Email\n";
print MAIL "Subject: $Subject1\n";
print MAIL "First Name: $first_name\n";
print MAIL "Last Name: $last_name\n";

close (MAIL);
}

# _________________________________________________________

sub SendAutoReply {
open (MAIL,"|$MailProgram -t");
print MAIL "To: $Email\n";
print MAIL "From: $YourEmail\n";
print MAIL "Subject: $Subject\n";
print MAIL "$Message1\n\n";

close (MAIL);
}

# _________________________________________________________

sub GetDate {
@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
@months = ('01','02','03','04','05','06','07','08','09','10','11','12');
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
$year = $year+1900;
$Date = "$days[$wday] $months[$mon]/$mday/$year";
}

# _________________________________________________________

sub ReadParse { local (*in) = @_ if @_; 
local ($i, $key, $val); if ( $ENV{'REQUEST_METHOD'} eq "GET" ) 
{$in = $ENV{'QUERY_STRING'};} 
elsif ($ENV{'REQUEST_METHOD'} eq "POST") 
{read(STDIN,$in,$ENV{'CONTENT_LENGTH'});} 
else { 
$in = ( grep( !/^-/, @ARGV )) [0];
$in =~ s/\\&/&/g; } @in = split(/&/,$in);
foreach $i (0 .. $#in) { 
$in[$i] =~ s/\+/ /g; 
($key, $val) = split(/=/,$in[$i],2); 
$key =~ s/%(..)/pack("c",hex($1))/ge; 
$val =~ s/%(..)/pack("c",hex($1))/ge; 
$in{$key} .= "\0" if (defined($in{$key})); 
$in{$key} .= $val; } return length($in); }

# _________________________________________________________

sub CheckEmailAddressFormat {
if (index($Email, "@") < 1)  {&DoEmailError;}
if (index($Email, ".") < 1)  {&DoEmailError;}
if (index($Email, " ") > -1) {&DoEmailError;}
}
sub CheckFields {

if (!$first_name || $first_name eq ' ') {&DoEmailError;}
if (!$last_name || $last_name eq ' ') {&DoEmailError;}

}
sub DoEmailError {
print "Location: $ErrorPage\n\n";
exit;
}

# _________________________________________________________

sub CheckReferingURL {
if ($ENV{'HTTP_REFERER'}) {
foreach $referer (@referers) {
if ($ENV{'HTTP_REFERER'} =~ /$referer/i) {
$check_referer = '1';
last;
}}}
else {$check_referer = '1';}
if ($check_referer != 1) {
print "Location: $Referer\n\n";
exit;
}}

# _________________________________________________________

exit;

##### End-of-Script #######################


------------------------------

Date: Wed, 29 Jan 2003 10:08:59 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Need help with sendmail routine <file attachments>
Message-Id: <pan.2003.01.29.08.49.18.258003@kamelfreund.de>

On Wed, 29 Jan 2003 00:52:35 +0000, Tara wrote:

> Hello, I have this simple script that is submitted from a form that I
> want to add file attachments too.  How can I work in this process
> under the sub SendSubmission routine?  I know it has something to do
> with encode_base64, but I have no idea on how to implement this.  Can
> someone please help?

I would recommend to use any of the Mail::
modules.

As there also some other thing odd,
I'll try to give some hints.

> #!/usr/bin/perl

use strict;
use warnings;

> 
> [snipped some declarations]
> 
> sub SendSubmission {
> open (MAIL,"|$MailProgram -t");

_Always_ check the result of an open statement:
open MAIL, "|$MailProgram -t" or die "Couldn't open $MailProgram";

> print MAIL "To: $YourEmail\n";
> print MAIL "From: $Email\n";
> print MAIL "Subject: $Subject1\n";
Here's a shorter way to express it:

print MAIL <<HEADER;
To: $YourEmail
From: $Email
Subject: $Subject1
HEADER


Or 

print MAIL join "\n", "To: $YourMail",
                      "From: $Email",
                      "Subject: $Subject1";

> print MAIL "First Name: $first_name\n";  
> print MAIL "Last Name: $last_name\n";    
                                           
Are you sure that these fields are valid fields for an email header ?

> [...]
> 
> sub GetDate {
> @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
> @months = ('01','02','03','04','05','06','07','08','09','10','11','12');
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> localtime(time);
> $year = $year+1900;
> $Date = "$days[$wday] $months[$mon]/$mday/$year";
> }

A simpler way to get that date format is the POSIX way:
use POSIX qw/strftime/;

my $date = strftime "%A %B/%d/%Y", localtime;

> 
> # _________________________________________________________
> 
> sub ReadParse { local (*in) = @_ if @_; 
> local ($i, $key, $val); if ( $ENV{'REQUEST_METHOD'} eq "GET" ) 
> {$in = $ENV{'QUERY_STRING'};} 
> elsif ($ENV{'REQUEST_METHOD'} eq "POST") 
> {read(STDIN,$in,$ENV{'CONTENT_LENGTH'});} 
> else { 
> $in = ( grep( !/^-/, @ARGV )) [0];
> $in =~ s/\\&/&/g; } @in = split(/&/,$in);
> foreach $i (0 .. $#in) { 
> $in[$i] =~ s/\+/ /g; 
> ($key, $val) = split(/=/,$in[$i],2); 
> $key =~ s/%(..)/pack("c",hex($1))/ge; 
> $val =~ s/%(..)/pack("c",hex($1))/ge; 
> $in{$key} .= "\0" if (defined($in{$key})); 
> $in{$key} .= $val; } return length($in); }
> 

That's really something for that modules like CGI or URI are done for.

> # _________________________________________________________
> 
> sub CheckEmailAddressFormat {
> if (index($Email, "@") < 1)  {&DoEmailError;}
> if (index($Email, ".") < 1)  {&DoEmailError;}
> if (index($Email, " ") > -1) {&DoEmailError;}
> }

A good module checking email addresses is e.g.
Email::Valid

However, I've never used the index method in Perl,
as you'll nearly never need it.
If you want to assert that a variable must have an @ and a . inside,
use a regexp.

unless ($Email =~ /[@.]/) { ... }

Similiar check for a whitespace:

if ($Email =~ /\s/) { ... }

But note that a " " is a valid character in an email address,
e.g.:
"Janek Schleicher" <bigj@kamelfreund.de>



Greetings,
Janek


------------------------------

Date: Wed, 29 Jan 2003 10:08:59 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Need help with sendmail routine <file attachments>
Message-Id: <pan.2003.01.29.08.49.12.410198@kamelfreund.de>

On Wed, 29 Jan 2003 00:52:35 +0000, Tara wrote:

> Hello, I have this simple script that is submitted from a form that I
> want to add file attachments too.  How can I work in this process
> under the sub SendSubmission routine?  I know it has something to do
> with encode_base64, but I have no idea on how to implement this.  Can
> someone please help?

I would recommend to use any of the Mail::
modules.

As there also some other thing odd,
I'll try to give some hints.

> #!/usr/bin/perl

use strict;
use warnings;

> 
> [snipped some declarations]
> 
> sub SendSubmission {
> open (MAIL,"|$MailProgram -t");

_Always_ check the result of an open statement:
open MAIL, "|$MailProgram -t" or die "Couldn't open $MailProgram";

> print MAIL "To: $YourEmail\n";
> print MAIL "From: $Email\n";
> print MAIL "Subject: $Subject1\n";
Here's a shorter way to express it:

print MAIL <<HEADER;
To: $YourEmail
From: $Email
Subject: $Subject1
HEADER


Or 

print MAIL join "\n", "To: $YourMail",
                      "From: $Email",
                      "Subject: $Subject1";

> print MAIL "First Name: $first_name\n";  
> print MAIL "Last Name: $last_name\n";    
                                           
Are you sure that these fields are valid fields for an email header ?

> [...]
> 
> sub GetDate {
> @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
> @months = ('01','02','03','04','05','06','07','08','09','10','11','12');
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> localtime(time);
> $year = $year+1900;
> $Date = "$days[$wday] $months[$mon]/$mday/$year";
> }

A simpler way to get that date format is the POSIX way:
use POSIX qw/strftime/;

my $date = strftime "%A %B/%d/%Y", localtime;

> 
> # _________________________________________________________
> 
> sub ReadParse { local (*in) = @_ if @_; 
> local ($i, $key, $val); if ( $ENV{'REQUEST_METHOD'} eq "GET" ) 
> {$in = $ENV{'QUERY_STRING'};} 
> elsif ($ENV{'REQUEST_METHOD'} eq "POST") 
> {read(STDIN,$in,$ENV{'CONTENT_LENGTH'});} 
> else { 
> $in = ( grep( !/^-/, @ARGV )) [0];
> $in =~ s/\\&/&/g; } @in = split(/&/,$in);
> foreach $i (0 .. $#in) { 
> $in[$i] =~ s/\+/ /g; 
> ($key, $val) = split(/=/,$in[$i],2); 
> $key =~ s/%(..)/pack("c",hex($1))/ge; 
> $val =~ s/%(..)/pack("c",hex($1))/ge; 
> $in{$key} .= "\0" if (defined($in{$key})); 
> $in{$key} .= $val; } return length($in); }
> 

That's really something for that modules like CGI or URI are done for.

> # _________________________________________________________
> 
> sub CheckEmailAddressFormat {
> if (index($Email, "@") < 1)  {&DoEmailError;}
> if (index($Email, ".") < 1)  {&DoEmailError;}
> if (index($Email, " ") > -1) {&DoEmailError;}
> }

A good module checking email addresses is e.g.
Email::Valid

However, I've never used the index method in Perl,
as you'll nearly never need it.
If you want to assert that a variable must have an @ and a . inside,
use a regexp.

unless ($Email =~ /[@.]/) { ... }

Similiar check for a whitespace:

if ($Email =~ /\s/) { ... }

But note that a " " is a valid character in an email address,
e.g.:
"Janek Schleicher" <bigj@kamelfreund.de>



Greetings,
Janek


------------------------------

Date: Wed, 29 Jan 2003 05:09:56 -0500
From: dk henderson <dalehend@softhome.net>
Subject: Re: Need Perl Web-based email script
Message-Id: <83af3v4jb3sa8vm6jd7pqdnpasju5lgpoe@4ax.com>



What protocol(s) is supported on the mail server?

http://www.astray.com/acmemail/ supports POP3/IMAP

If it is just a local account and you have ssh access, then it is
possible to modify an existing script such as openwebmail.org to
support a local spool through remote access.



On 26 Jan 2003 15:27:46 -0800, Jean Andre Vallery
<Jean_member@newsguy.com> wrote:

>I'm trying to access my email on two domains on red hat and apache server.
>I'm running sendmail and python app called mailman. I would like to access the
>servers email without being at the server. I checked perl.org and
>cgi-resources.com .
>Anyone have a tried and true simple, and semi-secure perl script?
>Thank you
>Jean Andre Vallery
>Sarasota, Florida
>www.2453.net
>JeanVallery@BicycleMessenger.com



------------------------------

Date: Wed, 29 Jan 2003 03:06:52 +0100
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: Newbie looking for direction
Message-Id: <2838951.nWaVJ5WJrX@nyoga.dubu.de>

Kirk McElhearn wrote:
> Would anyone like to point me in the right direction: books,
> tutorials, on-line info, etc.?

In addition to what Andras already said: You can find the Perl
documentation also online at http://www.perldoc.com/.
The FAQ contains useful pointers to other sources of information,
including books.

Ciao,
        Harald
-- 
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
perl -le'$/=1;{$/++;map$/%$_||redo,@_;push@_,$/;print$/;redo}'



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 4480
***************************************


home help back first fref pref prev next nref lref last post