[22272] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4493 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 31 03:05:53 2003

Date: Fri, 31 Jan 2003 00:05:07 -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           Fri, 31 Jan 2003     Volume: 10 Number: 4493

Today's topics:
    Re: $G->add_weighted_edge($u, $w, $v, $a) "the uknown $ (Brandon Reddish)
    Re: $G->add_weighted_edge($u, $w, $v, $a) "the uknown $ <mgjv@tradingpost.com.au>
    Re: ActivePerl 5.8 / MySQL / Apache Problem (Randy Kobes)
    Re: Checking for a file <mgjv@tradingpost.com.au>
    Re: creating a binary file with desired size (Walter Roberson)
    Re: Creating my own Guestbook. (Jay Tilton)
    Re: Creating my own Guestbook. <mgjv@tradingpost.com.au>
        Perl Operations (Brandon Reddish)
    Re: Perl Operations <ajglist@izzy.net>
    Re: Perl Operations <GPatnude@adelphia.net>
    Re: Perl Operations (Tad McClellan)
    Re: Perl Operations <family2@aracnet.com>
    Re: Perl Operations <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Perl Operations <jurgenex@hotmail.com>
    Re: Search a text <dmuren@start.no>
    Re: Timestamps to thousandths of a second. (Jeremy Gooch)
    Re: user logins and profiles <moo@cow.com>
    Re: Using cgi-script to add unix user (need to modify s <josef.moellers@fujitsu-siemens.com>
    Re: Very Basic Question on the Use of the __DATA__ Toke <gbarbay@NOnetscapeSPAM.net>
    Re: Very Basic Question on the Use of the __DATA__ Toke (Tad McClellan)
    Re: Why is this script sending 0 byte file attachments? <GPatnude@adelphia.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 30 Jan 2003 18:28:23 -0800
From: mechman991@hotmail.com (Brandon Reddish)
Subject: Re: $G->add_weighted_edge($u, $w, $v, $a) "the uknown $a variable"
Message-Id: <60d818b.0301301828.5d3c654b@posting.google.com>

"Alexandros" <a_valarakos@hotmail.com> wrote in message news:<b1c6ll$1jec$1@ulysses.noc.ntua.gr>...
> I found the following:
> 
>    "$G->add_weighted_edge($u, $w, $v, $a)
>  Adds in the graph $G an edge from vertex $u to vertex $v and the edge
> attribute 'weight' set to $w."
> They forgot to say something about the variable $a?????
> 
> Any suggestion?
> 
> 
> 
>  Thanks in advance
> 
> Alexandros

The $a variable is used in packaging (see perlvar) and when used
otherwise, it can result in strange results.


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

Date: Fri, 31 Jan 2003 03:18:52 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: $G->add_weighted_edge($u, $w, $v, $a) "the uknown $a variable"
Message-Id: <slrnb3jqos.se5.mgjv@verbruggen.comdyn.com.au>

On 30 Jan 2003 18:28:23 -0800,
	Brandon Reddish <mechman991@hotmail.com> wrote:
> "Alexandros" <a_valarakos@hotmail.com> wrote in message news:<b1c6ll$1jec$1@ulysses.noc.ntua.gr>...
>> I found the following:
>> 
>>    "$G->add_weighted_edge($u, $w, $v, $a)
>>  Adds in the graph $G an edge from vertex $u to vertex $v and the edge
>> attribute 'weight' set to $w."
>> They forgot to say something about the variable $a?????
>> 
>> Any suggestion?
>> 
>> 
>> 
>>  Thanks in advance
>> 
>> Alexandros
> 
> The $a variable is used in packaging (see perlvar) and when used
> otherwise, it can result in strange results.

Euhmmm. no. What makes you think that? And what is 'packaging'?

The global package variable $a is automatically set by the sort
builtin for use by a sort code block or subroutine. You are absolutely
free to use it (or a lexical $a) yourself for all kinds of other
things, as long as you're aware of the fact that a call to sort could
interact with the values in them, and the presence of a lexical $a
will make accessing the packahe variable $a in a sort code block
harder. 

Besides that, the material quoted in the OP is documentation, not Perl
code. The "variables" there are placeholders for things you are
supposed to put in yourself, they do not say that you _have_ to use
the $a variable as the fourth argument.

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | Curiouser and curiouser, said Alice.
                        | 


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

Date: 31 Jan 2003 03:47:49 GMT
From: randy@theoryx5.uwinnipeg.ca (Randy Kobes)
Subject: Re: ActivePerl 5.8 / MySQL / Apache Problem
Message-Id: <slrnb3js3s.431.randy@theoryx5.uwinnipeg.ca>

On Fri, 31 Jan 2003 00:48:10 -0000, Alex Banks <alex@alexbanks.com> wrote:
>Okay... truly bizarre. I'm having a conversation with myself 
>here, but I solved the problem anyway so I'm happy.
>
>It's a bit messy, but I copied the \mysql\lib\opt\libmySQL.dll file to
>C:/Perl/site/lib/auto/DBD/mysql/ and it worked.
>
>Be interested to know if anyone can explain why!

It might be that adding the path to libmySQL.dll to PATH
didn't get propagated into the Apache environment. The
current directory is searched for dlls, which is why it
worked when libmySQL.dll was copied to
C:/Perl/site/lib/auto/DBD/mysql/. You may have to use
the Apache directives SetEnv or PassEnv in this case
for a non-standard PATH location, if you didn't want to
copy it to C:/Perl/site/lib/auto/DBD/mysql/.

-- 
best regards,
randy


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

Date: Fri, 31 Jan 2003 03:31:06 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Checking for a file
Message-Id: <slrnb3jrfq.se5.mgjv@verbruggen.comdyn.com.au>

On 30 Jan 2003 17:54:26 -0800,
	Brandon Reddish <mechman991@hotmail.com> wrote:
> Andrew Lee wrote in message news:<7tvi3vcu76thd2t5tqm3tjdvp9t708542s@4ax.com>...
>> On Thu, 30 Jan 2003 16:37:29 GMT, "TBN" <ihave@noemail.com> wrote:
>> 
>> >I'm still pretty new to Perl, so bear with me on this probably simple
>> >question.
>> >
>> >I know that I can open a file using the following...
>> >open (CODE, $filename) || &OtherStuff;
>> >
>> >But I'm not really interested in opening this file. 
>> 
>> perldoc perlfunc
>> 
>> Look for -X FILEHANDLE ... the list of filetest operators.
> 
> Hello,
> The easiest way to check to see if a file exists would be;
> 
> if (-e file.html)
> {
> Insert whatever here.
> }

However, be careful about the fact that your OS might not have the
same idea about what a 'file' is as you have. On unix, for example, a
symbolic link and a directory and a device are just files. Most people
(at least the ones that need to ask this question) have a much less
sophisticated idea of what they consider to be a file. often they just
mean the thing that in the -X documentation is called a "plain file"
which can be tested for with -f.

> This checks to see if the file simply exists.  Check this page for
> more information: http://pageresource.com/cgirec/ptut17.htm

Instead of that, I would most definitely suggest that the OP read the
perlfunc documentation, as was suggested earlier.

In fact, I would like to take this opportunity to advise anyone
interested, to not use that tutorial. A cursory glance of that
referenced page suggests that it is incomplete and not very precise
about the -X operators.  On the next subject, "opening directories",
the author does check for opendir() success (good), but then does not
include $! in the error message (bad). There is no mention whatsoever
of the important largest unexpected problem with readdir() (to access
files, you should prepend the directory).

(quick glance at first few tutorial topics)
No strictures.
No warnings.
No mention of lexical variables and scoping.

I could probably find more problems, if I could be bothered.

But then, Perl is organised under CGI there. Enough said, I suppose.

Martien
-- 
                        | 
Martien Verbruggen      | Freudian slip: when you say one thing but
Trading Post Australia  | mean your mother.
                        | 


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

Date: 31 Jan 2003 02:38:38 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: creating a binary file with desired size
Message-Id: <b1cnje$n90$1@canopus.cc.umanitoba.ca>

In article <146277ca.0301301646.62e40a15@posting.google.com>,
James Lee <csejl@yahoo.com> wrote:
:i have a script that takes file name and size and creates a file of
:the size specified.  this is currently done with texts and i was
:wondering if i can do this with binary files.  thanks for your help in
:advance.

Should be the same method either way: open the file for writing,
invoke the perl function 'truncate' giving the length you want it
to be.


-- 
Can a statement be self-referential without knowing it?


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

Date: Fri, 31 Jan 2003 02:35:01 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Creating my own Guestbook.
Message-Id: <3e39dd59.10003341@news.erols.com>

mechman991@hotmail.com (Brandon Reddish) wrote:

[snip N-thousand lines of code and HTML nobody is going to read
anyway]

: How do I have the form to append to the center of a file?

perldoc -q insert



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

Date: Fri, 31 Jan 2003 03:38:35 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Creating my own Guestbook.
Message-Id: <slrnb3jrts.se5.mgjv@verbruggen.comdyn.com.au>

On 30 Jan 2003 18:01:59 -0800,
	Brandon Reddish <mechman991@hotmail.com> wrote:
> I have the following form mail codes .. scroll to the bottom for my
> question:

Next time, don't include so much stuff. If you have this much code,
put it on your web site, not here.

[SNIP of large amount of non-Perl related stuff]

> ----------[ This is the form that recieves the data and writes it to
> an html file: ]
> 
> #!/usr/bin/perl

no warnings, no strict.

> require "cgi-lib.pl";
> 
> &ReadParse(*input);

Use of ancient perl 4 code. Don't. Use the CGI module.

[snip of rest]

Please, consider using the guest book at
http://nms-cgi.sourceforge.net/, or at least look at their code to see
how it should be done.

> You get the idea.  How do I have the form to append to the center of a
> file?  Thanks!

I haven't read any of the code I snipped, but I didn't need to. 

Your question is a frequently asked one, and therefore appears in the
list of frequently asked questions, which are shipped with Perl as
part of the standard documentation. You can find the answer in section
5 of the FAQ (the perlfaq5 document), under the question "How do I
change one line in a file/delete a line in a file/insert a line in the
middle of a file/append to the beginning of a file?". Note that the
answer is different for different versions of Perl; in perl 5.8.0 you
would use the standard module Tie::File, for 5.6.1 and before you
would need to download that module or do all the work yourself.

Martien
-- 
                        | 
Martien Verbruggen      | Little girls, like butterflies, need no
Trading Post Australia  | excuse - Lazarus Long
                        | 


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

Date: 30 Jan 2003 18:25:50 -0800
From: mechman991@hotmail.com (Brandon Reddish)
Subject: Perl Operations
Message-Id: <60d818b.0301301825.7c1eb924@posting.google.com>

This is a pretty generic question, but does anyone have a link to a
list of Perl modules, and there uses / definitions?  This would be
great, thanks.  :)


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

