[18677] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 845 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 7 03:07:33 2001

Date: Mon, 7 May 2001 00:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <989219108-v10-i845@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 7 May 2001     Volume: 10 Number: 845

Today's topics:
    Re: automating ftp download using perl (Logan Shaw)
    Re: DBI and fetch <troyr@vicnet.net.au>
        dbmopen and tie <SiStie@nuclear-network.com>
    Re: dbmopen and tie (Anno Siegel)
    Re: Execute script at certain times? <goldbb2@earthlink.net>
    Re: Execute script at certain times? <carlos@plant.student.utwente.nl>
        fork, glibc and weirdness <guys@home.net>
    Re: fork, glibc and weirdness <jfreeman@tassie.net.au>
    Re: fork, glibc and weirdness <guys@home.net>
        getting line by line from $ (Robert Wedge)
    Re: Help on optimization wanted (Abigail)
    Re: Help on optimization wanted (Gwyn Judd)
    Re: Help slim down Perl code <joe+usenet@sunstarsys.com>
    Re: Help slim down Perl code <uri@sysarch.com>
    Re: Help slim down Perl code (Anno Siegel)
    Re: Help with a script <goldbb2@earthlink.net>
    Re: How to execute a perl script from a perl script? -  <jfreeman@tassie.net.au>
    Re: Multi-Line Text Editor <goldbb2@earthlink.net>
    Re: Multi-Line Text Editor <goldbb2@earthlink.net>
        perl weirdness <ultramafic1@yahoo.com>
    Re: sessions and closures (F. Xavier Noria)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 6 May 2001 23:06:36 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: automating ftp download using perl
Message-Id: <9d570c$eb7$1@boomer.cs.utexas.edu>

In article <RYoJ6.1340$Tl2.915897@typhoon.san.rr.com>,
Dilmeet Kohli <dkohli@san.rr.com> wrote:
>I want to write a perl script to automatically down load files from ftp
>sites.

You may want to look at the Net::FTP module; see
http://search.cpan.org/search?module=Net::FTP .

  - Logan
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: Mon, 7 May 2001 16:45:15 +1000
From: "Troy Boy" <troyr@vicnet.net.au>
Subject: Re: DBI and fetch
Message-Id: <kzrJ6.2254$ZJ.84048@ozemail.com.au>

> Maybe not on the Perl/DBI side, but perhaps your database can skip the
> first 12 rows if it supports the LIMIT clause.
>
>   my $sql = "SELECT * FROM table LIMIT 13, 100"; #  pulls rows 13-100
>
Thanks..exactly what i wanted.

I didn't know limit could be used like that :)




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

Date: Sun, 6 May 2001 19:22:07 +0200
From: Simon Stiefel <SiStie@nuclear-network.com>
Subject: dbmopen and tie
Message-Id: <Pine.LNX.4.31.0105061919160.2437-100000@server.stiefel.priv>

Hi,

I have to use "dbmopen" and "tie" at the same time (for a convert-script).
But when I use the DB_File-module, dbmopen doesn't work.
I need "DB_File" for "tie".

Can somebody help me?

Thanks.


Mit freundlichen Gr=FC=DFen,        .~.     Open Minds.
with best regards               /V\             Open Sources.
                               // \\                    Open Future!
Simon Stiefel                 /(   )\_ I N U X
                               ^ ~ ^
--=20
|Simon Stiefel | Zwerbachstrasse 17 | 72555 Metzingen-Glems | Germany |
|SimonStiefel@nuclear-network.com   |  http://www.nuclear-network.com |
|ICQ#: 20196644 | phone: +49(0)7123/379070 | fax: +49(0)179/335990106 |
|Tux#: 114751 | PingoS - Linux-User helfen Schulen | Powered by LiNUX |



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

Date: 7 May 2001 05:18:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: dbmopen and tie
Message-Id: <9d5b7g$d1j$1@mamenchi.zrz.TU-Berlin.DE>

According to Simon Stiefel  <SimonStiefel@nuclear-network.com>:
> Hi,
> 
> I have to use "dbmopen" and "tie" at the same time (for a convert-script).
> But when I use the DB_File-module, dbmopen doesn't work.
> I need "DB_File" for "tie".

Why do you think you need both?  I can't think of anything you can
do with dbmopen that can't be done with tie.

Anno


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

Date: Mon, 07 May 2001 04:45:22 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Execute script at certain times?
Message-Id: <3AF629AF.128DD0FB@earthlink.net>

Abigail wrote:
> 
> Bernard El-Hagin (bernard.el-hagin@lido-tech.net) wrote on MMDCCXCIII
> September MCMXCIII in <URL:news:slrn9eacp6.bfu.bernard.el-hagin@gdndev25.lido-tech>:
> :}  On Tue, 24 Apr 2001 00:52:34 -0700, Preston Price
> :}  <pric3596@cs.uidaho.edu> wrote:
> :} >I was wondering if anyone knew of a way to have a program run at a
> :} >certain time everyday. I want something that will run at midnight
> :} >every night. Does anyone know of a way to do this?
> :} >Thanks in advance.
> :}
> :}  If you can prove that this is a Perl question I'll give you the
> :} answer.
> 
>     _:_ while ((localtime) [2] || (localtime) [1] || (localtime) [0]);
>     mid_night_run;
>     goto _;

