[19878] in Perl-Users-Digest
Perl-Users Digest, Issue: 2073 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 5 18:11:02 2001
Date: Mon, 5 Nov 2001 15:10:17 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005001817-v10-i2073@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 5 Nov 2001 Volume: 10 Number: 2073
Today's topics:
File uploading without CGI.pm <loophole64@home.com>
Re: File uploading without CGI.pm (Eric Bohlman)
Re: File uploading without CGI.pm <loophole64@home.com>
Format conversion <email@timlauterborn.de>
Re: Format conversion <wuerz@yahoo.com>
Re: Grep on Last Line Only <hunter@nortelnetworks.com>
Re: Grep on Last Line Only (Tad McClellan)
Re: Grep on Last Line Only <uri@stemsystems.com>
Re: Need help: Looping mailer using too many resources <tintin@snowy.calculus>
Re: Newbie needing assistance in setting up server for <tintin@snowy.calculus>
Re: Newbie needing assistance in setting up server for <wwonko@rdwarf.com>
Re: One for the Perl Wizards... <mgjv@tradingpost.com.au>
Re: Passwd changes every 90 days nobull@mail.com
Re: Perl Module problem <tintin@snowy.calculus>
perlguts and perlembed (Kevin J. Schmidt)
Re: perlguts and perlembed <wwonko@rdwarf.com>
Re: Please help beginner with using cookies! <tintin@snowy.calculus>
POST in PERL <onephunkydj@yahoo.com>
Re: POST in PERL (Tad McClellan)
Re: Question on File uploading. (Jason Kelley)
Re: reading and writing with perl CGI to client machine <wwonko@rdwarf.com>
Re: Sending Content Type in email <stuart@otenet.gr>
Teaching Perl to Middle School Students <ritchie@svs.com>
Re: Teaching Perl to Middle School Students <rereidy@indra.com>
Re: Teaching Perl to Middle School Students <tex@lager.engsoc.carleton.ca>
Re: Teaching Perl to Middle School Students <tintin@snowy.calculus>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 5 Nov 2001 14:27:54 -0600
From: "Jason Kelley" <loophole64@home.com>
Subject: File uploading without CGI.pm
Message-Id: <9s6sl5$co9$1@news.chorus.net>
For some reason my original post on this subject isn't visible to me, so I
will just create a new post. I'm posting this because I've seen lots of
posts about this same subject in this group when I was searching for my
answers, and most of the time the question was answered with code that I
didn't really understand, or "Just use CGI.pm." Hopefully someone else will
find this information usefull as well.
I'm trying to write a script to process form data that includes several
input fields, including a file input. I don't want to use CGI.pm for
effeciency reasons. Also, I am simply curious about the format of the data
sent by the client, and in coming up with new ways to process that data for
specific uses.
I grab the data with my script using the following lines:
# Get the input from the form.
binmode (STDIN);
read (STDIN, $upload_data, $ENV{'CONTENT_LENGTH'});
RFC 1867 (http://www.faqs.org/rfcs/rfc1867.html) summarizes the format of
this data, and gives specifics as follows:
3.3 use of multipart/form-data
The definition of multipart/form-data is included in section 7. A
boundary is selected that does not occur in any of the data. (This
selection is sometimes done probabilisticly.) Each field of the form
is sent, in the order in which it occurs in the form, as a part of
the multipart stream. Each part identifies the INPUT name within the
original HTML form. Each part should be labelled with an appropriate
content-type if the media type is known (e.g., inferred from the file
extension or operating system typing information) or as
application/octet-stream.
If multiple files are selected, they should be transferred together
using the multipart/mixed format.
--Snip--
6. Examples
Suppose the server supplies the following HTML:
<FORM ACTION="http://server.dom/cgi/handle"
ENCTYPE="multipart/form-data"
METHOD=POST>
What is your name? <INPUT TYPE=TEXT NAME=submitter>
What files are you sending? <INPUT TYPE=FILE NAME=pics>
</FORM>
and the user types "Joe Blow" in the name field, and selects a text
file "file1.txt" for the answer to 'What files are you sending?'
The client might send back the following data:
Content-type: multipart/form-data, boundary=AaB03x
--AaB03x
content-disposition: form-data; name="field1"
Joe Blow
--AaB03x
content-disposition: form-data; name="pics"; filename="file1.txt"
Content-Type: text/plain
... contents of file1.txt ...
--AaB03x--
If the user also indicated an image file "file2.gif" for the answer
to 'What files are you sending?', the client might client might send
back the following data:
Content-type: multipart/form-data, boundary=AaB03x
--AaB03x
content-disposition: form-data; name="field1"
Joe Blow
--AaB03x
content-disposition: form-data; name="pics"
Content-type: multipart/mixed, boundary=BbC04y
--BbC04y
Content-disposition: attachment; filename="file1.txt"
Content-Type: text/plain
... contents of file1.txt ...
--BbC04y
Content-disposition: attachment; filename="file2.gif"
Content-type: image/gif
Content-Transfer-Encoding: binary
...contents of file2.gif...
--BbC04y--
--AaB03x--
This is what I was looking for. So a delimiter is choosen by the client that
does not appear in the data itself. When multiple files are sent, a seperate
delimiter is chosen for each file, in addition to the original delimiter.
The name of the file can be found on the "Content-disposition" line.
Mark... Thanks for the warm welcome. =\ I'm not looking to "re-implement"
CGI.pm. I just want to write a small clean function for a specific task. Am
I the first person you've ever seen who didn't want to use a prewritten
library for a small task? Thank you for referring me to the rfc.
-Jason Kelley
------------------------------
Date: 5 Nov 2001 22:23:09 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: File uploading without CGI.pm
Message-Id: <9s73gd$kke$2@bob.news.rcn.net>
Jason Kelley <loophole64@home.com> wrote:
> I'm trying to write a script to process form data that includes several
> input fields, including a file input. I don't want to use CGI.pm for
> effeciency reasons. Also, I am simply curious about the format of the data
^^^^^^^^^^
One could be forgiven for seeing that unintentionally scatological typo
and reading it as "reasons that are full of shit."
------------------------------
Date: Mon, 5 Nov 2001 16:41:36 -0600
From: "Jason Kelley" <loophole64@home.com>
Subject: Re: File uploading without CGI.pm
Message-Id: <9s74fq$da5$1@news.chorus.net>
"Eric Bohlman" <ebohlman@omsdev.com> wrote in message
news:9s73gd$kke$2@bob.news.rcn.net...
> Jason Kelley <loophole64@home.com> wrote:
> > I'm trying to write a script to process form data that includes several
> > input fields, including a file input. I don't want to use CGI.pm for
> > effeciency reasons. Also, I am simply curious about the format of the
data
> ^^^^^^^^^^
> One could be forgiven for seeing that unintentionally scatological typo
> and reading it as "reasons that are full of shit."
>
=( Why are you flaming me, I was just looking for some help, and then I
posted info I thought would be helpful to some. What does it matter my
reasons for not wanting to use CGI.pm? It's not like I posted "Hey I need
cgi script to work for make good database. Can you tell me code??"
------------------------------
Date: Mon, 5 Nov 2001 21:13:11 +0100
From: "Tim Lauterborn" <email@timlauterborn.de>
Subject: Format conversion
Message-Id: <9s6rsp$fcn$1@nets3.rz.RWTH-Aachen.DE>
Hi,
I would like to format a number like 1500 in 1.500,00
Does someone know how that is possible?
Thanks!
Greetings,
Tim
------------------------------
Date: 05 Nov 2001 15:45:17 -0500
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: Format conversion
Message-Id: <m33d3tq74y.fsf@DCCMBX01.njitdm.campus.njit.edu>
"Tim Lauterborn" <email@timlauterborn.de> writes:
> I would like to format a number like 1500 in 1.500,00
>
> Does someone know how that is possible?
Do like laid out in perlfaq5:
"How can I output my numbers with commas added?"
Then do a `tr/.,/,./;' on the result.
--
$_="\n,rekcah egnufeB rehtona tsuJ";#v1<?>g\:pv-<5<
s s\S+(?:B)sunpack'u',q q$;')E4qsee;#>60#^<(v!<)g6<
print scalar reverse,$@ unless m,[+;#]55,;m:_,:#^1<
------------------------------
Date: Mon, 5 Nov 2001 14:42:49 -0500
From: "dh" <hunter@nortelnetworks.com>
Subject: Re: Grep on Last Line Only
Message-Id: <9s6q44$6ir$1@news.storm.ca>
How about this:
#!/usr/bin/ksh
for foo in $(ls);do
tail -1 $foo | grep "^$" >> file
done
Then just do a wc -l on the file.
dave
"Buck Turgidson" <jc_va@hotmail.com> wrote in message
news:b6da963eb9462b867278b8b578c34160.38849@mygate.mailgate.org...
> I have a directory of files, and I want to find where the last line is
blank,
> i.e. just contains a carriage return.
>
> I know I can search for ^$, but is there a way to limit it to flag only
the
> last line of a file?
>
>
>
> --
> Posted from [65.193.99.4]
> via Mailgate.ORG Server - http://www.Mailgate.ORG
------------------------------
Date: Mon, 05 Nov 2001 20:08:33 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Grep on Last Line Only
Message-Id: <slrn9udotd.7ef.tadmc@tadmc26.august.net>
Buck Turgidson <jc_va@hotmail.com> wrote:
>I have a directory of files, and I want to find where the last line is blank,
>i.e. just contains a carriage return.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
So you are on a Mac then?
>I know I can search for ^$,
That does not do what you describe above, did you mean "newline"
or "line feed" instead of "carriage return"?
>but is there a way to limit it to flag only the
>last line of a file?
---------------------------
#!/usr/bin/perl
use warnings;
use strict;
foreach my $fname ( @ARGV ) {
open FILE, $fname or die "could not open '$fname' $!";
while ( <FILE> ) {
next unless eof FILE;
print "$fname\n" if /^\n/;
}
}
---------------------------
But that is pretty darn crude. Probably faster to seek() to two
(or four, depending on OS) chars before EOF and see what they are.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 05 Nov 2001 20:50:16 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Grep on Last Line Only
Message-Id: <x7u1w9uekk.fsf@home.sysarch.com>
>>>>> "BT" == Buck Turgidson <jc_va@hotmail.com> writes:
BT> I have a directory of files, and I want to find where the last
BT> line is blank, i.e. just contains a carriage return.
BT> I know I can search for ^$, but is there a way to limit it to flag
BT> only the last line of a file?
use File::ReadBackwards ;
you can just read the last line of a file and check it.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 6 Nov 2001 07:33:20 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Need help: Looping mailer using too many resources
Message-Id: <NGCF7.3$265.55351@news.interact.net.au>
"Marc Bissonnette" <dragnet@internalysis.com> wrote in message
news:Xns91506A65BBCA7dragnetinternalysisc@207.35.177.135...
> Hi All;
>
> I need some help: I have a mass-mailer that is used for a client's mailing
> list (It is *not* for spam!), but it keeps crashing with a 500 server
error
> after about 100 mailings. There are no entries in the error log, and I
> can't see anything funky in /var/mesages. I emailed my ISP's support and
> they say it is probably using up all the allocated memory for our virtual
> server. It is reading names and emails in from a text file in the format
of
> fname lname email
Try Mail::Bulkmail
http://search.cpan.org/search?dist=Mail-Bulkmail
------------------------------
Date: Tue, 6 Nov 2001 07:40:39 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Newbie needing assistance in setting up server for PerlScripts capability
Message-Id: <DNCF7.4$l55.9226@news.interact.net.au>
"-=bina" <robin@cboss.com> wrote in message
news:1004986027.468258@unix.cboss.com...
> I'm new to PerlScripts -- we do everything in ASP -- but I have a valued
> client interested in using Perl for their website.
>
> Using a WindowsNT v4 Server with IISv4 -- how does one go about supporting
> such scripts?? I went to www.perl.com and downloaded the latest source
code
> distribution: stable.zip.
Grab it from http://www.activestate.com/
>
> After unzipping the file -- I can't quite narrow down exactly how to
> configure it to work with IIS to allow my client to operate with
> PerlScripts.
Do you really mean PerlScript or Perl scripts?
If you are talking about PerlScript, see:
http://aspn.activestate.com/ASPN/Reference/Products/ActivePerl/Components/Wi
ndows/PerlScript.html
If you are talking CGI scripts, see:
http://aspn.activestate.com//ASPN/Reference/Products/ActivePerl/faq/Windows/
ActivePerl-Winfaq6.html#How_do_I_configure_Microsoft_IIS
------------------------------
Date: Mon, 5 Nov 2001 21:08:16 +0000 (UTC)
From: Louis Erickson <wwonko@rdwarf.com>
Subject: Re: Newbie needing assistance in setting up server for PerlScripts capability
Message-Id: <9s6v40$akl$1@holly.rdwarf.com>
-=bina <robin@cboss.com> wrote:
: I'm new to PerlScripts -- we do everything in ASP -- but I have a valued
: client interested in using Perl for their website.
Good for them. =) And good for you for being willing to support them.
: Using a WindowsNT v4 Server with IISv4 -- how does one go about supporting
: such scripts?? I went to www.perl.com and downloaded the latest source code
: distribution: stable.zip.
: After unzipping the file -- I can't quite narrow down exactly how to
: configure it to work with IIS to allow my client to operate with
: PerlScripts.
That, as I understand it, is the source for the Unix version of Perl. It
may or may not compile on NT - I don't remember - and you'd need the
compiler installed to do so. That's at best a pain, and at worst
impossible.
For NT/Win2k/XP, go to http://www.activestate.com/ and get their Perl
package. It installs easily, and works very well, AND has support for
IIS built right in. The installation program should take care of
everything.
It also has some lovely Perl docs as HTML. (I admit, I use the HTML
docs more than the Perl lately.)
: I have Windows2000 Advanced Servers with IISv5 too in case the site would
: need setup on a different server???
Nope, Perl and ASP can coexist happily. Perl winds up being .pl and .plx
scrits under NT.
(This is the second time today I've suggested Active State to someone.
No, I don't work there or anything! They just do a good job.)
------------------------------
Date: Tue, 6 Nov 2001 08:47:00 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: One for the Perl Wizards...
Message-Id: <slrn9ue26j.flu.mgjv@martien.heliotrope.home>
On 4 Nov 2001 21:30:11 -0800,
mario <mgaffi@acxiom.com> wrote:
> In the following piece of code, any idea why the index() call, which
> is outside the while loop, slows down the while loop? For some reason,
> using the index() function decreases program performance, even if its
> called only once outside any looping block...
For me it makes no significant difference (5.6.1 on i686-linux). The
running time is approximately equal with or without the line with index.
What's your version of Perl and OS?
A few comments:
It is very, very useful when you're debugging problems to make sure to
use strict, and enable warnings. I _know_ you didn't do that.
> use constant VERBOSE => scalar 500000;
What is that scalar for there? it doesn't do anything.
> open(DATA, "Version1-1/IB.dat");
> open(OUTPUT_FILE, ">test.dat");
Always check the result of an open:
open(DATA, "Version1-1/IB.dat") or die "Cannot open Version1-1/IB.dat: $!";
> $tm = `date`; chomp($tm); print STDERR "[$tm] $. records.\n";
Don't put multiple comments on one line.
Don't use external programs when an internal command exists.
external programs make your code less portable, and waste resources.
$. is undefined at this point.
my $tm = localtime;
print STDERR "[$tm]\n";
> $s = index($tm, 0, 3);
index() works on strings, not numbers.
$s = index $tm, "0", 3;
And you do realise that 3 is a position which isn't inside the string
you gave it, right?
> while (<DATA>)
> {
> print OUTPUT_FILE;
> next unless ($. % VERBOSE == 0);
> $tm = `date`; chomp($tm); print STDERR "[$tm] $. records.\n";
See above.
> }
None of these remarks could cause or cure the problem you're seeing,
_if_ you are actually seeing a problem. How did you measure this? Maybe
you should have a look at the Benchmark module so that you can create
some numbers instead of a vague qualification like "slows down the while
loop".
Martien
--
|
Martien Verbruggen | Make it idiot proof and someone will
| make a better idiot.
|
------------------------------
Date: 05 Nov 2001 19:13:36 +0000
From: nobull@mail.com
Subject: Re: Passwd changes every 90 days
Message-Id: <u9y9ll115r.fsf@wcl-l.bham.ac.uk>
tadermann@hotmail.com (Tony) writes:
> Looking for a script
This is comp._lang_.perl.misc.
This means it is a programming language group.
We are fairly liberal about how that's interpreted but if you are
simply looking for a ready made program to perform some function you
are in the wrong place.
> that would change a users passwd every 90 days,
Most scripts don't get left running for that sort of time.
You'd be better to write a script that get runs periodically and looks
to see if the password is 90 days old and if so changes it. Of course
you are going to have to somehow communicate the changed password to
the user and this of course creates a chicken and egg problem. Also
you have to worry seriously about having a script sittinhg about
that's running with that level of authority.
The mechanism for actually changing the password depends, of course,
on what sort of system is using the password and how you are
communicating with it.
Perhaps you should simply get the person administering whatever it is
to remove the requirement for periodic changes. If they are reluctant
to do so you shouldn't have too much trouble finding studies that show
that enforced periodic password changes reduce security. Actually
finding such studies is harder than you may initially think as anyone
who has given the matter enough thought to the matter to devise such a
study will also realise that the outcome is obvious.
> 1. Check the password against a mask.
That could mean anything.
> 2. Check that the same passwd not used before for that user.
I'd probably recommend storing a crypo hash of old passwords. Of
course this too can reduce security so better not to do it at all.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 6 Nov 2001 07:29:18 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Perl Module problem
Message-Id: <%CCF7.2$R65.97376@news.interact.net.au>
"Anthony Heuveline" <Anthony.Heuveline@wanadoo.fr> wrote in message
news:9s5qfk$qs0$1@wanadoo.fr...
> Hi,
>
> I am working on a server where all Perl core modules are installed. The
> problem is that I want to use some functions that are not included in
these
> core modules. I have already installed CGI.pm and DBI.pm, uploading these
> two files on the server, and it works.
>
> I also need to use File::Basename and File::Copy modules but I didn't find
> them, even on CPAN. As I am a newbie in perl and in server handling, could
> you help me to find the needed files?
Unless you have an ancient version of Perl and/or you have an incomplete
installation, CGI.pm, File::Basename and File::Copy all exist in the core
distribution.
------------------------------
Date: 5 Nov 2001 12:19:09 -0800
From: kschmidt@mindspring.com (Kevin J. Schmidt)
Subject: perlguts and perlembed
Message-Id: <92541e99.0111051219.16589ed7@posting.google.com>
I'm trying to write a C program that will use libperl to create Perl
variables. The C application breaks up lines of input and "tokenizes"
them. For example, if it receives the input line
Perl is great
I want to create three Perl variables in my C application that are
each named $token1, $token2, and $token3, and set each (respectively)
to "Perl", "is", and "great", which will be available to a Perl script
that will later be executed in the C application. I've read the
perlguts, perlembed, and other related man pages and understand how to
create Perl variables in C, but am not sure how I would go about
creating these token variables I need, especially when there is no way
to know ahead of time how many of the token variables are needed for a
giving line of input.
If anyone has any suggestions or can point me to some source that does
what I'm trying to do I'd appreciate it.
Thanks,
-Kevin
------------------------------
Date: Mon, 5 Nov 2001 21:33:58 +0000 (UTC)
From: Louis Erickson <wwonko@rdwarf.com>
Subject: Re: perlguts and perlembed
Message-Id: <9s70k6$bd9$1@holly.rdwarf.com>
Kevin J. Schmidt <kschmidt@mindspring.com> wrote:
: I'm trying to write a C program that will use libperl to create Perl
: variables. The C application breaks up lines of input and "tokenizes"
: them. For example, if it receives the input line
: Perl is great
: I want to create three Perl variables in my C application that are
: each named $token1, $token2, and $token3, and set each (respectively)
: to "Perl", "is", and "great", which will be available to a Perl script
: that will later be executed in the C application. I've read the
: perlguts, perlembed, and other related man pages and understand how to
: create Perl variables in C, but am not sure how I would go about
: creating these token variables I need, especially when there is no way
: to know ahead of time how many of the token variables are needed for a
: giving line of input.
: If anyone has any suggestions or can point me to some source that does
: what I'm trying to do I'd appreciate it.
Well, I'll suggest creating a magic array that has elements for each
item that you need. That's a lot of code to write off the cuff, so
I'm not going to try and show you how.
In an application I'm working on, and will probably be asking some
questions about later, I have a need to do something similar. I
cheat and use code like the following in C:
/* Note that this is untested, as my code depends on many helpful
objects that I am not going to paste in to a news article. */
sprintf(setString, "$%s = %ld;\n", THREAD_SV_NAME, (long)this);
eval_pv(setString, FALSE);
if(SvTRUE(ERRSV))
{
/* Something bad happened. */
}
Basically, this gives Perl a string to evaluate. The string is
generated by the C, and winds up creating a variable by setting it
to a value. You could do this in a for loop, sprintf-ing the names
of the Perl variables and appropriate values for them.
In your case, I doube the eval_pv would fail, and you might get away
with using TRUE as the second parameter, so that it'll blow up if
there is an error, as an error on the setting of a scalar is pretty
unlikely, and probably pretty fatal. I always like to handle
errors myself, though, rather than just having the library bomb
out.
(Yes, I'm storing my this pointer in Perl. Later, a callback uses
get_sv to get that number back, and casts it in to a pointer so
I can call members on it.)
Hope that helps. It might not be the most efficient in the world,
(you might be able to call sv_setpv, but I haven't tried this) but
I can say it does work.
------------------------------
Date: Tue, 6 Nov 2001 07:13:14 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Please help beginner with using cookies!
Message-Id: <WnCF7.1$Y65.104551@news.interact.net.au>
"Marianne Sisto" <msisto@chat.carleton.ca> wrote in message
news:9s4c2j$4qs$1@bertrand.ccs.carleton.ca...
> Thank you
>
> "Mark Taylor" <mtaylor@lrim.com> wrote in message
> news:Xns914F96EFD1728maintainersetifaqorg@128.242.171.114...
> > "Marianne Sisto" <msisto@chat.carleton.ca> wrote in
> > <9s47kh$1al$1@bertrand.ccs.carleton.ca>:
> >
> > >Hi, I have a question about cookies. I need to create multiple
cookies,
> > >one for each person who 'logs on' to my website so it should store the
> > >userID for example - this is no problem I can do this part. But, when
> > >the person logs on AGAIN, I then need to read these cookies and find
the
> > >one containing their ID and then display other information stored in
the
> > >cookie - is there a way to do this? Like read a certain field of each
> > >cookie such as userID, until I find the one I want, and then read the
> > >rest of the information? Or is there a simpler way to do this?
> > >Thank you
> > >
> > >
> > >
> > >
> >
> > As I understand cookies, you will be writing one cookie per visitor to
> your
> > site, on his computer, not yours. And you can store multiple values in a
> > cookie like in...
> >
> > print "Set-cookie: user$COOKIE_ID=$username_in; expires=Tuesday,
> 4-Jul-2000
> > 12:00:00 GMT; path=/\n";
> >
> >
> > And you can read and parse the values with something like:
> >
> > sub read_cookie {
> > $buffer = $ENV{'HTTP_COOKIE'};
> > @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;
> > $COOKIE{$name} = $value;
> > }
> > }
>
> Hi, thank you for that information. I have to write the code myself rather
> than use a module though.
Why reinvent the wheel? You have a standard module that comes with all
modern versions of Perl that will handle most cookie operations.
> Also, I need to store for each user, a list of courses. I have these
> courses stored in an array. How can I store the data from an array into a
> cookie?
Look at the CGI.pm documentation
------------------------------
Date: Mon, 5 Nov 2001 20:07:48 -0000
From: "a@a" <onephunkydj@yahoo.com>
Subject: POST in PERL
Message-Id: <9s6rn2$8mb$1@news6.svr.pol.co.uk>
Hi,
I would like to know how to emulate POST using PERL?
i want to write a script that will post a variable to another web page, just
as if the variable had been in a form which had "METHOD=POST" and the user
had clicked submit.
is there any way to do this?
a@a
------------------------------
Date: Mon, 05 Nov 2001 21:17:00 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: POST in PERL
Message-Id: <slrn9udtrr.7rn.tadmc@tadmc26.august.net>
a@a <onephunkydj@yahoo.com> wrote:
>I would like to know how to emulate POST using PERL?
^^^^^^^
No need to fake it, you can do a _real_ POST.
>is there any way to do this?
use LWP::UserAgent; # part of the lib-www bundle on CPAN
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 5 Nov 2001 11:33:28 -0800
From: loophole64@home.com (Jason Kelley)
Subject: Re: Question on File uploading.
Message-Id: <bc7d7750.0111051133.60f7a98a@posting.google.com>
To answer my own question, rfc 1867
(http://www.faqs.org/rfcs/rfc1867.html) States the following summary
of the format, followed by the details of the format:
3.3 use of multipart/form-data
The definition of multipart/form-data is included in section 7. A
boundary is selected that does not occur in any of the data. (This
selection is sometimes done probabilisticly.) Each field of the
form
is sent, in the order in which it occurs in the form, as a part of
the multipart stream. Each part identifies the INPUT name within
the
original HTML form. Each part should be labelled with an
appropriate
content-type if the media type is known (e.g., inferred from the
file
extension or operating system typing information) or as
application/octet-stream.
If multiple files are selected, they should be transferred together
using the multipart/mixed format.
--Snip--
6. Examples
Suppose the server supplies the following HTML:
<FORM ACTION="http://server.dom/cgi/handle"
ENCTYPE="multipart/form-data"
METHOD=POST>
What is your name? <INPUT TYPE=TEXT NAME=submitter>
What files are you sending? <INPUT TYPE=FILE NAME=pics>
</FORM>
and the user types "Joe Blow" in the name field, and selects a text
file "file1.txt" for the answer to 'What files are you sending?'
The client might send back the following data:
Content-type: multipart/form-data, boundary=AaB03x
--AaB03x
content-disposition: form-data; name="field1"
Joe Blow
--AaB03x
content-disposition: form-data; name="pics";
filename="file1.txt"
Content-Type: text/plain
... contents of file1.txt ...
--AaB03x--
If the user also indicated an image file "file2.gif" for the answer
to 'What files are you sending?', the client might client might
send
back the following data:
Content-type: multipart/form-data, boundary=AaB03x
--AaB03x
content-disposition: form-data; name="field1"
Joe Blow
--AaB03x
content-disposition: form-data; name="pics"
Content-type: multipart/mixed, boundary=BbC04y
--BbC04y
Content-disposition: attachment; filename="file1.txt"
Content-Type: text/plain
... contents of file1.txt ...
--BbC04y
Content-disposition: attachment; filename="file2.gif"
Content-type: image/gif
Content-Transfer-Encoding: binary
...contents of file2.gif...
--BbC04y--
--AaB03x--
So the client chooses a boundary that will not appear in the data, and
you can grab that and use it as a delimiter while parsing the data.
New delimiters are chosen for each file when sending multiple files,
in addition to the original delimiter. The filename can be read from
the "Content-disposition: attachment; filename="..."" line.
Now the question I have left is, if you are transfering a binary file,
and you set the reading of the data to binmode in your script, how can
you read the ascii of the other form elements? Is there a perl
function that will convert them back, or can you switch modes in mid
read? Someone help please? =\
------------------------------
Date: Mon, 5 Nov 2001 20:44:01 +0000 (UTC)
From: Louis Erickson <wwonko@rdwarf.com>
Subject: Re: reading and writing with perl CGI to client machines?
Message-Id: <9s6tmh$9m4$1@holly.rdwarf.com>
hugo <hugo@fractalgraphics.com.au> wrote:
: Hi
<snip>
: However, (and I know this can normally not be done for sound security
: reasons) I would like a file to be uploaded from a client (e.g. a
: windows machine), and the output file being written away in the same
: directory of the client machine as well. So rather than getting my input
: file from /tmp/test.txt, I would like to get if from, for example,
: C:\mydirectory\test.txt and write the output file to that directory as
: well.
: Totally impossible?
With pure HTTP, as far as I know, yes. You won't be able to write
back to the user's hard disc.
Another poster has suggested that if the client is running an FTP
server, you could put the data back that way. This is true, and if
you can enforce this on all your clients, a possible answer. Myself,
I would find this a terrible security hole, considering both FTP
servers in general, and IIS, the one most Microsoft clients would
try to use.
: Note that when I try to upload from my local machine, the file is not
: found (as expected, as my C drive is not available to the server). So in
: short, my questions are:
: (1) How do I get the server to read in the file from the client
: directory and (2) how do I allow the server to write an output file back
: to the same directory on the client machine.
Calling $query->param('uploaded_file_field_name') will get you the
name of the file on the user's machine. If you keep reading in the
CGI.pm docs, you can use that return as a file handle.
: Here is my code so far (note that $datafile is obtained by performing a
: $query->param on the contents of an upload field and that the
: $double_spaced_file is a simple conversion changing the extension from
: whatever it was to *.out. The strings for $datafile and
: $double_spaced_file include the full path.)
: open(INFILE, "$datafile")|| die "Could not open $datafile:
: $!\nStopped";
: open(OUTFILE, ">$double_spaced_file") || die "Could not open
: $double_spaced_file: $!\nStopped";
: while (<INFILE>) {
: print OUTFILE "$_\n";
: }
: close (INFILE);
: close(OUTFILE);
You don't actually have to open the file; CGI.pm did it for you.
Untested:
open(OUTFILE, ">$double_spaced_file") || die "Could not open
$double_spaced_file: $!\nStopped";
while (<$datafile>)
{
print OUTFILE "$_\n";
}
close (OUTFILE);
Basically, your handling of the output file is normal. CGI.pm has
opened the input file for you; just use that variable as the file
handle. (I can't say I understand exactly how it does that, but it
does work, and I have used it.)
The problem of uploading it back to the user is much stickier. If
you send the response back as a different type that the browser
dosen't understand, then it will offer to "save as" the document.
I did this by: print $query->header('applicaton/RFC822');
My solution was to provide directions to the user, "Right click
on this link, and select save as" and to then have the server send
the file back. Since I was reading the data from a database which
I had to keep, this was fine. I presume you don't want to have to
keep this edited file around so they can fetch it as a seperate
step.
Other than putting directions on the form before the "OK" button,
and then having it send the data back as an odd type, and depending
on the user to follow directions and save it correctly, I see no
really visible answer.
: Any help will be greatly appreciated.
Hope it helps. The problem of putting it back is a pain, and
I didn't find a perfectly clear answer, either.
------------------------------
Date: Tue, 6 Nov 2001 00:14:59 +0200
From: "Stuart Gall" <stuart@otenet.gr>
Subject: Re: Sending Content Type in email
Message-Id: <9s7531$mq4$1@usenet.otenet.gr>
"Glenn White" <spam.killer@home.com_nospam> wrote in message
news:Xns914FA7943A022ccruizermydejacom@24.0.0.25...
> spam.killer@home.com_nospam (Glenn White) wrote in
> <Xns914EB018994A7ccruizermydejacom@24.0.0.25>:
>
> >I've created a Perl program that runs on NT that uses sendmail to email
> >text that contains mono-spaced tables.
> <-- snip -->
>
> Thanks for the info. The change request is actually a case of scope creep
> and was not in the original specs. I will heed Tassilo's suggestions:
> Either they can do it or submit it as a new request to create a
> "multipart/alternative email ." Otherwise, the best suggestion is, "But
> don't do it and instead leave the font used as a choice for the
recipient."
You can also use text/html type. You are not realy supposed to (I think) so
perhaps it should not be done on internet. but I use text/html on most of
the automailer scripts on our intranet, it works fine and it is very easy to
change a text/plain script to text/html going to multipart alternative is a
pain.
--
Stuart Gall
------------------------------------------------
This message is not provable.
------------------------------
Date: Mon, 05 Nov 2001 13:33:16 -0600
From: "David J. Ritchie" <ritchie@svs.com>
Subject: Teaching Perl to Middle School Students
Message-Id: <3BE6E97B.69DF61F5@svs.com>
I have put up my document that I have used for several years as
the basis for teaching Perl to Middle School students in an
after-school Computer Club setting. This is a revised approach
of an earlier document which is also available on the web site.
See:
http://home.mindspring.com/~djrassoc01/PoP/Pop1.html
I'd be interested in your feedback.
David J. Ritchie
--
djrassoc01@mindspring.com
http://home.mindspring.com/~djrassoc01/
------------------------------
Date: Mon, 05 Nov 2001 12:47:52 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: Teaching Perl to Middle School Students
Message-Id: <3BE6ECE8.74B033C@indra.com>
"David J. Ritchie" wrote:
>
> I have put up my document that I have used for several years as
> the basis for teaching Perl to Middle School students in an
> after-school Computer Club setting. This is a revised approach
> of an earlier document which is also available on the web site.
>
> See:
>
> http://home.mindspring.com/~djrassoc01/PoP/Pop1.html
>
> I'd be interested in your feedback.
>
> David J. Ritchie
>
> --
> djrassoc01@mindspring.com
> http://home.mindspring.com/~djrassoc01/
I don't understand why you use the terminolgy you are using. If you are
teaching Perl, use Perl idioms, syntax and descriptions that are know
throughout the Perl community. For instance, there is no such thing as
a "paragragh" in Perl. What you are describing is a block. To describe
it any other way will confuse the students.
--
Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.
------------------------------
Date: 5 Nov 2001 19:52:20 GMT
From: "Clayton L. Scott" <tex@lager.engsoc.carleton.ca>
Subject: Re: Teaching Perl to Middle School Students
Message-Id: <9s6qlk$69k$1@bertrand.ccs.carleton.ca>
David J. Ritchie <ritchie@svs.com> wrote:
> I have put up my document that I have used for several years as
> the basis for teaching Perl to Middle School students in an
> after-school Computer Club setting. This is a revised approach
> of an earlier document which is also available on the web site.
> See:
> http://home.mindspring.com/~djrassoc01/PoP/Pop1.html
> I'd be interested in your feedback.
I noticed that you neglegted to mention which IDE product you are using in your examples.
Perhaps taht should be in an appendix "Supporting Materials"
Clayton
--
Web and Perl monkey seeking position. 5+ years experience. Willing to learn
C++ on your dime. E-mail: tex@engsoc.org
------------------------------
Date: Tue, 6 Nov 2001 07:45:45 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Teaching Perl to Middle School Students
Message-Id: <qSCF7.5$085.134276@news.interact.net.au>
"David J. Ritchie" <ritchie@svs.com> wrote in message
news:3BE6E97B.69DF61F5@svs.com...
> I have put up my document that I have used for several years as
> the basis for teaching Perl to Middle School students in an
> after-school Computer Club setting. This is a revised approach
> of an earlier document which is also available on the web site.
>
> See:
>
> http://home.mindspring.com/~djrassoc01/PoP/Pop1.html
>
> I'd be interested in your feedback.
Trying to teach any programming language in terms of English grammar is only
going to confuse the students. Just as there are specific terms in English
grammar, there are specific terms for programming languages. It doesn't
make any sense to intermingle the two.
------------------------------
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 2073
***************************************