Date: Fri, 31 Jan 2003 02:39:17 GMT
From: Alan Gutierrez <ajglist@izzy.net>
Subject: Re: Perl Operations
Message-Id: <pll_9.65230$GX4.2699367@news2.east.cox.net>

Brandon Reddish wrote:

> This is a pretty generic question, but does anyone have a link to a
> list of Perl modules, and there uses / definitions?  This would be
> great, thanks.  :)

Ask Google about CPAN. Type `perldoc CPAN` in your shell.

From now on you will start with:

perldoc perlfaq

You need to learn about posting to c.l.p.misc.

Alan Gutierrez - ajglist@izzy.net


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

Date: Fri, 31 Jan 2003 04:49:00 GMT
From: "codeWarrior" <GPatnude@adelphia.net>
Subject: Re: Perl Operations
Message-Id: <0fn_9.15659$ni5.2795348@news1.news.adelphia.net>


"Brandon Reddish" <mechman991@hotmail.com> wrote in message
news:60d818b.0301301825.7c1eb924@posting.google.com...
> This is a pretty generic question, but does anyone have a link to a
> list of Perl modules, and there uses / definitions?  This would be
> great, thanks.  :)

Yeah... sure do.... http://www.cpan.org/

GP




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

Date: Thu, 30 Jan 2003 21:50:29 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl Operations
Message-Id: <slrnb3jsk5.m18.tadmc@magna.augustmail.com>