A busy loop?  Yuck.

while(1) {
	my @t = (localtime); sleep 86400 - $t[0]+$t[1]*60+$t[2]*3600;
	&mid_night_run; }

-- 
Shift to the left, shift to the right, mask in, mask out, BYTE, BYTE,
BYTE !!!


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

Date: Mon, 7 May 2001 08:12:16 +0200
From: "carlos" <carlos@plant.student.utwente.nl>
Subject: Re: Execute script at certain times?
Message-Id: <9d5e51$etc$1@dinkel.civ.utwente.nl>

cr0n
"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3AF629AF.128DD0FB@earthlink.net...
> Abigail wrote:
> >
> > Bernard El-Hagin (bernard.el-hagin@lido-tech.net) wrote on MMDCCXCIII
> > September MCMXCIII in
<URL:news:slrn9eacp6.bfu.bernard.el-hagin@gdndev25.lido-tech>:
> > :}  On Tue, 24 Apr 2001 00:52:34 -0700, Preston Price
> > :}  <pric3596@cs.uidaho.edu> wrote:
> > :} >I was wondering if anyone knew of a way to have a program run at a
> > :} >certain time everyday. I want something that will run at midnight
> > :} >every night. Does anyone know of a way to do this?
> > :} >Thanks in advance.
> > :}
> > :}  If you can prove that this is a Perl question I'll give you the
> > :} answer.
> >
> >     _:_ while ((localtime) [2] || (localtime) [1] || (localtime) [0]);
> >     mid_night_run;
> >     goto _;
>
> A busy loop?  Yuck.
>
> while(1) {
> my @t = (localtime); sleep 86400 - $t[0]+$t[1]*60+$t[2]*3600;
> &mid_night_run; }
>
> --
> Shift to the left, shift to the right, mask in, mask out, BYTE, BYTE,
> BYTE !!!




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

Date: Mon, 07 May 2001 04:18:07 GMT
From: "Guy Smith" <guys@home.net>
Subject: fork, glibc and weirdness
Message-Id: <3mpJ6.42003$Jh5.39454053@news1.rdc1.sfba.home.com>

I am trying to get a 3rd party package working.  The package includes:

    1) An executable program (compiled C++)
    2) A PERL wrapper (Linkpoint cc auth software) that forks the executable

When I run the executable from command line I receive no errors.  When it is
forked from the PERL wrapper I get:

"error in loading shared libraries: /usr/local/linkpoint/lbin: symbol
gethostbyname_r, version GLIBC_2.1.2 not defined in file libc.so.6 with link
time reference"

So, now I get to show my ignorance.  I'm betting the executable receives the
link references from the parent.  However, I built this version of PERL
(5.6.0) on the same system and the libs were 2.1.3, not 2.1.2.

I'm not sure what to check/correct.  I do not have the source to the
executable.

ENV:    RedHat 6.2
            glibc 2.1.3
            PERL 5.6.0




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

Date: Mon, 07 May 2001 14:56:50 +1000
From: James freeman <jfreeman@tassie.net.au>
Subject: Re: fork, glibc and weirdness
Message-Id: <3AF62B12.3154EE9F@tassie.net.au>



Guy Smith wrote:

> I am trying to get a 3rd party package working.  The package includes:
>
>     1) An executable program (compiled C++)
>     2) A PERL wrapper (Linkpoint cc auth software) that forks the executable
>
> When I run the executable from command line I receive no errors.  When it is
> forked from the PERL wrapper I get:
>
> "error in loading shared libraries: /usr/local/linkpoint/lbin: symbol
> gethostbyname_r, version GLIBC_2.1.2 not defined in file libc.so.6 with link
> time reference"
>
> So, now I get to show my ignorance.  I'm betting the executable receives the
> link references from the parent.  However, I built this version of PERL
> (5.6.0) on the same system and the libs were 2.1.3, not 2.1.2.
>
> I'm not sure what to check/correct.  I do not have the source to the
> executable.
>
> ENV:    RedHat 6.2
>             glibc 2.1.3
>             PERL 5.6.0

Need to see wrapper to comment. If executable is fine as you say wrapper holds
key. No wrapper, no realistic comments possible.

James




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

Date: Mon, 07 May 2001 05:19:51 GMT
From: "Guy Smith" <guys@home.net>
Subject: Re: fork, glibc and weirdness
Message-Id: <XfqJ6.42040$Jh5.39578194@news1.rdc1.sfba.home.com>


"James freeman" <jfreeman@tassie.net.au> wrote in message
news:3AF62B12.3154EE9F@tassie.net.au...
>
>
> Guy Smith wrote:
>
> > I am trying to get a 3rd party package working.  The package includes:
> >
> >     1) An executable program (compiled C++)
> >     2) A PERL wrapper (Linkpoint cc auth software) that forks the
executable
> >
> > When I run the executable from command line I receive no errors.  When
it is
> > forked from the PERL wrapper I get:
> >
> > "error in loading shared libraries: /usr/local/linkpoint/lbin: symbol
> > gethostbyname_r, version GLIBC_2.1.2 not defined in file libc.so.6 with
link
> > time reference"
> >
> > So, now I get to show my ignorance.  I'm betting the executable receives
the
> > link references from the parent.  However, I built this version of PERL
> > (5.6.0) on the same system and the libs were 2.1.3, not 2.1.2.
> >
> > I'm not sure what to check/correct.  I do not have the source to the
> > executable.
> >
> > ENV:    RedHat 6.2
> >             glibc 2.1.3
> >             PERL 5.6.0
>
> Need to see wrapper to comment. If executable is fine as you say wrapper
holds
> key. No wrapper, no realistic comments possible.
>
> James
>

