[19309] in Perl-Users-Digest
Perl-Users Digest, Issue: 1504 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 12 21:06:38 2001
Date: Sun, 12 Aug 2001 18: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)
Message-Id: <997664708-v10-i1504@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 12 Aug 2001 Volume: 10 Number: 1504
Today's topics:
Re: confused - can't print to file <krahnj@acm.org>
copy anonymous hashes <pilsl_@goldfisch.at>
Re: copy anonymous hashes <bart.lateur@skynet.be>
Re: Encrypted Email (Yves Orton)
FAQ: How come when I open a file read-write it wipes it <faq@denver.pm.org>
Re: how to test $X le 'z' (Poul H. Sorensen)
Re: how to verify $dir is null (Yves Orton)
Re: how to verify $dir is null <krahnj@acm.org>
Re: Learning Perl, 2nd Edition (Tim Hammerquist)
Re: permuting extremely large string (Yves Orton)
Re: permuting extremely large string <godzilla@stomp.stomp.tokyo>
Re: prob.. for each (open, file) <tinamue@zedat.fu-berlin.de>
Re: repeating substituation (Yves Orton)
setting a cookie <jerseycat10@yahoo.com>
Re: setting a cookie <ilya@martynov.org>
Re: Shouldn't sub foo {} be equivalent to sub foo {retu (John Lin)
Re: Statement modifiers?? ctcgag@hotmail.com
Re: Uploading a file via a browser w/out using CGI.pm <leapius@hotmail.com>
Re: Uploading a file via a browser w/out using CGI.pm <cdawson@webiphany.com>
Re: Uploading a file via a browser w/out using CGI.pm <gnarinn@hotmail.com>
using Inline.pm to distribute binary perl modules <cdawson@webiphany.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 12 Aug 2001 23:08:17 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: confused - can't print to file
Message-Id: <3B770C9E.28C81A95@acm.org>
"John W. Krahn" wrote:
>
> Terry wrote:
> >
> > print PROG
> > $prog[0]."\n".$prog[1]."\n".$prog[2]."\n".$prog[3]."\n".$prog[4].";".$in{mem
> > num};
>
> chomp $prog[4];
> print PROG "@prog[0..4];$in{memnum}"
Sorry, should be:
chomp $prog[4];
print PROG @prog[0..4], ";$in{memnum}"
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 13 Aug 2001 00:51:05 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: copy anonymous hashes
Message-Id: <3b77085b@e-post.inode.at>
I store a lot of information in an single anonymous hash with depth>1
Example:
$ptr->{sysdata}->{elephant}->[4]->{big}='ear';
Now I want to create a copy of this structure, so that modifying values in
the original structure will not affect the copy. This is not so easy, cause
if I just perform
%temp=%{$ptr};
$ptr2=/%temp;
I get a copy in the first level, but this first level are pointers again
and points to the same values than $ptr1 does.
(I hope this is clear)
Is there any simple way to create a copy trough all levels or will I need
to setup an recursive function with typecasting to do this ?
thnx,
peter
--
mag. peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Sun, 12 Aug 2001 23:01:22 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: copy anonymous hashes
Message-Id: <ei2entgfgd7v2493ajuenkfh2ifoomtcu0@4ax.com>
peter pilsl wrote:
>
>I store a lot of information in an single anonymous hash with depth>1
>
>Example:
>$ptr->{sysdata}->{elephant}->[4]->{big}='ear';
>
>Now I want to create a copy of this structure, so that modifying values in
>the original structure will not affect the copy.
You want a "deep copy". The module Storable has a function for that. The
trick is that a dump of the data structure is made, which is then turned
back into a live data structure.
--
Bart.
------------------------------
Date: 12 Aug 2001 16:02:11 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Encrypted Email
Message-Id: <74f348f7.0108121502.1c259b6f@posting.google.com>
"Jeff Snoxell" <Jeff@aetherweb.co.uk> wrote in message news:<9l0kj0$sr1$1@neptunium.btinternet.com>...
> Hi,
>
> Thanks for everyone's help with my BigInt and other problems.
>
> I'm still no closer to a solution however.
>
> I need a way to send 128-bit (minimum) encrypted emails from my ISP's linux
> server to my Outlook Express inbox. I have CGI and FTP access to the server
> but I don't have telnet and hence cannot easily install modules (I never
> seem to have any luck with installing modules even when I do have telnet
> access). I'm willing to spend a small amount of money to register some
> shareware if necessary.
I would have a look at OpenSSL if I were you. Nice command line SSL
tool. You might have to look into the Mime:: tree for building more
complicated mails (such as ones that contain attachments) but OpenSSL
will handle the en/decryption/ authentication of mails using SMIME
just fine.
Ive used OpenSSL and Perl together quite nicely in the past.
Good luck...
Yves
------------------------------
Date: Mon, 13 Aug 2001 00:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How come when I open a file read-write it wipes it out?
Message-Id: <10Fd7.66$V3.171041280@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How come when I open a file read-write it wipes it out?
Because you're using something like this, which truncates the file and
*then* gives you read-write access:
open(FH, "+> /path/name"); # WRONG (almost always)
Whoops. You should instead use this, which will fail if the file doesn't
exist.
open(FH, "+< /path/name"); # open for update
Using ">" always clobbers or creates. Using "<" never does either. The
"+" doesn't change this.
Here are examples of many kinds of file opens. Those using sysopen() all
assume
use Fcntl;
To open file for reading:
open(FH, "< $path") || die $!;
sysopen(FH, $path, O_RDONLY) || die $!;
To open file for writing, create new file if needed or else truncate old
file:
open(FH, "> $path") || die $!;
sysopen(FH, $path, O_WRONLY|O_TRUNC|O_CREAT) || die $!;
sysopen(FH, $path, O_WRONLY|O_TRUNC|O_CREAT, 0666) || die $!;
To open file for writing, create new file, file must not exist:
sysopen(FH, $path, O_WRONLY|O_EXCL|O_CREAT) || die $!;
sysopen(FH, $path, O_WRONLY|O_EXCL|O_CREAT, 0666) || die $!;
To open file for appending, create if necessary:
open(FH, ">> $path") || die $!;
sysopen(FH, $path, O_WRONLY|O_APPEND|O_CREAT) || die $!;
sysopen(FH, $path, O_WRONLY|O_APPEND|O_CREAT, 0666) || die $!;
To open file for appending, file must exist:
sysopen(FH, $path, O_WRONLY|O_APPEND) || die $!;
To open file for update, file must exist:
open(FH, "+< $path") || die $!;
sysopen(FH, $path, O_RDWR) || die $!;
To open file for update, create file if necessary:
sysopen(FH, $path, O_RDWR|O_CREAT) || die $!;
sysopen(FH, $path, O_RDWR|O_CREAT, 0666) || die $!;
To open file for update, file must not exist:
sysopen(FH, $path, O_RDWR|O_EXCL|O_CREAT) || die $!;
sysopen(FH, $path, O_RDWR|O_EXCL|O_CREAT, 0666) || die $!;
To open a file without blocking, creating if necessary:
sysopen(FH, "/tmp/somefile", O_WRONLY|O_NDELAY|O_CREAT)
or die "can't open /tmp/somefile: $!":
Be warned that neither creation nor deletion of files is guaranteed to
be an atomic operation over NFS. That is, two processes might both
successfully create or unlink the same file! Therefore O_EXCL isn't as
exclusive as you might wish.
See also the new the perlopentut manpage if you have it (new for 5.6).
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
05.12
--
This space intentionally left blank
------------------------------
Date: 13 Aug 2001 01:56:47 +0200
From: poul@asp.infostream.no (Poul H. Sorensen)
Subject: Re: how to test $X le 'z'
Message-Id: <ukitfsde80.fsf@bjarne.ppp.asp.infostream.no>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> According to Ilya Martynov <ilya@martynov.org>:
> >
> > jp> I seem to be having a problem testing for the value of a character
> > jp> variable.
> > jp> the code is as follows
> >
> > jp> for ( $letter = 'a' ; $letter le 'z'; $letter++)
> > jp> {
> > jp> print $letter."\n";
> > jp> }
> >
Try:
foreach my $letter ( 'a'..'z' ) {
print $letter,"\n";
}
The $letter++ construct is used for generating unique identifiers (like filenames),
and could be used in conjunction with numerals:
$str = 'a_'00';
while ( -f $str ) { $str++ };
and it is useful for brute-force attacks on crosswords....
From perlop:
If, however, the variable has been used
in only string contexts since it was set, and has a value
that is not the empty string and matches the pattern
"/^[a-zA-Z]*[0-9]*\z/", the increment is done as a string,
preserving each character within its range, with carry:
print ++($foo = '99'); # prints '100'
print ++($foo = 'a0'); # prints 'a1'
print ++($foo = 'Az'); # prints 'Ba'
print ++($foo = 'zz'); # prints 'aaa'
The auto-decrement operator is not magical.
Good luck
Poul
- - - - - - - - - - - - - - -
print $Std{'Disclaimer'};
$CC = +-1; # the Computer Constant - very useful when writing loops.
$|=1; printf "Just another [lazy] %s hacker\r",("PERL","perl")[sleep(1)+$i] while ($i=$i?0:$CC,1);
__EOF__
------------------------------
Date: 12 Aug 2001 15:53:54 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: how to verify $dir is null
Message-Id: <74f348f7.0108121453.76228cbf@posting.google.com>
Ilya Martynov <ilya@martynov.org> wrote in message news:<87lmkrpqyl.fsf@abra.ru>...
> if(defined $dir) {
Why defined() and not
if ($dir) {
Just curious....
Yves
------------------------------
Date: Sun, 12 Aug 2001 23:11:34 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how to verify $dir is null
Message-Id: <3B770D63.6542D58D@acm.org>
Yves Orton wrote:
>
> Ilya Martynov <ilya@martynov.org> wrote in message news:<87lmkrpqyl.fsf@abra.ru>...
> > if(defined $dir) {
>
> Why defined() and not
>
> if ($dir) {
>
> Just curious....
$dir = '0'; # :-)
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sun, 12 Aug 2001 23:07:14 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Learning Perl, 2nd Edition
Message-Id: <slrn9ne3jh.ad1.tim@vegeta.ath.cx>
Me parece que Dat Nguyen <thucdat@hotmail.com> dijo:
> hakonrk@fys.uio.no (Haakon Riiser) wrote in message news:<slrn9ncvjs.a9.hakonrk@s.hn.org>...
> > [Randal L. Schwartz]
> >
> > > The second edition is a fine book, but I also think the third edition
> > > is better. Those are not contradictory positions! Although depending
> > > on your goals they may end up supporting different behaviors.
> >
> > I was planning on using Perl in Unix system administration, replacing
> > sed & awk for many tasks. I've heard that the 3rd edition is targeted
> > less towards Unix users, so I think I'll keep the 2nd edition. I assume
> > the difference between Perl 5.004 and 5.6 isn't very important in an
> > introductory book such as this.
> >
> > Anyway, thanks for answering my question!
>
> With the upcoming "Parrot", should I bother with "Programming Perl
> 3rd" and "Learning Perl 3rd" at all?
Well, with the upcoming "Parrot", you have the opportunity to shell out
$20 bucks for one of the few books in the "Technical Fiction" genre. =)
"The funny part was that setting up the whole joke was the biggest
collaboration between Perl and Python we've seen for a long time!"
-- Simon Cozens, re. "Parrot" April Fools prank
--
I am following my fish.
-- Delirium, The Sandman
------------------------------
Date: 12 Aug 2001 15:17:53 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: permuting extremely large string
Message-Id: <74f348f7.0108121417.88a1751@posting.google.com>
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message news:<3B758FE0.131BA172@stomp.stomp.tokyo>...
> Old String: Godzilla Rocks And Rolls! Oh Yes! She Rocks My Socks Off!
>
> New String: Rocks And Rolls! Oh Yes! She Rocks My Socks Off! Godzilla
> New String: And Rolls! Oh Yes! She Rocks My Socks Off! Godzilla Rocks
> New String: Rolls! Oh Yes! She Rocks My Socks Off! Godzilla Rocks And
> New String: Oh Yes! She Rocks My Socks Off! Godzilla Rocks And Rolls!
> New String: Yes! She Rocks My Socks Off! Godzilla Rocks And Rolls! Oh
> New String: She Rocks My Socks Off! Godzilla Rocks And Rolls! Oh Yes!
> New String: Rocks My Socks Off! Godzilla Rocks And Rolls! Oh Yes! She
> New String: My Socks Off! Godzilla Rocks And Rolls! Oh Yes! She Rocks
> New String: Socks Off! Godzilla Rocks And Rolls! Oh Yes! She Rocks My
> New String: Off! Godzilla Rocks And Rolls! Oh Yes! She Rocks My Socks
>
>
> New String: Godzilla And Rolls! Oh Yes! She Rocks My Socks Off! Rocks
> New String: And Rolls! Oh Yes! She Rocks My Socks Off! Rocks Godzilla
> New String: Rolls! Oh Yes! She Rocks My Socks Off! Rocks Godzilla And
> New String: Oh Yes! She Rocks My Socks Off! Rocks Godzilla And Rolls!
> New String: Yes! She Rocks My Socks Off! Rocks Godzilla And Rolls! Oh
> New String: She Rocks My Socks Off! Rocks Godzilla And Rolls! Oh Yes!
> New String: Rocks My Socks Off! Rocks Godzilla And Rolls! Oh Yes! She
> New String: My Socks Off! Rocks Godzilla And Rolls! Oh Yes! She Rocks
> New String: Socks Off! Rocks Godzilla And Rolls! Oh Yes! She Rocks My
> New String: Off! Rocks Godzilla And Rolls! Oh Yes! She Rocks My Socks
>
>
> New String: Rolls! Godzilla Rocks Oh Yes! She Rocks My Socks Off! And
> New String: Godzilla Rocks Oh Yes! She Rocks My Socks Off! And Rolls!
> New String: Rocks Oh Yes! She Rocks My Socks Off! And Rolls! Godzilla
> New String: Oh Yes! She Rocks My Socks Off! And Rolls! Godzilla Rocks
> New String: Yes! She Rocks My Socks Off! And Rolls! Godzilla Rocks Oh
> New String: She Rocks My Socks Off! And Rolls! Godzilla Rocks Oh Yes!
> New String: Rocks My Socks Off! And Rolls! Godzilla Rocks Oh Yes! She
> New String: My Socks Off! And Rolls! Godzilla Rocks Oh Yes! She Rocks
> New String: Socks Off! And Rolls! Godzilla Rocks Oh Yes! She Rocks My
> New String: Off! And Rolls! Godzilla Rocks Oh Yes! She Rocks My Socks
>
>
> New String: Godzilla Rocks Rolls! Oh Yes! She Rocks My Socks Off! And
> New String: Rocks Rolls! Oh Yes! She Rocks My Socks Off! And Godzilla
> New String: Rolls! Oh Yes! She Rocks My Socks Off! And Godzilla Rocks
> New String: Oh Yes! She Rocks My Socks Off! And Godzilla Rocks Rolls!
> New String: Yes! She Rocks My Socks Off! And Godzilla Rocks Rolls! Oh
> New String: She Rocks My Socks Off! And Godzilla Rocks Rolls! Oh Yes!
> New String: Rocks My Socks Off! And Godzilla Rocks Rolls! Oh Yes! She
> New String: My Socks Off! And Godzilla Rocks Rolls! Oh Yes! She Rocks
> New String: Socks Off! And Godzilla Rocks Rolls! Oh Yes! She Rocks My
> New String: Off! And Godzilla Rocks Rolls! Oh Yes! She Rocks My Socks
My oh my, you are the egotist arent you.
Yves The Friendly Troll
--
PS I am not, nor have ever been, anyone else!
------------------------------
Date: Sun, 12 Aug 2001 15:50:12 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: permuting extremely large string
Message-Id: <3B770824.FEC02294@stomp.stomp.tokyo>
Yves Orton wrote:
> Godzilla! wrote:
(snipped)
> > Old String: Godzilla Rocks And Rolls! Oh Yes! She Rocks My Socks Off!
> My oh my, you are the egotist arent you.
Your thought is borne of your fragile masculine ego.
It is quite the norm for you and most men to think in
terms of individual ego.
My realistic nature and personally dictate any
expressions I convey are well supported by my
extraordinary self-confidence and by my healthy
stout feminine ego. I suffer not this timeless
malady of men, boy-men and Neandertal men,
Terminal Testosterone Poisoning.
Your sore lack of good thinking is reflected by
your not testing my method, then pitching one of
your stereotypical CLPM Troll anal retentive fits.
This code of mine contains one glaring error and
two rather amusing bugs.
> PS I am not, nor have ever been, anyone else!
PS. I have tiny blue monkeys flying out of my big butt,
each harmoniously singing Steppenwolf's "Born To Be Wild."
Godzilla! Queen Of Wildland.
--
http://la.znet.com/~callgirl3/bornwild.mid
------------------------------
Date: 12 Aug 2001 22:09:50 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: prob.. for each (open, file)
Message-Id: <9l6ure$7o1io$2@fu-berlin.de>
Jerry Nezlick <jnez367@yahoo.com> wrote:
> I get a STDIN Chunk 1 error. Is there something wrong here?
> ##
> ## @wind is all the files in the directory from Open DIR
> foreach $item (@wind){open(32, "C:/Snort/log/192.168.1.110/$item") or
> die "could not open";
> @logs=<32>;
> @results=grep(/$guery/, @logs); #query is text to search for.
> close 32;
> }
my $path = 'C:/Snort/log/192.168.1.110';
foreach my $item (@wind) {
open FILE, "$path/$item" or die "could not open <$item>: $!\n";
my @results = grep (/$query/, <FILE>);
close FILE;
print @results;
}
> print @results;
in @results in your version you will just have the @results from the
last loop. do you want that?
> Any help would be greatly appreciated. The program works when I
> specify a path to a file rather than using the variable.
well, try my (untested!) version and see what happens.
<guessing>
you may want to use chomp(@wind)
perldoc -f chomp
</guessing>
hth, tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
--- Warning: content of homepage hopelessly out-dated ---
------------------------------
Date: 12 Aug 2001 15:47:35 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: repeating substituation
Message-Id: <74f348f7.0108121447.4bdc2931@posting.google.com>
Richard Chamberlain <richard@sunsetandlabrea.com> wrote in message news:<pF5d7.17383$tq.1881540@news6-win.server.ntlworld.com>...
> Thomas Bätzler wrote:
[Rearranged]
> I've no idea what all that means so I'll sit down and work it out for bit
> :-(.
>
[referring to..]
>
> > Hm, OTTOH:
> >
> > my %replace = ( "\'" => "\\\'",
> > "ffffff" => "000000",
> > "Times" => "Verdana" );
Hes setting up a hash (ie named pairs) of search/replace options
> > my $strings = join '|', keys %replace;
Now he is taking the search options and building a regex from them:
$strings="\'|ffffff|Times"
after this line...
> >
> > $sectionHTML =~ s/($strings)/$replace{$1}/g;
This searches for anything that matches $string, store what it matches
in $1 as well as use the same for looking up the replacement in the
hash.
ie if the match is "\'" then it replaces it with "\\\'"
Yves
------------------------------
Date: Sun, 12 Aug 2001 18:23:08 -0400
From: "AJ M" <jerseycat10@yahoo.com>
Subject: setting a cookie
Message-Id: <9l6vpr$p71$1@bob.news.rcn.net>
Hello, I seem to have no trouble( i think) retrieving cookie(s). I retrieve
it like this:
%cookies = fetch CGI::Cookie;
$status = defined $cookies{'validity'} ? $cookies{'validity'}->value :
undef;
(THANKS TO Ilya Martynov )
However, I cannot seem to figure out how to set it properly, it always comes
up as being empty.
I only need to be able to set this one cookie (with a timeout when browser
it closed).
I know that it is only like 2-3 lines of code, but I cannot figure it out or
find it anywhere!
Thanks for any help!
AJ
------------------------------
Date: 13 Aug 2001 03:41:04 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: setting a cookie
Message-Id: <87y9oon8xb.fsf@abra.ru>
AM> Hello, I seem to have no trouble( i think) retrieving cookie(s).
AM> I retrieve it like this:
AM> %cookies = fetch CGI::Cookie;
AM> $status = defined $cookies{'validity'} ? $cookies{'validity'}->value :
AM> undef;
AM> (THANKS TO Ilya Martynov )
AM> However, I cannot seem to figure out how to set it properly, it
AM> always comes up as being empty.
AM> I only need to be able to set this one cookie (with a timeout when
AM> browser it closed).
AM> I know that it is only like 2-3 lines of code, but I cannot figure
AM> it out or find it anywhere!
Read 'perldoc CGI::Cookie'. It have an example how you can set a
cookie:
my $c = new CGI::Cookie(-name => 'foo',
-value => 'bar');
print "Set-Cookie: $c\n";
print "Content-Type: text/html\n\n";
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 12 Aug 2001 17:38:25 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Re: Shouldn't sub foo {} be equivalent to sub foo {return} or sub foo {()} ?
Message-Id: <a73bcad1.0108121638.2ec17243@posting.google.com>
"Martien Verbruggen" wrote
> John Lin wrote:
> > package X;
> >
> > sub new {
> > my $self = bless {};
> > for($self->using) { push @{$self->{objects}},$_ }
> > return $self;
> > }
> >
> > sub using {}
> >
> > sub load {
> > my $self = shift;
> > $_->load for @{$self->{objects}};
> > }
> >
> > package main;
> > X->new->load;
> As written above, it would always return an empty list in list context,
> which means that your for loop above simply wouldn't ever get executed.
No, it returns "last evaluated expression" which is the "return $self".
Thus, @{$self->{objects}} surprisingly contains an object, which causes
deep recursion at "$_->load" later. Cool, right?
If it returns an empty list, what causes the "deep recursion"? Belive me.
> Out of curiosity, what do you want using() to do? What is its purpose?
> What did you _expect_ an empty sub to do?
The X.pm is the base class. Users can inherit and overwrite it:
package Y;
use base 'X';
sub using { 'A','B','C' } # overwrite the "using list"
Then, when you say
Y->new->load;
A->load, B->load, C->load will also be called.
sub using {} in X:: is used to set empty "using list" for default.
(Note: modify the bless into 2 arguments first before experimenting)
Thank you.
John Lin
------------------------------
Date: 13 Aug 2001 00:09:02 GMT
From: ctcgag@hotmail.com
Subject: Re: Statement modifiers??
Message-Id: <20010812200902.398$NG@newsreader.com>
Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
> Hi everyone,
>
> Uri stated in another thread...
>
> "learn to use perl's statement modifiers as it will clean up your
> code. one big win for them is reducing the unneeded braces and indents
> of simple conditionals..."
>
> I have looking all over the place for info on statement
> modifiers (searching www.perl.com and Google) and have come up with very
> scant stuff.
When you wish to use a foreach, if, while, unless, etc with only one
statement, you can put the statement first, then the modifier, without
using braces.
die "AAAggg, you idiot, you can't do that" unless $x>0 ;
I tend to use them less often than I could get away with due to
Murphy's law. If I use one, it will usually turn out later that
I need to add another statement to the construct, and have to rewrite it.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service
------------------------------
Date: Mon, 13 Aug 2001 01:09:46 +0100
From: "Leo Hemmings" <leapius@hotmail.com>
Subject: Re: Uploading a file via a browser w/out using CGI.pm
Message-Id: <9l75r7$1qv$1@neptunium.btinternet.com>
Hi all,
I need to develop a script to upload files to a web server via a html form
but without using CGI.pm. I have used CGI.pm to do this successfully but
need to be able to do it without that module installed. I currently parse
STDIN from GET and POST methods with the routine below:
sub readform {
read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
my @pairs = split(/&/, $input);
foreach my $pair (@pairs) {
(my $name,my $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
my @vars = split(/&/, $ENV{QUERY_STRING});
foreach my $var (@vars) {
(my $v,my $i) = split(/=/, $var);
$v =~ tr/+/ /;
$v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$i =~ tr/+/ /;
$i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$i =~ s/<!--(.|\n)*-->//g;
$INFO{$v} = $i;
}
$action = $INFO{'action'};
$section = $INFO{'section'};
}
Now this works perfectly for all GET and POST requests that I need. However
I am at a loss as to know where to begin including the 'file upload'
routines that are in CGI.pm into this routine. Currently and data sent via
POST in a form which uses <form enctype="multipart/form-data"> does not get
loaded into my hash %FORM. Any ideas would be greatly appreciated. Would it
be possible for instance to 'rip' out the appropriate code from CGI.pm and
include it in my routine?
Thankyou in advance,
Leo
P.S. I know I'm doing it the hard way but CGI.pm is just not an option for
my application.
------------------------------
Date: Sun, 12 Aug 2001 17:41:12 -0700
From: "Chris Dawson" <cdawson@webiphany.com>
Subject: Re: Uploading a file via a browser w/out using CGI.pm
Message-Id: <tne8bf86mb5rf1@corp.supernews.com>
Leo,
Just to confirm with you on your reasons for not using CGI.pm. You do know
that you could copy the perl module itself from another machine, and place
it in any directory on the server, even the one where this web script you
are writing resides, and then do something like this:
use lib '/path/where/script/sits/'
use CGI.pm;
The "use lib" statement allows you to setup your own perl modules directory.
For security reasons, it is probably better to not place this module in the
same directory where it could be served up by the webserver.
CGI.pm is a pure perl module so you can feel free to install it this way.
It seems like you'd be better off doing this than copying code from CGI.pm
into your script. I assume your web server admin won't install this module
for you? I can't think of anything other than religious reasons (or
possibly that you can't use the "use" statement for some reason) why you
wouldn't want to use CGI.pm. Remember, one of the prime virtues of Perl is
laziness, and what you are doing seems to break this rule! :)
If there is another reason, I would love to know what it is.
Chris
"Leo Hemmings" <leapius@hotmail.com> wrote in message
news:9l75r7$1qv$1@neptunium.btinternet.com...
> Hi all,
>
> I need to develop a script to upload files to a web server via a html form
> but without using CGI.pm. I have used CGI.pm to do this successfully but
> need to be able to do it without that module installed. I currently parse
> STDIN from GET and POST methods with the routine below:
>
> sub readform {
> read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
> my @pairs = split(/&/, $input);
> foreach my $pair (@pairs) {
> (my $name,my $value) = split(/=/, $pair);
> $name =~ tr/+/ /;
> $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",
hex($1))/eg;
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",
hex($1))/eg;
> $FORM{$name} = $value;
> }
> my @vars = split(/&/, $ENV{QUERY_STRING});
> foreach my $var (@vars) {
> (my $v,my $i) = split(/=/, $var);
> $v =~ tr/+/ /;
> $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $i =~ tr/+/ /;
> $i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $i =~ s/<!--(.|\n)*-->//g;
> $INFO{$v} = $i;
> }
> $action = $INFO{'action'};
> $section = $INFO{'section'};
> }
>
> Now this works perfectly for all GET and POST requests that I need.
However
> I am at a loss as to know where to begin including the 'file upload'
> routines that are in CGI.pm into this routine. Currently and data sent via
> POST in a form which uses <form enctype="multipart/form-data"> does not
get
> loaded into my hash %FORM. Any ideas would be greatly appreciated. Would
it
> be possible for instance to 'rip' out the appropriate code from CGI.pm and
> include it in my routine?
>
> Thankyou in advance,
> Leo
>
> P.S. I know I'm doing it the hard way but CGI.pm is just not an option for
> my application.
>
>
------------------------------
Date: Mon, 13 Aug 2001 00:31:06 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Uploading a file via a browser w/out using CGI.pm
Message-Id: <997662666.16096543520689.gnarinn@hotmail.com>
In article <9l75r7$1qv$1@neptunium.btinternet.com>,
Leo Hemmings <leapius@hotmail.com> wrote:
>Hi all,
>
>I need to develop a script to upload files to a web server via a html form
>but without using CGI.pm. I have used CGI.pm to do this successfully but
>need to be able to do it without that module installed. I currently parse
>STDIN from GET and POST methods with the routine below:
>
>sub readform {
(snipped typical GET and application/x-www-form-urlencoded POST decoding)
>
>Now this works perfectly for all GET and POST requests that I need. However
>I am at a loss as to know where to begin including the 'file upload'
>routines that are in CGI.pm into this routine. Currently and data sent via
>POST in a form which uses <form enctype="multipart/form-data"> does not get
>loaded into my hash %FORM. Any ideas would be greatly appreciated. Would it
>be possible for instance to 'rip' out the appropriate code from CGI.pm and
>include it in my routine?
>
well, it would probably help you if you looked at the HTTP specs
(used to be RFC-1945). you must realize that a multipart/form-data POST
content is basically a multipart mime message, where each part can have
its own Content-Type and Content-Transfer-Encoding, and can in turn be
multipart. if you want to do this without using modules, you should
get familiar with the HTTP and MIME RFCs, and do thorough testing with
all possible browser you plan to support.
gnari
------------------------------
Date: Sun, 12 Aug 2001 16:53:33 -0700
From: "Chris Dawson" <cdawson@webiphany.com>
Subject: using Inline.pm to distribute binary perl modules
Message-Id: <tne5i4efvsv100@corp.supernews.com>
Hi there,
I have written a perl module using Inline.pm. Fantastic module, I have to
say. I now want to distribute the binary DLL that is created by Inline. I
have another win32 NT machine where I want to run this script, but this
machine doesn't have any of the third-party libraries used to compile the C
code, nor does it even have a developer environment with a c compiler or
linker. I could probaby install cygwin and fiddle with this, but I was
hoping there would be some way that I could bundle the DLL that I see is
residing deep within the _Inline directory, and use this from within my
script without it attempting a recompile. One other issue I anticipate
with this idea is that I will need to install an additional library, since
the DLL is itself only 20K, and I know that my perl application uses a
third-party library which is obviously not statically built into the DLL.
Anyone have any tips for me here?
I realize some of these questions lean more to the side of C issues, BUT
since the purpose of the Inline.pm module is to insulate me from knowing
much about compilers and linkers, I was hoping there might be an easy way to
do this. I also realize that it is probably a better idea to distribute the
precompiled perl only code, and generate the binary on each host platform to
guard against differences in compilers etc., and if I were distributing this
as a public module I would try to achieve perl code that did this. In this
case, howerver, I want to install this on one machine and sacrificing
potential lack of portability is worth what time I would otherwise spend on
getting a build environment setup on this NT machine which I am accessing
remotely.
Thanks for your time in advance.
Chris
------------------------------
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 1504
***************************************