Brandon Reddish <mechman991@hotmail.com> wrote:

> This is a pretty generic question, 


It is a Question that is Asked Frequently.


> but does anyone have a link to a
> list of Perl modules, and there uses / definitions?


   perldoc -q module

      "What modules and extensions are available for Perl?  What
       is CPAN?  What does CPAN/src/... mean?"


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 30 Jan 2003 22:21:16 -0600
From: Abernathey Family <family2@aracnet.com>
Subject: Re: Perl Operations
Message-Id: <3E39F9BC.2C76E912@aracnet.com>

Tad McClellan, a recent gradute of the perldocIsRevelationFromADeity
seminary wrote:
> 
> Brandon Reddish <mechman991@hotmail.com> wrote:
> 
> > This is a pretty generic question,
> 
> It is a Question that is Asked Frequently.
> 
> > but does anyone have a link to a
> > list of Perl modules, and there uses / definitions?
> 
>    perldoc -q module
--snip--
Do you suppose that it is possible that this person doesn't have access
to Unix at the moment?
<gag>

-Don


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

Date: Fri, 31 Jan 2003 06:56:03 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Perl Operations
Message-Id: <Xns93145015B188Aelhber1lidotechnet@62.89.127.66>

Abernathey Family wrote:

> Tad McClellan, a recent gradute of the perldocIsRevelationFromADeity
> seminary wrote:
>> 
>> Brandon Reddish <mechman991@hotmail.com> wrote:
>> 
>> > This is a pretty generic question,
>> 
>> It is a Question that is Asked Frequently.
>> 
>> > but does anyone have a link to a
>> > list of Perl modules, and there uses / definitions?
>> 
>>    perldoc -q module
> --snip--
>
> Do you suppose that it is possible that this person doesn't have access
> to Unix at the moment?
> <gag>