That's not possible as the wrappers are copyrighted and have
non-distribution clauses.  Scanning the code I can say the child process
creation is pretty straight forward.  There is a $pid = fork() followed by
an exec() with the path to the executable passed.




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

Date: Sun, 6 May 2001 23:59:48 -0500 (CDT)
From: RWEDGE@webtv.net (Robert Wedge)
Subject: getting line by line from $
Message-Id: <23522-3AF62BC4-256@storefull-623.iap.bryant.webtv.net>

  I am trying to display the source of a remote file line by line. 

I can do it in a local file :

open(INFO, $file);   
@lines = <INFO>;      
close(INFO);  
$lines = @lines;    

$count = 0;
foreach $lines (@lines)  {
$count++;
print "<li><xmp>$lines</xmp>";
} 

I can get the source of a remote file in a scaler and print it out, but
do not know how to break it down line by line.

use LWP::Simple;
use LWP::UserAgent;
use URI::URL;
$source = get($url);

How can I get a numbered line by line print out of $source or convert it
to an array to do the same?
Thanks for any help on this.
/Bob 



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

Date: Mon, 7 May 2001 05:39:21 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Help on optimization wanted
Message-Id: <slrn9fcd89.998.abigail@tsathoggua.rlyeh.net>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCVI
September MCMXCIII in <URL:news:9d5275$879$1@mamenchi.zrz.TU-Berlin.DE>:
][  According to Abigail <abigail@foad.org>:
][ > Craig Berry (cberry@cinenet.net) wrote on MMDCCCV September MCMXCIII in
][ > <URL:news:tfb5nd19910l1d@corp.supernews.com>:
][ > }}  
][ > }}  #!/usr/bin/perl -w
][ > }}  # sieve - find primes using a sieve
][ > }}  # Craig Berry (20010506)
][ > }}  
][ > }}  use strict;
][ > }}  
][ > }}  my $max   = shift || 100;
][ > }}  my $limit = int sqrt($max);
][ > }}  my @sieve = (0, 0, (1) x ($max - 1));
][ > 
][ > That takes a lot of memory.
][ > 
][ > Here's a sieve that uses approx. 1 byte/20 numbers:
][  
][  [delightful code snipped]
][  
][  Thanks for the thorough analysis.  I like the way to save space
][  by skipping the numbers in each decade that can't be primes.
][  
][  This particular method seems to be inspired by the decimal number
][  system.  Could a different base inspire a system that saves even
][  more?  A base that is the product of the first few primes looks
][  promising, but I get the distinct feeling I'm re-inventing some
][  wheel here.  Off to the literature I go, instead of perpetrating
][  more off-topic ruminations.


Base 30, being the lcm of 2, 3, 5 seems an obvious choice. But I
was looking for a balance between saving memory and keeping the code
simple and efficient. You don't want to make your inner loop too large;
I'm already no happy with the 'next if' statement. Perhaps some loop
unrolling in combination with Duff's device will make it fast.


Abigail
-- 
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))


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

Date: Mon, 07 May 2001 06:41:24 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Help on optimization wanted
Message-Id: <slrn9fckpe.11o.tjla@thislove.dyndns.org>

"mein Luftkissenfahrzeug ist voll von den Aalen"
said Abigail (abigail@foad.org) in 
<slrn9fbi29.ti0.abigail@tsathoggua.rlyeh.net>:

>I would expect a compiler to be smart enough to know both expressions
>are equivalent, and to do whatever is the fastest on the platform it
>runs on.

I would expect that would be nice. However, even with "use integer", $_
* $_ is faster than $_ ** 2.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Let He who taketh the Plunge Remember to return it by Tuesday.


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

Date: 07 May 2001 00:21:01 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Help slim down Perl code
Message-Id: <m3wv7t23iq.fsf@mumonkan.sunstarsys.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:

> According to Uri Guttman  <uri@sysarch.com>:
> 
> [...]
> 
> > 	read( FH, $buf, -s FH ) ;
> > 	return $buf ;
> > 
> > # older slow way
> > #	local( $/ ) unless wantarray ;
> > #	<FH>
> > }
> 
> Is it known to be slower?  I do like the read() method because it's
> actually clearer than the time-honored way of undef'ing $/.  It has
> the disadvantage that it fails if -s isn't applicable to FH as with
> terminals, sockets and their ilk.

Maybe he meant to use sysread? Otherwise I can't see any reason why
there should be a significant performance difference between the two.

-- 
Joe Schaefer   "I must have a prodigious quantity of mind; it takes me as much
                             as a week sometimes to make it up."
                                               --Mark Twain


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

