[15864] in Perl-Users-Digest
Perl-Users Digest, Issue: 3277 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 7 14:05:45 2000
Date: Wed, 7 Jun 2000 11:05:26 -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: <960401125-v9-i3277@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 7 Jun 2000 Volume: 9 Number: 3277
Today's topics:
"constant" problem squidrocks@my-deja.com
Re: "constant" problem <abe@ztreet.demon.nl>
[HELP] chomp and loops <noone@nowhere.org>
Re: [HELP] chomp and loops <aqumsieh@hyperchip.com>
Re: [HELP] chomp and loops <lauren_smith13@hotmail.com>
Best Way to Test if File Exists <grichard@uci.edu>
Re: Best Way to Test if File Exists <aqumsieh@hyperchip.com>
Re: Best Way to Test if File Exists (Andrew Johnson)
Re: Best Way to Test if File Exists (John Gehman)
Re: Best Way to Test if File Exists <lauren_smith13@hotmail.com>
calling LWP::Simple::get from browser vs. from command afedorova@my-deja.com
CGI code for downloading <campbell@coaps.fsu.edu>
change priority <zfido88@zr.ru>
Re: change priority <care227@attglobal.net>
CRONING DELETE OF DIRECTORY ould@my-deja.com
Re: Dumb question.. How to prompt the user and get the <abe@ztreet.demon.nl>
Re: dump a hash? <tony_curtis32@yahoo.com>
Re: dump a hash? <aqumsieh@hyperchip.com>
Re: dump a hash? <tcuffel@exactis.com>
Re: each not looping on a hash <aqumsieh@hyperchip.com>
exists() example <steve@gte.net>
Re: exists() example <steve@gte.net>
Re: exists() on sub-hash creates a key in super-hash <chuppin@ncsa.uiuc.edu>
Re: external program stdout to screen and log <rhomberg@ife.ee.ethz.ch>
Re: external program stdout to screen and log <aqumsieh@hyperchip.com>
General failure reading device (Win32) <vwilding@digizen.net>
Get and post from/to news groups <mnarvaja@geocities.xyz.com>
Re: Get and post from/to news groups <care227@attglobal.net>
Re: Get and post from/to news groups <rhomberg@ife.ee.ethz.ch>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 Jun 2000 15:07:45 GMT
From: squidrocks@my-deja.com
Subject: "constant" problem
Message-Id: <393e604a.81042082@news.it.gvsu.edu>
This is a fully functioning program with one exception. The if
statement at the bottom doesn't work because of some data problem with
the scalar. It never reckognizes that I already have the file. If I
substitute $tl='whatever.exe' instead of trying to match it with the
variable @file it works fine, but since the file in @file is what I
need to check and it will change I cannot assign it a constant value.
Thanks to anyone who can help.
#!/usr/local/bin/perl
system ("rm mcafee_4x.asp");
#retrieves web page
system ("wget
http://www.nai.com/asp_set/download/dats/mcafee_4x.asp");
open (WP, "mcafee_4x.asp");
@webpage=<WP>;
close (WP);#converts webpage into array
@link=grep /superdat.english.nai.intel/, @webpage;
@truelink=map {split 'name: <a href="',} @link;
@truelink=map {/http.*exe/} @link;
@tlink=map {split '">.*</a>',} @truelink;
@file=map{split 'http.*/',} @tlink;
open (LF,">link");
print LF @file;
close (LF);
open (NF,"link");
$tl=<NF>;
close (NF);
if (-e $tl) {
die "hey, $tl is already here, dufus!";
}
print "I'm gonna get $tl";
system ("wget @tlink");
------------------------------
Date: Wed, 07 Jun 2000 19:02:47 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: "constant" problem
Message-Id: <1rssjskk4ds5krpcu1pqlr8c16bjdhfhvs@4ax.com>
On Wed, 07 Jun 2000 15:07:45 GMT, squidrocks@my-deja.com wrote:
> This is a fully functioning program with one exception. The if
> statement at the bottom doesn't work because of some data problem with
> the scalar. It never reckognizes that I already have the file. If I
> substitute $tl='whatever.exe' instead of trying to match it with the
> variable @file it works fine, but since the file in @file is what I
> need to check and it will change I cannot assign it a constant value.
The general problem with your program is that you are using arrays (the
@thingies) where you should be using scalars (the $thingies), while you
don't seem to know how to access individual elements of an array.
>
> Thanks to anyone who can help.
>
> #!/usr/local/bin/perl
no '-w' and no 'use strict;'
Let perl help you as much as it can :-)
> system ("rm mcafee_4x.asp");
> #retrieves web page
> system ("wget
> http://www.nai.com/asp_set/download/dats/mcafee_4x.asp");
>
> open (WP, "mcafee_4x.asp");
> @webpage=<WP>;
> close (WP);#converts webpage into array
Now all those lines could be replaced with:
use LWP::Simple;
my $wpg = 'http://www.nai.com/asp_set/download/dats/mcafee_4x.asp';
my $web_page = get($wpg) or die "Couldn't get '$wpg'";
The contents of that page ar now in $web_page as one single string.
>
> @link=grep /superdat.english.nai.intel/, @webpage;
> @truelink=map {split 'name: <a href="',} @link;
> @truelink=map {/http.*exe/} @link;
> @tlink=map {split '">.*</a>',} @truelink;
I will not comment on the 4 lines above.
But you could have written that (well if the page was in a scalar) like:
my($link) = $web_page =~
m!<a href="(http.*?/superdat/english/nai/intel/.*?\.exe)">!i;
Just match (the pattern is between the m!!i) as big a string as you need
to get your link out of that page. (Mind you if there were more
occurences of that pattern, it would only match the first.)
The part between the parans is the part you actualy want to 'capture'
and is assigned to $link.
>
> @file=map{split 'http.*/',} @tlink;
> open (LF,">link");
> print LF @file;
> close (LF);
> open (NF,"link");
> $tl=<NF>;
> close (NF);
I guess this is a rather long way to say:
$tl = $file[0];
What you wanted was the part after the last slash in (for my case)
$link:
my($file) = $link =~ m!.+/(.+)$!;
now you can your copy of the update:
print "Update '$file' already exists\n" and exit if -e $file;
print "Get it: $link\n";
system('wget', $link);
Reading about these things helps.
Your original question is answerd in perlfunc:
perldoc -f -X
the rest is found in:
perldoc perlre
perldoc LWP::Simple
--
Good luck,
Abe
------------------------------
Date: Wed, 07 Jun 2000 17:01:34 GMT
From: "Mike Ray" <noone@nowhere.org>
Subject: [HELP] chomp and loops
Message-Id: <Odv%4.3673$2X2.142687@newsread2.prod.itd.earthlink.net>
Greetings,
I have a few questions which aren't clearly answered by either the
perdocs or the camel book.
I understand that chomp will remove the input separator (newline in my
environment) from the end of a string. I am using the following to
remove all whitespace and the newline at the end of a string:
chomp $string;
$string =~ s/\s+$//;
Is the chomp really needed here as it would seem the pattern replacement
would remove the newline anyway? Also, since the docs state that "$" and
a regexp points between the last character in the string and the
newline, am I creating some unexpected side-effect with the above code
sequence?
Another question. Does "next" and "last" work in for loops as they do in
while loops. The docs only talk explicitly about while loops. Will
"next" immediately cause the next iteration of the for loop without
executing any further code in the for loop. Also, will "last"
immediately exit execution of the for loop without executing any further
code in the for loop. For example, will the for loop work as follows:
for (--whatever--) { #<-will "next" go here
...do something here
if (--some condition--) {next}
...do something else
if (--another condition--) {last}
...and maybe do something here
}
...more code here #<-will "last" go here
Thanks!
Mike
------------------------------
Date: Wed, 07 Jun 2000 17:38:41 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: [HELP] chomp and loops
Message-Id: <7asnupqtlp.fsf@merlin.hyperchip.com>
"Mike Ray" <noone@nowhere.org> writes:
> I have a few questions which aren't clearly answered by either the
> perdocs or the camel book.
Are you sure?
> I understand that chomp will remove the input separator (newline in my
> environment) from the end of a string. I am using the following to
> remove all whitespace and the newline at the end of a string:
>
> chomp $string;
> $string =~ s/\s+$//;
>
> Is the chomp really needed here as it would seem the pattern replacement
> would remove the newline anyway?
The chomp() is not necessary. \s means a whitespace which includes
spaces, tabs and newlines. So the second line will remove any newlines
you might have at the end of your string.
> Also, since the docs state that "$" and
> a regexp points between the last character in the string and the
> newline, am I creating some unexpected side-effect with the above code
> sequence?
No.
> Another question. Does "next" and "last" work in for loops as they do in
> while loops. The docs only talk explicitly about while loops. Will
> "next" immediately cause the next iteration of the for loop without
> executing any further code in the for loop.
Yes.
> Also, will "last"
> immediately exit execution of the for loop without executing any further
> code in the for loop.
Yes.
> For example, will the for loop work as follows:
>
> for (--whatever--) { #<-will "next" go here
> ...do something here
> if (--some condition--) {next}
> ...do something else
> if (--another condition--) {last}
> ...and maybe do something here
> }
> ...more code here #<-will "last" go here
Why didn't you try it? You already developped the code to test it. Just
add a few print() statements to clarify what is exactly
happening. And it takes much less time than posting and waiting for a
reply. Please avoid posting questions that can be very easily verified
by yourself. Posting should be your LAST resort, after you have tried
several approaches.
--Ala
------------------------------
Date: Wed, 7 Jun 2000 10:46:34 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: [HELP] chomp and loops
Message-Id: <8hm1oh$q9r$1@brokaw.wa.com>
Mike Ray <noone@nowhere.org> wrote in message
news:Odv%4.3673$2X2.142687@newsread2.prod.itd.earthlink.net...
> I understand that chomp will remove the input separator (newline in my
> environment) from the end of a string. I am using the following to
> remove all whitespace and the newline at the end of a string:
>
> chomp $string;
> $string =~ s/\s+$//;
>
> Is the chomp really needed here as it would seem the pattern replacement
> would remove the newline anyway? Also, since the docs state that "$" and
> a regexp points between the last character in the string and the
> newline, am I creating some unexpected side-effect with the above code
> sequence?
You could try it out.
$str1 = $str2 = "abcdef \n";
$str1 =~ s/\s+$//;
print "|$str1|\n";
chomp $str2;
$str2 =~ s/\s+$//;
print "|$str2|\n";
^Z
|abcdef|
|abcdef|
>
> Another question. Does "next" and "last" work in for loops as they do in
> while loops. The docs only talk explicitly about while loops. Will
> "next" immediately cause the next iteration of the for loop without
> executing any further code in the for loop. Also, will "last"
> immediately exit execution of the for loop without executing any further
> code in the for loop. For example, will the for loop work as follows:
Again, you could have tried it.
for (qw(a b c)) {
print $_, "\n";
last;
}
^Z
a
Lauren
------------------------------
Date: Wed, 7 Jun 2000 09:55:42 -0700
From: "Gabe" <grichard@uci.edu>
Subject: Best Way to Test if File Exists
Message-Id: <8hlv1k$6i5$1@news.service.uci.edu>
I'm sure there is a better way to do this, but I want to test if a file
exists. Below is what I'm currently doing, if there's is a better way please
tell me and/or direct me to the relevant doc.
if (open(FILE, $file)) {
close FILE;
do stuff;
}
Gabe
------------------------------
Date: Wed, 07 Jun 2000 17:40:10 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Best Way to Test if File Exists
Message-Id: <7apuptqtj7.fsf@merlin.hyperchip.com>
"Gabe" <grichard@uci.edu> writes:
> I'm sure there is a better way to do this, but I want to test if a file
> exists. Below is what I'm currently doing, if there's is a better way please
> tell me and/or direct me to the relevant doc.
>
> if (open(FILE, $file)) {
> close FILE;
> do stuff;
> }
if (-e $file) {
do_stuff();
}
--Ala
------------------------------
Date: Wed, 07 Jun 2000 17:45:02 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: Best Way to Test if File Exists
Message-Id: <ySv%4.3495$55.41587@news1.rdc1.mb.home.com>
In article <8hlv1k$6i5$1@news.service.uci.edu>,
Gabe <grichard@uci.edu> wrote:
> I'm sure there is a better way to do this, but I want to test if a file
> exists. Below is what I'm currently doing, if there's is a better way please
see the perlfunc manpage (perldoc perlfunc) for the -X filetest
operators -- you are looking for the -e file exists operator.
regards,
andrew
--
Andrew L. Johnson http://members.home.net/perl-epwp/
Reality is that which, when you stop believing in
it, doesn't go away.
-- Philip K. Dick
------------------------------
Date: 7 Jun 2000 17:46:17 GMT
From: jdg28@pantheon.yale.edu (John Gehman)
Subject: Re: Best Way to Test if File Exists
Message-Id: <8hm1p9$b1$1@news.ycc.yale.edu>
use -e file test operator. Page 85 of camel book
Gabe (grichard@uci.edu) wrote:
: I'm sure there is a better way to do this, but I want to test if a file
: exists. Below is what I'm currently doing, if there's is a better way please
: tell me and/or direct me to the relevant doc.
: if (open(FILE, $file)) {
: close FILE;
: do stuff;
: }
: Gabe
------------------------------
Date: Wed, 7 Jun 2000 10:47:23 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Best Way to Test if File Exists
Message-Id: <8hm1q3$uod$1@brokaw.wa.com>
Gabe <grichard@uci.edu> wrote in message
news:8hlv1k$6i5$1@news.service.uci.edu...
> I'm sure there is a better way to do this, but I want to test if a file
> exists. Below is what I'm currently doing, if there's is a better way
please
> tell me and/or direct me to the relevant doc.
>
> if (open(FILE, $file)) {
> close FILE;
> do stuff;
> }
perldoc -f -X
Lauren
------------------------------
Date: Wed, 07 Jun 2000 16:02:06 GMT
From: afedorova@my-deja.com
Subject: calling LWP::Simple::get from browser vs. from command line
Message-Id: <8hlrli$5tb$1@nnrp1.deja.com>
I am experiencing inconsistent behavior when calling LWP::Simple::get
([some url]) from command line vs. from a browser. In particular, I
have a perl script that does the following:
--------------------------
use LWP::Simple;
print "Content-type: text/html\n\n";
my $page = LWP::Simple::get("http://www.yahoo.com");
if ( defined ($page) )
{
print $page;
}
--------------------------
When I call this perl script from a command line, it works great. When
I try to launch this script from the browser, the script itself gets
launched, but the $page is always undefined - it is empty.
Please help me with this problem if you can!
Sasha
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 07 Jun 2000 12:50:01 -0400
From: Stacey Campbell <campbell@coaps.fsu.edu>
Subject: CGI code for downloading
Message-Id: <393E7D38.BB558D46@coaps.fsu.edu>
I am trying to figure out CGI code that someone else wrote, which accepts
form data, processes it into the correct path and filename for our unix system,
and allows the user to download that file over the internet. The problem is
that I have never written CGI code for downloading files over the internet, the
code is not mine, it has all kinds of HTML and perl mixed up all together (he
didn't use CGI.pm), and I can't decipher it well enough to modify it.
His code downloads entire groups of files. I was asked to add a function to
the page that downloads individual files, but I might end up having to write the
page over completely, just so I know what is going on.
Does anyone have some simple, maybe generic CGI code for downloading files
from a unix system over the internet? It could be for single files or groups of
files. I would appreciate the form code and the data handling code. If you are
worried about security of your page, please let me know if you have a generic
version, or point me to a book or website that will help me do these things.
Thanks,
-Stacey Campbell-
------------------------------
Date: Wed, 7 Jun 2000 21:04:12 +0400
From: "Roman Chumakov" <zfido88@zr.ru>
Subject: change priority
Message-Id: <8hlv9k$gvf$1@news.sovam.com>
I need to low priority for executing a perl script.
How a perl script can do it itself?
May a perlscript to low itself priority? If yes - How?
Hlp pls.
thx. Ruslan
------------------------------
Date: Wed, 07 Jun 2000 13:38:30 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: change priority
Message-Id: <393E8896.15BF1539@attglobal.net>
Roman Chumakov wrote:
>
> I need to low priority for executing a perl script.
>
> How a perl script can do it itself?
> May a perlscript to low itself priority? If yes - How?
>
> Hlp pls.
> thx. Ruslan
Depending on your system (I'll assume generic UNIX), you can
determine what PID the script is running under and then have
the script "nice" itself up or down.
------------------------------
Date: Wed, 07 Jun 2000 16:59:42 GMT
From: ould@my-deja.com
Subject: CRONING DELETE OF DIRECTORY
Message-Id: <8hlv1i$8oi$1@nnrp1.deja.com>
Hello,
I use Windows NT 4.
I'm wondering for a perl script allowing
me to delete all contents of some directory
except 3 (that I precise as file.db, file.js...).
The directory is named
"cache" ( D:\users\user_name\netscape\cache)
I want to be able to run this script as "cron" of
Unis OS each hour in order to avoid crash of my users
disk.
Thanks,
Ould
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 07 Jun 2000 17:19:47 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Dumb question.. How to prompt the user and get the input.
Message-Id: <otpsjskicgvjoljj4hf9aclje4n26nf880@4ax.com>
On Wed, 07 Jun 2000 13:56:41 GMT, bart.lateur@skynet.be (Bart Lateur)
wrote:
> $input = <STDIN>;
>
> obviously! But don't forget that there will be a newline at the end of
> the line. And it won't "work" if data was piped into the script (er...
> can you even do that with perl on Win32?)
You mean like:
echo Hello i'ts me | perl -pe ""
--
Good luck,
Abe
------------------------------
Date: 07 Jun 2000 10:05:16 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: dump a hash?
Message-Id: <87ya4h351v.fsf@limey.hpcc.uh.edu>
>> On Wed, 07 Jun 2000 14:48:39 GMT,
>> Dr. Markus <nasobem_hh@my-deja.com> said:
> Hi, We just came accross an interesting question: Is it
> possible to dump a hash (preferrably raw) to disk for
> future reference? Best would be a selfdescribing format
> (i.e. the structure can be derived when the dump is
> read). Any ideas? Markus
http://search.cpan.org/doc/RAM/Storable-0.6.11/Storable.pm
hth
t
--
"Trying is the first step towards failure"
Homer Simpson
------------------------------
Date: Wed, 07 Jun 2000 15:29:46 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: dump a hash?
Message-Id: <7a4s75se51.fsf@merlin.hyperchip.com>
Dr. Markus <nasobem_hh@my-deja.com> writes:
> Is it possible to dump a hash (preferrably raw) to disk for future
> reference?
Yes, and there are various ways. One way is to use a DB module that will
automatically keep your hash on disk. 'perldoc DB_File' for an example.
Another is to use the Data::Dumper module to print the hash to a
file. Then you simply do() the file with the hash inside.
'perldoc Data::Dumper' for more info.
You can also use the Storable module, among others. Check CPAN for
details.
--Ala
------------------------------
Date: Wed, 7 Jun 2000 09:45:05 -0500
From: "Tim" <tcuffel@exactis.com>
Subject: Re: dump a hash?
Message-Id: <9Rt%4.7807$Rx.749190@den-news1.rmi.net>
Dr. Markus wrote in message <8hlnbv$243$1@nnrp1.deja.com>...
>Hi,
>We just came accross an interesting question:
>Is it possible to dump a hash (preferrably raw) to disk for future
>reference?
>Best would be a selfdescribing format (i.e. the structure can be derived
>when the dump is read).
>Any ideas?
>Markus
Do you need it in a human readible format, or just something
your program can look at on a latter invocation?
If it the latter, check out DB_File, and tied hashes in general.
-T
------------------------------
Date: Wed, 07 Jun 2000 15:16:42 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: each not looping on a hash
Message-Id: <7a7lc1seqs.fsf@merlin.hyperchip.com>
"Tintin" <you.will.always.find.him.in.the.kitchen@parties> writes:
> This one is driving me nuts.
>
> I have a simple hash that maps a URL path to a directory, ie:
>
> %URLMappings= (
> '~fred', '/home/fred/public_html',
> );
>
> In one of my subroutines, it does not even run through the while loop once.:
>
> while (($key,$value) = each %URLMappings) {
> print "$key,$value\n";
> }
>
> I've confirmed that there is a value in URLMappings, by adding the line:
>
> print "$URLMappings{'fred'}\n";
>
> before the while loop.
>
> Any ideas? I'm using Perl 5.005_02
You probably iterate through the same hash somewhere else in your
program, and exit that loop via a 'last' call. Iterating again will
simply continue where the last each() left off. This is explained in
perlfunc:
There is a single iterator for each hash, shared by all
C<each()>, C<keys()>, and C<values()> function calls in the
program; it can be reset by reading all the elements from the
hash, or by evaluating C<keys HASH> or C<values HASH>.
Now, if your first loop ended at the last key-value pair of the hash,
the next call to each() will return false. Here's a short example to
illustrate this:
my %hash = qw/a 1 b 2 c 3/;
my $i = 0;
# First loop.
while (my($k, $v) = each %hash) {
print "Iteration1: $k => $v.\n";
last if ++$i == 3;
}
# Second loop.
while (my($k, $v) = each %hash) {
print "Iteration2: $k => $v.\n";
}
print "Done.\n";
__END__
Iteration1: a => 1.
Iteration1: b => 2.
Iteration1: c => 3.
Done.
As we see here, the second loop did not execute although the hash is
clearly populated. So, to fix it, you have to reset the hash. I would do
this simply by:
scalar keys %hash;
before starting the second loop.
HTH,
--Ala
------------------------------
Date: Wed, 07 Jun 2000 17:01:22 GMT
From: "SteveSingletary" <steve@gte.net>
Subject: exists() example
Message-Id: <Cdv%4.738$oH1.78315@dfiatx1-snr1.gtei.net>
I can't seem to get this working.
I am reading in a file and getting hash variables:
@filelist = ($podata);
unlink @filelist;
open (FILE,">$podata");
read(STDIN, $text, $ENV{'CONTENT_LENGTH'});
my @value_pairs = split (/&/,$text);
my %form_results = ();
foreach $pair (@value_pairs)
($key, $value) = split (/=/,$pair);
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
$form_results{$key} = $value; # store the key in the results hash
}
(I know very raw)
The problem is I need to be sure some fields are not blank.
When I print the fields out I do a:
if ($form_results{'SHIP_METH_PAY'}) {
print FILE "($form_results{'SHIP_METH_PAY'})\n";
This works perfect, and if the field is blank it will not print it.
However, I need to validate this field before I get to this print
sub-routine. I have tried if(not(($form_results{'SHIP_METH_PAY'}) ) and
I've tried if(exists(($form_results{'SHIP_METH_PAY'}) ) but niether are
working properly. They out whether the field is blank or not.
Any ideas...
Steve
------------------------------
Date: Wed, 07 Jun 2000 17:47:10 GMT
From: "SteveSingletary" <steve@gte.net>
Subject: Re: exists() example
Message-Id: <xUv%4.954$oH1.89234@dfiatx1-snr1.gtei.net>
Nevermind - I have the if(not) working. I have errors in the subroutine
logic of the whole program.
Thanks anyways,
Steve
SteveSingletary <steve@gte.net> wrote in message
news:Cdv%4.738$oH1.78315@dfiatx1-snr1.gtei.net...
> I can't seem to get this working.
> I am reading in a file and getting hash variables:
> @filelist = ($podata);
> unlink @filelist;
> open (FILE,">$podata");
> read(STDIN, $text, $ENV{'CONTENT_LENGTH'});
> my @value_pairs = split (/&/,$text);
> my %form_results = ();
> foreach $pair (@value_pairs)
>
> ($key, $value) = split (/=/,$pair);
> $value =~ tr/+/ /;
> $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
> $form_results{$key} = $value; # store the key in the results hash
> }
> (I know very raw)
> The problem is I need to be sure some fields are not blank.
> When I print the fields out I do a:
> if ($form_results{'SHIP_METH_PAY'}) {
> print FILE "($form_results{'SHIP_METH_PAY'})\n";
>
> This works perfect, and if the field is blank it will not print it.
> However, I need to validate this field before I get to this print
> sub-routine. I have tried if(not(($form_results{'SHIP_METH_PAY'}) ) and
> I've tried if(exists(($form_results{'SHIP_METH_PAY'}) ) but niether are
> working properly. They out whether the field is blank or not.
> Any ideas...
> Steve
>
>
>
------------------------------
Date: Wed, 07 Jun 2000 10:57:20 -0500
From: Anton Chuppin <chuppin@ncsa.uiuc.edu>
Subject: Re: exists() on sub-hash creates a key in super-hash
Message-Id: <393E70E0.8A19C680@ncsa.uiuc.edu>
Vincent wrote:
>
> Hi All,
<snip>
> - The test with 'exists()' for $hash{'bar'}{'foo'} obviously fails. But,
> it seems to create a key 'bar' in %hash with a reference to an empty
> hash.
<snip>
> Question:
> Is this behaviour 'as designed', an ommision in the design or a bug?
<snip>
> Cheers,
> Vincet Zocca
Hi Vincent,
this feature is mentioned in 'exists' function description in perldoc:
" ....
Note that the EXPR can be arbitrarily complicated as
long as the final operation is a hash key lookup:
if (exists $ref->{A}->{B}->{$key}) { }
if (exists $hash{A}{B}{$key}) { }
Although the last element will not spring into existence
just because its existence was tested, intervening one
will. Thus `$ref->{"A"}' and `$ref->{"A"}->{"B"}' will
spring into existence due to the existence test for a
$key element. This happens anywhere the arrow operator
is used, including even
undef $ref;
if (exists $ref->{"Some key"}) { }
print $ref; # prints HASH(0x80d3d5c)
This surprising autovivification in what does not at
first--or even second--glance appear to be an lvalue
context may be fixed in a future release."
Anton
------------------------------
Date: Wed, 07 Jun 2000 17:57:01 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: external program stdout to screen and log
Message-Id: <393E70CD.7E5D2D8C@ife.ee.ethz.ch>
bradley_johnston@my-deja.com wrote:
>
> I want to run external programs from my Perl program (like a "VSS GET"
> and "msdev project.dsw..."). I want to log the output to file, and I
> still want to see the output to screen.
>
> Right now I am doing this...
>
> $command = 'SS Get $/project/*.* -R -GCK';
> @result = `$command`;
>
> Then I can print the @result array to file and screen after the
> external program completes, but I am looking for something a little
> more real time.
use open() to spawn the external program, see the docs for open
open PROGI,"$command |" or die "I'm unhappy with $command: $!";
while(<PROGI>) {
print;
push @result, $_;
}
- Alex
------------------------------
Date: Wed, 07 Jun 2000 16:13:28 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: external program stdout to screen and log
Message-Id: <7avgzlqxjr.fsf@merlin.hyperchip.com>
bradley_johnston@my-deja.com writes:
> I want to run external programs from my Perl program (like a "VSS GET"
> and "msdev project.dsw..."). I want to log the output to file, and I
> still want to see the output to screen.
perlfaq5:
How do I dup() a filehandle in Perl?
--Ala
------------------------------
Date: Wed, 7 Jun 2000 15:14:58 GMT
From: Vince Wilding <vwilding@digizen.net>
Subject: General failure reading device (Win32)
Message-Id: <393E66F2.24C0CA1B@digizen.net>
Using ActiveState Build 522 on Win98 (This NEVER happened on NT) I get
a "General failure reading device" error (no device mentioned!) when I
try to do a file OPEN. Sometimes I see the light come on on the A:
drive, even though I don't reference it anywhere in the code. I give it
a cupla "f"'s and it goes on its merry way. I've tried the "/f" switch
for COMMAND.COM but that doesn't help.
Any Ideas?
--
Vince Wilding, Web Wrangler, MetaData Maven, Perl Hacker Wannabe
USGS/BRD/OBIO
mailto:vince_wilding@usgs.gov --- http://biology.usgs.gov/~vwilding/
The truth is out there, I just forgot the URL
------------------------------
Date: Wed, 07 Jun 2000 12:07:51 -0300
From: Marcelo <mnarvaja@geocities.xyz.com>
Subject: Get and post from/to news groups
Message-Id: <393E6546.4743710D@geocities.xyz.com>
Does anyone have a good example of a script that read news, headers from
or post messages to news groups.
I have been unsuccessfully trying with the examples that come in the
HTTP module ...
Thanks in advanced,
Marcelo
------------------------------
Date: Wed, 07 Jun 2000 11:53:43 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Get and post from/to news groups
Message-Id: <393E7007.74AF2379@attglobal.net>
Marcelo wrote:
>
> Does anyone have a good example of a script that read news, headers from
> or post messages to news groups.
> I have been unsuccessfully trying with the examples that come in the
> HTTP module ...
>
Hmm.. USENET is NNTP, not HTTP. I guess the following modules might
be helpfull:
Net::NNTP
News::NNTPClinet
There may be others that suite your needs better, but since you've
so broadly defined these needs, I can't tell.
------------------------------
Date: Wed, 07 Jun 2000 18:07:53 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: Get and post from/to news groups
Message-Id: <393E7359.7E272676@ife.ee.ethz.ch>
Marcelo wrote:
>
> Does anyone have a good example of a script that read news, headers from
> or post messages to news groups.
> I have been unsuccessfully trying with the examples that come in the
> HTTP module ...
HTTP has nothing to do with news
NNTP is the network news protocol
Check cpan for News or NNTP
- Alex
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3277
**************************************