[29945] in Perl-Users-Digest
Perl-Users Digest, Issue: 1188 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 11 18:09:40 2008
Date: Fri, 11 Jan 2008 15:09:07 -0800 (PST)
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, 11 Jan 2008 Volume: 11 Number: 1188
Today's topics:
csv data file, but with a twist <junk@yahoo.com>
Re: csv data file, but with a twist <glex_no-spam@qwest-spam-no.invalid>
Re: csv data file, but with a twist <mgjv@tradingpost.com.au>
Re: csv data file, but with a twist <someone@example.com>
Re: Force return of the diamond operator from network s <hjp-usenet2@hjp.at>
Re: How to send email from perl-script with different p <simon.greenberg@gmail.com>
Re: Inserting, update and deleteting a database under c <bik.mido@tiscalinet.it>
Is there a way to send and alt-f4 to process joez3@yahoo.com
Parsing function args in Getopt::Long style <shtil@comcast.net>
Re: Parsing function args in Getopt::Long style <m@rtij.nl.invlalid>
Re: Parsing function args in Getopt::Long style <john@castleamber.com>
Question about arrays of hashes <SteveSpamTrap@yahoo.com>
Re: Question about arrays of hashes <damian@tvk.rwth-aachen.de>
Re: Question about arrays of hashes <noreply@gunnar.cc>
Re: Question about arrays of hashes xhoster@gmail.com
Testing CGI.pm-using code <socyl@987jk.com.invalid>
Re: Testing CGI.pm-using code <paduille.4061.mumia.w+nospam@earthlink.net>
Re: Testing CGI.pm-using code xhoster@gmail.com
Re: Using CPAN "lightweight" <brian.d.foy@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 11 Jan 2008 16:27:05 -0500
From: nun <junk@yahoo.com>
Subject: csv data file, but with a twist
Message-Id: <qOadnXT-L_C3QhranZ2dnUVZ_u-unZ2d@megapath.net>
I have a comma-delimited text file (example data below). The problem is
that *some* of the lines contain commas within the second field (named
DESC) which is obviously a problem.
I'd like to replace any such commas with a space followed by a hyphen.
Actual sample data:
SKU,DESC,LIST,COST,FLAG1,FLAG2,FLAG3,RELATED,FLAG4
0090 ,CUP-HOOK ,0012.34,0007.40,N,O, ,254-61,001
0110 ,HOOK ,0008.71,0006.53,Y,O, , ,001
0120 ,HOOK, TAPERED ,0004.57,0002.74,N,O, ,254-72 ,001
0130 ,HOOK, RED ,0003.11,0002.33,N, , ,254-79 ,001
What I'd like to and up with:
SKU,DESC,LIST,COST,FLAG1,FLAG2,FLAG3,RELATED,FLAG4
0090 ,CUP-HOOK ,0012.34,0007.40,N,O, ,254-61,001
0110 ,HOOK ,0008.71,0006.53,Y,O, , ,001
0120 ,HOOK - TAPERED ,0004.57,0002.74,N,O, ,254-72 ,001
0130 ,HOOK - RED ,0003.11,0002.33,N, , ,254-79 ,001
There *may* be lines which have more than one comma in the DESCR field.
but luckily the 3rd field always has the format XXXX.XX (four digits,
decimal, 2 digits)
Can any suggest a hunk of code that will accomplish this? I've seen
some "sed one liners" online that come close but so far no success.
Thanks for any help!
DB
------------------------------
Date: Fri, 11 Jan 2008 15:52:00 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: csv data file, but with a twist
Message-Id: <4787e501$0$3566$815e3792@news.qwest.net>
nun wrote:
> I have a comma-delimited text file (example data below). The problem is
> that *some* of the lines contain commas within the second field (named
> DESC) which is obviously a problem.
>
> I'd like to replace any such commas with a space followed by a hyphen.
>
> Actual sample data:
> SKU,DESC,LIST,COST,FLAG1,FLAG2,FLAG3,RELATED,FLAG4
> 0090 ,CUP-HOOK ,0012.34,0007.40,N,O, ,254-61,001
> 0110 ,HOOK ,0008.71,0006.53,Y,O, , ,001
> 0120 ,HOOK, TAPERED ,0004.57,0002.74,N,O, ,254-72 ,001
> 0130 ,HOOK, RED ,0003.11,0002.33,N, , ,254-79 ,001
>
>
> What I'd like to and up with:
>
> SKU,DESC,LIST,COST,FLAG1,FLAG2,FLAG3,RELATED,FLAG4
> 0090 ,CUP-HOOK ,0012.34,0007.40,N,O, ,254-61,001
> 0110 ,HOOK ,0008.71,0006.53,Y,O, , ,001
> 0120 ,HOOK - TAPERED ,0004.57,0002.74,N,O, ,254-72 ,001
> 0130 ,HOOK - RED ,0003.11,0002.33,N, , ,254-79 ,001
>
> There *may* be lines which have more than one comma in the DESCR field.
> but luckily the 3rd field always has the format XXXX.XX (four digits,
> decimal, 2 digits)
>
> Can any suggest a hunk of code that will accomplish this? I've seen
> some "sed one liners" online that come close but so far no success.
> Thanks for any help!
This can be a little shorter, but since you didn't show any code I'll
keep it pretty simple.
while( <DATA> )
{
my @field = split /,/;
if ( $field[2] !~ /\d\d\d\d\.\d\d/ )
{
$field[1] .= " -$field[2]";
splice( @field, 2, 1 );
}
print join( ',', @field );
}
__DATA__
0090 ,CUP-HOOK ,0012.34,0007.40,N,O, ,254-61,001
0110 ,HOOK ,0008.71,0006.53,Y,O, , ,001
0120 ,HOOK, TAPERED ,0004.57,0002.74,N,O, ,254-72 ,001
0130 ,HOOK, RED ,0003.11,0002.33,N, , ,254-79 ,001
The real issue though is the program that is creating this data.
------------------------------
Date: Sat, 12 Jan 2008 09:39:30 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: csv data file, but with a twist
Message-Id: <slrnfofs12.66j.mgjv@martien.heliotrope.home>
On Fri, 11 Jan 2008 16:27:05 -0500,
nun <junk@yahoo.com> wrote:
> I have a comma-delimited text file (example data below). The problem is
> that *some* of the lines contain commas within the second field (named
> DESC) which is obviously a problem.
A "real" CSV file would have had quotes around that field, so this is,
and I suppose that's the problem, a broken CSV file. I'm assuming it's
not possible to fix whatever created the file in the first place?
> Actual sample data:
> SKU,DESC,LIST,COST,FLAG1,FLAG2,FLAG3,RELATED,FLAG4
> 0090 ,CUP-HOOK ,0012.34,0007.40,N,O, ,254-61,001
> 0110 ,HOOK ,0008.71,0006.53,Y,O, , ,001
> 0120 ,HOOK, TAPERED ,0004.57,0002.74,N,O, ,254-72 ,001
> 0130 ,HOOK, RED ,0003.11,0002.33,N, , ,254-79 ,001
>
>
> What I'd like to and up with:
>
> SKU,DESC,LIST,COST,FLAG1,FLAG2,FLAG3,RELATED,FLAG4
> 0090 ,CUP-HOOK ,0012.34,0007.40,N,O, ,254-61,001
> 0110 ,HOOK ,0008.71,0006.53,Y,O, , ,001
> 0120 ,HOOK - TAPERED ,0004.57,0002.74,N,O, ,254-72 ,001
> 0130 ,HOOK - RED ,0003.11,0002.33,N, , ,254-79 ,001
> There *may* be lines which have more than one comma in the DESCR field.
> but luckily the 3rd field always has the format XXXX.XX (four digits,
> decimal, 2 digits)
It would have been nice if you actually included that in the sample
file.
Actually, you HAVE a line with the third field in the example file in
that format. In fact, you have two. However, I don't think that you mean
you want those joined up as well. Given that that field always has that
format, it's hardly going to be possible to use that fact. I've added an
example record with that extra third line.
So, maybe it's better to simply trigger on the number of fields. I can
assume that the target number of fields is always the same? 9?
The following simply concantenates fields 2 and up to field 1 if there
are too many fields, in such a way that you end up with 9 fields.
#!/usr/bin/perl
use warnings;
use strict;
while (<DATA>)
{
print, next if $. == 1;
my @l = split /,/;
if (@l != 9)
{
$l[1] = join " - ", @l[1 .. @l - 8];
splice @l, 2, @l - 9;
print join ",", @l;
}
else
{
print;
}
}
__DATA__
SKU,DESC,LIST,COST,FLAG1,FLAG2,FLAG3,RELATED,FLAG4
0090 ,CUP-HOOK ,0012.34,0007.40,N,O, ,254-61,001
0110 ,HOOK ,0008.71,0006.53,Y,O, , ,001
0120 ,HOOK, TAPERED ,0004.57,0002.74,N,O, ,254-72 ,001
0130 ,HOOK, RED ,0003.11,0002.33,N, , ,254-79 ,001
0130 ,HOOK, BLUE, 9999.99 ,0003.11,0002.33,N, , ,254-79 ,001
I would probably also leave the description field as it was, rather than
rewriting it.
$l[1] = '"' . join(",", @l[1 .. @l - 8]) . '"';
Also, if you want the leading and trailing spaces to be preserved, you
should also enclose those with quotes. You might as well enclose all of
them with quotes, which would also make the code a bit simpler:
#!/usr/bin/perl
use warnings;
use strict;
while (<DATA>)
{
my @l = split /,/;
if (@l != 9)
{
$l[1] = join " - ", @l[1 .. @l - 8];
splice @l, 2, @l - 9;
}
s/(.*)/"$1"/ for @l;
print join ",", @l;
}
__DATA__
SKU,DESC,LIST,COST,FLAG1,FLAG2,FLAG3,RELATED,FLAG4
0090 ,CUP-HOOK ,0012.34,0007.40,N,O, ,254-61,001
0110 ,HOOK ,0008.71,0006.53,Y,O, , ,001
0120 ,HOOK, TAPERED ,0004.57,0002.74,N,O, ,254-72 ,001
0130 ,HOOK, RED ,0003.11,0002.33,N, , ,254-79 ,001
0130 ,HOOK, BLUE, 9999.99 ,0003.11,0002.33,N, , ,254-79 ,001
If you don't blindly want to put quotes around everything, you could use
Text::CSV to create the CSV record for you (make sure to remove the
newline first or to set the correct options for CSV::Text).
Regards,
Martien
--
|
Martien Verbruggen | "In a world without fences,
| who needs Gates?"
|
------------------------------
Date: Fri, 11 Jan 2008 23:06:48 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: csv data file, but with a twist
Message-Id: <cEShj.26950$fj2.3696@edtnps82>
nun wrote:
> I have a comma-delimited text file (example data below). The problem is
> that *some* of the lines contain commas within the second field (named
> DESC) which is obviously a problem.
>
> I'd like to replace any such commas with a space followed by a hyphen.
>
> Actual sample data:
> SKU,DESC,LIST,COST,FLAG1,FLAG2,FLAG3,RELATED,FLAG4
> 0090 ,CUP-HOOK ,0012.34,0007.40,N,O, ,254-61,001
> 0110 ,HOOK ,0008.71,0006.53,Y,O, , ,001
> 0120 ,HOOK, TAPERED ,0004.57,0002.74,N,O, ,254-72 ,001
> 0130 ,HOOK, RED ,0003.11,0002.33,N, , ,254-79 ,001
>
>
> What I'd like to and up with:
>
> SKU,DESC,LIST,COST,FLAG1,FLAG2,FLAG3,RELATED,FLAG4
> 0090 ,CUP-HOOK ,0012.34,0007.40,N,O, ,254-61,001
> 0110 ,HOOK ,0008.71,0006.53,Y,O, , ,001
> 0120 ,HOOK - TAPERED ,0004.57,0002.74,N,O, ,254-72 ,001
> 0130 ,HOOK - RED ,0003.11,0002.33,N, , ,254-79 ,001
>
> There *may* be lines which have more than one comma in the DESCR field.
> but luckily the 3rd field always has the format XXXX.XX (four digits,
> decimal, 2 digits)
>
> Can any suggest a hunk of code that will accomplish this? I've seen
> some "sed one liners" online that come close but so far no success.
> Thanks for any help!
my @headers;
while ( <> ) {
if ( $. == 1 ) {
@headers = split /,/, $_, -1;
print;
next;
}
my @fields = split /,/, $_, -1;
if ( @fields > @headers ) {
my $offset = @fields - @headers + 1;
splice @fields, 1, $offset, join ' - ', @fields[ 1 .. $offset ];
}
print join ',', @fields;
}
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: Fri, 11 Jan 2008 22:04:38 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Force return of the diamond operator from network socket
Message-Id: <slrnfofmf6.9mj.hjp-usenet2@hrunkner.hjp.at>
On 2008-01-09 21:11, Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "NB" == Nate Bargmann <n0nb.DO.NOT.SPAM@ME.n0nb.us> writes:
>
> NB> while (<$socket>) {
> NB> chomp;
> NB> print "$_\n";
> NB> }
>
> NB> however, the diamond operator doesn't return despite trying to
> NB> send a NULL string from the C program through the socket. Here is
> NB> a snippet of my C program:
>
> NB> fprintf(fout, "");
> NB> fflush(fout);
>
> first, use write() so you don't need the fflush call. that means you
> need to do an open() and not an fopen. it will run faster as well as you
> avoid the stdio overhead.
>
> a c null string is a single byte of 0.
fprintf(fout, "");
doesn't include the terminating null byte (Otherwise files written by C
programs would be riddled with 0 bytes), so it adds exactly nothing to
the output buffer.
> the <> operator expects to read a
> line of text which a 0 byte is not.
Depends on the value of $/. But since the 0 byte is never sent it cannot
be received and hence cannot have any effect.
hp
------------------------------
Date: Fri, 11 Jan 2008 13:34:58 -0800 (PST)
From: sg <simon.greenberg@gmail.com>
Subject: Re: How to send email from perl-script with different priorities : normal or high
Message-Id: <f4219966-8698-45a2-8cf5-18ad4a34ff26@k39g2000hsf.googlegroups.com>
On Jan 10, 3:27=A0pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> sg wrote:
> > On Jan 10, 12:54 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> >> sg wrote:
>
> >>> open =A0( MAIL, "|/usr/bin/mail $email") or die;
>
> >> Try sendmail instead of mail:
>
> >> open MAIL, "|/usr/sbin/sendmail -t $email" or die $!;
>
> > 2. Both, /usr/bin/mail and /usr/sbin/mail -t are correctly
> > interpreting "HIGH" priopity parameter.
>
> [guess you meant to say: /usr/sbin/sendmail]
>
> Funny, I thought that Keith was right in that 'mail' doesn't allow
> message headers to be set the way you described.
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
yes, you are right - It is a typo - should be /usr/sbin/sendmail
Thank you
------------------------------
Date: Fri, 11 Jan 2008 21:33:16 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Inserting, update and deleteting a database under conditions
Message-Id: <ngkfo3tkgb3fkobq5jqvfbhgk90jnb0kd3@4ax.com>
On Fri, 11 Jan 2008 04:33:23 -0800 (PST), Nikos <nikos1337@gmail.com>
wrote:
>> before reposting your question verbatim here, you should let people
>> know that you asked it in perlmonks first. So people will know what
>> that has been told you, and you will save them some duplication of
>> efforts:
>
>Sorry Michael i asked there and here at the sametime in case my
>question ouldn't be answered there, and it wasnt. can you help?
I'm afraid I can't, since it seems to me that your question *was*
answered there. But since this differs from your own perception, I
doubt I can add anything. It would be nice of you to specify, instead,
*what* of those answers did failt o satisfy you.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Fri, 11 Jan 2008 11:19:11 -0800 (PST)
From: joez3@yahoo.com
Subject: Is there a way to send and alt-f4 to process
Message-Id: <8797b3fc-0519-4a91-b545-67159306b042@v46g2000hsv.googlegroups.com>
I am using:
Win32::Process::Create($processObjHost, $appName, $opt, 0,
NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE |
CREATE_NEW_PROCESS_GROUP , '.');
To log into a server and I want to exit out of the session when I am
done. I can use the method: $processObjHost->Kill(0) to kill the
application that came up, but the server still sees the session open.
Is there a way to send 'alt-f4' instead of just killing the app?
Thanks,
zim
------------------------------
Date: Fri, 11 Jan 2008 13:11:23 -0800
From: "Yuri Shtil" <shtil@comcast.net>
Subject: Parsing function args in Getopt::Long style
Message-Id: <pdydnUiwp4PgRhranZ2dnUVZ_qainZ2d@comcast.com>
Is there a module to parse named function parameters in Getopt::Long style?
What I have in mind is something like:
# Call function
&foo('-p1' -> $v1, '-p2' => $v2);
#Define function
sub foo {
my $options = PARSER(@_);
my $v1 = $options->{'p1'};
# ....
}
------------------------------
Date: Fri, 11 Jan 2008 22:40:27 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Parsing function args in Getopt::Long style
Message-Id: <pan.2008.01.11.21.40.22@rtij.nl.invlalid>
On Fri, 11 Jan 2008 13:11:23 -0800, Yuri Shtil wrote:
> Is there a module to parse named function parameters in Getopt::Long
> style?
>
> What I have in mind is something like:
>
> # Call function
> &foo('-p1' -> $v1, '-p2' => $v2);
>
> #Define function
> sub foo {
> my $options = PARSER(@_);
>
> my $v1 = $options->{'p1'};
>
> # ....
> }
Maybe something like this?
sub foo {
local @ARGV = @_;
$r = GetOptions(...);
...
}
M4
------------------------------
Date: 11 Jan 2008 23:03:19 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Parsing function args in Getopt::Long style
Message-Id: <Xns9A22AD7F0CAEcastleamber@130.133.1.4>
"Yuri Shtil" <shtil@comcast.net> wrote:
> Is there a module to parse named function parameters in Getopt::Long
> style?
>
> What I have in mind is something like:
>
> # Call function
> &foo('-p1' -> $v1, '-p2' => $v2);
^ don't use & unless you know what it does.
foo( '-p1' => $v1, '-p2' => $b2 );
> #Define function
> sub foo {
> my $options = PARSER(@_);
my %options = @_;
> my $v1 = $options->{'p1'};
my $v1 = $options{ '-p1' );
--
John
http://johnbokma.com/perl/
------------------------------
Date: Fri, 11 Jan 2008 17:35:49 -0500
From: Steve <SteveSpamTrap@yahoo.com>
Subject: Question about arrays of hashes
Message-Id: <5uq9a6F1j4mffU1@mid.individual.net>
Forgive a newbie question, but I'm hoping that someone can shed some
light for me on weirdness I'm seeing when trying to access a particular
hash from an array-of-hashes. I had a lot of difficulty assigning a
particular element to its own variable, but after some experimentation I
found that this works:
my @array = MyModule->getArrayOfHashes();
my $hash = $array[$index];
%hash = %$hash;
I have to first create the variable in scalar context, then do a funky
dereferencing thing while changing the context to hash. For one thing,
I'd like to better understand what is really going on here... I just
stumbled across this solution through experimentation and dumb luck, I
don't really understand it. Secondly, I'm wondering if there's some
shorthand technique for doing this that doesn't require three lines of
code. Thanks in advance!
------------------------------
Date: Sat, 12 Jan 2008 00:03:58 +0100
From: Damian Lukowski <damian@tvk.rwth-aachen.de>
Subject: Re: Question about arrays of hashes
Message-Id: <5uqauvF1jfitiU1@mid.dfncis.de>
Steve schrieb:
> my @array = MyModule->getArrayOfHashes();
> my $hash = $array[$index];
> %hash = %$hash;
Get n'th hash-Reference from the array: (MyModule->getArrayOfHashes())[n]
Get value of hash-key 'foo' from n'th hash-reference from the array:
(MyModule->getArrayOfHashes())[n]->{'foo'}
------------------------------
Date: Sat, 12 Jan 2008 00:08:12 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Question about arrays of hashes
Message-Id: <5uqb71F1ikh3nU1@mid.individual.net>
Steve wrote:
> Forgive a newbie question, but I'm hoping that someone can shed some
> light for me on weirdness I'm seeing when trying to access a particular
> hash from an array-of-hashes. I had a lot of difficulty assigning a
> particular element to its own variable, but after some experimentation I
> found that this works:
>
> my @array = MyModule->getArrayOfHashes();
> my $hash = $array[$index];
> %hash = %$hash;
>
> I have to first create the variable in scalar context, then do a
> funky dereferencing thing while changing the context to hash. For one
> thing, I'd like to better understand what is really going on here...
perldoc perlref
> I'm wondering if there's some shorthand technique for doing this that
> doesn't require three lines of code.
What's "this"? Copying one of the hashes to a named hash?
my %hash = %{ $array[$index] };
Or assigning a value to one of the anonymous hashes?
$array[$index]->{somekey} = 'somevalue';
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 11 Jan 2008 23:08:31 GMT
From: xhoster@gmail.com
Subject: Re: Question about arrays of hashes
Message-Id: <20080111180834.495$Uf@newsreader.com>
Steve <SteveSpamTrap@yahoo.com> wrote:
> Forgive a newbie question, but I'm hoping that someone can shed
> some light for me on weirdness I'm seeing when trying to access a
> particular hash from an array-of-hashes. I had a lot of difficulty
> assigning a particular element to its own variable, but after some
> experimentation I found that this works:
>
> my @array = MyModule->getArrayOfHashes();
> my $hash = $array[$index];
> %hash = %$hash;
>
> I have to first create the variable in scalar context, then do a
> funky dereferencing thing while changing the context to hash. For one
> thing, I'd like to better understand what is really going on here... I
> just stumbled across this solution through experimentation and dumb luck,
> I don't really understand it.
See the "perldoc"s for perlref, perlreftut, and perldsc. I don't how to
describe it better than they do. (If I did, I would propose replacing them
with my better description.)
> Secondly, I'm wondering if there's some
> shorthand technique for doing this that doesn't require three lines of
> code. Thanks in advance!
You need get the right element out of the list, which you do by
subscripting the list with the ()[] form:
my $hashref = (MyModule->getArrayOfHashes())[$index];
Although this does seem strange for me for semantic rather than syntactic
reasons. It seems like an odd OO module design that would lead me to
already know which index I want from a list when I don't yet have the list
but need to go to the module to get it. I know that is the way things work
with things like the "stat" function, but the stat function isn't OO.
Then you need to dereference that, which you do by %{} form:
my %hash=%{(MyModule->getArrayOfHashes())[$index]};
Although 90+% of the time, I would just get the $hashref and dereference
it as needed, rather than making a dereferenced copy up-front.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Fri, 11 Jan 2008 22:06:26 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Testing CGI.pm-using code
Message-Id: <fm8p92$3bc$1@reader2.panix.com>
Here's the problem. I'm trying to test some code that uses CGI.pm,
running on Linux. I want to do this "locally", without involving
an HTTP server (Apache, etc.).
Each of the intended tests will result in the execution of the
following code from CGI.pm:
read(\*STDIN, $$buff, $len, $offset);
I want the input that is read by this line to come from a scalar
variable (a different one for each test). But I can't get CGI to
read different inputs each time.
The following snippet illustrates the problem:
use CGI ();
sub test {
my $in = shift;
$ENV{ REQUEST_METHOD } = 'POST';
$ENV{ CONTENT_TYPE } = 'text/plain';
$ENV{ CONTENT_LENGTH } = length $in;
close STDIN;
open STDIN, '<', \$in or die $!;
print CGI->new->param( 'POSTDATA' ), "\n";
}
test( 'foo' );
test( 'bar' );
__END__
foo
foo
As you can see, the first call to test() produces the required
output, but the second one doesn't. In fact all calls to test()
will produce the same output as the first one does.
Can anyone suggest a way in which I could, within the execution of
a single script, give CGI different inputs via STDIN?
TIA!
Kynn Jones
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: Fri, 11 Jan 2008 16:51:42 -0600
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: Testing CGI.pm-using code
Message-Id: <13ofsolggud6nbe@corp.supernews.com>
On 01/11/2008 04:06 PM, kj wrote:
> Here's the problem. I'm trying to test some code that uses CGI.pm,
> running on Linux. I want to do this "locally", without involving
> an HTTP server (Apache, etc.).
> [...]
Hello Kynn. Try this for your test function:
sub test {
my $cgi = CGI->new(\$_[0]);
print $cgi->param('POSTDATA'), "\n";
}
I hope that your code was not meant to test reading from STDIN because
you don't need STDIN to set up a CGI.pm object.
__HTH__
------------------------------
Date: 11 Jan 2008 22:53:41 GMT
From: xhoster@gmail.com
Subject: Re: Testing CGI.pm-using code
Message-Id: <20080111175343.938$CG@newsreader.com>
kj <socyl@987jk.com.invalid> wrote:
> Here's the problem. I'm trying to test some code that uses CGI.pm,
> running on Linux. I want to do this "locally", without involving
> an HTTP server (Apache, etc.).
What is it you are trying to test?
>
> Each of the intended tests will result in the execution of the
> following code from CGI.pm:
>
> read(\*STDIN, $$buff, $len, $offset);
>
> I want the input that is read by this line to come from a scalar
> variable (a different one for each test). But I can't get CGI to
> read different inputs each time.
>
> The following snippet illustrates the problem:
>
> use CGI ();
>
> sub test {
> my $in = shift;
> $ENV{ REQUEST_METHOD } = 'POST';
> $ENV{ CONTENT_TYPE } = 'text/plain';
> $ENV{ CONTENT_LENGTH } = length $in;
>
> close STDIN;
> open STDIN, '<', \$in or die $!;
>
> print CGI->new->param( 'POSTDATA' ), "\n";
CGI->new can take an argument.
open my $fh, '<', \$in or die $!;
print CGI->new($fh)->param( 'POSTDATA' ), "\n";
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Fri, 11 Jan 2008 15:23:32 -0600
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: Using CPAN "lightweight"
Message-Id: <110120081523327087%brian.d.foy@gmail.com>
In article <gp3co394e0sipift14c7b1alea03v7m4mi@library.airnews.net>,
Bernie Cosell <bernie@fantasyfarm.com> wrote:
> brian d foy <brian.d.foy@gmail.com> wrote:
>
> } ... It's easy to
> } configure CPAN.pm from within a program. You just have to do it (and
> } then it won't go looking for CPAN/MyConfig.pm. Your best bet is to do
> } the manual configuration, adjust it as you need it, then load that
> } configuration programmatically.
>
> I'm not sure "easy" is quite fair... There's a very long list of config
> vbls with not much said about them,
The docs for CPAN::FirstTime explains all of them, including how to
disable certain messages.
> and not much said overall about making
> CPAN quiet
When you use the programmers interface, you just don't output anything
you don't wnat to output. It's up to you.
> But the "CPAN" directory is *read*only*
No, that's a relative path, and it's relative to where you tell CPAN.pm
to put it. You could, but don't hve to, make the config file
interactively using this methong.
> Basically, CPAN seems to be trying to do a LOT more than I really want and
> it doesn't seem easy to trim it down, which is why CPANPLUS seemed to wor
> out better, but even *IT* is trying to do some fancier-than-I-need
> stuff...:o)
Both of them can do quite a bit, and fi either works for you that's
great. Just be careful that what you say about either of them is true.
:)
------------------------------
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 1188
***************************************