Date: Mon, 07 May 2001 04:27:12 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Help slim down Perl code
Message-Id: <x7k83tdbra.fsf@home.sysarch.com>

>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

  AS> According to Uri Guttman  <uri@sysarch.com>:
  AS> [...]

  >> read( FH, $buf, -s FH ) ;
  >> return $buf ;
  >> 
  >> # older slow way
  >> #	local( $/ ) unless wantarray ;
  >> #	<FH>
  >> }

  AS> Is it known to be slower?  I do like the read() method because
  AS> it's actually clearer than the time-honored way of undef'ing $/.
  AS> It has the disadvantage that it fails if -s isn't applicable to FH
  AS> as with terminals, sockets and their ilk.

i did a benchmark and it is noticably faster. it doesn't have to loop
inside perl until EOF, it just reads the right amount of data. i imagine
the read internals to be very streamlined as there is no thinking to
do. the <> interface has many options and has to track them as it does
the input. there was a thread on this a while back and that convinced me
to switch.

also, the sub is called read_file for a reason. it is not meant to be
used on sockets, etc. it is a common enough op that i have had a version
in many of my programs for years. this is the fastest version.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: 7 May 2001 04:43:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Help slim down Perl code
Message-Id: <9d5969$879$3@mamenchi.zrz.TU-Berlin.DE>

According to Uri Guttman  <uri@sysarch.com>:
> >>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
> 
>   AS> According to Uri Guttman  <uri@sysarch.com>:
>   AS> [...]
> 
>   >> read( FH, $buf, -s FH ) ;
>   >> return $buf ;
>   >> 
>   >> # older slow way
>   >> #	local( $/ ) unless wantarray ;
>   >> #	<FH>
>   >> }
> 
>   AS> Is it known to be slower?  I do like the read() method because
>   AS> it's actually clearer than the time-honored way of undef'ing $/.
>   AS> It has the disadvantage that it fails if -s isn't applicable to FH
>   AS> as with terminals, sockets and their ilk.
> 
> i did a benchmark and it is noticably faster. it doesn't have to loop
> inside perl until EOF, it just reads the right amount of data. i imagine
> the read internals to be very streamlined as there is no thinking to
> do. the <> interface has many options and has to track them as it does
> the input. there was a thread on this a while back and that convinced me
> to switch.

Thanks for that, a benchmark saved is an hour saved (at least).  I seem
to remember the thread.  Come to think of it, read() could understand
an undefined length argument (which is an error now) to mean read to
EOF.
 
> also, the sub is called read_file for a reason. it is not meant to be
> used on sockets, etc. it is a common enough op that i have had a version
> in many of my programs for years. this is the fastest version.

True.  In fact, you don't want to read to EOF from a socket-like file
often.

Anno


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

Date: Mon, 07 May 2001 06:48:26 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Help with a script
Message-Id: <3AF6466B.4CAB9A8F@earthlink.net>

Matt Ross wrote:
> 
> Hi,
> 
> Would anyone be willing to help with a script I've got to maintain a
> mailing list?
> 
> Below is the code used, but it keeps returning a '500' server error -
> but I can't see why.

500 usually means that there's an error with the server, not necessarily
with the script.  As Paul Kersay said, you might have the wrong #! path,
or you might have the wrong permissions on the script.  Another
possibility is that the script is dying for some reason, and the server
is interpreting that as cause to give a 500 http code (this will depend
on what http server you are using).

As to the first two, I would suggest you try making a tiny cgi script
(maybe a hello world thing) and see what you need to do to get it to
run.  Then try doing the things you did to it, to your mailing list
script.  If that doesn't work, I don't know what will.

> I have uploaded as ASCII.
> 
> Thanks,
> 
> Matt
> matt@mattross.co.uk
> 
> Code:
> 
> #!/usr/sbin/perl

Make sure this is the right path.  Also, use -w

I don't see a use strict;  You ought to have it.

> $buffer = <STDIN>;
> if ($buffer eq "") { $buffer = $ENV{'QUERY_STRING'}; }
> @pairs = split(/\&/, $buffer);
> foreach $pair (@pairs) {
>     ($name, $value) = split(/=/, $pair);
>     $value =~ tr/+/ /;
>     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>     $FORM{$name} = $value;
> }

Yuck.  You should be using CGI.pm

Do this with
	use CGI;
at the top of the file.

Also, since you use query 'address' so often, stick that in it's own
variable, so as not to use a hash or function call every time.
	my $address = query('address');

Most of your html all follows the same pattern.  You would be best off
putting the constant stuff into some kind of template.

	my $template = <<ENDHTML;
<HTML>
<HEAD>
	<TITLE>[ mr:uk ] - %s</TITLE>
	<LINK REL="stylesheet"
	 HREF="http://www.mattross.co.uk/style.css"
	 TYPE="text/css">
</HEAD>
<BODY>
	<FONT FACE="Tahoma" SIZE="3"><STRONG>%s</STRONG></FONT>
	<BR><HR><BR>
	<FONT FACE="Tahoma" SIZE="2">%s</FONT>
	</BODY>
</HTML>
EndHtml


