[7091] in Perl-Users-Digest
Perl-Users Digest, Issue: 716 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 10 01:07:25 1997
Date: Wed, 9 Jul 97 22:00:30 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 9 Jul 1997 Volume: 8 Number: 716
Today's topics:
Re: /x problem <usenet-tag@qz.little-neck.ny.us>
A few questions about invoking a perl script. <sehynes@cise.ufl.edu>
a question about modules... <raymond@sj.bigger.net>
Re: Best idiom for defaulting, getting & untainting an (Gerold Meerkoetter)
Re: Best idiom for defaulting, getting & untainting an <rootbeer@teleport.com>
Creating a detached process <nichori@cat.com>
Re: daemon in perl (Greg Bacon)
Re: Foreach with lists of arrays (Andrew M. Langmead)
Re: Foreach with lists of arrays (Greg Bacon)
Re: How do I find out the requesting Country??? <me@anon.com>
Re: How do you do a 'cut -cx-y' with Perl? <clark@s3i.com>
How to run another script with do and pass argument? <hong@taligent.com>
Re: how to s '?' ? (Rubinstein Dmitry)
Linux fails?? [was Re: Perl on Linux] (Linux Enthusiast)
MS-DOS port of the Perl programming language @jumbo.com
Re: Output to a file (Tung-chiang Yang)
Re: pattern matching problem <usenet-tag@qz.little-neck.ny.us>
Re: POP3 Help!! (Nathan V. Patwardhan)
Re: Q: Why doesn't "eval" work in this trivial example (Charles DeRykus)
Re: Q: duping filehandles, OO (Charles DeRykus)
Question - help (Afgin Shlomit)
Re: reverse chop? <ajohnson@gpu.srv.ualberta.ca>
solaris IPC <dhoover@textwise.com>
Re: SSI on apache (Tung-chiang Yang)
Re: Use of Reverse function <ajohnson@gpu.srv.ualberta.ca>
Re: Use of Reverse function (Tad McClellan)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 9 Jul 1997 16:13:59 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: /x problem
Message-Id: <eli$9707091201@qz.little-neck.ny.us>
Posted and mailed.
Fan Ng <FANNGMAIL@prodigy.net> wrote:
> I looked a book where said The /x modifier can break up your regular
> expression into (slightly) more readable parts.
> My qurestion is "How to break up"????
Compare this:
# Be very generous about accepting "only US$15,- p min" text.
/\b(just|only)\s+([a-z]{2}\s*)?((\$|\#)\s*)?(\d+([.,](\d{2}|-)?)?\
|\.\d+)(\s*cents)?\s*(\/|p(er|\.)?)\s*m(in(ute)?)?/i
With this:
# Be very generous about accepting "only US$15,- p min" text.
/\b(just|only) # first they try to de-emphasize it
\s+([a-z]{2}\s*)? # Sometimes with something for the currency
((\$|\#)\s*)? # Sometimes a currency notation (needs more)
(\d+ # A number
([.,](\d{2}|-)?)? # with an optional fractional portion
|\.\d+) # or exclusively fractional
(\s*cents)? # an alternative currency location
\s*(\/|p(er|\.)?) # "per" and variations
\s*m(in(ute)?)? # "minute" and variations
/ix # Ignore case and use free-format regexp
With /x you can have # to end of line as an embeded comment, and
most whitespace gets ignored. # or whitespace inside of a [] character
class or backslash escaped will not be ignored.
Elijah
------
probably should have (?:...)s for all those (...)s
------------------------------
Date: Wed, 09 Jul 1997 10:21:49 -0400
From: sean hynes <sehynes@cise.ufl.edu>
Subject: A few questions about invoking a perl script.
Message-Id: <33C39E7C.90C81DEC@cise.ufl.edu>
Hello. I have a couple of questions that may seem easy, but I can't
figure them out.
1. Is there a way cause a PERL script to be invoked when an html link
is selected / or when a page is opened, other than SSI's?
2. I have a page with multiple frames. Is there a way to have a CGI
PERL link in one frame, that produces HTML output in another frame on
the same page?
Any help or suggestions would be extremely appreciated. Thank you,
Sean.
------------------------------
Date: Wed, 09 Jul 1997 20:43:17 -0700
From: ray <raymond@sj.bigger.net>
Subject: a question about modules...
Message-Id: <33C45A55.1003@sj.bigger.net>
I am having problems creating a module. The package source code is
below, but doesn't work. What I want is to have a few globals stored in
a file that are used in several different utilities written in perl. In
general, the globals are to be used to define constants. Any clues?
Also, is it okay to use a package from within a package?
# package to indicate common globals
package CommonGlobs;
require Exporter;
@ISA = qw(Exporter);
# Items to export into callers namespace by default.
@EXPORT = qw();
@EXPORT_OK = qw( $file1 $file2 $trace $DEBUG );
$file1 = "text.doc";
$file2 = "index.doc";
$trace = 1;
$DEBUG = 1;
1;
------------------------------
Date: 10 Jul 1997 01:08:20 +0200
From: gerold@cc.fh-lippe.de (Gerold Meerkoetter)
Subject: Re: Best idiom for defaulting, getting & untainting an env variable.
Message-Id: <5q15l4$1m3@m4.des.fh-lippe.de>
over@the.net (dave) writes:
>($inval = $ENV{INVAL} ||= "default") =~ /^(exp)$/ and $inval = $1;
>C'mon folks, it MUST be possible to have only one reference to $inval.
Since "default" is obviously not tainted, I'd suggest
$inval = ($ENV{INVAL} =~ /^(exp)$/) ? $1 : "default";
HTH,
Gerold
--
Gerold Meerkoetter, Fachhochschule Lippe, Germany
Moreover, Greek is no longer a language we expect cultured gentlemen
to understand; but these days perl *is*. -- Alan Bostick
------------------------------
Date: Wed, 9 Jul 1997 08:33:16 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: dave <over@the.net>
Subject: Re: Best idiom for defaulting, getting & untainting an env variable.
Message-Id: <Pine.GSO.3.96.970709083035.14216H-100000@kelly.teleport.com>
On Tue, 8 Jul 1997, dave wrote:
> The particular environment variable I am using defines a file
> containing a perl fragment to be executed via a do statement.
That's about as dangerous a thing as you can do. :-) Are you sure that
you're willing to execute arbitrary code, sight unseen? Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 09 Jul 1997 08:28:27 -0500
From: "Rowland I. Nicholson" <nichori@cat.com>
Subject: Creating a detached process
Message-Id: <33C391FB.59DB@cat.com>
I have an application where a user fills out a form, submits it,
a datafile is uploaded, and a cgi processes it. The cgi written in
perl, processes the user input and starts up an executable to analyze
the datafile. It takes the executable 4 minutes to run, so I need
to have the perl program start the executable in a detached process
so I don't tie up the browser.
I originally experimented with 'fork', but couldn't get it to work
properly. I was able to solve this problem by submitting a batch
job via 'at'. However, I'm concerned about the security by opening
up 'at'. Recently, I saw an example of an application where 'fork'
was used to create a detached process. I've tried it, but it doesn't
seem to work on my system. I've include the code here, in hopes that
someone can point me in the right direction.
Here's the perl script:
----------
#!/usr/local/bin/perl
$|=1;
print "Content-type: text/plain\n\n";
if ($pid = fork) {
print "Parent Process has forked child process $pid.\n";
} else {
close(STDOUT);
system("./testy");
exit(0);
}
print "Done";
exit(0);
----------
And here's the application './testy' that it calls:
----------
#!/bin/ksh
sleep 10
----------
My result is that in my browser I see the line "Parent Process ..."
and then 10 seconds later it adds the "Done".
Any thoughts, ideas, solutions are greatly appreciated, and I
thank you in advance.
Rowland
------------------------------
Date: 10 Jul 1997 00:18:25 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: "Raymond K. Bush" <rbush@up.net>
Subject: Re: daemon in perl
Message-Id: <5q19oh$97o$2@info.uah.edu>
[Posted and mailed]
In article <33C4186F.6117@up.net>,
"Raymond K. Bush" <rbush@up.net> writes:
: I've written a small daemon in perl that listens on a socket. It works
: fine and all but i noticed the following while running top.
:
: PID USERNAME PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND
: 328 root -25 0 2380K 1640K run 71:31 83.14% 84.31% special.d
:
: Now i am concerned that my program is being a cpu hog. BTW the daemon
: is not supposed to be doing anything right now other than waiting on a
: socket. Is there some special way i am supposed to implement this so
: that this doesn't occur or should i not worry at all.
Since you didn't post your code, I can't say for certain, but the first
place I'd look is your select loop (if you're even using select at all).
To avoid eating up every CPU cycle in sight, this should probably
be a blocking call rather than a polling call, i.e. the timeout should
be undef rather than 0.
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Thu, 10 Jul 1997 01:45:20 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Foreach with lists of arrays
Message-Id: <ED2y7K.Eqy@world.std.com>
Joshua Gemmell <joshg@ola.bc.ca> writes:
>Howdy,
> Is it possible to iterate through a list of arrays and get the whole
>array?
Have your read through the perlref, perllol, and perldsc man pages?
You seem to know enough so that I would think that you have, but you
seem to be missing something.
>@List = (['one','two','three'],['a','b','c'],['1','2','3']);
>foreach $Thing (@List) {
> print " This is $Thing\n";
>}
Each element of @List is a reference to an array. Perl doesn't do any
automatic dereferencing, so you have to give an explicit dereferencing
operator to get at the data:
foreach $Thing (@list) {
print "@$Thing\n";
}
--
Andrew Langmead
------------------------------
Date: 10 Jul 1997 00:07:25 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: joshg@ola.bc.ca
Subject: Re: Foreach with lists of arrays
Message-Id: <5q193t$97o$1@info.uah.edu>
[Posted and mailed]
In article <33C4072B.69B@ola.bc.ca>,
Joshua Gemmell <joshg@ola.bc.ca> writes:
: Is it possible to iterate through a list of arrays and get the whole
: array?
Sure it is. :-)
: But if I try this with a list of arrays, things get screwy.
:
: @List = (['one','two','three'],['a','b','c'],['1','2','3']);
: foreach $Thing (@List) {
: print " This is $Thing\n";
: }
:
: And the output is...
: This is ARRAY(0x217e738)
: This is ARRAY(0x2180288)
: This is ARRAY(0x21802c4)
This is the correct output. Take a moment to consider this snippet from
the perldata(1) manpage:
Perl has three data structures: scalars, arrays of scalars,
and associative arrays of scalars, known as "hashes".
Thus enlightened, we realize that @List is an array of three *references*
(references are just scalars with a bit of magical spin to them) to
other lists (much like two-dimensional arrays in C are arrays of
pointers to arrays.. man, say that five times fast :-).
Armed with this knowledge, you could incant something like the following:
@List = (['one','two','three'],['a','b','c'],['1','2','3']);
foreach $ref (@List) {
foreach $Thing (@$ref) {
print " This is $Thing\n";
}
}
I'd imagine you'd want a matrix to look like a matrix, so you could even
@List = (['one','two','three'],['a','b','c'],['1','2','3']);
foreach $ref (@List) {
my $fmt = join(' ', ('%-10s') x @$ref) . "\n";
printf $fmt, @$ref;
}
Extending this to n dimensions such that n is greater than 2 is an
exercise to the reader. :-)
Hope this helps,
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Wed, 09 Jul 1997 14:41:36 -0700
From: Chris Hostetter <me@anon.com>
Subject: Re: How do I find out the requesting Country???
Message-Id: <33C40590.175C7BAE@anon.com>
http://www.iana.org/in-notes/iana/assignments/country-codes
> What I am interested in doing is finding out the country that $hostname
> originates from... Could _ANYBODY_ Help me out???
---
------------------------ The Hoss Man --- "c4"
-------------------- Chris M Hostetter -- --Deep Blue
---------- hossman@uclink3.berkeley.edu - "Resign!"
http://www.rescomp.berkeley.edu/~hossman/ --Gary Kasparov
------------------------------
Date: 08 Jul 1997 11:29:13 -0400
From: Clark Dorman <clark@s3i.com>
Subject: Re: How do you do a 'cut -cx-y' with Perl?
Message-Id: <dg1tpmuk6.fsf@s3i.com>
Chris Hostetter <me@anon.com> writes:
> Nathan V. Patwardhan wrote:
> >
> > Don Wallwork (wallwork@a1.flo.med.ge.com) wrote:
> > : I am trying to separate the fields in a file that are grouped by
> > : spacing.
> >
> > See your Perl documentation (perlfunc.pod) and search for split().
>
> ok, i admit, at first i thought you were smoking something, but then i
> whiped out the camel and looked up split... i never truely appreciated
> this function.
I dont think he (Don) really wants to separate fields based on spaces.
I think by spacing, he means column number. That's why he wants to
use cut. cut = substr as far as I can tell.
> but then i got to he end of the discription and i see: "To break apart a
> string with fixed-position fields, use unpack."
Where? Which version? I cannot seem to find this in 5.004 pods or in
the FAQ.
> now i never really thought of useing unpack in this way either... so i
> took a look at it again, and noticed the example where substr is written
> using unpack...
>
> ...
>
> "why not just use substr?"
> -- i thought to myself?
>
> doesn't:
>
> while (<>) {
> $name = substr($_, 0, 21);
> $name =~ s/ //g;
> $phone = substr($_, 21, 29);
> $phone =~ s/ //g;
> [etc...]
> }
>
> do exactly what the orriginal poster asked?
Why are you removing the spaces in the fields?
> (comeing from someone too lazy to acctualy try it myself)
It's really not that hard. Plus, it's good exercise and a fun way to play
with Benchmark. Try this:
#!/home/dorman/bin/perl -w
use Benchmark;
timethese( 500000, {
'use_substr' => '$line_of_data =
"FLINTSTONE Fred 555 1234 Caveman Bedrock USA";
$name = substr($line_of_data, 0,21);
$numb = substr($line_of_data,21,17);
$job = substr($line_of_data,38,17);
$city = substr($line_of_data,55,12);
$cont = substr($line_of_data,67, 3);
',
'use_unpack' => '$line_of_data =
"FLINTSTONE Fred 555 1234 Caveman Bedrock USA";
$name = unpack("x0 a21", $line_of_data);
$numb = unpack("x21 a17",$line_of_data);
$job = unpack("x38 a17",$line_of_data);
$city = unpack("x55 a12",$line_of_data);
$cont = unpack("x67 a3", $line_of_data);
',
'use_single_unpack' => '$line_of_data =
"FLINTSTONE Fred 555 1234 Caveman Bedrock USA";
@n = unpack("a21 a17 a17 a12 a3",$line_of_data);
'
});
__END__
Interestingly enough, I get:
elmo:~ (DING!) 48% timit.pl
Benchmark: timing 500000 iterations of use_single_unpack, use_substr, use_unpack...
use_single_unpack: 28 secs (27.31 usr 0.00 sys = 27.31 cpu)
use_substr: 15 secs (14.08 usr 0.00 sys = 14.08 cpu)
use_unpack: 30 secs (29.71 usr 0.00 sys = 29.71 cpu)
elmo:~ (11:01am) 49%
That is, the 5 substr's takes less time than a single unpack
statement. I'd go with substr. It makes more sense to me anyway.
--
Clark
------------------------------
Date: Wed, 09 Jul 1997 17:15:34 -0700
From: Deyoung Hong <hong@taligent.com>
Subject: How to run another script with do and pass argument?
Message-Id: <33C429A6.680230E5@taligent.com>
I want to invoke another Perl script from a Perl script.
Using the statement
do 'another.pl';
works fine but I can't pass argument like
do 'another.pl 3';
How do I do this, other than using the 'system' or 'open' command which
may invoke a different perl?
Thanks,
hong@taligent.com
------------------------------
Date: 9 Jul 1997 12:28:39 GMT
From: dimrub@nsof.co.il (Rubinstein Dmitry)
Subject: Re: how to s '?' ?
Message-Id: <5q005n$c72$2@lnews.actcom.co.il>
Yee Man, Chan (ymc@umich.edu) wrote:
: Hi, everybody,
: I tried to substitute '?' but unsuccessful. Can you tell me how to
: substitute '?' and why what I did doesn't work?
: $line = 'ax?yb';
: $temp = 'x?y';
: $_ = $temp;
: tr/a-z/A-Z/;
: $line =~ s/$temp/$_/;
: print $line; # what I want is 'aX?Yb' but what I get is 'ax?yb'
'?' is another 'special' character. It means '0 or 1 of the previous
character/string'. You have to put \ before it. Like this:
s/foo\?bar/$_/;
Or use \Q to quote all metacharacters until \E, like this:
s/\Qfoo?bar\E/$_/;
And, ofcourse, read perlre(1) ;-)
--
Dmitry Rubinstein
dimrub@math.tau.ac.il
http://www.math.tau.ac.il/~dimrub
------------------------------
Date: 10 Jul 1997 00:29:44 GMT
From: brett@teleport.com (Linux Enthusiast)
Subject: Linux fails?? [was Re: Perl on Linux]
Message-Id: <slrn5s8bcs.aa.brett@teleport.com>
In article <5pekq2$d6d@fridge-nf0.shore.net>, Nathan V. Patwardhan wrote:
>Ed Vander Bush (temp.ed.vanderbush@bentley.com) wrote:
>: How well does Perl run on a Intel box running Red Hat Linux 4.2?
>: compared to regular UNIX? Thanks,
>
>No difference if Perl has been built correctly by Red Hat, or by you -
>if you choose to build your own.
I though I saw a post a while back (cant find it now) about pipes on
linux not working correctly. Anyone know about this?
-brett
>
>--
>Nathan V. Patwardhan
>nvp@shore.net
>
------------------------------
Date: 8 Jul 1997 17:02:28 -0400
From: @jumbo.com
Subject: MS-DOS port of the Perl programming language
Message-Id: <5pu9t4$r4q@orion.jumbo.com>
Get NEW MS-DOS port of the Perl programming language Shareware As It's Written!
The latest and greatest MS-DOS port of the Perl programming language shareware and
freeware as soon as it's created! We download new programs DAILY
(10 a.m. EST) from more than 300 sites all over the world.
Check out the new programs everyday in the "TODAY'S FREE COMPUTER
PROGRAMS" section on the all new JUMBO! --- bigger and faster
than ever with over 200,000 files and programs --- more than 1.8 million
links --- including a HUGE multimedia section with sounds, graphics, videos,
streaming music, VRML, animations, clip art, icons,
schockwave, screen savers --everything! --- http://www.jumbo.com.
Get the latest at:
http://www.jumbo.com/pages/programming/dos/perl/
http://www.jumbo.com/pages/programming/mac/languages/
------------------------------
Date: Thu, 10 Jul 1997 01:45:16 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: Output to a file
Message-Id: <tcyangED2y7G.14F@netcom.com>
In this group you are supposed to post your code (or at least part of
it which you believe to be relevant) for anyone to offer help.
=========================================
David Zeng wrote after zapping the scum of the universe:
: Hi, there,
: Thanks for the lots of help last time I posted a question. Well, I
: have another question.
: After reading and processig data from a file, I wanted to output the
: parsed information to another file, line by line. What I did is that
: I opened up another file by:
: open(OUTFILE, ">$outname") or die (blah, blah...)
: and later printed each line into a file from a for loop like this:
: print OUTFILE $outline;
: The files I am reading are quite long, with over 100 lines. If I limit
: the number of line printed into OUTFILE is 40 or less (around 40), then
: I get the result I want. If I read in more than 40 lines, the file
: created by OUTFILE turns out to be empty.
: What kind of problem is this? I couldn't have run out of memory here
: and caused some kind of failure of Perl functions? I got 64MB on a
: Sparc 5. Is there some built-in limitation on my format of printing
: lines into another file?
: Thanks for any help.
: David Zeng
--
========= Try the low-crossposting robomoderated 'alt.culture.taiwan' ===
soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
http://www.iglou.com/tcyang/Taiwan_faq.shtml, China_faq.shtml
------------------------------
Date: 9 Jul 1997 16:05:41 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: pattern matching problem
Message-Id: <eli$9707091150@qz.little-neck.ny.us>
Mark W. Manley <mwm3q@ultra1-2.unixlab.Virginia.EDU> wrote:
> I've got a pattern matching problem which is driving me absolutely
> bonkers. I have a marked up SGML file which contains, of course, series
> of SGML tags. Now, what I want to do is simply remove all the
> underscores from those tags and replace those underscores with periods.
> <tag data="underscore_to_change">some information</tag>
Assume text to test is in $text, and try this
$text =~ s/(< # start tag
[^>]* # chars that do not close the tag
_ # at least one underscore
[^>]* # more chars that do not close it
>) # close tag
/ # end match portion; begin sub portion
($tmp=$1, # make a writable copy
$tmp =~ # operate on that copy
tr:_:.:, # substitute periods for underscores
$tmp) # return the new text
/xe; # eXtended format (allows comments), Execute sub part
> I am using perl 5, if this helps...
Hopefully 5.002 or newer. Most sources claim /x is not reliable prior
to that.
> My second problem, which actually really wouldn't matter if the first
> problem is solved, is sort of an exception handling problem, but it also
I certainly can't solve this without more info. Someone else maybe
can.
> If you have any ideas on how to solve either problem (esp. the first,
> which is more critical!), please e-mail me at "mwm3q@virginia.edu". My
Posted and mailed.
Elijah
------
#!/usr/bin/perl -w
$_="<j!y~f^v* >h.g=c+m\@q[p;r} ?x/t|d:l# )e\\p.d-s]p{c<,\n";$j=0;while(
s"[^\w\s,](.*)"($u=$1,$u=~s;(\w);(($s=ord($1)-97),chr((($s+$j++)%26)+97
));gex,$u)"ex){}exit !print;#18/5/97:etb
------------------------------
Date: 10 Jul 1997 02:49:08 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: POP3 Help!!
Message-Id: <5q1ij4$24h@fridge-nf0.shore.net>
Todd (admin@mailstuff.com) wrote:
[snip]
: I send mail to a user account I create on my 4.2 linux box. Then I try
: and pull it from netscape on another machine. It does not work, I can
: send mail from netscape using linux as smtp server
: but can't pull it. In Netscape it says "an error in the pop3 server,
: contact administrator".
Lions, tigers, and Netscape ... oh my! For the life of me I can't
figure out what this has to do with Perl, but I'd suggest the
following:
Use Net::Telnet or Net::POP3 to talk to port 110 of your Linux
machine. If you cannot connect to this port, your pop server is
probably not running (or not running there).
Once you've figured out why you can't retrieve mail using POP (NOT a
Perl question), I'd seriously consider Net::POP3 or Mail::POP3Client
to transfer the mail for you.
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: Wed, 9 Jul 1997 22:29:03 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Q: Why doesn't "eval" work in this trivial example?
Message-Id: <ED2p4F.HtG@bcstec.ca.boeing.com>
In article <33b97068.23354624@athos.cc.bellcore.com>,
Ron Levenberg <ral@cc.bellcore.com> wrote:
> #!/opt/public/pkg/perl5.003/bin/perl
>
> print "Perl version $]\n";
> eval {
> $SIG{ALRM} = { die "timeout" };
>
> alarm 15;
> $line = <STDIN>;
> alarm 0;
> };
>
> print "line = '$line', \$@ = $@\n";
> exit 0;
>
> When the above file (c.pl) is executed, it prints the following
> output:
> Perl version 5.003
> line = '', $@ = timeout at c.pl line 5.
>
> PROBLEM: The script should wait 15 seconds for me to enter a line on
> the standard input, but in fact the timeout message above is
> output immediately upon execution, as if the SIG assignment worked
> but the following 3 statements (those bracketed by alarm 15 .. alarm)
> are not executed.
>
>
Here's a correction:
$SIG{ALRM} = sub { die "timeout" };
The behavior was deceptive because I would've expected a -w message about
"odd number of elements in hash list" since
{ die "timeout" }
without a leading "sub" keyword would try to create an anonymous hash.
This gets even curiouser if you replace the errant line with
$SIG{ALRM} = { undef };
which generates the following messages:
Odd number of elements in hash list at c.pl line 5.
line = '', $@ = Not a subroutine reference at c.pl line 5.
I expected the first message which unmasks the error; the second was a
suprise though. In fact, the timeout still "works" as you'd expect
when I would've guessed that the invalid subroutine reference would've
caused an "Alarm clock" message to appear. Here's a clear case of
crime going unpunished :)
HTH,
--
Charles DeRykus
ced@carios2.ca.boeing.com
------------------------------
Date: Wed, 9 Jul 1997 21:28:32 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Q: duping filehandles, OO
Message-Id: <ED2MBK.DHD@bcstec.ca.boeing.com>
Keywords: dup, filehandle, objects
In article <5pvjc8$8f1$1@mosquito.HL.Siemens.DE>,
Marek Rouchal <marek@buffalo.HL.Siemens.DE> wrote:
>
> I've RTFM and tried everything that came to my mind, but I just didn't
> find out what the correct object-oriented syntax for duping filehandles
> is. Here's the code snippet with the ugly kludge ($kid_* were created
> by Filehandle::pipe):
>
> [...]
> $kid_wtr->autoflush(1);
> $kid_rdr->autoflush(1);
>
> *KWTR = $kid_wtr;
> *KRDR = $kid_rdr;
>
> open(STDOUT,">&KWTR") || die "dup failed: $!";
> open(STDIN, "<&KRDR") || die "dup failed: $!";
>
> exec "$cmd";
> [...]
>
> This is the only way to dup the kid_* filehandles to STDIN/STDOUT that works.
> I've tried:
>
> *STDOUT = $kid_wtr; # works for perl, but not for exec'ed programs.
>
> and
>
> open(STDOUT,">&$kid_wrt") || die "dup failed: $!"
> # dies with "Invalid Argument"
>
> I'm using perl5.00305/Solaris 2.5.1/Ultra-1. Any help is appreciated!
> (NB: I do not want to use IPC::open2() or IPC::open3().)
There may be a better method but the following works:
open(STDOUT, ">&@{[fileno($kid_wrt)]}") || die "dup failed: $!";
HTH,
--
Charles DeRykus
ced@carios2.ca.boeing.com
------------------------------
Date: Sun, 6 Jul 1997 07:30:59 GMT
From: vshlomit@wishful.weizmann.ac.il (Afgin Shlomit)
Subject: Question - help
Message-Id: <1997Jul6.073059.20925@wisipc.weizmann.ac.il>
Hi everyone,
I would like to know how I can get the last parameters in a variable.
I mean if the variable conatin: aa.bb.cc.gg and the delimiter is '.'
I would like to get gg as an answer.
the problem is that the number of element in the variable is not always
the same it can be more or less (eg: aa.bb.cc or aa.bb.cc.gg.tt).
I would very appriciated replays to vshlomit@wishful.weizmann.ac.il.
Thanks,
Shlomit.
--
Shlomit.
------------------------------
Date: Wed, 09 Jul 1997 20:18:45 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: reverse chop?
Message-Id: <33C43875.5BD34E19@gpu.srv.ualberta.ca>
the count wrote:
>
> Is there any trivial way to remove the first character of a string?
> Right now I am using:
>
> while (<>) {
> @line = split;
> print "substr($line[0], 1, length($line[0] - 1))\n";
> }
>
> but I feel like there should be an easier way... ;-)
> Is there any function like chop that would remove the first
> character, as opposed to the last?
you really do that in a double quoted string?
anyway, if you omit the last argument to substr() it
will go the end of the string so:
print substr($line[0],1),"\n";
will do what you want...if you want to be able to
do it with a simple function call like chop then
define yourself a subroutine:
sub hack ($) {
substr(shift,1);
}
$line="this is a string";
print hack $line;
regards
andrew
------------------------------
Date: Wed, 09 Jul 1997 14:25:04 -0400
From: Dean Hoover <dhoover@textwise.com>
Subject: solaris IPC
Message-Id: <33C3D780.2C3E@textwise.com>
I'm trying to experiment with using shared memory on solaris
with perl5.004 and am having some trouble, maybe someone can
give me a hint.
I ran "h2ph * sys/*" in /user/include
The following script:
---------------------------------
#!/home/dhoover/bin/perl -w
use strict;
require "sys/ipc.ph";
require "sys/shm.ph";
---------------------------------
Outputs the following when run:
Number found where operator expected at (eval 13) line 1, near ")0"
(Missing operator before 0?)
Number found where operator expected at (eval 66) line 1, near ")0"
(Missing operator before 0?)
Am I missing something fundamental here?
Thanks.
Dean Hoover
------------------------------
Date: Thu, 10 Jul 1997 02:05:15 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: SSI on apache
Message-Id: <tcyangED2z4r.37J@netcom.com>
This is not a Perl question; 'comp.lang.perl' is obsolete.
==============================
cREATURE dEM0N wrote after zapping the scum of the universe:
: I want to use SSI on my site, for a banner rotator. But how do i
: configure apache to use SSI. My provider uses apache as webserver. But
: he does'nt know how to do it.
: (deleted)
: Like i sayd, nothing is working, nor the advertiser, nor the
: guardian.cgi
--
========= Try the low-crossposting robomoderated 'alt.culture.taiwan' ===
soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
http://www.iglou.com/tcyang/Taiwan_faq.shtml, China_faq.shtml
------------------------------
Date: Wed, 09 Jul 1997 20:25:59 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Use of Reverse function
Message-Id: <33C43A27.41C4494C@gpu.srv.ualberta.ca>
maninder chhabra wrote:
>
> Hi,
>
> I ma trying to read string backwards. I tried using reverse function in the
> scalar context but it does'nt do anything. Let me know if there is any
> solution to this.
>
let us know what you are actually doing and what you mean
by saying 'it doesn't do anything' and perhaps someone can
try to help...
$string="this is a string";
$rev_string=reverse $string;
print "$string\n$rev_string\n";
prints the following:
this is a string
gnirts a si siht
regards
andrew
------------------------------
Date: Wed, 9 Jul 1997 20:25:03 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Use of Reverse function
Message-Id: <fld1q5.q07.ln@localhost>
maninder chhabra (mchhabra@rms1.com) wrote:
: I ma trying to read string backwards. I tried using reverse function in the
^^^^^^^
: scalar context but it does'nt do anything. Let me know if there is any
: solution to this.
So where is your code that doesn't work?
We like code here ;-)
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 716
*************************************