[11308] in Perl-Users-Digest
Perl-Users Digest, Issue: 4908 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 16 15:07:10 1999
Date: Tue, 16 Feb 99 12:00:25 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 16 Feb 1999 Volume: 8 Number: 4908
Today's topics:
Re: /i in regexp kills performance. (Ilya Zakharevich)
Re: /i in regexp kills performance. (Larry Rosler)
Re: calculate and print a period of days (Gregory Snow)
Can't connect to a port via Perl <aallen@ubkoch.de>
CGI script problem <smalunjk@cisco.com>
CGI script problem <smalunjk@cisco.com>
Re: cookie problem nospam_support@gethits.com
Re: Does an object have a given method? (Damian Conway)
Re: Does an object have a given method? <dboorstein@ixl.com>
Re: Does an object have a given method? <dboorstein@ixl.com>
Re: Does an object have a given method? <tchrist@mox.perl.com>
Re: Does an object have a given method? <sternji@mail.northgrum.com>
Re: free Perl for NT? hhuggins@fedex.com
Re: good code vs code that works (Greg Ward)
IPC::OPEN3 on Win NT does it works? georeq@my-dejanews.com
Re: NET::FTP with ActiveState jsmith7350@aol.com
Re: redefining a sub (Greg Ward)
Re: Redirectiong STDERR <tchrist@mox.perl.com>
Re: REGEX $1, $2 ... array? (Ilya Zakharevich)
Re: REGEX $1, $2 ... array? <rra@stanford.edu>
Re: REGEX $1, $2 ... array? <d-edwards@nospam.uchicago.edu>
Re: Regular expression for Currency ??? (Larry Rosler)
Re: Server Software <Allan@due.net>
user input to background script (David Efflandt)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 16 Feb 1999 19:54:08 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: /i in regexp kills performance.
Message-Id: <7acid0$h1h$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Larry Rosler
<lr@hpl.hp.com>],
who wrote in article <MPG.113369da3b38750f989a49@nntp.hpl.hp.com>:
> > It is not mentioned since there is no extra copying associated with //i.
>
> Now I have access to the books. You can argue with Jeffrey Friedl
We have nothing to argue about.
> , not
> me. Here is a quote from 'Mastering Regular Expressions', page 278:
>
> The Efficiency Penalty of the /i Modifier
As I explained it many times here, the Perl-specific part of Hip Owl
has very little to do with the contemporary Perl.
Ilya
------------------------------
Date: Tue, 16 Feb 1999 11:41:48 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: /i in regexp kills performance.
Message-Id: <MPG.113369da3b38750f989a49@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7aceta$f2d$1@mathserv.mps.ohio-state.edu> on 16 Feb 1999
18:54:34 GMT, Ilya Zakharevich <ilya@math.ohio-state.edu> says...
> [A complimentary Cc of this posting was sent to Larry Rosler
> <lr@hpl.hp.com>],
> who wrote in article <MPG.1132c4469b6214d9989a44@nntp.hpl.hp.com>:
> > > ### Takes over 19 seconds to complete
> > > if ($LINE =~ /(test)/i) { print "Match\n"; }
> > >
> > > ### Takes only 3 seconds to complete.
> > > if ($LINE =~ /(test)/) { print "Match\n"; }
>
> > It is an implementation detail (extra copying) which is documented,
> > though from home I can't put my finger on it in the books. I didn't
> > find it mentioned in the online docs or FAQ.
>
> It is not mentioned since there is no extra copying associated with //i.
Now I have access to the books. You can argue with Jeffrey Friedl, not
me. Here is a quote from 'Mastering Regular Expressions', page 278:
The Efficiency Penalty of the /i Modifier
...
Before a match or substitution operator applies an /i-governed regex,
Perl first makes a temporary copy of the _entire_ target string. This
copy is in addition to any copy in support of $& and friends. ...
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 16 Feb 1999 19:49:04 GMT
From: snow@biostat.washington.edu (Gregory Snow)
Subject: Re: calculate and print a period of days
Message-Id: <7aci3g$fei$1@nntp6.u.washington.edu>
In article <MPG.1131e1f2d23e0ddc989a3e@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
[snip]
>Very easy. First, compute the values of the starting and ending dates
>of the range as times in the Unix epoch. There is a function to do this
>in the new Perl Function Repository, at (kill the line-fold in the URL,
>of course):
>
>http://moiraine.dimensional.com/~dgris/cgi-
>bin/pfr?index=1&func=UTC_to_Epoch
>
>Then use the starting time as the argument to localtime(), adding 24 *
>60 * 60 each time through the loop until you reach the ending time. The
>components of the result of localtime() in list context are what you
>want to reformat.
Another option is to use the julian date functions also available at
the PFR. This doesn't give you time of day and you have to use 2
functions instead of the builtin localtime, but you only need to add 1
(instead of 24*60*60) and can print ranges outside the unix epoch.
>If, on the other hand, you prefer to use huge, slow modules, look at
>Date::Manip and Date::Calc available from CPAN. :-)
>
>--
>(Just Another Larry) Rosler
>Hewlett-Packard Company
>http://www.hpl.hp.com/personal/Larry_Rosler/
>lr@hpl.hp.com
--
-------------------------------------------------------------------------------
Gregory L. Snow | Barth's Distinction:
(Greg) | There are two types of people: those who divide
snow@biostat.washington.edu | people into two types, and those who don't.
------------------------------
Date: Tue, 16 Feb 1999 20:31:45 +0100
From: adrian allen <aallen@ubkoch.de>
Subject: Can't connect to a port via Perl
Message-Id: <36C9C7A1.1CD6FD2B@ubkoch.de>
Hi all,
I've done the rounds of the man pages, newsgroups and mailing lists
without luck. Even found my problem posted elsewhere but alas no
response so I hope someone can please help me out.
I've just installed mSQL 2.0 on my RedHat Linux 5.0 box and it works
just fine via the monitor. I then installed msqlperl 1.17 which seemed
to go ok until I run the make test script which gives me:
t/msql..............MSQL's message: Can't connect to local MSQL server
at
t/msql.t line 39.
not ok 1: Can't connect to local MSQL server
It looks as if your server is not up and running.
This test requires a running server.
Please make sure your server is running and retry.
FAILED tests 1-68
Failed 68/68 tests, 0.00% okay
t/msql2.............MSQL's message: Can't connect to local MSQL server
at
t/msql2.t line 11.
However the server is up and running and has the prerequisite "test"
database installed. Line 39 referred to is a straight connect. I
modified the script to print the $host variable and it came out null.
Unfortunately I'm very much a newbie but I figured the connect failure
must have something to do with Unix sockets.
Examination of the perl faq 8.1 man pages led me to write a simple
program using the IO package. When I specify a host (localhost) and a
service (http) I get a response from my web server. However when I
specify host and port number (80) the connect fails just as it does in
msqlperl. This seems to me (but what do I know?!) to confirm my theory
that the fault is not within msqlperl but perl and its socket
interface. I am running Perl 5.004.
The problem is I don't know how to go on from there. Any tips on how
you debug an error like this or any advice on a fix would be greatly
appreciated, I'm going round in circles now and its drving me nuts!
Many thanks for your time,
Ade
------------------------------
Date: Tue, 16 Feb 1999 10:44:45 -0800
From: sanjay malunjkar <smalunjk@cisco.com>
Subject: CGI script problem
Message-Id: <36C9BC9D.6B72817D@cisco.com>
Hi all,
I have a CGI script that runs for a long time (25-30 minutes) which
depends on the amount of processing it has do. after 5 minutes (server
timeout I suppose), I get a "Document contains no data" message on the
browser.
I tackled this problem by using the "multipart/x-mixed-replace;
boundary=$boundary" mime-type. I had to rename my script to begin with
nph (non parse header). What I do is I display a "Please be patient.
This may take a few minutes....." message initially. This is then
replaced by the output from the script when it finishes.
Now the problem is that above mentioned mime-type doesnt work correctly
with netscape browsers 4.04 or less. I get the "be patient" page but
when the script finishes, browser displays "Do you want to repost"
dialouge. If I click yes then it restarts the CGI sccript (when all I
wanted was to just see the output from the script).
I would appreciate if you can suggest:
1. Alternative solution to using the above mentioned mime-type.
or
2. How to solve "Do you want to repost" problem
thanks in advance and have a good day
sanjay
------------------------------
Date: Tue, 16 Feb 1999 10:47:12 -0800
From: sanjay malunjkar <smalunjk@cisco.com>
Subject: CGI script problem
Message-Id: <36C9BD2F.6D5F8CAA@cisco.com>
Hi all,
I have a CGI script that runs for a long time (25-30 minutes) which
depends on the amount of processing it has do. after 5 minutes (server
timeout I suppose), I get a "Document contains no data" message on the
browser.
I tackled this problem by using the "multipart/x-mixed-replace;
boundary=$boundary" mime-type. I had to rename my script to begin with
nph (non parse header). What I do is I display a "Please be patient.
This may take a few minutes....." message initially. This is then
replaced by the output from the script when it finishes.
Now the problem is that above mentioned mime-type doesnt work correctly
with netscape browsers 4.04 or less. I get the "be patient" page but
when the script finishes, browser displays "Do you want to repost"
dialouge. If I click yes then it restarts the CGI sccript (when all I
wanted was to just see the output from the script).
I would appreciate if you can suggest:
1. Alternative solution to using the above mentioned mime-type.
or
2. How to solve "Do you want to repost" problem
thanks in advance and have a good day
sanjay
------------------------------
Date: Tue, 16 Feb 1999 11:07:03 -0800
From: nospam_support@gethits.com
Subject: Re: cookie problem
Message-Id: <36C9C1D7.3DEAD54C@gethits.com>
you could append some indicator to a text file every time
a cookie is placed. For example, if a cookie get set, somefile.txt
is opened and the user's REMOTE_HOST env variable (or whatever
you want to use for a tag--writing the date and total number of cookies
set would be a good idea too) is appended to that file.
regards,
darryl dyck
gethits.com
Abukar Mohamed wrote:
> Hi
>
> I developed a scripts that writes a cookie to thier system whenever someone
> visit that script. I wonder if there is a way I can tell if the cookie was
> written or not?
>
> Thanks and I appreciate any help.
>
> Abukar
------------------------------
Date: 16 Feb 1999 18:40:45 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Does an object have a given method?
Message-Id: <7ace3d$fvl$1@towncrier.cc.monash.edu.au>
neutron@fc.hp.com (Jack Applin) writes:
>I want to find out, at run-time, whether an object has a given method
>defined. The following doesn't work:
> print defined($f->alpha) ? "defined\n" : "not defined\n";
You want:
print $f->can("alpha") ? "defined\n" : "not defined\n";
See the perlobj man page.
Damian
------------------------------
Date: Tue, 16 Feb 1999 14:08:29 -0500
From: Dan Boorstein <dboorstein@ixl.com>
Subject: Re: Does an object have a given method?
Message-Id: <36C9C22D.4DFDB139@ixl.com>
Jack Applin wrote:
>
> I want to find out, at run-time, whether an object has a given method
> defined. The following doesn't work:
>
[SNIP]
>
> This works, but it's horrible. Any suggestions?
> print eval "defined(&".ref($f)."::alpha)" ? "defined\n" : "not defined\n";
not much better, but it does away with the eval and concatenation:
$class = ref $f;
print defined &{"${class}::alpha"} ? "defined\n" : "not defined\n";
cheers!
dan
------------------------------
Date: Tue, 16 Feb 1999 14:25:10 -0500
From: Dan Boorstein <dboorstein@ixl.com>
Subject: Re: Does an object have a given method?
Message-Id: <36C9C616.AE94BFF@ixl.com>
silly me, i almost forgot the 'can' function. so it's really as simple
as:
print $f->can('alpha') ? "defined\n" : "not defined\n";
dan
Dan Boorstein wrote:
>
> Jack Applin wrote:
> >
> > I want to find out, at run-time, whether an object has a given method
> > defined. The following doesn't work:
> >
> [SNIP]
> >
> > This works, but it's horrible. Any suggestions?
> > print eval "defined(&".ref($f)."::alpha)" ? "defined\n" : "not defined\n";
>
> not much better, but it does away with the eval and concatenation:
>
> $class = ref $f;
> print defined &{"${class}::alpha"} ? "defined\n" : "not defined\n";
>
> cheers!
>
> dan
------------------------------
Date: 16 Feb 1999 12:40:17 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Does an object have a given method?
Message-Id: <36c9c9a1@csnews>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Dan Boorstein <dboorstein@ixl.com> writes:
:print defined &{"${class}::alpha"} ? "defined\n" : "not defined\n";
That's wrong. Your forgot inheritance.
--tom
--
Sometimes when you fill a vacuum, it still sucks. --Rob Pike
------------------------------
Date: Tue, 16 Feb 1999 19:14:18 GMT
From: "James M. Stern" <sternji@mail.northgrum.com>
Subject: Re: Does an object have a given method?
Message-Id: <36C9C38A.8411240F@mail.northgrum.com>
Jack Applin wrote:
>
> I want to find out, at run-time, whether an object has a given method
> defined. The following doesn't work:
>
> #! /usr/bin/perl -w
>
> package Foo;
>
> sub new { bless [] }
> [...]
Use 'can'. See perldoc perlobj.
--
James M. Stern Northrop Grumman Corp. Hawthorne, CA
Opinions expressed above are not necessarily my employer's.
------------------------------
Date: 16 Feb 1999 18:46:53 GMT
From: hhuggins@fedex.com
To: tad2x@node10.unix.virginia.edu
Subject: Re: free Perl for NT?
Message-Id: <7aceet$etj3@is1.network.fedex.com>
Todd Anthony Delong <tad2x@node10.unix.virginia.edu> sez:
--> I have project coming up that will involve Perl development on the PC
--> (probably under NT). I realize that I can purchase the Win32 Perl package
--> from O'Reilly, but I was wondering if there is a version of Perl 5 for NT for
--> "free" (where a small donation is greatly appreciated). Ordinarily, I
--> wouldn't mind purchasing Perl, but this project will eventually involve
--> running the Perl program on ~200 machines, and I'm not all that psyched about
--> having to purchase 200 copies of the Win32 version of Perl 5.
http://www.perl.com/CPAN-local/ports/index.html#win32
--> Thanks.
--
Hercules Huggins Federal Express Corporation
(407)916-3863 hhuggins@fedex.com
(888)935-0004 9350004@skytel.com
PGP Fingerprint: 9B 5C 2C 21 B4 77 C5 96 AD 99 44 B2 CA A8 45 14
Send email for my pgp key.
------------------------------
Date: 16 Feb 1999 19:02:12 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: good code vs code that works
Message-Id: <7acfbk$aru$4@news0-alterdial.uu.net>
23_skidoo <23_skidoo@geocities.com> wrote:
> is it considered bad practice to use return to jump out of a foreach
> loop in a subroutine? my reason for asking:
Not at all -- this is frequently useful. You might consider using
'last' to jump out of the loop, a very common idiom. (Hell, that's
why Perl *has* 'last'!)
> i'm writing a cgi subroutine (shown below) which compares an email
> address against a blacklist text file containing email addresses and the
> reasons they were banned. it works but i don't want develop bad habits
> as they tend to trip you up further down the road. any pointers
> appreciated
Don't worry, there are *plenty* of other bad habits you can pick up.
Jumping out of a loop is *nothing*. ;-)
>
> also,
> foreach local $user (@badusers)
>
> doesn't work, are variables local by default when used in a foreach
> loop? if not, how can i localise them so that i can cut and paste subs
> into other programs without worrying that i might corrupt a global
> variable?
Ooh, yuck, you should not use local unless you really know why --
generally, you only want it on Perl's builtin "special variables". For
your own variables, use "my". And "use strict" to make *sure* that you
use "my".
Speaking of which:
foreach my $user (@badusers)
*does* work, at least since Perl 5.004. Very handy idiom, and not a bad
habit at all.
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: Tue, 16 Feb 1999 19:33:40 GMT
From: georeq@my-dejanews.com
Subject: IPC::OPEN3 on Win NT does it works?
Message-Id: <7ach6k$8hr$1@nnrp1.dejanews.com>
I am trying to create a perl wrapper to a program using open3.
the code is similar to the cookbook code but it will not work on NT. I have
it working on solaris but NT is the target platform.
Does Open3 work on windows NT
Thanks
George Q
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 16 Feb 1999 18:55:24 GMT
From: jsmith7350@aol.com
Subject: Re: NET::FTP with ActiveState
Message-Id: <7aceun$6cv$1@nnrp1.dejanews.com>
In article <#JO1$vZW#GA.269@nih2naac.prod2.compuserve.com>,
"Arnold M|ller" <Arnold_Mueller@csi.com> wrote:
> Hello,
>
> I have some problems accessing the NET::FTP module in ActiveState-PERL for
> NT. Is it not included in the distribution? Or else, can I take any FTP.pm
> or does it depend on the version of PERL and the Winsock?
>
> Thanks in advance
>
> Arnold
>
>
The Net::FTP package is contained within the libnet module available at
http://www.activestate.com/packages/zips/, I could not find it within
ActiveState's win32 perl distribution (but I have been known to be wrong
before). Just unzip the package and read the README file (use winzip, I had
problems using pkunzip). The ppm command will auto install the package. I've
found some other great documentation at http://www.connect.net/gbarr/pod/Net/.
Hope this helps.
JS
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 16 Feb 1999 18:58:48 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: redefining a sub
Message-Id: <7acf58$aru$3@news0-alterdial.uu.net>
Ekkis <ekkis@arix.com> wrote:
> My little script below generates "new" as I expect it should:
[code deleted]
> ...however, if I break it up into 2 files as such:
>
> --> FILE: t.inc
> #!/bin/ksh
> sub tst1 { print 'old'; }
> sub tst { tst1(); }
>
> --> FILE t.pl
> #!/bin/ksh
>
> $\ = "\n";
> require 't.inc';
> sub tst1 { print 'new'; }
> tst();
>
> ...I get "old". Can someone explain to me why? how can I override a
> function defined inside of t.inc?
It's a compile-time vs. run-time thing. The short answer: change your
"require" line in t.pl to
BEGIN { require 't.inc'; }
The long answer: here's the sequence of events in your split-up-into-two-
files version:
* t.pl is compiled (parsed and turned into bytecodes)
-> sideeffect: sub tst1 is defined to print 'new'
* t.pl starts running; when it hits the "require" line, then...
* t.inc is compiled
-> sideeffect: sub tst1 is redefined to print 'old'
-> sideeffect: sub tst is defined to call tst1
* t.inc is run, but there's nothing to run since it's all
sub definitions
* t.pl continues running; the only interesting thing is
when it calls tst(), which calls tst1(), which is the
redefined tst1() from t.inc
Now, if you change the require line to use BEGIN, here's what happens:
* t.pl starts compiling, but...
* when we hit the BEGIN block, we suspend compilation and
immediately run the code in the BEGIN, so...
* t.inc starts compiling
-> sideeffect: sub tst1 is defined to print 'old'
-> sideeffect: sub tst is defined to call tst1
* t.inc is run (nothing happens)
* finish compiling t.pl
-> sideeffect: sub tst1 is redefined to print 'new'
* run t.pl
-> call tst()
-> call tst1 (the 'new' version)
This is really the difference between use and require, but you can't use
"use" because your included file is not a module. Run "perldoc perlmod"
for details.
BTW, your #! line should probably refer to perl, not ksh. And require'd
files should always end with a true value, eg. "1". And if you had run
this with "perl -w", you would have gotten a warning message telling a)
that tst1 was being redefined, b) *where* tst1 was being redefined.
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: 16 Feb 1999 11:13:00 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Redirectiong STDERR
Message-Id: <36c9b52c@csnews>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, palfrader@usa.net (Peter Palfrader) writes:
:how can I pipe STDERR?
Gosh, I don't know. Maybe there's something in the FAQ about it.
=head1 NAME
perlfaq8 - System Interaction ($Revision: 1.36 $, $Date: 1999/01/08 05:36:34 $)
=head1 DESCRIPTION
=head2 How can I capture STDERR from an external command?
There are three basic ways of running external commands:
system $cmd; # using system()
$output = `$cmd`; # using backticks (``)
open (PIPE, "cmd |"); # using open()
With system(), both STDOUT and STDERR will go the same place as the
script's versions of these, unless the command redirects them.
Backticks and open() read B<only> the STDOUT of your command.
With any of these, you can change file descriptors before the call:
open(STDOUT, ">logfile");
system("ls");
or you can use Bourne shell file-descriptor redirection:
$output = `$cmd 2>some_file`;
open (PIPE, "cmd 2>some_file |");
You can also use file-descriptor redirection to make STDERR a
duplicate of STDOUT:
$output = `$cmd 2>&1`;
open (PIPE, "cmd 2>&1 |");
Note that you I<cannot> simply open STDERR to be a dup of STDOUT
in your Perl program and avoid calling the shell to do the redirection.
This doesn't work:
open(STDERR, ">&STDOUT");
$alloutput = `cmd args`; # stderr still escapes
This fails because the open() makes STDERR go to where STDOUT was
going at the time of the open(). The backticks then make STDOUT go to
a string, but don't change STDERR (which still goes to the old
STDOUT).
Note that you I<must> use Bourne shell (sh(1)) redirection syntax in
backticks, not csh(1)! Details on why Perl's system() and backtick
and pipe opens all use the Bourne shell are in
http://www.perl.com/CPAN/doc/FMTEYEWTK/versus/csh.whynot .
To capture a command's STDERR and STDOUT together:
$output = `cmd 2>&1`; # either with backticks
$pid = open(PH, "cmd 2>&1 |"); # or with an open pipe
while (<PH>) { } # plus a read
To capture a command's STDOUT but discard its STDERR:
$output = `cmd 2>/dev/null`; # either with backticks
$pid = open(PH, "cmd 2>/dev/null |"); # or with an open pipe
while (<PH>) { } # plus a read
To capture a command's STDERR but discard its STDOUT:
$output = `cmd 2>&1 1>/dev/null`; # either with backticks
$pid = open(PH, "cmd 2>&1 1>/dev/null |"); # or with an open pipe
while (<PH>) { } # plus a read
To exchange a command's STDOUT and STDERR in order to capture the STDERR
but leave its STDOUT to come out our old STDERR:
$output = `cmd 3>&1 1>&2 2>&3 3>&-`; # either with backticks
$pid = open(PH, "cmd 3>&1 1>&2 2>&3 3>&-|");# or with an open pipe
while (<PH>) { } # plus a read
To read both a command's STDOUT and its STDERR separately, it's easiest
and safest to redirect them separately to files, and then read from those
files when the program is done:
system("program args 1>/tmp/program.stdout 2>/tmp/program.stderr");
Ordering is important in all these examples. That's because the shell
processes file descriptor redirections in strictly left to right order.
system("prog args 1>tmpfile 2>&1");
system("prog args 2>&1 1>tmpfile");
The first command sends both standard out and standard error to the
temporary file. The second command sends only the old standard output
there, and the old standard error shows up on the old standard out.
--
"That which does not kill me makes me stranger." --Larry Wall
------------------------------
Date: 16 Feb 1999 19:02:33 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: REGEX $1, $2 ... array?
Message-Id: <7acfc9$fch$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Russ Allbery
<rra@stanford.edu>],
who wrote in article <ylsoc6mcni.fsf@windlord.stanford.edu>:
> > Get real! Do not pretend you do not read p5p. 5.00502's h2ph is
> > useless
>
> I, like thousands of other users of Perl, have no need for h2ph for any of
> the Perl scripts we run. I don't use Sys::Syslog, or any other module
> that requires it. And 5.005_02 is running well enough on Solaris to
> handle posting duties for comp.lang.perl.moderated.
I'm very glad you enjoy your installation of Perl. ;-)
However, this does not fix things which are broken. I got *very* hot
mail from our system administrator after he spend enormous time trying
to switch to 5.005_02 (as a result, we are running 5.005_54 - he could
not go back to 5.004 - per users' requests?).
And after an upgrade my *only* Perl script I use frequently at work
(one for posting to p5p) broke - per __sparc being undefined. Hmm,
probably it broke due the switch to Solaris 7, it just happened that
the .ph files were recompiled only during the upgrade to 5.005*.
Ilya
------------------------------
Date: 16 Feb 1999 10:22:41 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: REGEX $1, $2 ... array?
Message-Id: <ylsoc6mcni.fsf@windlord.stanford.edu>
Ilya Zakharevich <ilya@math.ohio-state.edu> writes:
> Get real! Do not pretend you do not read p5p. 5.00502's h2ph is
> useless
I, like thousands of other users of Perl, have no need for h2ph for any of
the Perl scripts we run. I don't use Sys::Syslog, or any other module
that requires it. And 5.005_02 is running well enough on Solaris to
handle posting duties for comp.lang.perl.moderated.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Tue, 16 Feb 1999 19:16:42 GMT
From: Darrin Edwards <d-edwards@nospam.uchicago.edu>
Subject: Re: REGEX $1, $2 ... array?
Message-Id: <tg3e46duqt.fsf@noise.bsd.uchicago.edu>
"William H. Asquith" <asquith@macconnect.com> writes:
>
> Why isn't there a special array that contains
> $1, $2, $3, etc . . . from application of a regex.
> This would really make things easier.
Others have already responded assuming your problem was
with m//; as Bart Lateur said, s// is somewhat different.
On the off chance that you were interested in the s// case,
here is something I found myself doing just this morning.
Obviously one could capture the matches with an m//, and
then go back using the same pattern with an s//, but that seemed
redundant to me. Instead I did something more or less like:
my @keys;
$Input_string =~ s/{(\w+)}/push (@keys, $1);
$Matches{$1}/gex;
So I had a string, and wanted to replace instances of "{KEY}"
with the corresponding value in a given hash, while remembering
the keys that had matched. Looks a bit silly perhaps, and probably
far from being the best way to do this, but it's the first time
I've ever needed (wanted?) to use the /x switch on the s// operator.
Cheers,
Darrin
------------------------------
Date: Tue, 16 Feb 1999 10:41:01 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Regular expression for Currency ???
Message-Id: <MPG.11335b9cc88cfa6a989a47@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7ac306$qrt$1@nnrp1.dejanews.com> on Tue, 16 Feb 1999
15:31:17 GMT, bill_mcintyre@my-dejanews.com <bill_mcintyre@my-
dejanews.com> says...
> What would the regular expression be to test the proper format of currency.
>
> For example $123,234.00 (I want to ensure 2 decimal places and a comma every
> thousand)
/^\$(?:(?:\d{1,3},)(?:\d{3},)*\d{3}|\d{1,3})\.\d\d$/
/^\$ # a dollar sign at the beginning
(?: # either
(?:\d{1,3},) # one to three digits and a comma
(?:\d{3},)* # three digits and a comma (0 or more)
\d{3} # three digits
| # or
\d{1,3} # one to three digits
)\.\d\d$/x # a period and two digits at the end
This would reject '$.02' but if you want to accept it, the fix is
obvious.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 16 Feb 1999 14:00:00 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Server Software
Message-Id: <7acfo3$oj0$1@camel18.mindspring.com>
Bababozorg wrote in message <19990216132854.09721.00001092@ng144.aol.com>...
:hi
:i need a server software which supports .cgi/.pl files and .htaccess files
:at the moments i use OmniHTTPd server but it doesnt sopport .htaccess
:or i dont know how to do it.
WWW.apache.org for Windoze and all flavors of UNIX.
HTH
AmD
------------------------------
Date: 16 Feb 1999 19:19:35 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: user input to background script
Message-Id: <slrn7cjh4e.fc.efflandt@efflandt.xnet.com>
I am using a perl script to substitute for a missing fax_queue in
StarOffice 5.0 (Linux) to filter a phone number from data being piped
between SO and a fax program (efax through lpr). I want the user to
confirm if the correct fax phone number was found or correct it if not.
What is the best (most universal) method to pop up a text window from a
background process in X (granted, this may not be a perl specific
question)?
I can launch an xterm running a separate perl script with parameters for
default phone# and tmp file to pass the data. But is there a way to fork
the calling script to run in xterm directly instead of indirectly
through a totally isolated script? There is a -S switch for xterm for
applications to use a pseudo tty, but limited info and no examples.
--
David Efflandt efflandt@xnet.com
http://www.xnet.com/~efflandt/
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 4908
**************************************