> sub error {
> 
> print "Content-type: text/html\n\n";
> print <<EndHTML;
> <HTML>
> <HEAD>
> <TITLE>[ mr:uk ] - Subscribe</TITLE>
> <LINK REL="stylesheet" HREF="http://www.mattross.co.uk/style.css"
> TYPE="text/css">
> </HEAD>
> <BODY>
> <FONT FACE="Tahoma" SIZE=\"3\"><STRONG>Error</STRONG><BR><HR>
> <FONT FACE="Tahoma" SIZE=\"2\">
> <BR>
> Please enter an email address</H2>
> </BODY>
> </HTML>
> 
> EndHTML
> ;
> 
> exit;
> }

sub error {
	print header;
	printf $template, "Subscribe", "Error",
	"<H2>Please enter an email address</H2>";
	exit 0;
}

Besides the slight changes to the html, note where I moved the ; for the
here-document.  This is the preferred place to put it.

> 
> #
> # End additions.
> #
> 
> if ($FORM{'action'} eq "add")
> {
>   &error unless $FORM{'address'};

The above lines should be:

if( query('action') eq 'add' ) {
	error unless $address;

>   open (subscriberlist, ">>subscribers.txt");
>                 # Add the new address to the bottom of the list
>   print subscriberlist "$FORM{'address'}\n";
>   close (subscriberlist);
> 
>   open (subscriberlist, "<subscribers.txt");
>                 # Read the contents
>   read (subscriberlist, $list, 10000);
>   close (subscriberlist);

You should really try to avoid using lowercase globs... Also, you should
always check both the return values of open and of close.

	use CGI::Carp qw(fatalsToBrowser);
	# This makes it so that any of these die messages get sent
	# to the browser.

	open SUBSCRIBERLIST, ">>", "subscribers.txt"
	or die "Could not open subscribers.txt for append: $!";
	print SUBSCRIBERLIST $address,"\n";
	close SUBSCRIBERLIST # errors can happen if disk is full
	or die "Could not close subscribers.txt: $!";

	open SUBSCRIBERLIST, "<", "subscribers.txt"
	or die "Could not open subscribers.txt for read: $!";
	{ local $/ = undef; $list = <SUBSCRIBERLIST>; }
	close SUBSCRIBERLIST or die $!; # should not ever error

Also note how I read the file in.  Using read like that is not what you
want -- what would happen if the file was over 10000 bytes long?

>   open (SENDMAIL, "|/usr/sbin/sendmail -t");
>                 # E-mail the  contents to list owner

	open (SENDMAIL, "|/usr/sbin/sendmail -t")
	or die "Could not fork/exec sendmail: $!";

# The next section can also be cleaned up, made more readable

	# Have some comment on what this is doing, it might not be
	# self-evident.  In this case, it's sending a mail to the
	# webmaster with the new list.
	# Also, you don't need a reply-to if it's the same as the From
	print SENDMAIL <<'MailHeader';
To: webmaster@mattross.co.uk ([ mr:uk ] Webmaster)
From: webmaster@mattross.co.uk ([ mr:uk ] Webmaster)
Subject: New subscription

MailHeader
	print SENDMAIL "New Address: ", $address, "\n\n";
	print SENDMAIL "Complete list:\n$list";
	# And always, always, always check the return value of close
	# when the filehandle is to or from pipe
	unless( close SENDMAIL ) {
		my $signal = $? >> 8;
		my $return = $? & 255;
		die "Sendmail aborted with signal $signal" if $signal;
		die "Sendmail exited with code $return" if $return;
		die "close failed with error $!" if $error;
		die "close failed with unknown error";
	}

> 
> #
> # Matt, edit the message in the email body to what you want.
> #
You need more comment than just this... Say that it's sending a mail to
the new user telling him he's been added.

	open (SENDMAIL, "|/usr/sbin/sendmail -t")
	or die "Could not fork/exec sendmail: $!";

	print SENDMAIL, "To: ", $address, "\n";
	print SENDMAIL, <<'ConfirmationMessage';
From: webmaster@mattross.co.uk ([ mr:uk ] Webmaster)
Subject: Welcome to the [ mr:uk ] Mailing List

Hi there,

This is just a confirmation email.

If you joined this list in error, or someone added your email address
without your permission, use the link below to be removed from the
list.

ConfirmationMessage
	print SENDMAIL "http://www.mattross.co.uk/cgi-bin/subscribe.pl";
	print SENDMAIL "?action=remove&address=", $address;
	print SENDMAIL "\n\nThankyou\n\n";
	unless( close SENDMAIL ) {
		my $signal = $? >> 8;
		my $return = $? & 255;
		die "Sendmail aborted with signal $signal" if $signal;
		die "Sendmail exited with code $return" if $return;
		die "close failed with error $!" if $error;
		die "close failed with unknown error";
	}

It occurs to me that you should always, always, make it so that the web
form *only* sends the message to the person being added, and does *not*
actually add him to the list.  Only when the user *replies*, via email,
*confirming* his desire to be on the list, should he actually be added.

Also, you should have a check for that particular user being already in
the list, and printing an error message if he is.

> #
> # End additions
> #
> 
> # Show a confirmation page

This was almost ok, but a bit of indentation can make it loads more
readable.  Also, you should not have to backslashes your quotes.

	print header;
	printf $template, "Subscribe!", "Thank You", <<EndHTML;
Your email address, $address, has been added to the
[&nbsp;mr:uk&nbsp;] subscription list.<BR>
Please check your mailbox to ensure you receive confirmation.
<BR><BR>
<A HREF="javascript:window.close();">Close Window</A>
EndHTML
	exit 0;
}

> 
> elsif ($FORM{'action'} eq "remove")
> {

elsif( query('action') eq "remove" ) {

>   open (subscriberlist, "<subscribers.txt");
>                 # Read the list file and close
>   read (subscriberlist, $buffer, 10000);
>   close (subscriberlist);

	open SUBSCRIBERLIST, "<", "subscribers.txt"
	or die "Could not open subscribers.txt for reading: $!";
	my @list_lines = <SUBSCRIBERLIST>;
	close SUBSCRIBERLIST or die $!;

	my $r = @list_lines;
	@list_lines = grep !/^\Q$address\E$/ @list_lines
	$r -= @list_lines; # Number of instances removed, should be 1

>   @list_lines = split (/\n/, $buffer);

Note that I did not split them... so their \ns are intact.

> 
>   open (subscriberlist, ">subscribers.txt");
>                 # Open list file again, for output
>   foreach $line(@list_lines)
>   {
>     # Only re-write the line if it's different
>     # from the one to be removed
>     if ($line ne $FORM{'address'})
>     {
>       print subscriberlist "$line\n";
>     }
>   }
>   close (subscriberlist);

	open SUBSCRIBERLIST, ">", "subscribers.txt"
	or die "Could not open subscribers.txt for writing: $!";
	print SUBSCRIBERLIST @list_lines;
	close SUBSCRIBERLIST
	or die "Could not close subscribers.txt when writing: $!";

> 
> print "Content-type: text/html\n\n";
> print <<EndHTML;
> <HTML>
> <HEAD>
> <TITLE>[ mr:uk ] - Subscribe!</TITLE>
> <LINK REL="stylesheet" HREF="http://www.mattross.co.uk/style.css"
> TYPE="text/css">
> </HEAD>
> <BODY>
> <FONT SIZE=\"3\"><STRONG>Unsubscribe Confirmation</STRONG><BR><HR>
> <FONT SIZE=\"2\">
> <BR>
> Your e-mail address, $FORM{'address'}, has been removed from the
> subscription list.
> <BR><BR>
> </BODY>
> </HTML>
> 
> EndHTML
> ;

	print header;
	printf $template, "Subscribe!", "Unsubscribe Confirmation",
	"You email address, $address, has been removed from the list.";

> 
>   open (SENDMAIL, "|/usr/sbin/sendmail -t");
>   print SENDMAIL "To: Webmaster\@mattross.co.uk ([ mr:uk ] Webmaster\n";
>   print SENDMAIL "From: webmaster\@mattross.co.uk ([ mr:uk ] Webmaster)\n";
>   print SENDMAIL "Reply-to: webmaster\@mattross.co.uk ([ mr:uk ]
> Webmaster)\n";
>   print SENDMAIL "Subject: Subscription Cancellation\n\n";
>   print SENDMAIL "Address: $FORM{'address'}\n\n";
>   print SENDMAIL "Complete list:\n";
>   print SENDMAIL "$buffer";
>   close (SENDMAIL);

Hmm.  The way you'd had it, $buffer contains the old list, prior to the
removal.

	print SENDMAIL <<'MailHeader';
To: webmaster@mattross.co.uk ([ mr:uk ] Webmaster)
From: webmaster@mattross.co.uk ([ mr:uk ] Webmaster)
Subject: Subscription Cancellation

MailHeader
	print SENDMAIL "Address: $address\n\n";
	print SENDMAIL "$r instance(s) removed\n\n";
	print SENDMAIL "Complete list:\n";
	print SENDMAIL @list_lines;
	# And always, always, always check the return value of close
	# when the filehandle is to or from pipe
	unless( close SENDMAIL ) {
		my $signal = $? >> 8;
		my $return = $? & 255;
		die "Sendmail aborted with signal $signal" if $signal;
		die "Sendmail exited with code $return" if $return;
		die "close failed with error $!" if $error;
		die "close failed with unknown error";
	}

> 
> exit;
> }
> 

Now this code below is totally horrible... it opens sendmail again and
again for each user.  I have a fix underneath.


> elsif ($FORM{'action'} eq "concrete")
> {
>   open (subscriberlist, "<subscribers.txt");                 # Read the list
> file and close
>   read (subscriberlist, $buffer, 10000);
>   close (subscriberlist);
>   @subscribers = split (/\n/, $buffer);
>
>   foreach $subscriber (@subscribers)
>   {
>     open (SENDMAIL, "|/usr/sbin/sendmail -t");
>     print SENDMAIL "To: $subscriber\n";
>     print SENDMAIL "From: webmaster\@mattross.co.uk ([ mr:uk ]
> Webmaster)\n";
>     print SENDMAIL "Reply-to: webmaster\@mattross.co.uk ([ mr:uk ]
> Webmaster)\n";
>     print SENDMAIL "Subject: Website Update Notification\n\n";
> 
> # Matt, i've added these 3 lines that takes the message from the form and
> does stuff to it :)
> # I borrowed it from a script i use to email myself so it does work (crosses
> fingers ;)
> 
>     $FORM{'message'} =~ s/\cM\n/<br>\n/g;
>     $message = $FORM{'message'};
>     $message =~ s/<br>//g;
> 
>     print SENDMAIL "$message\n\n\n";
>     print SENDMAIL "To unsubscribe from [ mr:uk ] updates, use this URL:\n";
>     print SENDMAIL
> "http://www.mattross.co.uk/cgi-bin/subscribe.pl?action=remove&address=$subsc
> riber\n\n";
>     print SENDMAIL "If there are any problems with this service then contact
> the webmaster by replying to this e-mail.\n";
>     close (SENDMAIL);
>   }

