[26289] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8471 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 30 03:05:19 2005

Date: Fri, 30 Sep 2005 00:05:05 -0700 (PDT)
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, 30 Sep 2005     Volume: 10 Number: 8471

Today's topics:
    Re: I have problems with download scripts, it's trying  <tadmc@augustmail.com>
    Re: I have problems with download scripts, it's trying  <noreply@gunnar.cc>
    Re: I have problems with download scripts, it's trying  <noreply@gunnar.cc>
    Re: I have problems with download scripts, it's trying  <noreply@gunnar.cc>
    Re: Order of Elements in Hash <tadmc@augustmail.com>
        Print substitution ? <uctraing@ultranet.com>
    Re: Print substitution ? <sherm@dot-app.org>
    Re: Print substitution ? <sherm@dot-app.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 29 Sep 2005 20:23:58 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: I have problems with download scripts, it's trying to print instead of saving the file
Message-Id: <slrndjp4te.85j.tadmc@magna.augustmail.com>

E Arredondo <atk@sbcglobal.net> wrote:

> #!/usr/bin/perl -w
> 
> use CGI;


You are missing a line that should be included in all of your Perl programs:

   use strict;


> $filename = $query->param("photo");
> $filename =~ s/.*[\/\\](.*)/$1/;


   perldoc File::Basename


> $upload_filehandle = $query->upload("photo");


That variable contains a *string*, not a filehandle...


> open UPLOADFILE, ">$upload_dir/$filename";


You should always, yes *always*, check the return value from open():

   open UPLOADFILE, ">$upload_dir/$filename" or
      die "could not open '$upload_dir/$filename'  $!";


>  while ( <$upload_filehandle> )


You need to put an _actual_ filehandle inside the input operator.


><HEAD>
><TITLE>Thanks!</TITLE>
><HEAD>
><TITLE>Thanks!</TITLE>
></HEAD>


That is a rather bizarre document structure...


> And here's the log file :
> binmode() on closed filehandle UPLOADFILE at 


Your open() failed, but you didn't know it because you did
not check its return value.


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


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

Date: Fri, 30 Sep 2005 06:07:11 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: I have problems with download scripts, it's trying to print instead of saving the file
Message-Id: <3q3rvhFcu4s0U1@individual.net>

E Arredondo wrote:
> 
> use CGI;
> 
> $upload_dir = "/upload";
> $query = new CGI;
> $filename = $query->param("photo");
> $claim = $query->param("claim");
> $filename =~ s/.*[\/\\](.*)/$1/;
> $upload_filehandle = $query->upload("photo");
> open UPLOADFILE, ">$upload_dir/$filename";
>  binmode UPLOADFILE;
>  while ( <$upload_filehandle> )
>  {
>    print UPLOADFILE;
>  }
> close UPLOADFILE;
> print $query->header ( );

You may want to use the CPAN module CGI::UploadEasy. The above part of 
your script can be replaced with:

     use CGI::UploadEasy;
     my $ue = CGI::UploadEasy->new(-uploaddir => "/upload");
     my $cgi = $ue->cgiobject;
     my $claim = $cgi->param('claim');
     print $cgi->header;

Now, as others have said, I doubt that you have a directory "/upload" 
under the server root. Maybe you mean "$ENV{DOCUMENT_ROOT}/upload".
CGI::UploadEasy includes the necessary checks to find out.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Fri, 30 Sep 2005 06:20:53 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: I have problems with download scripts, it's trying to print instead of saving the file
Message-Id: <3q3sp7Fd5ac4U1@individual.net>

Tad McClellan wrote:
> E Arredondo wrote:
>> 
>> $filename = $query->param("photo");
>> $filename =~ s/.*[\/\\](.*)/$1/;
> 
>    perldoc File::Basename