So?


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



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

Date: Fri, 31 Jan 2003 07:08:18 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl Operations
Message-Id: <Chp_9.322$2A4.100@nwrddc04.gnilink.net>

Abernathey Family wrote:
> Tad McClellan, a recent gradute of the perldocIsRevelationFromADeity
> seminary wrote:
[...]
>>> but does anyone have a link to a
>>> list of Perl modules, and there uses / definitions?
>>
>>    perldoc -q module
> --snip--
> Do you suppose that it is possible that this person doesn't have
> access to Unix at the moment?
> <gag>

In which way would having access to Unix be relevant to using perldoc?

jue





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

Date: Fri, 31 Jan 2003 07:13:11 +0100
From: "Djm" <dmuren@start.no>
Subject: Re: Search a text
Message-Id: <Xto_9.22193$Rc7.312431@news2.e.nsc.no>

The format of my bible is a plain text file.
gen1:2 Bla bla bla bla
            bla lba bla
gen:1:3 bla bla
gen1:4 bla bla bla
bla bla bal
gen1:5

As you can see the text in each verse is not just on one line, so I need to
find a way to print out one verse at a time - any verse.

"Djm" <dmuren@start.no> wrote in message
news:8J5_9.21813$Rc7.306417@news2.e.nsc.no...
> I need some help to search a text. I have read in some of the perl faqs,
but
> since I am a newbie I do not understand how I can solve this.
>
> I want to search the bible. For those of you who are familiar with the
bible
> knows that it is build by books, chapters and verses. Now, I want to
search
> for e.g. gen2:3. The text can be found on several lines so I need to
extract
> the text between gen2:3 and gen2:4. I also have to have in mind that
> somewhere down the line the books change.
>
> Anyone know how to deal with this "problem"?
>
> I need help because I´ve started to learn perl 3 days ago.
>
> Djm
>
>




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

Date: 30 Jan 2003 23:54:18 -0800
From: jeremy.gooch@axa-im.com (Jeremy Gooch)
Subject: Re: Timestamps to thousandths of a second.
Message-Id: <723f1c02.0301302354.40e824ee@posting.google.com>

news@roaima.freeserve.co.uk wrote in message news:<p3q81b.dvu.ln@moldev.cmagroup.co.uk>...
> Jeremy Gooch <jeremy.gooch@axa-im.com> wrote:
> > I need to generate a current date/timestamp in the format
> > yyyymmddhhmmssxxx where xxx are the thousandths of a second.  The code
> > must be portable across Solaris and NT.
> 
> Are those two platforms sufficiently accurate to be able to give you
> meaningful results to that precision? Solaris on SPARC is notoriously
> unreliable (unless driven by a recent version of NTP from a good
> time source), and I have also heard bad things about NT's timekeeping
> generally.
> 
> Chris

An interesting point, but I think it's OK.  As long as the machine on
which we're implementing it gives a different stamp every thousandth
of a second, it'll work.  We using it as part of a correlationID for
some MQ messages.