elsif( query('action') eq "concrete" ) {
	my $message = query('message');
	die "No message specified" unless $message;
	$message =~ s[\r\n|\r|\n][\n];

	open SUBSCRIBERLIST, "<", "subscribers.txt"
	or die "Could not open subscribers.txt for reading: $!";
	my @list_lines = <SUBSCRIBERLIST>;
	close SUBSCRIBERLIST or die $!;

	chomp @list_lines;

	open (SENDMAIL, "|/usr/sbin/sendmail -t")
	or die "Could not fork/exec sendmail: $!";

	print SENDMAIL, "Bcc: ", join(", ",@list_lines), "\n";
	# The above line sends one message to everyone in the list, but
	# doesn't Show each who the others are.
	print SENDMAIL, <<'Message';
To: webmaster@mattross.co.uk ([ mr:uk ] Webmaster)
From: webmaster@mattross.co.uk ([ mr:uk ] Webmaster)
Subject: WWebsite Update Notification

$message


If you wish to be removed from this list, use this URL and enter your
address into the form.

http://www.mattross.co.uk/cgi-bin/subscribe.pl

Message
	unless( close SENDMAIL ) {
		my $signal = $? >> 8;
		my $return = $? & 255;
		die "Sendmail aborted with signal $signal" if $signal;
		die "Sendmail exited with code $return" if $return;
		die "close failed with error $!" if $error;
		die "close failed with unknown error";
	}


> 
> print "Content-type: text/html\n\n";
> print <<EndHTML;
> <HTML>
> <HEAD>
> <TITLE>Confirmation</TITLE>
> <LINK REL="stylesheet" HREF="http://www.mattross.co.uk/style.css"
> TYPE="text/css">
> </HEAD>
> <BODY>
> <FONT SIZE=\"3\"><STRONG>Confirmation</STRONG><BR><HR>
> <FONT SIZE=\"2\">
> <BR>
> The following message has been sent to the subscribers.
> <BR>
> <PRE>$FORM{'message'}</PRE>
> <BR>
> <A HREF=\"http://www.mattross.co.uk/admin\">Return to admin page</A>
> </BODY>
> </HTML>
> 
> EndHTML
> ;
> 
> exit;
> }

	print header;
	$message =~ s[&][&amp;];
	$message =~ s[<][&lt;];
	printf $template, "Confirmation", "Confirmation", <<EndHTML;
