[18386] in Perl-Users-Digest
Perl-Users Digest, Issue: 554 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 23 11:05:37 2001
Date: Fri, 23 Mar 2001 08:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <985363508-v10-i554@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 23 Mar 2001 Volume: 10 Number: 554
Today's topics:
?? Size limit on files/arrays?? <Mike_Matteson@dg.com>
Re: checkbox problem (Damian James)
Code Generator for Perl 5.0 <michaelw@elkhart.net>
every 15 seconds <bkaiser@trans-it.de>
Re: every 15 seconds <djberge@uswest.com>
Re: fetch back STDERR outputs <johnlin@chttl.com.tw>
Re: Followup - evaluating functions in a FILE <mjcarman@home.com>
Re: form to mail Can I send the mail as an attachment? <djberge@uswest.com>
Hmmm... Which PERL Book Is Best Suited For This??? (---Pete---)
Re: Hmmm... Which PERL Book Is Best Suited For This??? (Chris Fedde)
Re: Need help with script as I suck at perl. (Kev.-)
Passing arguments to subroutines... <N.Hirani@hgmp.mrc.ac.uk>
Re: POST method and cgi.pm <fty@mediapulse.com>
Problem with sockets and name based virtual host <johnm@aiamail.com>
Read and write a hash of arrays ? u665313720@spawnkill.ip-mobilphone.net
Re: Regex question (Rafael Garcia-Suarez)
Re: Statistics <jonni@ifm.liu.se>
Re: Still can't die with Tar <goldbb2@earthlink.net>
Re: using closures (road to OO) (Greg Bacon)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 23 Mar 2001 10:39:52 -0500
From: "Mike Matteson" <Mike_Matteson@dg.com>
Subject: ?? Size limit on files/arrays??
Message-Id: <99fqo3$hrd$1@imas0002.us.dg.com>
I've encountered an odd limit twice now in trying to process a list (of DNS
host/IP lines) where the perl script didn't complain, but didn't process
some of the lines. I have a 48,419 item list, and the sort and copy would
only process 48,215 lines. No errors given, just silently went on with a
smaller-than-expected output file. Odly enough, it works in a small test
script, but not in the main script that contains other arrays, etc.
If anyone has encountered this and has a 'fix' or some idea of where to
attack it, I'd sure appreciate any ideas/comments.
Thanks,
Mike Matteson
IS - Data General, A Division of EMC
Matteson_Mike@emc.com
------------------------------
Date: 23 Mar 2001 14:10:53 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: checkbox problem
Message-Id: <slrn9bmmai.k35.damian@puma.qimr.edu.au>
uNcONvEntiOnaL chose Thu, 22 Mar 2001 03:25:27 GMT to say this:
>...
>
>I run my perl scripts on my unix shell account at my ISP.
>All are involked from web pages. I cannot get either the perl
>library or module mechanism to work...
>
You know you can install Perl on your own computer? Doesn't matter
what kind of weird platform you're running. You can then test and learn to
use this stuff independently to grappling with your ISP.
You should have a look at www.perl.com and investigate getting a copy of
perl for your platform.
Cheers,
Damian
--
@;=0..23;@;{@;}=split//,<DATA>;while(@;){for($;=@;;--$;;){next if($:=rand($;
+1))==0+$;;@;[$;,$:]=@;[$:,$;]}print map{$;{$_}}(@| ,@;);push@|,shift@;if$;[
0]==@|;$|=1;select$&,$&,$&,1/80;print"\b"x(@;+@|)}print"\n"__END__
Just another Perl Hacker
------------------------------
Date: Fri, 23 Mar 2001 09:44:20 -0500
From: Michael Wenzelmaier <michaelw@elkhart.net>
Subject: Code Generator for Perl 5.0
Message-Id: <3ABB6144.84854EA5@elkhart.net>
Hi guys,
check out the Code Generator for PHP, ASP, PERL, JSP, COLDFUSION with
database connect to ODBC, Oracle, MSSQL, mSQL, MySQL
Download the Trial Version and check it out.
http://www.webprocenter.net/codecharge
Thanks
Michael
------------------------------
Date: Fri, 23 Mar 2001 16:35:06 -0000
From: "Bjoern Kaiser" <bkaiser@trans-it.de>
Subject: every 15 seconds
Message-Id: <99fqg4$h6l$1@desperado.vew-telnet.net>
how do i output something every 15 seconds?
------------------------------
Date: Fri, 23 Mar 2001 09:40:11 -0600
From: Daniel Berger <djberge@uswest.com>
Subject: Re: every 15 seconds
Message-Id: <3ABB6E5B.7A51BFB8@uswest.com>
--------------B25CC9114932B0EA8FDE5346
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Bjoern Kaiser wrote:
> how do i output something every 15 seconds?
while(1){
print "Hello World!\n";
sleep(15);
}
Dan
--
"Evil will always triumph because Good is *dumb*"
- Dark Helmet, Spaceballs
--------------B25CC9114932B0EA8FDE5346
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Bjoern Kaiser wrote:
<blockquote TYPE=CITE>how do i output something every 15 seconds?</blockquote>
while(1){
<br> print "Hello World!\n";
<br> sleep(15);
<br>}
<p>Dan
<br>
<pre>--
"Evil will always triumph because Good is *dumb*"
- Dark Helmet, Spaceballs</pre>
</html>
--------------B25CC9114932B0EA8FDE5346--
------------------------------
Date: Fri, 23 Mar 2001 22:37:52 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: fetch back STDERR outputs
Message-Id: <99fmhk$f55@netnews.hinet.net>
nobull wrote:
>"John Lin" writes:
>
>> package AG;
>> use strict;
>> local *ERR;
>
> Get rid of the local().
Hmm... I thought it was a good habbit to make
'strict' happy (or -w ?). Now I know it's unnecessary
within a package. Just needed in package main.
(New behavior of Perl5.6, right?)
>BTW: unless you've made $, and $\ unequal:
> print for <ERR>;
>Is just a less eficient way to:
> print <ERR>;
>What I think you meant to say:
> local $_;
> print while <ERR>;
Yes, thank you indeed.
John Lin
------------------------------
Date: Fri, 23 Mar 2001 07:48:59 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Followup - evaluating functions in a FILE
Message-Id: <3ABB544B.ECF2DB92@home.com>
Gregory Toomey wrote:
>
> [A]ssume we have a file test.htm that contains the following 3 lines:
> Element is $mylist[1+2]
> Server is $ENV{"SERVER_NAME"}
> Func is @{[myfunc()]}
>
> It's trivial to read the file into a list or variable.
> But can the file be processed to correctly evaluate each line?
You want a template. There are lots of modules for doing this:
HTML::Template
Text::Template
Text::MetaText
Template Toolkit
...
Have a look at CPAN and see which one looks right for your purposes.
-mjc
------------------------------
Date: Fri, 23 Mar 2001 09:43:22 -0600
From: Daniel Berger <djberge@uswest.com>
Subject: Re: form to mail Can I send the mail as an attachment??
Message-Id: <3ABB6F1A.1674EA26@uswest.com>
--------------1201DE2070E8FC7056C4D841
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Wing Commander wrote:
> I am using a script that e-mails the contents of the form to me.
>
> Currently the contents of the form is in the body of the e-mail, but I would
> like to receive the form info as an attachment - is this possible??
>
> if so are there any pre-written scripts available or is it just a couple of
> lines of code I can add to my existing script??
>
> Thanks in advance............
Check out the Mail::Sender module out on CPAN. I've used it myself
and it seems to work quite well.
Dan
--
"Evil will always triumph because Good is *dumb*"
- Dark Helmet, Spaceballs
--------------1201DE2070E8FC7056C4D841
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Wing Commander wrote:
<blockquote TYPE=CITE>I am using a script that e-mails the contents of
the form to me.
<p>Currently the contents of the form is in the body of the e-mail, but
I would
<br>like to receive the form info as an attachment - is this possible??
<p>if so are there any pre-written scripts available or is it just a couple
of
<br>lines of code I can add to my existing script??
<p>Thanks in advance............</blockquote>
<p><br>Check out the Mail::Sender module out on CPAN. I've used it
myself
<br>and it seems to work quite well.
<p>Dan
<br>
<pre>--
"Evil will always triumph because Good is *dumb*"
- Dark Helmet, Spaceballs</pre>
</html>
--------------1201DE2070E8FC7056C4D841--
------------------------------
Date: Fri, 23 Mar 2001 14:53:45 GMT
From: bogus@erol.com (---Pete---)
Subject: Hmmm... Which PERL Book Is Best Suited For This???
Message-Id: <3abb627d.87528499@news.earthlink.net>
Everyone,
Just to let you know, I searched the last 3000+ posts for
"BOOK" titles and none of the posts addressed what I
am ask here. Allow me to explain:
I'm a Visual Basic programmer, new to PERL and only read
one book so far titled "SAMS Teach Your Perl in 24hours".
Well, about a month later, it's clear that I need another book
to get me past the basics <grin>.
I know everyone has their favorite book but I need a
recomendation for a book to be used in a specific
manner as follows:
I'm looking for a reference book that is instructional as well
as extensively indexed such that I can pickup a sample
Perl script and quiclky find topics or functions like sysread(),
or even simple things like "$!" that I find in the sample Perl
code. This PERL book should also written with the CGI in
mind.
PS: For newbies, the SAMS book I mentioned above is
good for the learning the basics but once you begin to
actually write scripts, you end up frustrated thinking..
"Damn, I know I read about 'this or that' and it's in this
book somewhere but I just can't seem to find it now."
In other words, it's instructional but not a very good
reference simply becasue they did not index it
properly.
Any recomendations?
---pete---
------------------------------
Date: Fri, 23 Mar 2001 16:04:32 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Hmmm... Which PERL Book Is Best Suited For This???
Message-Id: <kuKu6.200$T3.170159616@news.frii.net>
In article <3abb627d.87528499@news.earthlink.net>,
---Pete--- <bogus@erol.com> wrote:
>Everyone,
>Just to let you know, I searched the last 3000+ posts for
>"BOOK" titles and none of the posts addressed what I
>am ask here. Allow me to explain:
>
>I'm a Visual Basic programmer, new to PERL and only read
>one book so far titled "SAMS Teach Your Perl in 24hours".
>Well, about a month later, it's clear that I need another book
>to get me past the basics <grin>.
>
>I know everyone has their favorite book but I need a
>recomendation for a book to be used in a specific
>manner as follows:
>
>I'm looking for a reference book that is instructional as well
>as extensively indexed such that I can pickup a sample
>Perl script and quiclky find topics or functions like sysread(),
>or even simple things like "$!" that I find in the sample Perl
>code. This PERL book should also written with the CGI in
>mind.
>
Sounds to me like you want the online perl manual that came with
your installaton. If you are not comfortable working with the
manual pages using the perldoc command then you can go to one of
the web resources such as http://www.cpan.org/doc/manual/html/pod/perl.html
For printed matter you can do worse than get the Camel book by Wall, et al.
chris
--
This space intentionally left blank
------------------------------
Date: Fri, 23 Mar 2001 14:26:59 GMT
From: java2e@yahoo.com (Kev.-)
Subject: Re: Need help with script as I suck at perl.
Message-Id: <3abb5cf6.6659025@ns1.nothingbutnet.net>
You know some people are just complete jerks and you are one of those
people. You suck.
On Fri, 23 Mar 2001 11:39:30 +0100, "Mark Kuin"
<mkuin@globalrangers.com> wrote:
>You don't only suck at perl. You also suck in telling what you actually
>need. This has nothing to do with perl, but with asking the wrong guy to do
>something he doesn't understand, and who doesn't know how to get things
>clear. Please get some education before posting to this newsgroup.
>
>hth Mark
>
>> I am suppose to call this link:
>> http://www.abc.com/xxx.cgi?link=Dude/1/test&seed=41FLZ9FJJ
>> which return this:
>> http://www.xzy.com/default.asp?seed=41FLZ9FJJ &pop=12&receipt=12
>> Then I am suppose to pass the pop to a function called valid.
>> How heck to I do this??
>> I am suppose to recall the abc.com link but I cant figure it out.
>
>
>
------------------------------
Date: Fri, 23 Mar 2001 15:09:58 +0000
From: Naran Hirani <N.Hirani@hgmp.mrc.ac.uk>
Subject: Passing arguments to subroutines...
Message-Id: <3ABB6746.CDCFEB76@hgmp.mrc.ac.uk>
Hi All,
I have this piece of noddy code in perl which works but I was
wondering if some one
could tell me how I can modify it so that arguments can be passed to my
little
subroutine.
...
my %LookUp = (Hello => 'Ola');
my %Translate = (English2Cockney => &Interpretor);
my $lingo = "Hello";
print "I say $lingo, and you say ", $Translate{English2Cockney}, "\n";
sub Interpretor {
return $LookUp{'Hello'};
}
------------------------------
Date: Fri, 23 Mar 2001 14:27:44 GMT
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: POST method and cgi.pm
Message-Id: <A3Ju6.96148$LM.6291482@news2.aus1.giganews.com>
"Prasad, Victor [FITZ:K500:EXCH]" <vprasad@americasm01.nt.com> wrote in
message news:99fa7p$e8c$1@bcrkh13.ca.nortel.com...
> If you have html code and you use the POST method - pass the data to a
> cgi.pm module using script - to what variable does it pass it to?
>
> How does the POST method work - I have seen it with out cgi.pm and it uses
> pack and unpack and hex commands - what are these?
>
> Any sample code of html using post passing it to a cgi.pm script for use?
> Maybe a text fields send a first and last name?
Did you try reading the docs that came with the module? Try perldoc CGI or
man CGI or even go to:
http://stein.cshl.org/WWW/software/CGI/cgi_docs.html
Jay
------------------------------
Date: 23 Mar 2001 15:37:29 GMT
From: "John Michael" <johnm@aiamail.com>
Subject: Problem with sockets and name based virtual host
Message-Id: <99fqjp$o0o@dispatch.concentric.net>
Hi
I am trying to connect to a remote server using sockets and the server is
apache setup using name based virtual host(multiply host are sharing an ip
number).
The script does work on ip based virtual host setups.
How can I get it to work for name based.
#!/usr/bin/perl
require 5.002;
use strict;
use Socket;
⊤
my $port = 80;
my $remote_host = "mydomain.com";
my $query = "/cgi-bin/petest/info_handler.pl?site_id=1000&date=3/21/2001";
&open_tcp($remote_host, $query, $port);
while (my $line = <SOCK>){
print qq~<p>$line</p>~;
}
close(SOCK);
⊥
exit;
############################################################################
########################
sub open_tcp {
my ($remote, $add, $port) = @_;
if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
die "No port specified." unless $port;
my $iaddr = inet_aton($remote) || die "Could not find
host: $remote";
my $paddr = sockaddr_in($port, $iaddr);
my $proto = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "Socket Error: $!";
connect(SOCK, $paddr) || die "Connect Error: $!";
my $old_fh = select(SOCK);
$| = 1;
select($old_fh);
print SOCK "GET $add HTTP/1.0\n\n";
print SOCK "Host: $remote\n";
print SOCK "Connection: Keep-Alive\n";
print SOCK "User-Agent: Real Time Scripts Agent/1.0\n";
print SOCK "Content-type: application/x-www-form-urlencoded\n";
}
############################################################################
###############
sub top{
print "Content-type: text/html\n\n";
print qq~
<html>
<head>
<title>Socket Test</title>
</head>
<body link="#0000FF" vlink="#0000FF">~;
print qq~<p align="center"><font face="Verdana" size="3">Socket
Test</font></p>~;
}
############################################################################
###############
sub bottom{
print qq~
</body>
</html>~;
}
############################################################################
###############
Thanks in advance
John Michael
------------------------------
Date: Fri, 23 Mar 2001 15:34:25 GMT
From: u665313720@spawnkill.ip-mobilphone.net
Subject: Read and write a hash of arrays ?
Message-Id: <l.985361665.1477722167@botsun1.unizh.ch>
Hi,
I would like to read data records as given in the script
in the __DATA__ section below into a hash using the second
field as a key and keeping the multiple entries belonging
to one key in a array which is to be sorted in descending
order according to the value in the third field. Using the
script below I apparently read in the values in the hash, but
when trying to write them out, I just get the keys printed, but no
values from the array ???
Thanks in advance for any help and explanations,
Edith
#! /usr/bin/perl -w
# sort DATA as according:
# $best_hit_id, then according $e_value
# structure of best hits file:
# $clone $best_hit_id $e_value $percent_ident $aln_length $species $desc
use strict "vars";
use strict "subs";
# global variables
my %enzymes_hash;
while (<DATA>) {
my ($keyword) = ($_ =~ /^(\w+)::$/);
my ($clone, $best_hit_id, $e_value, $percent_ident, $aln_length, $species, $desc) =
($_ =~ /^(\w+)\s+(\w+)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?\s+.*?)\s+(.*)/);
my $clone_id = $e_value." ".$clone." ".$best_hit_id." ".$percent_ident." "
.$aln_length." ".$species." ".$desc;
# use best_hit_id as array identifier
my $clone_array = "clone_array_{$best_hit_id}"; # use proper clone_array name
# to add $clone_id
$enzymes_hash{$best_hit_id} = push(@{$clone_array}, $clone_id);
foreach my $element (@{$clone_array}) {
print "$element\n";
}
print "\n";
}
# print hash of arrays
foreach (sort keys %enzymes_hash) {
print "$_: @{$enzymes_hash{$_}}\n";
}
__DATA__
ACYLASE::
HVSMEb0011A11f ACY1_PIG 1.10e-06 38,32% 107 Sus scrofa AMINOACYLASE-1 (EC 3.5.1.14) (N-ACYL-L-AMINO-ACID
HVSMEb0011A21f ACY1_PIG 9.40e-35 51,15% 217 Sus scrofa AMINOACYLASE-1 (EC 3.5.1.14) (N-ACYL-L-AMINO-ACID
HVSMEb0014B21f FABD_BACSU 2.00e-12 47,14% 140 Bacillus subtilis MALONYL COA-ACYL CARRIER PROTEIN TRANSACYLASE (EC
HVSMEc0009D01f ACY1_HUMAN 2.60e-24 52,07% 169 Homo sapiens AMINOACYLASE-1 (EC 3.5.1.14) (N-ACYL-L-AMINO-ACID
HVSMEf0010D05f ACY1_HUMAN 1.70e-14 52,38% 84 Homo sapiens AMINOACYLASE-1 (EC 3.5.1.14) (N-ACYL-L-AMINO-ACID
HVSMEf0023M23f FABD_BACSU 4.00e-13 38,38% 99 Bacillus subtilis MALONYL COA-ACYL CARRIER PROTEIN TRANSACYLASE (EC
HVSMEg0013L23f ACY1_PIG 1.20e-23 51.46% 171 Sus scrofa AMINOACYLASE-1 (EC 3.5.1.14) (N-ACYL-L-AMINO-
HVSMEk0024P21f FABD_BACSU 6.60e-29 39,50% 200 Bacillus subtilis MALONYL COA-ACYL CARRIER PROTEIN TRANSACYLASE (EC
--
Sent by ediths from botinst within area unizh part from ch
This is a spam protected message. Please answer with reference header.
Posted via http://www.usenet-replayer.com/cgi/content/new
------------------------------
Date: Fri, 23 Mar 2001 14:18:43 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Regex question
Message-Id: <slrn9bmmqb.dqt.rgarciasuarez@rafael.kazibao.net>
Ave Wrigley wrote in comp.lang.perl.misc:
> Anyone know a neat regex for the follwing; capture from a string a
> substing which contains any given 2 (3,4, ...) words, in any order.
> Something along the lines of:
>
> $string =~ /(?=.*foo)(?=.*bar)(.*?)(?<=foo.*)(?<=bar.*)/;
>
> execpt that variable length lookbehind not implemented.
A solution that does not use regexps :
$searched = "There are a bar, a foo and a baz here.";
@words = qw/foo bar baz/;
my $beg = (sort { $a <=> $b } map { index $searched, $_ } @words)[0];
my $end = (sort { $b <=> $a } map { (length) + index $searched, $_ } @words)[0];
print substr($searched,$beg,$end-$beg),"\n";
Note that it's possible to enhance this solution by optimizing the way
of calculating the max and the min of a list of integers.
Also, handling cases where $searched does not match all words is left as
an exercise the reader.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Fri, 23 Mar 2001 15:19:44 +0100
From: "Jonas Nilsson" <jonni@ifm.liu.se>
Subject: Re: Statistics
Message-Id: <99flsv$lbl$1@newsy.ifm.liu.se>
"Bernard El-Hagin" <bernard.el-hagin@lido-tech.net> wrote in message
news:slrn9bmccn.s3u.bernard.el-hagin@gdndev32.lido-tech...
> More than it used to be when?
More than a month ago?
/jN
--
_______________________________
Jonas Nilsson
------------------------------
Date: Fri, 23 Mar 2001 15:45:31 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Still can't die with Tar
Message-Id: <3ABB704D.65942D1D@earthlink.net>
What A Man ! wrote:
>
> Benjamin Goldberg wrote:
> >
> > BUCK NAKED1 wrote:
> > >
> > [snip]
> > > system("tar -zxf failure.tar.gz 2>&1");
> >
> > Hmm, I just noticed this... if you use the -z option to tar, and a
> > .gz file, which means that tar must call on gzip to decompress the
> > file.
> >
> > This complicates things and can cause problems.
> >
> Thank You. Everyone sounded like this shouldn't be that complicated,
> and I didn't think so either; but this has got complicated and
> frustrating, though perhaps interesting and informative.
<gg> Are frustrating and interesting ever synonyms?
> > [snip]
> > > Now, WHY is "SUCCESS: 0" printing whether the tar operation is
> > > successful or fails?
> >
> > Gzip fails to find the file. It outputs an empty file, and returns
> > an error code.
>
> If gzip fails to find the file, why do I get different return values
> in my test below? Isn't the problem with the return value of tar, not
> gzip?
>
> > Tar sees the error code, but stupidly ignores it. It also
> > sees that you are trying to unarchive an empty file. It decides
> > that empty files are perfectly valid empty archives, and says to
> > itself "Ok, nothing in the file. We sucessfully unarchived all 0
> > files," and then gives a 0 exit code, for having "succeeded" at
> > unarchiving nothing.
>
> Hmmm... still sounds like a "tar" problem, not a gzip problem.
I guess... a problem with the imlementation of tar, though, not in how
you're using it. And of course, problems in other people's
implementations are generally things you can't fix, only work around.
> So there's a problem with Tar and what it returns. Bart mentioned
> something about "parsing" the results to get the success or failure,
> but I don't know how. FWIW, I've been spending much time reviewing man
> tar.
To parse something means to examine it and pick it apart for meaning.
For example, splitting $? into exit_value, signal_num, and dumped_core
would be considered parsing $?.
> [snip]
> >
> > If you run tar using open() with a pipe (a "|" at the beginning or
> > end), you use close() to check the success.
> >
> Now, that's another way I had not thought of.
>
> [snip]
> >
> > Return codes are found there[$?], yes, and these may represent
> > errors. But there're also errors printed to stderr, which you could
> > also check.
> >
> How do I do that? I tried "print STDERR;" and also sending the values
> of system to dev/null and got a blank page.
Heh. That's not how you use stderr. It's a stream, just like stdout,
or stdin.
To explain a bit more clearly, when your perl script runs, it gets a
stdin stream from the browser, which usually contains nothing, but
sometimes contains the contents of an http POST operation. Your perl
script usually reads its stdin using either (whatever = <STDIN>) or
(whatever = <>). Your perl script's stdout gets sent to the browser.
You usually send data to stdout using either (print whatever) or (print
STDOUT whatever). Your perl script's stderr gets sent to the web
server's error logs. You usually send data to stderr using (print
STDERR whatever). NOTE: when explicitly printing to a stream, there is
no comma between the name of the stream (STDOUT or STDERR) and the data
being printed, although there normally are commas between items being
printed.
The stdin, stdout, and stderr streams of the programs which your perl
script runs are different. If you run a program using system, it gets a
copy of your script's streams, and your script doesn't get to see what
the program is doing at all. If you run a program using backticks, then
the program gets a copy of your script's stdin and stderr, but all of
it's stdout is captured in a string and handed back to the script as the
return value of the backtick command. If you open a program using
open(FILEHANDLE, "|program"), the program gets a copy of your program's
stdout and stderr, but it's stdin is from FILEHANDLE, which you can
print to using (print FILEHANDLE whatever). If you open a program using
open(FILEHANDLE, "program|"), the program gets a copy of your program's
stdin and stderr, but it's stdout goes to FILEHANDLE, which you can read
from using (whatever = <FILEHANDLE>).
Standard input is file descriptor 0, output is 1, error is 2. If
instead of running "program", you run "program 2>&1", the program's
stderr is a copy of it's stdout, so regardless of whether it prints to
stdout or stderr, it goes to stdout (all mixed together). If you don't
have the ability to parse them seperately, this can be good.
If you run a program as "program 2>/dev/null" it discards the stderr.
If you run a program as "program 1>/dev/null 2>&1" it discards the
normal stdout, and then sends normal stderr to real stdout.
> > The best thing to do, would be to test for the file's existance
> > yourself, rather than relying on tar to do it for you. This is much
> > faster, and will save you alot of grief. If you have made sure that
> > the file does exist, then it's quite likely that tar's exit code
> > (the value in $?) will be exactly what you expect it to be... 0 for
> > success, and nonzero for failure.
> >
> > To see if file exists, simple use the -f operator.
> > unless( -f "failure.tar.gz" ) {
> > die "FAILURE";
> > }
>
> Thanks, I'll try this. It sounds like a good solution for checking a
> "zip" operation, too. I was hoping to find the same solution for
> failure or success of 'tar' or 'zip', if possible. This has become so
> complicated and frustrating that I'm almost willing to abort a real
> error message, and just check tar's results for an empty file , and
> print "FAILED" based on an empty file.
>
> As you'll see below, I can check the return of gzip and print success
> or failure according to a different return value of $?, but tar still
> wants to be difficult.
>
> Here's a little test I ran that is interesting...
>
> #!/usr/bin/perl -w
> use CGI::Carp qw(fatalsToBrowser);
> print "Content-type: text/html\n\n";
>
> system("tar -x success.tar");
> print "Tar Success returns a Value of $?";
> print "<BR>";
> system("tar -x failure.tar");
> print "Tar Failure returns a Value of $?";
> print "<BR><BR>";
>
> system("gzip success.tar.gz");
> print "Gunzip Success returns a Value of $?";
> print "<BR>";
> system("gzip failure.tar.gz");
> print "Gunzip Failure returns a Value of $?";
> print "<BR><BR>";
First off, gzip compresses, unless passed an option to decompress (I
think it's "-c"). If you want to uncompress, use gunzip.
> system("tar -zx success.tar.gz");
> print "Tar w/-z Success returns a Value of $?";
success.tar.gz no longer exists, since in the earlier part of the script
it's been compressed (or if you fix that, decompressed). You would need
to be looing for sucess.tar.gz.gz, or perhaps success.tar
> print "<BR>";
> system("tar -zx failure.tar.gz");
> print "Tar w/-z Failure returns a Value of $?";
> print "<BR><BR>";
>
> OUTPUT...
>
> Tar Success returns a Value of 768
> Tar Failure returns a Value of 768
>
> Gunzip Success returns a Value of 256
Exit value 1
> Gunzip Failure returns a Value of 512
Exit value 3
> Tar w/-z Success returns a Value of 0
> Tar w/-z Failure returns a Value of 0
>
> I've also tried printing the following per instructions from
> perldoc -f system...
> $exit_value = $? >> 8;
> $signal_num = $? & 127;
> $dumped_core = $? & 128;
>
> Of course, these too return 0 whether tar -z is successful or not.
>
> I can understand Gary's frustration. My head hurts too. Just so you
> know, I have appreciated ALL of the responses, and am still reviewing
> the thread for things I may have missed or misunderstood.
>
> Regards,
> --Dennis
--
The difference between theory and practice is that in theory, theory and
practice are identical, but in practice, they are not.
------------------------------
Date: Fri, 23 Mar 2001 15:52:35 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: using closures (road to OO)
Message-Id: <tbmsa3da2jsb24@corp.supernews.com>
In article <985346252.10004@itz.pp.sci.fi>,
Ilmari Karonen <usenet11404@itz.pp.sci.fi> wrote:
: In article <tbk5ub44ktf1f7@corp.supernews.com>, Greg Bacon wrote:
:
: >No. There's no closure.
:
: Of course there's a closure, [...]
RTFM (from the perlref manpage):
Anonymous subroutines act as closures with respect to my()
variables, that is, variables lexically visible within the current
scope. Closure is a notion out of the Lisp world that says if you
define an anonymous function in a particular lexical context, it
pretends to run in that context even when it's called outside the
context.
The OP's code contained no anonymous subs.
The perlsub manpage addresses the OP's question:
Here's a mechanism for giving a function private variables with
both lexical scoping and a static lifetime. If you do want to
create something like C's static variables, just enclose the whole
function in an extra block, and put the static variable outside the
function but in the block.
{
my $secret_val = 0;
sub gimme_another {
return ++$secret_val;
}
}
# $secret_val now becomes unreachable by the outside
# world, but retains its value between calls to gimme_another
If this function is being sourced in from a separate file via
`require' or `use', then this is probably just fine. If it's all
in the main program, you'll need to arrange for the `my' to be
executed early, either by putting the whole block above your main
program, or more likely, placing merely a `BEGIN' sub around it to
make sure it gets executed before your program starts to run:
sub BEGIN {
my $secret_val = 0;
sub gimme_another {
return ++$secret_val;
}
}
Greg
--
Are you suggesting that Y2K could interrupt Beer production, ye gods, it's
worse than I thought! Surely they got the breweries in the first pass along
with other critical systems like nuclear power stations.
-- Nik Simpson
------------------------------
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 V10 Issue 554
**************************************