[25707] in Perl-Users-Digest
Perl-Users Digest, Issue: 7947 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 6 11:05:38 2005
Date: Wed, 6 Apr 2005 08:05:17 -0700 (PDT)
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, 6 Apr 2005 Volume: 10 Number: 7947
Today's topics:
Bug in timelocal? <yocoyote@gmail.com>
C++, Perl Embed, and "Out of Memory during request..." sleepymish@gmail.com
Comparing Regular Expressions <robert@deadspam.com>
Re: Comparing Regular Expressions (Anno Siegel)
Re: Comparing Regular Expressions <nobull@mail.com>
Re: Comparing Regular Expressions <jm@bourguet.org>
Re: Comparing Regular Expressions (=?iso-8859-1?q?Torben_=C6gidius_Mogensen?=)
Re: erase element in array but keep the order (Anno Siegel)
Re: erase element in array but keep the order <lskatz@gmail.com>
install module with CPAN - how to change default compil <lard@tardis.ed.ac.molar.uk>
Re: Perl on TRIPOD hosted sites..file uploading questio <noreply@gunnar.cc>
Re: Perl on TRIPOD hosted sites..file uploading questio <noreply@gunnar.cc>
Re: Q: // and "magic" <joe@inwap.com>
Re: Q: // and "magic" (Anno Siegel)
Re: Regular expression question. <someone@example.com>
Re: Regular expression question. <1usa@llenroc.ude.invalid>
Re: Regular expression question. <tadmc@augustmail.com>
Re: Regular expression question. <tadmc@augustmail.com>
Re: Regular expression question. <1usa@llenroc.ude.invalid>
Re: Shell Commands (Getting PID and Timing Them) <joe@inwap.com>
Re: Shell Commands (Getting PID and Timing Them) <nobull@mail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Apr 2005 07:54:30 -0700
From: "yocoyote" <yocoyote@gmail.com>
Subject: Bug in timelocal?
Message-Id: <1112799270.458682.191040@o13g2000cwo.googlegroups.com>
I'm writing scripts which make heavy use of the timelocal() fct.
(Time::Local) to get epochtime from a MM/DD hh:mm:ss text date. I'm
using activestate perl 5.8.4 build 810 on my pc. I've found one date,
among the 10,000's I've successfully transformed, is offset by 3600
sec. The 3600 (=1 hour) struck me as not likely a conincidence. I'm
wondering if others have seen this before.
syntax:
use Time::Local
$epochTime = timelocal($sec, $min, $hour, $day, $month - 1);
Anyone seen instances in which a date, seemingly at random, has 3600
added or subtracted from the correct output of timelocal?
thanks
yocoyote
------------------------------
Date: 6 Apr 2005 08:04:22 -0700
From: sleepymish@gmail.com
Subject: C++, Perl Embed, and "Out of Memory during request..." Problem
Message-Id: <1112799862.279574.161230@g14g2000cwa.googlegroups.com>
Hi,
I have cygwin running on a P4 2.4 GHZ with 512 MB RAM machine. I also
have perl 5.0.8 installed with my cygwin. I wrote a C++ application
with perl embedded to do string matching for strings of about 256
characters long. When I run the program I got the following error:
Out of memory during request for 1208 bytes, total sbrk() is 393910272
bytes!
Anyone know what this error mean?
What happens is I have a huge html file, about 80MB big, and I wrote a
parser in C++ to do string matching in the html file. Because Perl has
such a powerful regular expression capability, I decided to use Perl
instead of writing my own in C++. So I use fget to get strings line by
line from the html, then use perl to find any integer values in it. My
program works fine when the html file is 20MB or less.. but craps out
when it's 80MB. BTW, I'm using STL Vector to store the strings matched
from Perl.
Anyone know what might be the problem w/ the "OUt of memory error"? I'm
trying to narrow it down to a perl or STL vector problem. After initial
searching, I saw that other people with this error usu. orginates from
perl.
Anybody encountered this problem? Knows how to fix this?
Thanks,
Michelle
------------------------------
Date: 06 Apr 2005 10:27:45 +0100
From: Robert Inder <robert@deadspam.com>
Subject: Comparing Regular Expressions
Message-Id: <f517jjgxnji.fsf@3lg.org>
I'm interested in comparing the "coverage" of regular expressions.
In particular, if I have two regular expressions, I want to know
whether it is possible to construct a string that will match
both, or indeed that will match one and not the other.
So, for instance, suppose I believe that if an object has a
descripiton string matching regexp R1, it is of type A.
Someone now tells me that an object with a
descripiton string matching regexp R2 is of type B. What can I tell
about (the sets of things of type) A and B by looking at R1 and R2?
So if R1= "^a.*$" and R2 = "^b.*$", I know that A and B are disjoint.
Whereas if R1= "foo" and R2 = "foobar", I know that B is a subset of A.
But how do I formalise (i.e. program) this comparison process?
This strikes me as a very general problem/issue and there
just has to be some work on formalising and solving it. But I don't
know how to find it: Google searches for things like "regular
expression comparison" are swamped by algorithms for matching regexps
against strings and so forth, which isn't what I want.
Can anyone point me in the right direction?
Robert.
--
__ To avoid the spam trap, mail me
|_) _ |_ _ ._ |- | _ _| _ ._ at bcs.org.uk, not deadspam.com.
| \(_)|_)(-'| |_ || |(_|(-'| '
Best viewed in Ebriated.
------------------------------
Date: 6 Apr 2005 10:06:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Comparing Regular Expressions
Message-Id: <d30cbg$h2t$2@mamenchi.zrz.TU-Berlin.DE>
Robert Inder <robert@deadspam.com> wrote in comp.lang.perl.misc:
>
> I'm interested in comparing the "coverage" of regular expressions.
>
> In particular, if I have two regular expressions, I want to know
> whether it is possible to construct a string that will match
> both, or indeed that will match one and not the other.
[snip]
That will be utterly non-trivial.
Consider the partial problem of finding a string that a given regex
matches. Since there are patterns that don't match anything (/$.^/),
there can't be a general solution. At the very least you'll need a
complete regex parser before you can tackle this problem.
Anno
------------------------------
Date: Wed, 06 Apr 2005 12:15:16 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Comparing Regular Expressions
Message-Id: <d30g15$729$1@sun3.bham.ac.uk>
Robert Inder wrote:
> I'm interested in comparing the "coverage" of regular expressions.
>
> In particular, if I have two regular expressions, I want to know
> whether it is possible to construct a string that will match
> both, or indeed that will match one and not the other.
My instinct says that will be "hard". Not just "hard" in the common
sense, but hard in the CompSci sense of being equivalent to the halting
problem (i.e. insoluble in the general case in finite time).
Note I'm reading this in clp.misc. I suspect the nettizens of
comp.theory will be much more clued-up on this.
------------------------------
Date: 06 Apr 2005 13:55:59 +0200
From: Jean-Marc Bourguet <jm@bourguet.org>
Subject: Re: Comparing Regular Expressions
Message-Id: <pxbu0mk9l0w.fsf@news.bourguet.org>
Robert Inder <robert@deadspam.com> writes:
> I'm interested in comparing the "coverage" of regular expressions.
For which definition or regular expressions? I see this is crossposted
to comp.lang.perl.misc and comp.theory and the default meaning of
regular expression is quite different in the two groups.
> In particular, if I have two regular expressions, I want to know
> whether it is possible to construct a string that will match both,
> or indeed that will match one and not the other.
For the comp.theory adapted definition, it is possible to construct
FSM accepting the language described by a regular expressions.
Starting from the FSMs and using a variant of the algorithm used to
minimize them it is easy to construct an FSM which accept the union of
the two languages. As there is a know relation between the states in
the new FSM and the states in the old, it is easy to classify the
accepting states of the new FSM as having correspondance in only one
or both of the original FSM.
Yours,
--
Jean-Marc
------------------------------
Date: 06 Apr 2005 14:43:04 +0200
From: torbenm@diku.dk (=?iso-8859-1?q?Torben_=C6gidius_Mogensen?=)
Subject: Re: Comparing Regular Expressions
Message-Id: <7zhdikt6sn.fsf@app-2.diku.dk>
Robert Inder <robert@deadspam.com> writes:
> I'm interested in comparing the "coverage" of regular expressions.
>
> In particular, if I have two regular expressions, I want to know
> whether it is possible to construct a string that will match
> both, or indeed that will match one and not the other.
Regular languages are closed under intersection and set difference, so
you can not only find strings (if any exist) in the intersection and
difference sets, you can construct regular expressions or DFA's that
describe all such strings.
> So, for instance, suppose I believe that if an object has a
> descripiton string matching regexp R1, it is of type A.
> Someone now tells me that an object with a
> descripiton string matching regexp R2 is of type B. What can I tell
> about (the sets of things of type) A and B by looking at R1 and R2?
>
> So if R1= "^a.*$" and R2 = "^b.*$", I know that A and B are disjoint.
>
> Whereas if R1= "foo" and R2 = "foobar", I know that B is a subset of A.
Say what? The set containing only the string "foobar" is not a subset
of the set containing only "foo". Or do you consider a string to
match a regular expression if a prefix of the string does?
> But how do I formalise (i.e. program) this comparison process?
>
> This strikes me as a very general problem/issue and there
> just has to be some work on formalising and solving it. But I don't
> know how to find it: Google searches for things like "regular
> expression comparison" are swamped by algorithms for matching regexps
> against strings and so forth, which isn't what I want.
If you have a DFA D1 with states s_0 ... s_m for A and a DFA D2 with
states t_0 ... t_n for B, you can construct a DFA D3 for the
intersection of A and B in the following way:
1. The start state of D3 is the pair (s_0,t_0) of starting states of
D1 and D2.
2. If D1 has a transition on symbol c from s_i to s_j and D2 has a
transition on symbol c from t_k to t_l, D3 has a transition from
(s_i,t_k) to (s_j,t_l) on c.
3. If s_i is accepting in D1 and t_k is accepting in D2, (s_i,t_k) is
accepting in D3.
For A\B (A minus B), the construction is:
0. Add a non-accepting state t_(n+1) to D2. If there is a state t_k
in D2 and a symbol c such that t_k has no transition on c, add a
transition from t_k to t_(n+1) on c. There is a transition from
t_(n+1) to t_(n+1) on all symbols. This way, D2 has transitions
on all symbols from all states.
1. The start state of D3 is the pair (s_0,t_0) of starting states of
D1 and D2.
2. If D1 has a transition on symbol c from s_i to s_j and D2 has a
transition on symbol c from t_k to t_l, D3 has a transition from
(s_i,t_k) to (s_j,t_l) on c.
3. If s_i is accepting in D1 and t_k is not accepting in D2,
(s_i,t_k) is accepting in D3.
Torben
------------------------------
Date: 6 Apr 2005 10:13:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: erase element in array but keep the order
Message-Id: <d30cnr$h2t$3@mamenchi.zrz.TU-Berlin.DE>
Lee <lskatz@gmail.com> wrote in comp.lang.perl.misc:
> I have an array of DNA sequences, ordered by length.
> >From this, I want to be able to keep it ordered and just take out
> selected sequences. Thus, shift or pop won't work. I'm not so sure
> what splice does entirely, but I'm pretty sure it doesn't work either.
> Does anyone have a suggestion on a function or algorithm? Thanks.
As has been noted, splice (and even shift and pop) should work,
but the most direct solution is probably grep.
Then again, it may be more efficient to select first and sort (fewer
elements) later. In that case, conservation of order becomes irrelevant,
though grep may still be the method of choice.
Anno
------------------------------
Date: 6 Apr 2005 07:56:06 -0700
From: "Lee" <lskatz@gmail.com>
Subject: Re: erase element in array but keep the order
Message-Id: <1112799366.224291.241750@o13g2000cwo.googlegroups.com>
Thanks guys. I really didn't understand splice as I should have. I'll
go look into it in detail.
------------------------------
Date: Wed, 06 Apr 2005 12:54:43 GMT
From: Alex Hunsley <lard@tardis.ed.ac.molar.uk>
Subject: install module with CPAN - how to change default compiler flags?
Message-Id: <n_Q4e.35550$C12.16809@fe1.news.blueyonder.co.uk>
Pretty simple stuff... trying to install Text::CSV_XS module via cpano
on a redhat 8 system.
So I run the command and get the output:
[root@jura ~]# perl -MCPAN -e 'install "Text::CSV_XS"'
CPAN: Storable loaded ok
Going to read /root/.cpan/Metadata
Database was generated on Wed, 06 Apr 2005 00:54:44 GMT
Running install for module Text::CSV_XS
Running make for J/JW/JWIED/Text-CSV_XS-0.23.tar.gz
CPAN: Digest::MD5 loaded ok
Checksum for
/root/.cpan/sources/authors/id/J/JW/JWIED/Text-CSV_XS-0.23.tar.gz ok
Scanning cache /root/.cpan/build for sizes
Text-CSV_XS-0.23/
Text-CSV_XS-0.23/ChangeLog
Text-CSV_XS-0.23/CSV_XS.pm
Text-CSV_XS-0.23/CSV_XS.xs
Text-CSV_XS-0.23/Makefile.PL
Text-CSV_XS-0.23/MANIFEST
Text-CSV_XS-0.23/ppport.h
Text-CSV_XS-0.23/README
Text-CSV_XS-0.23/t/
Text-CSV_XS-0.23/t/base.t
Text-CSV_XS-0.23/t/file.t
Text-CSV_XS-0.23/t/misc.t
Text-CSV_XS-0.23/t/samples.t
Text-CSV_XS-0.23/t/types.t
Text-CSV_XS-0.23/test.pl
Removing previously used /root/.cpan/build/Text-CSV_XS-0.23
CPAN.pm: Going to build J/JW/JWIED/Text-CSV_XS-0.23.tar.gz
Checking if your kit is complete...
Looks good
Writing Makefile for Text::CSV_XS
cp CSV_XS.pm blib/lib/Text/CSV_XS.pm
/usr/bin/perl /usr/lib/perl5/5.8.5/ExtUtils/xsubpp -typemap
/usr/lib/perl5/5.8.5/ExtUtils/typemap CSV_XS.xs > CSV_XS.xsc && mv
CSV_XS.xsc CSV_XS.c
gcc -c -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING
-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -O2 -g -pipe -m32 -march=i386
-mtune=pentium4 -DVERSION=\"0.23\" -DXS_VERSION=\"0.23\" -fPIC
"-I/usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE" CSV_XS.c
cc1: invalid option `tune=pentium4'
make: *** [CSV_XS.o] Error 1
/usr/bin/make -- NOT OK
Running make test
Can't test without successful make
Running make install
make had returned bad status, install seems impossible
.... So it appears I need to get rid of the tune=pentium4 option being
passed to gcc, but I can't find out where to make this change, can
anyone help?
thanks
alex
------------------------------
Date: Wed, 06 Apr 2005 10:13:59 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl on TRIPOD hosted sites..file uploading question..
Message-Id: <3bhk5gF6gtl5qU1@individual.net>
joesplink wrote:
> They specifically state that they don't help debugging Perl .... fair
> enough...besides..there was no error msg.... the first read failed and
> no bytes were transferred....
Inspired by Bill's knowledge about Tripod, this seems to be a situation
where a Perl module I just wrote, CGI::UploadEasy, may come in handy.
http://search.cpan.org/perldoc?CGI%3A%3AUploadEasy
To check it out, follow these steps:
1) Create a subdirectory 'CGI' (case matters) in your cgi-bin and
upload UploadEasy.pm to that directory
2) Upload this script:
#!/usr/bin/perl
use strict;
use warnings;
use CGI::Carp 'fatalsToBrowser';
use CGI::UploadEasy;
my $ue = CGI::UploadEasy->(-uploaddir => '/path/to/upload/dir');
my $cgi = $ue->cgiobject;
print $cgi->header, "Done.\n";
__END__
3) Upload a file upload form that invokes the script at submission.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 06 Apr 2005 10:17:05 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl on TRIPOD hosted sites..file uploading question..
Message-Id: <3bhkbbF6gtl5qU2@individual.net>
Gunnar Hjalmarsson wrote:
>
> my $ue = CGI::UploadEasy->(-uploaddir => '/path/to/upload/dir');
Oops. That should be:
my $ue = CGI::UploadEasy->new(-uploaddir => '/path/to/upload/dir');
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 06 Apr 2005 02:00:19 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Q: // and "magic"
Message-Id: <M4ednZ8V9_6FOM7fRVn-sA@comcast.com>
Alex Hart wrote:
> This can be used instead of the "o" option. Meaning the regex will not
> be recompiled each time perl sees it. If perl sees a string inside a
> regex, it will recompile it each time, even if the string hasn't
> changed.
Earlier versions of perl operated in that fashion.
-Joe
------------------------------
Date: 6 Apr 2005 09:52:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Q: // and "magic"
Message-Id: <d30bgt$h2t$1@mamenchi.zrz.TU-Berlin.DE>
Alex Hart <alex_the_hart@yahoo.com> wrote in comp.lang.perl.misc:
> > So, does anyone find this behavior useful? I've never intentionally
> used
> > it, and I can't imagine doing so in the future.
>
> I use this all the time.
>
> This can be used instead of the "o" option. Meaning the regex will not
> be recompiled each time perl sees it. If perl sees a string inside a
> regex, it will recompile it each time, even if the string hasn't
> changed. If you set the "o" option, then it is fixed for the whole
> program, once it is compiled. Using // can avoid perl recompiling each
> time, but the string can still change later.
>
>
> Here's an example
>
>
> sub Search { # search a list of names for a string
> my ($string) = @_;
> $string =~ /$string/i;
That won't necessarily match. It will match if $string (which would be
better named $pattern) doesn't contain regex meta characters (and sometimes
if it does). It won't match, for instance, for "a[bc]".
That is exactly the problem with the // kludge: Given an arbitrary regex,
there is no way of constructing a string that the regex will match.
> foreach (@list_of_names) {
> if (//) {
> push @found, $_;
> }
> }
> }
>
> Now, the regex is only compiled once each time the function is called.
> With the "o" flag, running Search() twice would search for the same
> string twice.
>
> There are other ways to achieve the same thing, but I like //.
Why? It's obscure and unsafe. Use qr//.
Anno
------------------------------
Date: Wed, 06 Apr 2005 07:39:59 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Regular expression question.
Message-Id: <jnM4e.2233$7Q4.2067@clgrps13>
A. Sinan Unur wrote:
>
> use strict;
> use warnings;
>
>>$required_pattern = "(\\|Line 4)";
>
> my $required_pattern = '(\|Line 4)';
Or even better:
my $required_pattern = qr'(?:\|Line 4)';
> Why are you capturing?
Indeed.
> [snip]
>
>
>> if ($_ =~ m/$required_pattern/ms)
>
> By default, m// matches against $_, so no need to explicitly specify it.
>
> What do you think using both the m and s options for the match above
> achieves?
>
> From perldoc perlop:
>
> m Treat string as multiple lines.
> s Treat string as single line.
>
> Which one is it?
According to the OP's pattern he doesn't need either.
>> {
>> print $_;
>> }
>
> The whole thing can be written as
>
> print if /$required_pattern/ose;
/s ??? /e ???
There are no periods in the pattern for /s and there are no expressions for /e
to evaluate. (And if he uses qr// to compile the regexp there is no need for /o.)
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 06 Apr 2005 11:31:21 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Regular expression question.
Message-Id: <Xns96304C86ECAF3asu1cornelledu@127.0.0.1>
"John W. Krahn" <someone@example.com> wrote in
news:jnM4e.2233$7Q4.2067@clgrps13:
> A. Sinan Unur wrote:
>> print if /$required_pattern/ose;
>
> /s ??? /e ???
>
> There are no periods in the pattern for /s and there are no
> expressions for /e to evaluate. (And if he uses qr// to compile the
> regexp there is no need for /o.)
Indeed :)
Dunno what I was thinking.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Wed, 6 Apr 2005 08:31:22 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Regular expression question.
Message-Id: <slrnd57p5a.86i.tadmc@magna.augustmail.com>
John W. Krahn <someone@example.com> wrote:
> A. Sinan Unur wrote:
>> print if /$required_pattern/ose;
> there are no expressions for /e
> to evaluate.
It is worse than that. It won't even compile, since /e is only
valid for s/// not for m//. :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 6 Apr 2005 08:43:06 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Regular expression question.
Message-Id: <slrnd57pra.86i.tadmc@magna.augustmail.com>
A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
> chaitanyag@hotmail.com (MENTAT) wrote in
> news:5a286c02.0504051958.7eaa7f0@posting.google.com:
>> if (-e $file_name)
>
> This is a useless test.
>
>> {
>> open (THEFILE, $file_name) or die "Unable to open file $file_name";
>
> Because open will fail if the file does not exist.
It is not useless.
If the file does not exist: do nothing.
If the file exists but cannot be opened: complain and exit.
If the file exists and can be opened: normal processing.
Remove the test and those semantics change.
> What do you think using both the m and s options for the match above
> achieves?
(the OP needs neither of course)
> From perldoc perlop:
>
> m Treat string as multiple lines.
> s Treat string as single line.
>
> Which one is it?
This illustrates precisely why I don't like the doc's treatment
of these two modifiers. I'm sure the docs do it that way for
mnemonic reasons.
But it falsely implies that they are mutually exclusive.
There are times when you might use both modifiers.
So I'd prefer to give up on the mnemonicness:
m Makes ^ and $ match begin/end of line (rather than of string)
s Makes . match a newline
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 06 Apr 2005 13:23:03 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Regular expression question.
Message-Id: <Xns96305F76D4DE2asu1cornelledu@127.0.0.1>
Tad McClellan <tadmc@augustmail.com> wrote in
news:slrnd57pra.86i.tadmc@magna.augustmail.com:
> A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
>> chaitanyag@hotmail.com (MENTAT) wrote in
>> news:5a286c02.0504051958.7eaa7f0@posting.google.com:
>
>
>>> if (-e $file_name)
>>
>> This is a useless test.
>>
>>> {
>>> open (THEFILE, $file_name) or die "Unable to open file
>>> $file_name";
>>
>> Because open will fail if the file does not exist.
>
> It is not useless.
...
> Remove the test and those semantics change.
I see your point. I would prefer to handle the case where the file did
not exist, if that is an important special case, as part of handling the
failure from open.
On the other hand, in the OP's code, if the file did not exist, the
program did not convey this information to the user. Given that this
might be one of the most ways an open might fail, it would have been
better to 'tell' the user why open failed and be done with it.
>> What do you think using both the m and s options for the match above
>> achieves?
>
> (the OP needs neither of course)
>
>> From perldoc perlop:
>>
>> m Treat string as multiple lines.
>> s Treat string as single line.
>>
>> Which one is it?
>
> This illustrates precisely why I don't like the doc's treatment
> of these two modifiers. I'm sure the docs do it that way for
> mnemonic reasons.
>
> But it falsely implies that they are mutually exclusive.
Yeah, as I said, I don't know what I was thinking when I wrote that
part. Thanks for the correction.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Wed, 06 Apr 2005 02:28:47 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Shell Commands (Getting PID and Timing Them)
Message-Id: <c4SdnYUfLZ9JNs7fRVn-gA@comcast.com>
Hal Vaughan wrote:
> axel@white-eagle.invalid.uk wrote:
>>my $pid = open (PIPE, "-|") || exec("/what/ever");
>> ...
>>my $kesult = kill 9, $pid;
>
> I could use a bit of help understanding this. When the pipe is opened, and
> with the "||", it will exec the program, but still continue with the rest
> of the Perl program, with the pipe still open?
No, exec() and "continue with the rest of the program" are mutually
exclusive. The exec() function causes your computer to stop
executing the perl program and execute the other program instead.
A single process won't do both, but a parent process and a child
process can.
*) open(PIPE,"-|") does an implicit fork() to create a child process
and creates a pipe.
*) In the parent process: Set file handle PIPE to read from the
child process. Return the pid of the child (which is nonzero).
*) In the parent process: The statement evaluates to
(a value which is true) || exec();
which means that the exec() part is not executed. Perl continues
with the next statement.
*) In the child process: TConnect the pipe to STDOUT.
The open() function returns false in the child.
*) In the child process: The statement evaluates to
(a value which is false) || exec();
which means the exec() function will be invoked. If the
exec() is successful, the rest of the perl program will not
be executed.
The key to understanding how open(FH,'-|') works is to first
understand how fork() returns two different values.
-Joe
------------------------------
Date: Wed, 06 Apr 2005 12:21:13 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Shell Commands (Getting PID and Timing Them)
Message-Id: <d30gc9$729$2@sun3.bham.ac.uk>
axel@white-eagle.invalid.uk wrote:
> my $pid = open (PIPE, "-|") || exec("/what/ever");
Why not just do it in one step?
my $pid = open (PIPE, '-|', '/what/ever')
or die "Whatever failed: $!";
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 7947
***************************************