The following message has been sent to the subscribers.
<BR><PRE>$message</PRE><BR>
<A HREF="http://www.mattross.co.uk/admin">Return to admin page</A>
EndHTML
	exit 0;
}

exit 0;

-- 
Shift to the left, shift to the right, mask in, mask out, BYTE, BYTE,
BYTE !!!


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

Date: Mon, 07 May 2001 14:39:00 +1000
From: Jfreeman <jfreeman@tassie.net.au>
Subject: Re: How to execute a perl script from a perl script? - nearly got it    right !
Message-Id: <3AF626E4.4485AE0C@tassie.net.au>

HCCO admin wrote:

> On Sun, 06 May 2001 03:22:06 GMT, "flash" <bop@mypad.com> wrote:
>
> >I finally got home and re-read your message.
> >
> >you could do.
> >
> >system(perl /path/to/script ubb=whos_online_ssi');
> >
> >in the middle man cgi.
> >
>
> Ok, removed the trailing single quote in your text above and tried
> that - internal server error.
>
> Also tried
> system(/usr/bin/perl/perl /home/sites/site2/web/cgi-bin/ultimatebb.cgi
> ubb=whos_online_ssi);
> Internal server error.
>
> Tried
> system ('/home/sites/site2/web/cgi-bin/ultimatebb.cgi'
> 'ubb=whos_online_ssi');
> Internal server error.
>
> Tried
> system ('/home/sites/site2/web/cgi-bin/ultimatebb.cgi',
> 'ubb=whos_online_ssi');
>
> 'Perl' command not needed.  It runs the ultimatebb.cgi but ignores the
> argument ubb=whos_online_ssi.
>
> Without having to alter the apache server as suggested elsewhere, can
> anyone suggest an alternative syntax for 'system' or 'exec' which WILL
> accept the argument?

To pass the argument as you call it (which is actually a query string) you just
need a ? char. This is the start of the standard query string, and probably the
origin of the name.

'/home/sites/site2/web/cgi-bin/ultimatebb.cgi?ubb=whos_online_ssi'

This will pass ubb=whos_online_ssi to your script. Easy.

If you wish to pass more 'args' then the following pairs use & to seperate them

my_script.cgi?firstname=John&lastname=Smith

Note that you need to hex encode certain characters that have special
significance in web browser/server land. There are quite a few chars that need
encoding like ? & % and space ' ' \s. Don't wory what they are unless you really
want to, just use the following example as a guide to how to encode your query
strings.

Here is an edited real life example that generates the text of an HTML  link to
automatically pass a cgi script a name, email and unsubscribe request. This is
how I generate a click on this link to be unsubscribed link for the bottom of
ezines (opt in only and the link really does unsubscribe you!!!).

$scriptname = "maillist.cgi";
$http_script_path = "http://www.somewhere.com/cgi-bin";
 ..
 ..
 ..
# make the query string up ($name and $email store - no points for guessing this
one!)
 my $link = "name=$name&email=$email&subscribe=unsubscribe";

