[24330] in Perl-Users-Digest
Perl-Users Digest, Issue: 6519 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 5 03:05:58 2004
Date: Wed, 5 May 2004 00:05:13 -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 Wed, 5 May 2004 Volume: 10 Number: 6519
Today's topics:
At wits end! LWP and IIS(?) <calvine.is.not@starhub.net.sg>
Re: Books online???? <catcher@linuxmail.org>
Re: Books online???? <***************>
Re: Books online???? (Randal L. Schwartz)
Re: Books online???? <bernard.el-haginDODGE_THIS@lido-tech.net>
Re: Can perl be used for cookie setting? <webmaster @ infusedlight . net>
Email inbox to printer (Aki)
free source authentication script <webmaster @ infusedlight . net>
Re: free source authentication script <tassilo.parseval@rwth-aachen.de>
Help Needed Building Array Of Hashes From CSV <tsheetspublic@insightbb.com>
Re: Help Needed Building Array Of Hashes From CSV <jtc@shell.dimensional.com>
Re: Komodo as a editor? <webmaster @ infusedlight . net>
multimap equivalent in perl (Kapil Khosla)
Re: multimap equivalent in perl <jtc@shell.dimensional.com>
Re: need help with security <webmaster @ infusedlight . net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 5 May 2004 11:37:56 +0800
From: "Calvine Chew" <calvine.is.not@starhub.net.sg>
Subject: At wits end! LWP and IIS(?)
Message-Id: <c79m4b$806$1@reader01.singnet.com.sg>
I've been trying to get a script to post to another script for some time now
but to no avail! Sending the LWP POST request to the receiving script and
printing out the request/results, I get the following:
###################
POST http://llc.compsys.org/up.cgi Content-Length: 177 Content-Type:
multipart/form-data; boundary=xYzZY --xYzZY Content-Disposition: form-data;
name="upload"; filename="success.txt" Content-Length: 36 Content-Type:
text/plain IT WORKED!!! 5th May 2004 11:24am --xYzZY--
It didn't work. 501 (Not Implemented) syntax error Content-Type: text/plain
Client-Date: Wed, 05 May 2004 03:37:10 GMT Client-Warning: Internal response
501 syntax error
501 syntax error
###################
Both sending and receiving scripts are on the same server. I'm a relative
newbie to Perl so I desperately need help on this! Any URLs or FAQs I can
refer to to get more info on my troubles? Is it a Perl problem or a
webserver one?
Much appreciated in advance!
Below is my POSTer code:
###################
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use lib 'modules';
use LWP::UserAgent 2.031;
use HTTP::Request::Common 1.22 qw/POST/;
my $ua= LWP::UserAgent->new();
my $url = "http://llc.compsys.org/up.cgi";
my $fullpath_filename = param("upload");
my $filename = lc($fullpath_filename);
$filename =~ s/.*[\/\\](.*)/$1/;
print (header());
print (start_html( -title => 'Upload' ));
if (!$filename) {
print ("No file specified.<br>\n");
print qq~
<form action="upload.cgi" method="post" enctype="multipart/form-data">
File upload:
<input type="file" name="upload" size="60"><br>
<br>
<input type="submit" name="Submit" value="Upload">
</form>
</body></html>
~;
}
else {
open UPLOADFILE, ">$filename";
binmode(UPLOADFILE);
while ( <$fullpath_filename> ){ print UPLOADFILE; }
close UPLOADFILE;
print "$filename uploaded!<br>";
my $fullpath = $ENV{'DOCUMENT_ROOT'}."/cgi-bin/$filename";
print "FULLPATH = $fullpath<br>";
print "Above file exists!<br><br>" if -e $fullpath;
print "Above file does not exist!<br><br>" if !-e $fullpath;
my $request=POST $url , Content_Type=>'form-data',
Content => [upload=>[$filename]];
print $request->as_string; print "<br><br>";
my $results=$ua->request($request);
if($results->is_success){
print "It's good!\n";
print $results->as_string; print "<br><br>";
} else {
print "It didn't work.\n";
print $results->as_string; print "<br><br>";
print $results->status_line();
}
###################
This is my server code:
###################
#!/usr/bin/perl
use CGI qw(:standard);
$filename = param("upload");
$filename =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = param("upload");
print (header());
print (start_html( -title => 'Upload' ));
if (!$filename) {
print ("No file specified.<br>\n");
}
else {
$filename = lc($filename);
open UPLOADFILE, ">$filename";
binmode(UPLOADFILE);
while ( <$upload_filehandle> ){ print UPLOADFILE; }
close UPLOADFILE;
print ("<b>$filename</b> upload successful!<br>\n");
}
print ("</BODY>\n</HTML>");
###################
------------------------------
Date: Tue, 04 May 2004 21:37:06 -0400
From: Robert <catcher@linuxmail.org>
Subject: Re: Books online????
Message-Id: <RL2dnUjyt53e2AXd4p2dnA@adelphia.com>
Henry Williams wrote:
< ... >
>
> I apologize if I misread your remarks. This NG is like dodging
> bullets. One never knows for certain if one's post has the correct
> form, indeed it takes as much research to be sure of that as it does
> to answer the bloody question in the first instance, bringing into
> sharp relief the question of the necessity for this NG at all.
I can understand your reaction given the nature of some post responses
so that to me is no big deal.
> I can't busy myself with helping O'Reilly no matter how fond I am of
> their books. There are far too many nooks and crannies for things to
> hide away in on the 'Net. In notifying them I'd seem a crackpot. Not
> to mention that in today's world it's best to be quiet, what with RIAA
> and all. Why draw attention to yourself? It would be as if you were at
> the airport and said "I think that man has a gun!" They would grab
> you first.
>
That makes no sense at all. So maybe my post should have been harsher.
Basically what you are saying is "don't bother me". The reasons you give
for not notifying O'Reilly are rediculous. You should have just said "I
don't want to be bothered." and left it at that. Instead you give
non-sensical reasons for not doing the *right* thing. I can only hope in
real life you are a more ethical person.
Robert
------------------------------
Date: Tue, 04 May 2004 21:02:24 -0500
From: Henry Williams <***************>
Subject: Re: Books online????
Message-Id: <vnig909gqui8pit9krjcahrb47jlf060ai@4ax.com>
On Tue, 04 May 2004 21:37:06 -0400, Robert <catcher@linuxmail.org>
wrote:
>That makes no sense at all. So maybe my post should have been harsher.
>Basically what you are saying is "don't bother me". The reasons you give
>for not notifying O'Reilly are rediculous. You should have just said "I
>don't want to be bothered." and left it at that. Instead you give
>non-sensical reasons for not doing the *right* thing. I can only hope in
>real life you are a more ethical person.
>
>Robert
Robert you seem to be a fair-minded person. What I sought to point out
is that once I have undertaken the task of policing O'Reilly's
copyrights, I would, as an "ethical" person, scarcely have any
stopping point. If I found a copyright violation, and reported it to
O'Reilly, would I not then be obligated to be "on guard" on O'Reilly's
behalf in all my coming and goings on the Net?
Would it not be true at that point I would have undertaken a new
profession, that of copyright assuror?
As for my poor "airport" analogy, what I refer to is the old scenario
of the person making the compliant becoming the first suspect. I would
reference an Edgar Allen Poe story to support my assertion, have you
read "The Black Cat" ?
I have little hiding in my walls, however attention is not what one
wishes to draw to oneself. And if that single aspect of my character
renders me in someone's eyes as unethical paint me unethical.
Best Regards,
Henry
------------------------------
Date: Wed, 05 May 2004 02:41:14 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Books online????
Message-Id: <06584b098cfbb35c0067af666067f1bb@news.teranews.com>
>>>>> "Henry" == Henry Williams <***************> writes:
Henry> Robert you seem to be a fair-minded person. What I sought to point out
Henry> is that once I have undertaken the task of policing O'Reilly's
Henry> copyrights, I would, as an "ethical" person, scarcely have any
Henry> stopping point. If I found a copyright violation, and reported it to
Henry> O'Reilly, would I not then be obligated to be "on guard" on O'Reilly's
Henry> behalf in all my coming and goings on the Net?
Henry> Would it not be true at that point I would have undertaken a new
Henry> profession, that of copyright assuror?
You make it sound like it'll take an hour a day for the rest
of your life, simply because you noticed one and reported it.
Let me assure you, that I report *every* one I see, and at most it's
about 15 seconds to forward some report to infringement@ora.com, and
that I can count the amount of time I spend on this activity in terms
of minutes per decade. :)
If you see it, report it. You don't have to go crazy, but every bit
helps.
print "Just another Perl hacker,"; # and book writer
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 5 May 2004 08:49:02 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: Books online????
Message-Id: <Xns94E059B967266elhber1lidotechnet@62.89.127.66>
Henry Williams <***************> wrote:
[...]
> I can't busy myself with helping O'Reilly no matter how fond
> I am of their books.
Lucky you never posted a self righteous speech about not having the
urge to act like a bastard or that statement would make you look like
an idiot...oh, wait a minute...
--
Cheers,
Bernard
------------------------------
Date: Tue, 4 May 2004 22:24:34 -0800
From: "Robin" <webmaster @ infusedlight . net>
Subject: Re: Can perl be used for cookie setting?
Message-Id: <c7a1c4$pk8$2@reader2.nmix.net>
"Danny" <dannywork5@hotmail.com> wrote in message
news:NGalc.93810$Gd3.22108107@news4.srv.hcvlny.cv.net...
> I wrote some javascript to retrive/set cookie for user.
> The code just puts the reffering id passed in URL somewhere on the website
> for tracking purposes.
>
> I don't like how the code can be seen by all users if the wanted to. I
> would also prefer something server side.
> Is there a way I can use PERL to create a cookie in the same fashion?
> Just put a call to a cgi script in the header or body of all web pages to
> return the cookie info or set it if need be.
>
> Thanks in advance
btw, my latest post has some examples of cookies and CGI.pm...
-Robin
------------------------------
Date: 4 May 2004 20:12:52 -0700
From: google@d-kaff.co.uk (Aki)
Subject: Email inbox to printer
Message-Id: <9dc9f3b0.0405041912.2b293d98@posting.google.com>
Hi,
I am currently using fetchmail to retrieve mail from a POP server
every couple of minutes, and it is delivering it to the standard
/var/spool/mail/$user
I need a script to monitor this users new mail when fetchmail has
retrieved one, and make an audible alert to alert everyone of its
arrival and also to print out the new email to the default printer.
Any ideas? All help would be greatly received, I am open to any
suggestions.
regards,
Aki.
------------------------------
Date: Tue, 4 May 2004 22:22:45 -0800
From: "Robin" <webmaster @ infusedlight . net>
Subject: free source authentication script
Message-Id: <c7a18h$pk7$2@reader2.nmix.net>
www.infusedlight.net/robin/temp/auth.txt
Comments on this? The bottom two subs are meant for the script that the
auth.pl script goes to and the way the cookies are set, makes it secure in
that if someone forgets to logout of the administration or other script that
auth.pl goes to and someone else points their browser to that script that
auth points to, it will simply redirect them to whatever page the webmaster
chooses, ie: auth.pl again or the entry point to auth.pl. Some of you may
have been doing this very same thing, pointing your browser to the admin
script or something similar, and I spent an hour improving the script so
this major security flaw won't be present. At least now my site won't be
defaced in this form, anyway.
hehe...
--
Regards,
-Robin
--
[ webmaster @ infusedlight.net ]
www.infusedlight.net
------------------------------
Date: Wed, 5 May 2004 08:46:16 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: free source authentication script
Message-Id: <c7a2jr$1bs0g$1@ID-231055.news.uni-berlin.de>
Also sprach Robin:
> www.infusedlight.net/robin/temp/auth.txt
>
> Comments on this? The bottom two subs are meant for the script that the
> auth.pl script goes to and the way the cookies are set, makes it secure in
> that if someone forgets to logout of the administration or other script that
> auth.pl goes to and someone else points their browser to that script that
> auth points to, it will simply redirect them to whatever page the webmaster
> chooses, ie: auth.pl again or the entry point to auth.pl. Some of you may
> have been doing this very same thing, pointing your browser to the admin
> script or something similar, and I spent an hour improving the script so
> this major security flaw won't be present. At least now my site won't be
> defaced in this form, anyway.
So after a successful login procedure, you do a redirect to the actual
CGI script (e.g. admin.pl). Fine as far as that goes. However, how does
this script figure out that a user is properly authenticated? A visitor
could always call admin.pl directly.
Now I see that auth.pl does two other things: It creates a file
"Loggedinfile.log" and sets a cookie. Would admin.pl use these two
things to determine whether a user is logged in? I hope not.
"Loggedinfile.log" only exists once which means that anybody could log
in as long as at least one person is already authenticated. Doing
authentication based on a cookie is a very bad idea as well, as cookies
reside on the client machine and anybody could create such a thing
manually.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Wed, 05 May 2004 02:28:11 GMT
From: Tim Sheets <tsheetspublic@insightbb.com>
Subject: Help Needed Building Array Of Hashes From CSV
Message-Id: <%iYlc.24520$TD4.3466652@attbi_s01>
Hello group,
I am rather new to Perl (and programming in general) and am having a
problem building a hash. I have read several tutorials, examples, etc..
but nothing touches on exactly what I am trying to do.
I am trying to read data in from a CSV file (Excel export) and store the
information in an array of hashes. The first line of the file contains
field names, and the following lines contain data.
So, I am reading the first line into an array, splitting on the commas,
to use as the hash keys. Then all subsequent lines are read into
another array, splitting on the commas to be used as the values.
Then I am trying to build another array, and combine the 'keys' and
'values' from the first two arrays as a hash.
Here is the code I am trying to use:
# Begin reading csv dump
open (REFERENCEFILE,"$ARGV[1]") ;
$count=0;
while (<REFERENCEFILE>) {
if ($count == 0) {
@refdatakeys = split(/,/, $_);
$numelements = scalar (@refdatakeys);
} else {
@refdatavalues = split(/,/, $_);
for ($i=0; $i < $numelements; $i++) {
@arrefdata = ({$refdatakeys[$i] => '$refdatavalues[$i]'});
}
}
print ("SITE ID is: $arrefdata[$count]{'SITE ID'}\n");
$count++;
}
If I put print statements to test the values in @refdatakeys and
@refdatavalues, everything is stored in those two arrays. But, I can't
figure out what I am doing wrong when trying to store those values as
key/value pairs in @arrefdata. Or, I guess it's possible that values
are stored, but I am not correctly accessing that data in my print
statement.
If anyone can figure out what I am doing wrong, I sure would appreciate
some help.
Thanks all!!
Tim
------------------------------
Date: 4 May 2004 22:53:45 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Re: Help Needed Building Array Of Hashes From CSV
Message-Id: <slrnc9gsqp.nnr.jtc@shell.dimensional.com>
In article <%iYlc.24520$TD4.3466652@attbi_s01>, Tim Sheets wrote:
> Hello group,
>
> I am rather new to Perl (and programming in general) and am having a
> problem building a hash. I have read several tutorials, examples, etc..
> but nothing touches on exactly what I am trying to do.
>
> I am trying to read data in from a CSV file (Excel export) and store the
> information in an array of hashes. The first line of the file contains
> field names, and the following lines contain data.
>
> So, I am reading the first line into an array, splitting on the commas,
> to use as the hash keys. Then all subsequent lines are read into
> another array, splitting on the commas to be used as the values.
>
> Then I am trying to build another array, and combine the 'keys' and
> 'values' from the first two arrays as a hash.
I could read your code and guess, but instead, it might save time
to first ask: What exactly are you trying to do? You're describing
the problem in terms of an implementation, but I don't see any precise
problem description mentioned or implied from the above description (maybe
imprecise, but that's not good enough for a computer). In other words,
what are the requirements for your problem? (If you decide to spend
the time to become good at programming, you'll learn that being able to
state the problem without mentioning or implying an implementation is
one important skill you will need.)
Once your requirements are clear, people can then help you find a solution -
an implementation.
>
> Here is the code I am trying to use:
>
> # Begin reading csv dump
> open (REFERENCEFILE,"$ARGV[1]") ;
>
> $count=0;
>
> while (<REFERENCEFILE>) {
> if ($count == 0) {
> @refdatakeys = split(/,/, $_);
> $numelements = scalar (@refdatakeys);
> } else {
> @refdatavalues = split(/,/, $_);
> for ($i=0; $i < $numelements; $i++) {
> @arrefdata = ({$refdatakeys[$i] => '$refdatavalues[$i]'});
> }
> }
>
> print ("SITE ID is: $arrefdata[$count]{'SITE ID'}\n");
> $count++;
> }
>
> If I put print statements to test the values in @refdatakeys and
> @refdatavalues, everything is stored in those two arrays. But, I can't
> figure out what I am doing wrong when trying to store those values as
> key/value pairs in @arrefdata. Or, I guess it's possible that values
> are stored, but I am not correctly accessing that data in my print
> statement.
>
> If anyone can figure out what I am doing wrong, I sure would appreciate
> some help.
>
> Thanks all!!
>
> Tim
>
--
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]
------------------------------
Date: Tue, 4 May 2004 22:18:41 -0800
From: "Robin" <webmaster @ infusedlight . net>
Subject: Re: Komodo as a editor?
Message-Id: <c7a18g$pk7$1@reader2.nmix.net>
"Robert" <catcher@linuxmail.org> wrote in message
news:hJGdnQRF9eMnhAXdRVn-jw@adelphia.com...
> I am evaluating Komodo as an editor for work. I am doing a lot of Perl
> work as a sysadmin and am starting to get into Perl/Tk as well. We use
> PVCS for version control and I see Komodo integrates with that.
>
> All that to say "Do you use it and what do you think about it?".
>
> Robert
I haven't tried Komodo, but I've read it's good. I like optiPerl, myself,
even though you have to change a lot of settings to get it to work well. It
might be the same way with komodo too, a lot of those dlls, etc are
traded/sold from company to company, but if you want to try it, try it
man...
-Robin
------------------------------
Date: 4 May 2004 22:23:40 -0700
From: khoslakapil@yahoo.com (Kapil Khosla)
Subject: multimap equivalent in perl
Message-Id: <919aa2da.0405042123.d8a7cd8@posting.google.com>
Hi,
I am new to perl and am trying to count the number of instances of
unique strings in a file. The strings are like
s1\aaa s1\bbb s1\ccc s1\ddd s1\aaa s1\aaa s1\aaa s1\aaa s1\eee
Currently, I have no good way to count unique strings in the file.
This could be easily done using the multimap functionality in C++.
I read about associative arrays but they seem to be more like unique
key / value combination. Would you know how best could I count the
number of unique strings in a file. I am not looking for code, just a
pointer in the right directin.
Thanks for your help,
Kapil
------------------------------
Date: 4 May 2004 23:39:34 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Re: multimap equivalent in perl
Message-Id: <slrnc9gvgm.r31.jtc@shell.dimensional.com>
In article <919aa2da.0405042123.d8a7cd8@posting.google.com>, Kapil Khosla wrote:
> Hi,
> I am new to perl and am trying to count the number of instances of
> unique strings in a file. The strings are like
>
> s1\aaa s1\bbb s1\ccc s1\ddd s1\aaa s1\aaa s1\aaa s1\aaa s1\eee
>
> Currently, I have no good way to count unique strings in the file.
> This could be easily done using the multimap functionality in C++.
>
> I read about associative arrays but they seem to be more like unique
> key / value combination. Would you know how best could I count the
> number of unique strings in a file. I am not looking for code, just a
> pointer in the right directin.
>
> Thanks for your help,
> Kapil
Something like:
my %word_table = ();
for (all_words_in_file()) {
++$word_table{$_};
}
sub all_words_in_file {
# To be implemented
}
END {
for my $key (keys %word_table) {
print "$key occurs $word_table{$key} times.\n";
}
}
# Warning - the above is not tested.
--
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]
------------------------------
Date: Tue, 4 May 2004 22:23:57 -0800
From: "Robin" <webmaster @ infusedlight . net>
Subject: Re: need help with security
Message-Id: <c7a1c4$pk8$1@reader2.nmix.net>
"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:QBElc.20892$3Q4.485920@news20.bellglobal.com...
>
> "Robin" <robin @ infusedlight.net> wrote in message
> news:c74eqt$opc$1@news.f.de.plusline.net...
> > "gnari" <gnari@simnet.is> wrote in message
> > news:c742sf$6gh$1@news.simnet.is...
> >
> > > of course, it is your auth.pl that is the weakest link.
> > >
> >
> > agreed, thanks... I'll set it up to use cookies...
> >
>
> Please enlighten me as to how the use of cookies will make your scripts
any
> more secure? If you really understood what they are how they work, you'd
> know that they provide *no security* in and of themselves.
>
> Matt
>
see my latest post and read the source code for auth.pl up to the bottom two
subs and then read the source code for the bottom two subs as related to
being in another script that auth.pl goes to.
-Robin
------------------------------
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 6519
***************************************