[28999] in Perl-Users-Digest
Perl-Users Digest, Issue: 243 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 20 18:10:18 2007
Date: Tue, 20 Mar 2007 15:09:21 -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 Tue, 20 Mar 2007 Volume: 11 Number: 243
Today's topics:
Re: "Casting" a split into an array <someone@example.com>
Re: dealing with modified csv data format <someone@example.com>
Re: eq and =? problem? <adrian_200503@blinkenlights.ch>
Re: how to get next day <not_valid2@yahoo.com>
Re: how to get next day <mritty@gmail.com>
Re: I dotn understand this error <hjp-usenet2@hjp.at>
Need help understanding how a file input block works <tester.paul@gmail.com>
Re: Net::Telnet Error handling/trapping <spamtrap@dot-app.org>
Re: No -e allowed in setuid scripts? <joe@inwap.com>
Perl/CGI file upload <gratemyl@gmail.com>
Perl/CGI file upload <gratemyl@gmail.com>
Re: Perl/CGI file upload <joe@inwap.com>
Re: Perl/CGI file upload usenet@DavidFilmer.com
Re: Perl/CGI file upload <gratemyl@gmail.com>
Re: Perl/CGI file upload <gratemyl@gmail.com>
Re: Perl/CGI file upload <kkeller-usenet@wombat.san-francisco.ca.us>
Re: Perl/CGI file upload <gratemyl@gmail.com>
Re: Perl/CGI file upload <glennj@ncf.ca>
Re: Perl/CGI file upload <kkeller-usenet@wombat.san-francisco.ca.us>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 Mar 2007 21:36:37 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: "Casting" a split into an array
Message-Id: <FtYLh.67595$lY6.55283@edtnps90>
Fabrice Baro wrote:
>>the reason I do this is to be able to access each letter by index C++-style
> I want to randomly select a certain number of letters among my
> string.
> I'm planning to shuffle an index and pick the desired number of
> letters.
>
> Original:
> 0 1 2 3 4 5 <- index
> L G R D T I <- letters
>
> Shuffle:
> 4 2 5 1 0 3
> T R I G
> ^
> Pick until here
>
> Does anyone see a better way ?
Need ... more ... context. :-)
A lot depends on where and how often the code will be executed.
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Tue, 20 Mar 2007 22:06:41 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: dealing with modified csv data format
Message-Id: <RVYLh.112392$Du6.10665@edtnps82>
nun wrote:
> I wrote a script which parses csv data files which were provided to me
> in the following format.
>
> WL,WA6B,SCRAPE,N,5.99,6.85,8.56,4.98
> WL,W30,RULE6"",N,7.90,47.90,6.05,3.15
>
> Note the comma field separator and that some fields have double quotes
> in the data.
>
> My script read this data in as follows and all was well:
>
> ###############################
> # reading data in from file
> my (@AoA);
> while ( <> ) {
> chomp;
> push @AoA, [ split /,/ ];
> }
> ################################
>
> Now suddenly I'm being given the data in a slightly different format,
> still comma separated but now all fields are enclosed by double quotes,
> even those which have double quotes in the data, such as:
>
> "WL","WA6B","SCRAPE","N","5.99","6.85","8.56","4.98"
> "WL","W30","RULE6""","N","7.90","47.90","6.05","3.15"
>
>
> Is there an easy way I can modify my code to deal with this new format,
> or must I start over with something like TEXT::CSV instead of split? I'm
> no perl guru and am hoping for an easy cure :)
$ perl -le'
$_ = q[WL,WA6B,SCRAPE,N,5.99,6.85,8.56,4.98];
my @x = split /,/;
print "@x";
$_ = q["WL","WA6B","SCRAPE","N","5.99","6.85","8.56","4.98"];
my @y = map /\A"(.+)"\z/ ? $1 : $_, split /,/;
print "@y";
'
WL WA6B SCRAPE N 5.99 6.85 8.56 4.98
WL WA6B SCRAPE N 5.99 6.85 8.56 4.98
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Tue, 20 Mar 2007 21:54:51 +0100
From: Adrian Ulrich <adrian_200503@blinkenlights.ch>
Subject: Re: eq and =? problem?
Message-Id: <20070320215451.b6d12e1c.adrian_200503@blinkenlights.ch>
> I found a solution by changing the bp to bisplans to avoid any
> confusion between bp and bplann.
Maybe something adds some weird/unwanded chars to $path
print unpack("H*", $path)."\n";
should display them.
> How did you test out the code I posted?!
#!/usr/bin/perl
use strict;
my $path = "docs/applied-business/as/classroom-notes/edexcel/unit2/bplanning";
if ( $path eq "docs/applied-business/as/classroom-notes/edexcel/unit2/bp" ) {
die "1\n";
}
elsif ( $path eq "docs/applied-business/as/classroom-notes/edexcel/unit2/bplanning" ) {
die "2\n";
}
else {
die "3\n";
}
------------------------------
Date: Tue, 20 Mar 2007 16:00:51 -0500
From: "Bob" <not_valid2@yahoo.com>
Subject: Re: how to get next day
Message-Id: <46004b84$0$276$8046368a@newsreader.iphouse.net>
"Jrgen Exner" <jurgenex@hotmail.com> wrote in message
news:9GULh.8019$FS5.4363@trndny09...
> Bob wrote:
>> Trying to calculate next date after user enters a date ?
>
> One way: You could take the answer to FAQ
> "How do I find yesterday's date?"
> and adapt it to your slightly different needs.
>
> jue
Thanks for your info... perhaps you would help me with --
the following shows using today or NOW ....
what is the correct syntax for a different date -
like 1-Mar-2007.
use DateTime;
my $yesterday = DateTime->now->subtract( days => 1 );
print "Yesterday was $yesterday\n";
also use the "Date::Calc" module using its Today_and_Now
use Date::Calc qw( Today_and_Now Add_Delta_DHMS );
my @date_time = Add_Delta_DHMS( Today_and_Now(), -1, 0, 0, 0 );
print "@date\n";
------------------------------
Date: 20 Mar 2007 11:17:10 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: how to get next day
Message-Id: <1174414630.593398.182660@p15g2000hsd.googlegroups.com>
On Mar 20, 12:56 pm, "Bob" <not_val...@yahoo.com> wrote:
> Trying to calculate next date after user enters a date ?
> can this be done with strftime ?
>
> if user enters 1-Mar-2007, want to return 2-Mar-2007.
> if user enters 5-Mar-2007, want to return 6-Mar-2007.
>
> **************start of code ************************
> use strict;
> use warnings;
> use POSIX 'strftime';
> my $date1, date2;
> print ("\n Enter the start date ex: (1-Mar-2006): ");
> chomp($date1 = <STDIN>);
>
> # calculate next day here
>
> print ("You have entered a date of $date1 and the next day is: $date2 \n");
> ************** end of code ************************
Use the module Date::Parse, available from CPAN. This is one of the
many formats that it handles:
$ perl -MPOSIX -MDate::Parse -le'
print "Enter date:";
chomp (my $date = <STDIN>);
my @time = strptime($date);
$time[3]++;
my $tomorrow = POSIX::strftime("%e-%b-%Y\n", @time);
$tomorrow =~ tr/ //d;
print $tomorrow;
'
Enter date:
31-Mar-2007
1-Apr-2007
(the tr/ //d portion of that is necessary because I don't see a
strftime option for "date of month, single digits aren't preceded by
anything")
Paul Lalli
------------------------------
Date: Tue, 20 Mar 2007 19:31:12 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: I dotn understand this error
Message-Id: <slrnf00a3g.g31.hjp-usenet2@yoyo.hjp.at>
On 2007-03-20 13:49, Νίκος <hackeras@gmail.com> wrote:
> Joe Smith wrote:
>> Νίκος wrote:
>> >>>> [Mon Mar 19 11:49:06 2007] index.pl: Use of uninitialized value in
>> >>>> concatenation (.) or string at (eval 17) line 43.
>> >> None of the code lines. It's line 43 of eval 17.
>> >
>> > This is what i dont understand... when i see line 43 i opne index.pl
>> > and look at line 43 but this isnt the problem line as it seems....
>>
>> The problem is _NOT_ in line 43 of index.pl.
>>
>> Your program is calling eval() several times, possibly in the form of {s///e;}.
[...]
> Thanks for the answer its now clear to me that line 43 of index.pl
> isnt the problem.
> But, nowhere inside my index.pl iam using the function eval(), not
> only i dont use it but i really dont even know what it does ...which
> iam about to check now....
You don't say how you invoke index.pl. The name and the code suggest
that it is invoked by a web server, maybe through some kind of web
application framework. It is possible that this framework reads index.pl
and then evals it, possibly after doing some changes. Like this, for
example:
open (C, ".code");
my $code = "package $p;\n"
. "our \@ISA = (" . ref($self) . ");\n"
. "#line 1 \"" . cwd() . "/.code\"\n"
. <C>;
print "code = $code\n";
eval $code;
In this case line 43 of (eval 17) would refer to some line of index.pl,
but probably to some line before 43. You could introduce a deliberate
error to find out find out how much off the count is (for example, if
you introduce an error in line 23 of index.pl and then get a message
that the error is in line 27 of eval, you know that you have to subtract
4 lines), or you can find the place in the framework where the file is
read and insert a "#line" directive with the correct filename and line
number, as I have done in the code snippet above (and then send the
patch to the author).
hp
--
_ | Peter J. Holzer | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR | to write clearly is like blaming English for
| | | hjp@hjp.at | the circumlocutions of bureaucrats.
__/ | http://www.hjp.at/ | -- Charlton Wilbur in clpm
------------------------------
Date: 20 Mar 2007 14:47:52 -0700
From: "Paul" <tester.paul@gmail.com>
Subject: Need help understanding how a file input block works
Message-Id: <1174427272.571011.187520@e1g2000hsg.googlegroups.com>
Hello there. Please forgive this newbie question but I don't really
know Perl as I have only been using it for a few days.
I need to understand how a particular script works and am having
difficulty with one particular subroutine.
First, here is a sample of the input file (IN_FILE):
---
OVERVIEW
----------------------------
This is where notes and stuff goes.
And maybe some more notes here too.
MATERIALS
----------------------------
This is where more notes and stuff goes.
etc...
---
Second, here is a section of the Perl code that I am having
difficulties with:
---
sub parsefile
{
1: $overview=0; @overview = ();
2: # open file..
3: while ($line = <IN_FILE>)
4: {
5: if ($line =~ /^\U\w*/)
6: {
7: if ($line =~ /^OVERVIEW/)
8: {
9: $line = <IN_FILE>; next if $line !~ /--------+/;
10: if ($overview== 1) {error("More than one Overview section")}
11: $overview++;
12: $bin = \@overview;
13: next;
14: }
15: }
16: $line =~ s/\"/\'/g;
17: push (@$bin,$line);
18: }
19: if (!$overview) {error("Missing a Overview section")}
20: # etc...
}
---
So here's what I've figured out so far:
- line 3 starts a loop that goes through each line in the input file
- line 5 I had difficulties with, but I think it means "if the line
starts with an uppercase word char" then do this block
- line 7 says "if the line starts with 'OVERVIEW'" then do this block
(Here's where I start to lose it. I think I might be having
difficulties with the 'block' concept.. but let me continue..)
- line 9 starts by saying 'get the next line in the input file.
*Then* it says "next if" the line doesn't contain a bunch of dashes.
QUESTION 1: Where does "next" go? Does it go to the start of line 9
(i.e. the beginning of the current block) or to line 3?
- line 10 is an error check and calls some other method. (I'm okay
with this line.)
- line 11 increments the $overview count. ok.
- line 12 --> I HAVE NO IDEA!
QUESTION 2: What does line 12 do? Does it assign something to a
variable? If so, I don't get it. at all.
- line 13 - "next" to where? Line 3?
- line 16 does a double-quote substitution. ok.
- line 17 pushes the content of the $line into .. what *is* that
variable? where did it come from? (It's not used anywhere else in
the script!)
QUESTION 3: What is this variable in line 17?
Finally, somewhere along the line I think the @overview array is
assigned the content of each of the lines between the heading rows.
But I'm not sure how that's done. I'm pretty sure it happens in the
block above, but there's some kind of voodoo magic working that is
keeping me from seeing it.
Can some kind person please help me understand how this code works? I
have spent several hours, gone through 2 O'Reilly books and asked
everyone within yelling distance of my desk but so far I haven't been
able to completely understand this.
TIA.
------------------------------
Date: Tue, 20 Mar 2007 17:47:14 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <m2bqinegf1.fsf@local.wv-www.com>
"Chris G." <nospam@example.com> writes:
> Mumia W. (NOSPAM) wrote:
>
>> Please bottom-post your replies, like I am doing in this message, and
>> please read the posting guidelines for this newsgroup:
>>
>> http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
>
> I appreciate your concern over my posting habits, but I prefer
> top-posting
Your request to enter my killfile has been received and processed. Thank
you for so clearly announcing your desire to be ignored.
*plonk*
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Tue, 20 Mar 2007 12:51:49 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: No -e allowed in setuid scripts?
Message-Id: <sfidnW61-oDLpp3bnZ2dnUVZ_uLinZ2d@comcast.com>
maxshop wrote:
> Anyone?
Get rid of the -e and put the statements into a file.
------------------------------
Date: 20 Mar 2007 12:30:18 -0700
From: "Jerome" <gratemyl@gmail.com>
Subject: Perl/CGI file upload
Message-Id: <1174419018.355526.218880@d57g2000hsg.googlegroups.com>
Hi!
I am in need of a special file upload script using Perl.
The script needs to allow uploading any files from a form (without
knowing the form structure in advance) - basically *any* files given
to it.
I just need some short documented source code as a hint so that I can
go and do the rest of the research, but so far I found nothing which
handles forms without knowing the forms themselves.
Thanks!
-gratemyl
------------------------------
Date: 20 Mar 2007 12:30:21 -0700
From: "Jerome" <gratemyl@gmail.com>
Subject: Perl/CGI file upload
Message-Id: <1174419021.688937.219000@d57g2000hsg.googlegroups.com>
Hi!
I am in need of a special file upload script using Perl.
The script needs to allow uploading any files from a form (without
knowing the form structure in advance) - basically *any* files given
to it.
I just need some short documented source code as a hint so that I can
go and do the rest of the research, but so far I found nothing which
handles forms without knowing the forms themselves.
Thanks!
-gratemyl
------------------------------
Date: Tue, 20 Mar 2007 12:37:08 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Perl/CGI file upload
Message-Id: <sfidnW-1-oB1qp3bnZ2dnUVZ_uKknZ2d@comcast.com>
Jerome wrote:
> The script needs to allow uploading any files from a form (without
> knowing the form structure in advance) - basically *any* files given
> to it.
Why? Are you willing to accept totally random and inappropriate content?
To properly deal with a form submission, the CGI needs to know what
to expect. If you have several forms, each of which can upload files,
then you should have several programs (or bits of a combined program),
each of which can use common code to deal with the shared task of file uploads.
-Joe
------------------------------
Date: 20 Mar 2007 13:11:07 -0700
From: usenet@DavidFilmer.com
Subject: Re: Perl/CGI file upload
Message-Id: <1174421467.459004.231520@o5g2000hsb.googlegroups.com>
On Mar 20, 12:30 pm, "Jerome" <grate...@gmail.com> wrote:
> The script needs to allow uploading any files from a form (without
> knowing the form structure in advance)
If a form envokes a CGI script, it will pass all the HTML parameters
(the names/values of which may be discovered via the param() method of
CGI.pm). If the form contains only filefield-type params then you may
simply process each parameter with the file upload functionality of
CGI ('perldoc CGI' will show you the sample code you asked for).
The problem would be if you have a mixture of form-type elements, such
as file-fields for pictures and text-fields for captions. If you
don't know the structure of the form (and thus the names of the
parameters) then it's not easy (or maybe not even possible) to
reliably distinguish which parameters are filenames and which are not.
> basically *any* files given to it.
Egads.
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 20 Mar 2007 13:30:41 -0700
From: "Jerome" <gratemyl@gmail.com>
Subject: Re: Perl/CGI file upload
Message-Id: <1174422641.820361.60850@d57g2000hsg.googlegroups.com>
On Mar 20, 8:37 pm, Joe Smith <j...@inwap.com> wrote:
> Jerome wrote:
> > The script needs to allow uploading any files from a form (without
> > knowing the form structure in advance) - basically *any* files given
> > to it.
>
> Why? Are you willing to accept totally random and inappropriate content?
Yes
>
> To properly deal with a form submission, the CGI needs to know what
> to expect. If you have several forms, each of which can upload files,
> then you should have several programs (or bits of a combined program),
> each of which can use common code to deal with the shared task of file uploads.
>
> -Joe
------------------------------
Date: 20 Mar 2007 13:31:20 -0700
From: "Jerome" <gratemyl@gmail.com>
Subject: Re: Perl/CGI file upload
Message-Id: <1174422680.536182.190940@b75g2000hsg.googlegroups.com>
On Mar 20, 9:11 pm, use...@DavidFilmer.com wrote:
> On Mar 20, 12:30 pm, "Jerome" <grate...@gmail.com> wrote:
>
> > The script needs to allow uploading any files from a form (without
> > knowing the form structure in advance)
>
> If a form envokes a CGI script, it will pass all the HTML parameters
> (the names/values of which may be discovered via the param() method of
> CGI.pm). If the form contains only filefield-type params then you may
> simply process each parameter with the file upload functionality of
> CGI ('perldoc CGI' will show you the sample code you asked for).
>
> The problem would be if you have a mixture of form-type elements, such
> as file-fields for pictures and text-fields for captions. If you
> don't know the structure of the form (and thus the names of the
> parameters) then it's not easy (or maybe not even possible) to
> reliably distinguish which parameters are filenames and which are not.
I can assume that all but one specific one are.
>
> > basically *any* files given to it.
>
> Egads.
>
> --
> The best way to get a good answer is to ask a good question.
> David Filmer (http://DavidFilmer.com)
------------------------------
Date: Tue, 20 Mar 2007 13:45:14 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Perl/CGI file upload
Message-Id: <rnt5d4xabo.ln2@goaway.wombat.san-francisco.ca.us>
On 2007-03-20, Jerome <gratemyl@gmail.com> wrote:
>
> I am in need of a special file upload script using Perl.
What have you written so far?
> I just need some short documented source code as a hint so that I can
> go and do the rest of the research, but so far I found nothing which
> handles forms without knowing the forms themselves.
Start with perldoc CGI, and look for the upload() function. I think
it's an exceedingly bad idea to do what you're trying to do, however.
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information
------------------------------
Date: 20 Mar 2007 14:31:36 -0700
From: "Jerome" <gratemyl@gmail.com>
Subject: Re: Perl/CGI file upload
Message-Id: <1174426296.804717.50160@p15g2000hsd.googlegroups.com>
On Mar 20, 9:45 pm, Keith Keller <kkeller-use...@wombat.san-
francisco.ca.us> wrote:
> On 2007-03-20, Jerome <grate...@gmail.com> wrote:
>
>
>
> > I am in need of a special file upload script using Perl.
>
> What have you written so far?
>
> > I just need some short documented source code as a hint so that I can
> > go and do the rest of the research, but so far I found nothing which
> > handles forms without knowing the forms themselves.
>
> Start with perldoc CGI, and look for the upload() function. I think
> it's an exceedingly bad idea to do what you're trying to do, however.
I have looked at the upload function, but as far as I see it requires
me to specify a field name - I need to do this for all fields of
"type" file.
I understand this is a strange requirement, but it is the way things
are.
Thanks again!
>
> --keith
>
> --
> kkeller-use...@wombat.san-francisco.ca.us
> (try just my userid to email me)
> AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
> see X- headers for PGP signature information
------------------------------
Date: 20 Mar 2007 21:36:14 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Perl/CGI file upload
Message-Id: <slrnf00kuf.s5p.glennj@smeagol.ncf.ca>
At 2007-03-20 03:30PM, "Jerome" wrote:
> Hi!
>
> I am in need of a special file upload script using Perl.
>
> The script needs to allow uploading any files from a form (without
> knowing the form structure in advance) - basically *any* files given
> to it.
>
> I just need some short documented source code as a hint so that I can
> go and do the rest of the research, but so far I found nothing which
> handles forms without knowing the forms themselves.
If you're going with CGI.pm, make sure you read the section "Avoiding
Denial of Service Attacks" in the CGI documentation.
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
Date: Tue, 20 Mar 2007 14:50:37 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Perl/CGI file upload
Message-Id: <di16d4xc3p.ln2@goaway.wombat.san-francisco.ca.us>
On 2007-03-20, Jerome <gratemyl@gmail.com> wrote:
>
> I have looked at the upload function, but as far as I see it requires
> me to specify a field name - I need to do this for all fields of
> "type" file.
Okay...so now look for "FETCHING THE NAMES OF ALL THE PARAMETERS
PASSED TO YOUR SCRIPT:". And please try to do at least some of your own
work yourself; that's all the pointers you're getting from me, at least,
until you show some of your own effort.
Have you read the Posting Guidelines that are posted here frequently?
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information
------------------------------
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 V11 Issue 243
**************************************