# encode the query string
 $link =~ s/([^a-zA-Z0-9_.!~*'() -=&])/sprintf "%%%02X", ord($1)/eg;
 $link =~ tr/ /+/;

# complete the link, note we have avioded accidentally encoding the ? by adding
it now
# if you include the ? in the query string created above it will get encoded =
broken
 $link = "$http_script_path/$scriptname?".$link;

Hope this helps

James

>
>
> Thanks



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

Date: Mon, 07 May 2001 04:35:26 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Multi-Line Text Editor
Message-Id: <3AF6275B.1AE16297@earthlink.net>

-- 
Shift to the left, shift to the right, mask in, mask out, BYTE, BYTE,
BYTE !!!


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

Date: Mon, 07 May 2001 04:36:40 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Multi-Line Text Editor
Message-Id: <3AF627A1.FD27D7FF@earthlink.net>

Lyle Goldman wrote:
> 
>         Hello. Is there a Perl module that allows multi-line
> console-based text editing that will work under Microsoft Windows?
> What I want is something similar to the Curses packages but will run
> under Windows. It also must be console-based, so Tk is no good. Thank
> you.

I don't believe that such a thing currently exists.  You might have luck
taking the ReadLine module and modifying it, though.

-- 
Shift to the left, shift to the right, mask in, mask out, BYTE, BYTE,
BYTE !!!


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

Date: Sun, 06 May 2001 20:58:45 -0800
From: Steve Wilbur <ultramafic1@yahoo.com>
Subject: perl weirdness
Message-Id: <060520012058452660%ultramafic1@yahoo.com>

Ive been banging my head on this to no avail - i'm hoping someone can
help. 

Consider the following routine:

sub build_page()
my (@contents)
   <blah, blah, blah>
   print(@contents);
return(@contents);

now consider this line:

print(&build_page(@contents));


in build_page(), when i print @contents, i see what i expect. 
however, with print(&buildpage(@contents)) i don't get anything, for
some contents of @contents.  for what it's worth:

push(@results,&build_page());  print(@results);

also gives me nothing, again, for some contents of @contents.  
@contents clearly contains what it is supposed to, but
return(@contents) doesn't seem to be returning it in some instances. 

i'm at a loss.  ideas are appreciated. tia. (:

ultramafic1@yahoo.com


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

Date: Mon, 07 May 2001 06:43:55 GMT
From: fxn@isoco.com (F. Xavier Noria)
Subject: Re: sessions and closures
Message-Id: <3af63e47.647682@news.iddeo.es>

On Mon, 07 May 2001 03:35:37 +0400, Serge <admin@bestwebscripts.com> wrote:

: "F. Xavier Noria" wrote:
: >    behavior.  If you understand about continuations, one way
: >    to explain what we did would be to say that we wrote our
: >    software in continuation-passing style. [...]
: > 
: > Sounds elegant! Have any of you tried this approach with Perl?
: > Could you please comment a bit on this?
: 
: either inserting some additional data into documents being served... or
: using plain cookies :-)

Well, the article gives some more details, I didn't write them because
I thought that paragraph suggested how the logic works. It seems a
natural application of closures I quote two more paragraphs for the
sake of illustration and sharing (note they were writing Lisp) [*]:

   When most based-software generates a link on a page, it tends
   to be thinking, if the user clicks on this link, I want to
   call this cgi script with this arguments. When our software
   generated a link, it could think, if the user clicks on this
   link, I want to run this piece of code. And the piece of code
   could [be] an arbitrary piece of code, possibly (in fact, usually)
   containing free variables whose value came from the surrounding
   context.

   The way we did this was to write a macro that took an initial
   argument expected to be a closure, followed by a body of code.
   The code would then be stored in a global hash table under a
   unique id, and whatever output was generated by the code if the
   body would appear within a link whose url contained that hash
   key. If that link was the next clicked on, our software would
   find and call the corresponding bit of code, and the chain
   would continue. Effectively we were writing cgi scripts on the
   fly, except that they were closures that could refer to the
   surronding context.

I think this approach deserves study. Perhaps the closures could be easily
generated thanks to Lisp macros and their lack in Perl would imply this
approach to be impractical, I don't know. That's why I asked whether someone
had written (or had considered to write) cgis like that and would like to
share his or her thoughts.

-- fxn

[*] http://www.paulgraham.com/lwba.html


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

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 845
**************************************


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