Not for parsing the path that comes with a file upload request. 
File::Basename doesn't have a clue about the platform the file was 
uploaded from.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Fri, 30 Sep 2005 06:33:39 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: I have problems with download scripts, it's trying to print instead of saving the file
Message-Id: <3q3th4Fd4ld0U1@individual.net>

Gunnar Hjalmarsson wrote:
> Tad McClellan wrote:
>> E Arredondo wrote:
>>>
>>> $filename = $query->param("photo");
>>> $filename =~ s/.*[\/\\](.*)/$1/;
>>
>>    perldoc File::Basename
> 
> Not for parsing the path that comes with a file upload request. 
> File::Basename doesn't have a clue about the platform the file was 
> uploaded from.

CGI::UploadEasy uses this expression to remove the non-filename part of 
the path:

     s#.*[\]:\\/]##

Hopefully it's platform independent...

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 29 Sep 2005 20:13:48 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Order of Elements in Hash
Message-Id: <slrndjp4ac.85j.tadmc@magna.augustmail.com>

chris-usenet@roaima.co.uk <chris-usenet@roaima.co.uk> wrote:
> chris-usenet@roaima.co.uk <chris-usenet@roaima.co.uk> wrote:
>> Perl has never guaranteed any ordering of the hash keys [...]
> 
> Tad McClellan <tadmc@augustmail.com> wrote:
>> And your point is?
> 
> That we may have a documentation error? 


I don't see one.

First, I cannot find the above quote in perlsec (v5.8.0).

And even if I could find it, it does not contradict what
is being discussed in this thread, the relative order of the
lists returned by keys() and values().


> Perl clearly /does/ guarantee
> the ordering of the hash keys under well defined circumstances.


It may be clear to you, but I cannot see one at all.

Perl guarantess that the list from keys() will "line up" with
the list from values() if the hash has not been modified
between the two calls.

It says nothing with regard to what that order will be, only
that, whatever order it is, it will be the same for the return
values from keys() and from values().


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


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

Date: Fri, 30 Sep 2005 01:49:43 GMT
From: Bob <uctraing@ultranet.com>
Subject: Print substitution ?
Message-Id: <c56pj1hgn6figne4sbnre3ig16f3p1m8ld@4ax.com>

I am trying to read in the contents of a file (which contains psuedo
variables) and then print the file's contents and have variable
substitution occur. 

Example: 

[file contains this text: "Your name is $name"]

open (HEADER, "< ../header.htm") 
my @headerLines = <HEADER>;
my $name = "Freddy";
print_html("@headerLines");

When I do this, I get the contents of the file, but the variable does
not get substituted. So the output looks like this: 

	Your name is $name

Suggestions ? This is actually part of a much larger file read with
many more variables and I could really use substitution. 

Thanks,


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

Date: Thu, 29 Sep 2005 23:15:37 -0400
From: Sherm Pendley <sherm@dot-app.org>
Subject: Re: Print substitution ?
Message-Id: <m21x37qm92.fsf@Sherm-Pendleys-Computer.local>

Bob <uctraing@ultranet.com> writes:

> I am trying to read in the contents of a file (which contains psuedo
> variables) and then print the file's contents and have variable
> substitution occur.

Search CPAN for the word "template" - this is very well-explored territory,
so there's little need to reinvent that particular wheel.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Thu, 29 Sep 2005 23:18:15 -0400
From: Sherm Pendley <sherm@dot-app.org>
Subject: Re: Print substitution ?
Message-Id: <m2wtkzp7k8.fsf@Sherm-Pendleys-Computer.local>

Sherm Pendley <sherm@dot-app.org> writes:

> Bob <uctraing@ultranet.com> writes:
>
>> I am trying to read in the contents of a file (which contains psuedo
>> variables) and then print the file's contents and have variable
>> substitution occur.
>
> Search CPAN for the word "template" - this is very well-explored territory,
> so there's little need to reinvent that particular wheel.

Forgot the link:

  <http://search.cpan.org>

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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