Thanks again!


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

Date: Fri, 31 Jan 2003 06:49:15 GMT
From: zathras <moo@cow.com>
Subject: Re: user logins and profiles
Message-Id: <v55k3vg7sq12ftivf41i0pi0g9bmbgi2jk@4ax.com>

Thanks, Jeff.

Looks like I need to get a better understanding of how session
management works and how it's implemented...because I'm not sure what
you mean when you say this is a WWW question rather  hen a Perl
question.

I'll have a look at the links your provided.

To answer your question, the web server we are using is:

Apache/2.0.39 (Unix) mod_ssl/2.0.39 OpenSSL/0.9.6b vhostdb/1.0
Frontpage/5.0.0.0


On Thu, 30 Jan 2003 19:07:52 -0600, Jeff D Gleixner
<glex_nospam@qwest.net> wrote:

>zathras wrote:
>> I am beginning work on a web site that will display custom content
>> based on a username/password login. Something along the lines of, say,
>> "My Amazon", but not nearly that complex.
>> 
>> This is my first attempt at something like this. I think I have a
>> general idea of what needs to be done, but am not quite sure how to
>> put it all together.
>> 
>> I'll be using Perl/CGI and DBI.
>> 
>> Can anyone provide any good sources of information that covers this in
>> some detail. I've been googling the web, but have not found anything
>> thorough enough for what I need.
>
>This really is a WWW question about session management, however there are
>possible Perl solutions.
>
>Look at Appplications/Modules such as:
>
>Mason  http://www.masonhq.com/ (there's a book out on mason also)
>or possibly using TemplateToolkit.
>or
>PHP http:://www.php.net/  (not Perl, but possibly useful for your needs)
>
>They package everything up to make development of database/dynamic
>content driven sites much easier.  You don't mention your Web server, which
>may also decide on your solution.



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

Date: Fri, 31 Jan 2003 08:26:37 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Using cgi-script to add unix user (need to modify shadow file) How??
Message-Id: <3E3A252D.DE1837E8@fujitsu-siemens.com>

Tomas Nopp wrote:
> =

> Hi,
> we are running an application for which we on a linux system set up
> new accounts by executing a perl script as a cron job. The script gets
> the parameters needed from a html form.
> =

> On linux all this can be don with useradd but in this case we are
> running on solaris and useradd cannot take a password as a parameter
> (-p on linux)
> =

> ----
> my $cmd =3D sprintf "/usr/sbin/useradd -d /home/customers/a/%s -g
> customer -k/root/template -m -p %s %s", %$href->{username}, $pwd,
> %$href->{username};
> ----
> =

> So now I need to first set up the user then modify the shadow file to
> give the user a correct password. Does anyone have an example on how
> to do it? My perl skills are not so advanced.....

As Andrew Lee already pointed out, there are numerous security issues in
this idea, but otoh, you might generate a random password, enter that
into the shadow file, then send that password to the user involved over
a secure connection.

Take a look at "expect": it mimics a terminal connection using ptys
(pseudo ttys) and allows you to perform a dialogue with an interactive
program based upon a given script. One of the books covering expect
explicitly mentions the passwd program as a target to throw a script
against.
You may also want to look at Richard Stevens' "Advanced Programming in
the Unix Environment" and there the chapter about ptys. If all you need
to do is to communicate with exactly one application, just hard-coding
the conversation into a separate program might be worth the hassle.

Josef
-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: Fri, 31 Jan 2003 04:54:04 GMT
From: Gordon Barbay <gbarbay@NOnetscapeSPAM.net>
Subject: Re: Very Basic Question on the Use of the __DATA__ Token
Message-Id: <78nj3v8f4ps4trfeemr3qghm4h4jjbbcnf@4ax.com>

On Wed, 29 Jan 2003 04:35:02 GMT, Gordon Barbay
<gbarbay@NOnetscapeSPAM.net> wrote:

>On Tue, 28 Jan 2003 01:05:20 -0600, tadmc@augustmail.com (Tad
>McClellan) wrote:
>
>>Gordon Barbay <gbarbay@NOnetscapeSPAM.net> wrote:
>>
>>The DATA thing actually has nothing to do with your problem.
>You are correct!
>>
>>
>>> while (<main::DATA>) {
>>> find (\&sav_fd, @_);
>
>>You spelled the name of the variable incorrectly, that should be $_ .
>Unfortunately, thats not right either.  Program still bombs if I make
>that change.

Doh!  Tad was right.  That *did* work.  I had forgotten about the
chomp().  

I can even use the @_ :

while (chomp(@_=<DATA>)) {
 find (\&sav_fd, @_);
}

Thanks again Tad and you also, Tassilo for helping out, especially
with something so simple!

BTW Tad, I had never used 'map' before. Now you have given me
something else to go educate myself on! :-)


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

Date: Thu, 30 Jan 2003 23:40:12 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Very Basic Question on the Use of the __DATA__ Token
Message-Id: <slrnb3k31s.n41.tadmc@magna.augustmail.com>

Gordon Barbay <gbarbay@NOnetscapeSPAM.net> wrote:

> BTW Tad, I had never used 'map' before. Now you have given me
> something else to go educate myself on! :-)


I resisted learning it for a couple of years myself. When I
finally purposed myself to understand the Schwartzian Transform
I had to bite the bullet and learned it.

map isn't really too hard, it is just a foreach in disguise.

You could rewrite my code to use a foreach and a temp variable instead:

   # untested
   my @dirs;
   foreach ( <main::DATA> ) {
      chomp;
      push @dirs, $_;
   }
   find (\&sav_fd, @dirs);


But in this particular case, we don't really need either of map/foreach:

   my @dirs = <main::DATA>;  # list context
   chomp @dirs;
   find (\&sav_fd, @dirs);


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 31 Jan 2003 04:53:39 GMT
From: "codeWarrior" <GPatnude@adelphia.net>
Subject: Re: Why is this script sending 0 byte file attachments?
Message-Id: <njn_9.15662$ni5.2796093@news1.news.adelphia.net>

Your problem is HTML:

<FORM ACTION = '../../cgi-bin/employee/index.pl'
ENCTYPE="multipart/form-data">

