[26292] in Perl-Users-Digest
Perl-Users Digest, Issue: 8474 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 30 18:05:28 2005
Date: Fri, 30 Sep 2005 15:05:08 -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: 8474
Today's topics:
Re: I have problems with download scripts, it's trying <atk@sbcglobal.net>
Re: I have problems with download scripts, it's trying <atk@sbcglobal.net>
Re: I have problems with download scripts, it's trying <noreply@gunnar.cc>
Re: overload proxy object (Anno Siegel)
Re: string comparison <tassilo.von.parseval@rwth-aachen.de>
Re: Use of hash variables in module call - puzzling beh <news@lawshouse.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 30 Sep 2005 19:05:12 GMT
From: "E Arredondo" <atk@sbcglobal.net>
Subject: Re: I have problems with download scripts, it's trying to print instead of saving the file
Message-Id: <I%f%e.1835$Fi3.65@newssvr29.news.prodigy.net>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news: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;
>
I'm getting this on the log file after adding the strict command:
Global symbol "$query" requires explicit package name at
/usr/lib/apache/cgi-bin/upload.cgi line 11.
Global symbol "$upload_dir" requires explicit package name at
/usr/lib/apache/cgi-bin/upload.cgi line 13.
Global symbol "$filename" requires explicit package name at
/usr/lib/apache/cgi-bin/upload.cgi line 13.
Global symbol "$upload_dir" requires explicit package name at
/usr/lib/apache/cgi-bin/upload.cgi line 14.
Global symbol "$filename" requires explicit package name at
/usr/lib/apache/cgi-bin/upload.cgi line 14.
Global symbol "$upload_filehandle" requires explicit package name at
/usr/lib/apache/cgi-bin/upload.cgi line 16.
Global symbol "$query" requires explicit package name at
/usr/lib/apache/cgi-bin/upload.cgi line 22.
Global symbol "$claim" requires explicit package name at
/usr/lib/apache/cgi-bin/upload.cgi line 23.
Execution of /usr/lib/apache/cgi-bin/upload.cgi aborted due to compilation
errors.
[Fri Sep 30 11:57:15 2005] [error] [client 69.239.42.161] Premature end of
script headers: /usr/lib/apache/cgi-bin/upload.cgi
>
>> $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...
>
>
I screwed up when copying and pasting from my ssh window. sorry
>> 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.
>
>
I got it! Thanks!!! for your comments
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: Fri, 30 Sep 2005 19:10:10 GMT
From: "E Arredondo" <atk@sbcglobal.net>
Subject: Re: I have problems with download scripts, it's trying to print instead of saving the file
Message-Id: <m4g%e.1838$Fi3.1565@newssvr29.news.prodigy.net>
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news: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.
>
>
Thanks for your help, Indeed there was no /upload, I though wrong. Do you
know if the CPAN CGI:UploadEasy will let me download whole folders ? Or Is
there a way to do a whole folder download ?
Thanks
------------------------------
Date: Fri, 30 Sep 2005 23:15: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: <3q5o8bFdf0crU2@individual.net>
E Arredondo wrote:
> Do you know if the CPAN CGI:UploadEasy will let me download whole
> folders ?
Suppose you mean upload...
It sure will let you upload multiple files at once. One way would be to
include multiple file upload controls in the form, but then you'd need
to manually pick each file before the submission.
To _automatically_ have all the files in a folder uploaded, you would
need to do some pre-processing. It ought to be possible to grab a bunch
of filepaths and make the file upload request via the LWP family of modules.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 30 Sep 2005 21:03:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: overload proxy object
Message-Id: <dhk973$dhn$1@mamenchi.zrz.TU-Berlin.DE>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in comp.lang.perl.misc:
> Eric Anderson <eric@afaik.us> wrote in comp.lang.perl.misc:
[A class has expensive initialization, objects are created en masse, but
only a few are actually used. How to delay initialization to when
an object is actually used? OP had an AUTOLOAD-based solution that
didn't support overloading in the original class.]
It occurred to me that your original AUTOLOAD solution should
work just fine if you specify autoloading like this:
'""' => sub { $_[ 0]->stringify },
instead of
'""' => 'stringify',
The first one goes through overload (like any method call), the second
one doesn't. You can't access the object directly in these sub's (you
don't know if it is initialized), but method calls should be fine.
[I am proposing a solution based on overloading %{} which does:]
> Here is a sketch. It doesn't follow your setup exactly (I had no
> access to your posting when I wrote it), but I believe the principle
> is applicable. It could probably be streamlined some more. In
> particular, the class Data::User is hard-coded into Class::Delayed,
> which could mess up further inheritance. See what you can do with it.
[code sketch snipped]
I have cleaned up things a little. In the code below the problem
class (Heavy) is written more or less like any hash-based class.
Only ->new is split up in finer-grained sub-methods than usual.
Having an independent initialization method (init) is a good idea
in general, it also isolates the heavy-duty task. The internal method
_new defines the class as a hash-based one and nothing else.
The rest of the class is standard, there is an accessor ->name, also
used in overloading, and a method ->no_acc that doesn't use the
internals of its object at all.
The method new_delayed and the auxiliary class Heavy::Delayed can then be
added as an after-thought, without changes in the existing Heavy, and
with the code in Heavy::Delayed mostly independent from the implementation
of Heavy. ->new_delayed creates objects of a subclass of Heavy. On
the first attempt of any method to access the underlying hash, these
objects transform themselves into original objects of Heavy. That
delays initialization to the latest possible point.
Heavy::Delayed could become Class::Delayed.pm on CPAN, but I think
I'll resist.
In the main program you can create $h either through Heavy->new_delayed
(as shown) or through the original Heavy->new. The method call to ->no_acc
and overloading (hence a call to ->name) work the same in either case.
The exclamation "Man, Heavy!", which indicates (normally silent)
initialization, comes only with the stringification in the last
line when ->new_delayed is in effect. ->new initializes right away,
so "Man, Heavy!" comes first.
Anno
#!/usr/local/bin/perl
use strict; use warnings; $| = 1;
my $h = Heavy->new_delayed( 'Otto');
$h->no_acc;
print "Hi, I'm $h\n";
##########################################################
package Heavy;
sub _new { bless {}, shift }; # define type as hash
sub new {
my ( $class, @args) = @_;
$class->_new->init( @args);
}
sub init {
my $h = shift;
print "Man, ", __PACKAGE__, "!\n"; # do the hard work
@{ $h}{ qw( name)} = @_;
$h;
}
sub name { $_[ 0]->{ name} }
sub no_acc {
my $p = shift;
print "Didn't touch a thing, no sir.\n";
$p;
}
use overload '""' => 'name';
sub new_delayed {
Heavy::Delayed->new( @_); # class plus args
}
##########################################################
package Heavy::Delayed;
use base 'Heavy';
sub new {
my $class = shift;
$class->_new->init( @_); # inherited ->_new, own ->init
}
sub init {
my $hp = shift;
$hp->{ args} = [ @_];
$hp;
}
# transform Heavy::Delayed object into what Heavy->new( @args) would create
# this overloads %{} in Heavy::Delaed
sub switch {
my $p = shift;
return $p if caller eq __PACKAGE__; # don't recurse if we're the caller
my ( $class, @args) = @{ delete $p->{ args}};
bless $p, $class;
$p->init( @args);
}
use overload '%{}' => 'switch';
__END__
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Fri, 30 Sep 2005 21:53:49 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: string comparison
Message-Id: <slrndjr5ud.1d3.tassilo.von.parseval@localhost.localdomain>
Also sprach Anno Siegel:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
>> Babacio wrote:
>> > But if I guess what you really want to do, try that :
>> >
>> > if ($a eq 'apple' || $a eq 'banana') { etc }
>>
>> or this:
>>
>> if ( grep $a eq $_, ('apple', 'banana') ) {
>>
>> (perldoc -f grep)
>
> ...or use Quantum::Superposition
Yuck. I'd suggest
use List::MoreUtils qw/any/;
if (any { $a eq $_ } qw/apple banana/) {
Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
------------------------------
Date: Fri, 30 Sep 2005 22:39:13 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: Use of hash variables in module call - puzzling behaviour
Message-Id: <1128116353.86745.0@demeter.uk.clara.net>
Anno Siegel wrote:
> Strange indeed.
I installed Mail::Internet on another Linux server I have and tried my
tryit.pl program there - worked perfectly. So the problem manifests
itself on only my development server, and I have adopted the work-round
described below. Sooner or later I'll re-install it (probably at FC4)
and that will cure the problem I'm sure.
Many thanks to the many and various people who helped me localise the
problem and tried to find a solution.
> All I can think of is to apply random transformations to the string
> (copy it, append '', make it a hash key and retrieve it, capture it
> in a regex, ...) and see if anything has an effect.
On the offending server that's what I've done. I probably over-did it,
but I wrote a little subroutine which copied the characters of the
offending variable one by one into a new variable and returned it.
Whatever hex was on the old hash variable is thus destroyed and my
program works.
> One more thing. The error message is
>
>>Unrecognised line: postmaster@lawshouse.org at blib/lib/Mail/Internet.pm
>>(autosplit into blib/lib/auto/Mail/Internet/smtpsend.al) line 616
>
>
> An installed program shouldn't reside in blib/... but wherever the
> Perl library resides and the path shouldn't be relative. This looks
> like a pre-installation version is used for some reason.
Hmm; that was the CPAN installer wot did that. Maybe the problem lies
there; the re-install will sort it out.
--
Henry Law <>< Manchester, England
------------------------------
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 8474
***************************************