"Tara" <tararse@hotmail.com> wrote in message
news:27eb673f.0301301142.5bc9612d@posting.google.com...
> Hello, this script is passing the uploaded files as 0 bytes... can
> someone see what I am doing wrong here?  Perhaps it's in my encoding?
>
> Thanks and kind regards,
>
> Tara
>
> @@@@ START OF .PL SCRIPT
>
> #!/usr/local/bin/perl
>
> $|++;
> # _________________________________________________________
>
> use CGI;
>
> $query=new CGI;
>
> print $loc = "Location:/confirm.send.htm\n";
>
> print "Content-type: text/html\n\n";
>
> $dir_to_store="/tmp";
> $no_of_files=0;
> @list=();
>
> $email_recipient = 'tararse@hotmail.com;
> $subject = "Subject Line One";
> $Subject1 = "Subject Line Two";
> $Message1 = "Message";
>
> &mailAttachment;
> &confirmation;
>
> # _________________________________________________________
> sub mailAttachment {
>
> $boundary="Message-Boundary-19990614";
> $mailprog ="/usr/lib/sendmail";
>
> foreach ($query->param){
>     if ($query->param($_)){     ##     The user entered some value!!
>          if (/^file_attached_[A-Z]$/){     ##     The uploaded file!!
>               ++$no_of_files;
>               push(@list,$_);
>
>
>          }else{     ##     One of the other items (Sender's Name,
> Sender's Email, etc...).
>               ##     Store the value in a variable.
>               ##     The name of the variable is the same as the HTML
> form element name
>               ##     Eg if the HTML element is called name_sender, the
> PERL
>               ##     variable will be called $name_sender.
>               $$_=$query->param($_);
>
>          }
>     }
> }
>
>
>     open(MAIL, "| $mailprog -t ");
>     print MAIL "To: $name_recipient <$email_recipient>\n";
>     print MAIL "From: $name_sender <$email_sender>\n";
>     print MAIL "CC: $cc\n";
>     print MAIL "BCC: $bcc\n";
>     print MAIL "Subject: $subject\n";
>     print MAIL "MIME-Version: 1.0\n";
>     print MAIL "Content-type: Multipart/1;\n";
>     print MAIL "\tboundary=$boundary\n";
>     print MAIL "\n";
>     print MAIL "\n";
>     print MAIL "--$boundary\n";
>
>     foreach (@list){
>          $uploaded_file=$query->param($_);
>
>          $tmp_uploaded_file=$query->param($_);
>          $tmp_uploaded_file=~ s/\\/\//g;
>          @tmp_uploaded_file=split(/\//,$tmp_uploaded_file);
>
>          $filename = $tmp_uploaded_file[$#tmp_uploaded_file];
>
>          $content="";
>          while($bytesread=read($uploaded_file,$data,1024)){
>               $size+=$bytesread;
>               $content.=$data;
>          }
>          close($uploaded_file);
>
>          $size=0;
>
>          ##  Print the header for that attachment.
>          print MAIL "Content-type: application/octet-stream;
> name=\"$filename\"; type=Unknown\n";
>          print MAIL "Content-transfer-encoding: BASE64\n";
>          print MAIL "Content-disposition: attachment\n";
>          print MAIL "\n";
>
>          $content= encode_base64($content);  ##  Use base64 for
> encoding the contents
>
>          ##  Attach the file!!
>          print MAIL $content;
>          print MAIL "\n";
>          print MAIL "--$boundary\n";
>     }
>
>     ##     Add the text part of the message
>     print "Content-type: text/html\n\n";
>     print MAIL "Content-type: text/plain; charset=US-ASCII\n";
>     print MAIL "Content-description: Mail message body\n";
>     print MAIL "Content-transfer-encoding: 7BIT\n";
>     print MAIL "\n";
>     print MAIL "First Name: $first_name\n";
>     print MAIL "Last Name: $last_name\n";
>     print MAIL "Email: $email_sender\n\n";
>     print MAIL "Phone Number: $phone_number\n";
>     print MAIL "Address Line 1: $address_1\n";
>     print MAIL "Address Line 2: $address_2\n";
>     print MAIL "Address Line 3: $address_3\n";
>     print MAIL "City: $city\n";
>     print MAIL "State: $state\n";
>     print MAIL "Province: $province\n";
>     print MAIL "Country: $country_name\n";
>     print MAIL "Zip/Postal Code: $zippost\n";
>     print MAIL "--$boundary\n";
>
>     ##  Send out the contents!!
>     print MAIL "Message/Comments\n$main_message";
>     print MAIL "\n";
>     print MAIL "--$boundary--\n";
>     close(MAIL);
>
> }
> # _________________________________________________________
>
> sub confirmation {
>
> open(MAIL, "| $mailprog -t ");
> print MAIL "To: $email_sender\n";
> print MAIL "From: $email_recipient\n";
> print MAIL "Subject: $Subject1\n";
>
> print MAIL "$Message1\n\n";
>
> close (MAIL);
>
> }
> # _________________________________________________________
>
>     print "$loc\n\n";
>
>
> # _________________________________________________________
>
> sub encode_base64 ($;$){
>     my $res = "";
>     my $eol = $_[1];
>     $eol = "\n" unless defined $eol;
>     pos($_[0]) = 0;                          # ensure start at the
> beginning
>     while ($_[0] =~ /(.{1,45})/gs) {
>          $res .= substr(pack('u', $1), 1);
>          chop($res);
>     }
>     $res =~ tr|` -_|AA-Za-z0-9+/|;               # `# help emacs
>     # fix padding at the end
>     my $padding = (3 - length($_[0]) % 3) % 3;
>     $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
>     # break encoded string into lines of no more than 76 characters
> each
>     if (length $eol) {
>          $res =~ s/(.{1,76})/$1$eol/g;
>     }
>     $res;
> }
>
>
> @@@@ HTML TEST SNIPPET
>
> <html>
> <head>
>      <title>Test Upload</title>
> </head>
> <body>
> <FORM ACTION="./test_upload.pl" METHOD="post">
>
> <table>
> <tr>
>   <td width="125" height="30">File 1</td>
>   <td height="30" width="306"><input type="file"
> name="file_attached_A"</td>
> </tr>
> <tr>
>   <td width="125" height="30">File 2</td>
>   <td height="30" width="306"><input type="file"
> name="file_attached_B"</td>
> </tr>
> <tr>
> <td colspan="2">
> <input type="submit" value="Submit Files" name="submit">
> </td>
> </tr>
> </table>
> </form>
> </body><script> window.open=NS_ActualOpen; </script>
> <script> window.open=NS_ActualOpen; </script>
>
> </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 4493
***************************************


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