[17808] in Perl-Users-Digest
Perl-Users Digest, Issue: 5228 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 4 15:56:14 2001
Date: Thu, 4 Jan 2001 12:55:58 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978641757-v9-i5228@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 4 Jan 2001 Volume: 9 Number: 5228
Today's topics:
DBD::mySQL richard_dobson@my-deja.com
Re: DBD::mySQL <hmerrill@my-deja.com>
Re: DBD::mySQL <fty@mediapulse.com>
Re: DBIProxy question <loy_x@yahoo.com>
Re: DBIProxy question <loy_x@yahoo.com>
DNS Address <carlo@netverk.net>
Re: DNS Address (Rafael Garcia-Suarez)
Re: DNS Address (Garry Williams)
dumb newbie <choate@spot.colorado.edu>
Re: dumb newbie <variant@shell.pacifier.com>
Re: dumb newbie (Richard Zilavec)
Re: dumb newbie <newsonly@please.com>
Re: dumb newbie <bart.lateur@skynet.be>
Emacs modules for Perl programming (Jari Aalto+mail.perl)
error message of glob function <wsoto@my-deja.com>
Re: Extract the nth word from a line <rick.delaney@home.com>
Re: FAQ 6.11: Can I use Perl regular expressions to m <brannon@lnc.usc.edu>
Re: FAQ 6.11: Can I use Perl regular expressions to m (Chris Fedde)
Re: FAQ 6.11: Can I use Perl regular expressions to m <uri@sysarch.com>
Re: FAQ 6.21: What's wrong with using grep or map in (Eric Bohlman)
Re: FAQ 6.21: What's wrong with using grep or map in <joe+usenet@sunstarsys.com>
Re: FAQ 6.21: What's wrong with using grep or map in <joe+usenet@sunstarsys.com>
Re: FAQ 6.21: What's wrong with using grep or map in (Martien Verbruggen)
Re: FAQ 6.5: How do I substitute case insensitively o (Chris Fedde)
Re: FAQ 7.14: How can I pass/return a {Function, File <kapur@mts.jhu.edu>
Re: FAQ 7.14: How can I pass/return a {Function, File <uri@sysarch.com>
Re: FAQ 7.8: How do I declare/create a structure? (Victor Eijkhout)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 03 Jan 2001 10:21:22 GMT
From: richard_dobson@my-deja.com
Subject: DBD::mySQL
Message-Id: <92uuev$nut$1@nnrp1.deja.com>
Hi,
quick question. If I have a perl cgi script that connects to a mySQL
database in the following fashion:
$dbh = DBI->connect
("DBI:mysql:database=orders;host=localhost", "username", "password");
Am I going to get problems if a number of people run the script at the
same time and try and insert data into the database?
Thanks in advance
Richard
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 03 Jan 2001 13:00:00 GMT
From: Hardy Merrill <hmerrill@my-deja.com>
Subject: Re: DBD::mySQL
Message-Id: <92v7of$ubi$1@nnrp1.deja.com>
In article <92uuev$nut$1@nnrp1.deja.com>,
richard_dobson@my-deja.com wrote:
> Hi,
> quick question. If I have a perl cgi script that connects to a mySQL
> database in the following fashion:
>
> $dbh = DBI->connect
> ("DBI:mysql:database=orders;host=localhost", "username", "password");
>
> Am I going to get problems if a number of people run the script at the
> same time and try and insert data into the database?
I'm not a MySQL expert, but I don't think you need to worry about
conflicting updates - MySQL takes care of coordinating(with locking) the
updates of different users so you don't have to worry about it.
You should consider getting yourself a good MySQL book, and a good Perl
DBI Book - the "Programming the Perl DBI" book by Descartes & Bunce is
an excellent(in my opinion) Perl DBI book, and it has a section towards
the back that details the particulars of each database - MySQL is in
that section. Here's a quote from p.285(the section on DBD::mysql and
DBD::mSQL on "Transactions, Isolation, and Locking":
Both mSQL and MySQL do not support transactions.
Since both mSQL and MySQL currently execute statements from multiple
clients one at a time(atomic), and don't support transactions,
there's no need for a default locking behavior to protect
transaction isolation.
HTH.
Hardy Merrill
Mission Critical Linux, Inc.
http://www.missioncriticallinux.com
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 03 Jan 2001 14:41:13 GMT
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: DBD::mySQL
Message-Id: <dSG46.196406$DG3.4431369@news2.giganews.com>
"Hardy Merrill" <hmerrill@my-deja.com> wrote in message
news:92v7of$ubi$1@nnrp1.deja.com...
> In article <92uuev$nut$1@nnrp1.deja.com>,
> richard_dobson@my-deja.com wrote:
>
> You should consider getting yourself a good MySQL book, and a good Perl
> DBI Book - the "Programming the Perl DBI" book by Descartes & Bunce is
> an excellent(in my opinion) Perl DBI book, and it has a section towards
> the back that details the particulars of each database - MySQL is in
> that section. Here's a quote from p.285(the section on DBD::mysql and
> DBD::mSQL on "Transactions, Isolation, and Locking":
>
> Both mSQL and MySQL do not support transactions.
>
> Since both mSQL and MySQL currently execute statements from multiple
> clients one at a time(atomic), and don't support transactions,
> there's no need for a default locking behavior to protect
> transaction isolation.
mySQL has supported transactions since 05/09/2000 (ver. 3.23.15) using
Berkeley DB (current version 3.23.29a-gamma). There is also excellent online
docs for mySQL (http://www.mysql.com/documentation/)
and excellent module docs (perldoc DBI, perldoc DBD::mysql)
jay
--
###############################
Take care of your shoes...jay
Jay Flaherty fty@mediapulse.com
Mediapulse, Inc. -The pulse of your eBusiness
------------------------------
Date: Wed, 03 Jan 2001 13:11:41 -0800
From: news <loy_x@yahoo.com>
Subject: Re: DBIProxy question
Message-Id: <3A53958D.45519345@yahoo.com>
> Is it OK that new child is started in single mode?
What do you mean? I said I still get the same error on the client side. It
doesn't work.
------------------------------
Date: Wed, 03 Jan 2001 18:50:25 -0800
From: news <loy_x@yahoo.com>
Subject: Re: DBIProxy question
Message-Id: <3A53E4F1.4DB6B555@yahoo.com>
Nevermind, I found the problem. Although, in fork mode, the proxy server
still crashes after the first connect and disconnect. I don't know anything
about NT/win2K, is it likely that my machine cannot fork processes?
------------------------------
Date: Thu, 4 Jan 2001 11:14:56 -0000
From: "carlo costa" <carlo@netverk.net>
Subject: DNS Address
Message-Id: <3a54cbb8.0@news.isholf.is>
Hi there,
I am sure that there is someone so nice to tel me
"How can I get (in a perl program ) the address of the DNS that I am using
?"
Thank you
B.R.
Carlo
------------------------------
Date: Thu, 04 Jan 2001 12:40:07 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: DNS Address
Message-Id: <slrn958rm2.c8n.rgarciasuarez@rafael.kazibao.net>
carlo costa wrote in comp.lang.perl.misc:
> Hi there,
>
> I am sure that there is someone so nice to tel me
>
> "How can I get (in a perl program ) the address of the DNS that I am using
> ?"
Yes, and this guy is called "perldoc -q hostname".
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Thu, 04 Jan 2001 13:33:35 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: DNS Address
Message-Id: <PY_46.179$xb2.10019@eagle.america.net>
On Thu, 04 Jan 2001 12:40:07 GMT, Rafael Garcia-Suarez
<rgarciasuarez@free.fr> wrote:
>carlo costa wrote in comp.lang.perl.misc:
>> I am sure that there is someone so nice to tel me
>>
>> "How can I get (in a perl program ) the address of the DNS that I am using
>> ?"
>
>Yes, and this guy is called "perldoc -q hostname".
It's not entirely clear but what the OP probably wants is the IP
address of his resolving name server which isn't necessarily his own
host. If so, the Net::DNS module can help. The IP addresses of the
default resolvers are available from $res->nameservers() where $res is
a reference to a Net::DNS::Resolver object. (See the
Net::DNS::Resolver manual page.)
Of course, if the host is a Unix host, it's probably a lot easier to
read /etc/resolv.conf instead. (See resolv.conf(4).)
--
Garry Williams
------------------------------
Date: Tue, 2 Jan 2001 17:29:32 -0700
From: "Phyllis Choate" <choate@spot.colorado.edu>
Subject: dumb newbie
Message-Id: <92trsl$p3i$1@peabody.colorado.edu>
I can't get a cgi script to return data in html. could use alittle help.
------------------------------
Date: 2 Jan 2001 16:57:33 PDT
From: Jason Hurst <variant@shell.pacifier.com>
Subject: Re: dumb newbie
Message-Id: <3a5278fd_1@news.pacifier.com>
Phyllis Choate <choate@spot.colorado.edu> wrote:
> I can't get a cgi script to return data in html. could use alittle help.
If the script is producing output on the command line, there are two
things you should check.
1. make sure you have your #!/usr/bin/perl (unless your running iis, your
scripts will need this, and even if you are its good practice to get
into).
2. make sure you've got: print "content-type:text/html\n\n";
which tells the server what its doing.
hope this helps.
Might be able to give more information if you provided an error message..?
-jason
------------------------------
Date: Wed, 03 Jan 2001 05:40:27 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: dumb newbie
Message-Id: <3a52bad0.1549928@news.tcn.net>
On Tue, 2 Jan 2001 17:29:32 -0700, "Phyllis Choate"
<choate@spot.colorado.edu> wrote:
>I can't get a cgi script to return data in html. could use alittle help.
Can you post the code you think is failing and the error you are
receiving.
--
Richard Zilavec
rzilavec@tcn.net
------------------------------
Date: 03 Jan 2001 07:32:48 GMT
From: "David Cunningham" <newsonly@please.com>
Subject: Re: dumb newbie
Message-Id: <92ukj0$fkd@dispatch.concentric.net>
What happens when you run the script from the command line?
"Phyllis Choate" <choate@spot.colorado.edu> wrote in message
news:92trsl$p3i$1@peabody.colorado.edu...
> I can't get a cgi script to return data in html. could use alittle help.
>
>
------------------------------
Date: Wed, 03 Jan 2001 14:58:28 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: dumb newbie
Message-Id: <47f65t0g69h739nrs64qgfhdb75utbr5vd@4ax.com>
Phyllis Choate wrote:
>I can't get a cgi script to return data in html. could use alittle help.
Check out the "Idiot's Guide to CGI Programming", and make sure that you
take care of every remark.
<http://www.cpan.org/doc/FAQs/cgi/idiots-guide.html>
--
Bart.
------------------------------
Date: 04 Jan 2001 11:16:25 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_978606925@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs
XEmacs/Emacs, is available to various platforms:
o Unix:
If you don't have one, bust your sysadm.
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
Emacs resources at http://home.eu.org/~jari/emacs-elisp.html
o W9x/NT:
http://www.gnu.org/software/emacs/windows/ntemacs.html
Emacs Perl Modules
Cperl -- Perl programming mode
.ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
.<olson@mcs.anl.gov> Bob Olson (started 1991)
.<ilya@math.ohio-state.edu> Ilya Zakharevich
Major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
starndard in newest Emacs.
TinyPerl -- Perl related utilities
.http://home.eu.org/~jari/tiny-tools-beta.zip
.http://home.eu.org/~jari/emacs-tiny-tools.html
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Load source code into Emacs, like Devel::DProf.pm
o Grep through all Perl manpages (.pod)
o Follow POD manpage references to next pod page with TinyUrl
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o TinyUrl is used to jump to URLs (other pod pages, man pages etc)
mentioned in POD pages. (It's a general URL minor mode)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in the tgz mentioned above]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example in the tgz (ema-tigr.ini) that shows
how to set up datatbases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to run the find for you, You can adjust
recursive grep options, ignored case, add user grep options.
You can get `igrep.el' module from <kevinr@ihs.com>. Ask for copy.
Check also ftp://ftp.ihs.com/pub/kevinr/
TinyCompile -- Browsing grep results in Emacs *compile* buffer
TinyCompile is minor mode for *compile* buffer from where
you can collapse unwanted lines, shorten the file URLs
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: Wed, 03 Jan 2001 18:08:22 GMT
From: Walter Soto Encinas Jr <wsoto@my-deja.com>
Subject: error message of glob function
Message-Id: <92vpqe$elc$1@nnrp1.deja.com>
Hello
I am using the glob funtion to get a list of files that match some
patterns, like:
@files = glob("/home/soto/testbench/*/*.v")
When the directory tree not matches the pattern, this error message is
generated by perl:
nolink.pl line
216, <_GEN_0> chunk 4
How to avoid this error messages? Is there any way to check if the
directory tree matches pattern before perl generates the error message.
Or, at least, a way to omit the error message to check the result of
glob execution? Observe these patterns are hierarchical, therfore glob
couldn't be esasily replaced by a readdir.
Thanks in advance
--
Walter Soto Encinas Jr
IC Designer
Brazil
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sat, 30 Dec 2000 00:13:08 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Extract the nth word from a line
Message-Id: <3A4D2C47.8F80E537@home.com>
Jerome Abela wrote:
>
> //g keeps track of its position. If you repeat this code twice without
> 'last', it will work. If you 'last' out of the loop before //g fails, it
> will display the 6th fish instead of the 3rd on the second run.
Assuming there are at least 6 fish.
> Without 'last', the code always works, but with 'last' its behaviour
> depends on its context, which is bad.
Without 'last', you churn through data you're not interested in. With
'last' you stop when you're done. It is trivial to prevent the
situation you mention while retaining the benefit of quitting the loop
early.
while (/(\w+)\s+fish\b/gi) {
if (++$count == $WANT) {
print "The third fish is a $1 one.\n";
pos = 0;
last;
}
}
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Mon, 01 Jan 2001 04:31:16 GMT
From: Terrence Brannon <brannon@lnc.usc.edu>
Subject: Re: FAQ 6.11: Can I use Perl regular expressions to match balanced text?
Message-Id: <lbsnn3q4ff.fsf@lnc.usc.edu>
this doesnt recommend Text::Balanced
> This message is one of several periodic postings to comp.lang.perl.misc
> intended to make it easier for perl programmers to find answers to
> common questions. The core of this message represents an excerpt
> from the documentation provided with every Standard Distribution of
> Perl.
>
> +
> Can I use Perl regular expressions to match balanced text?
>
> Although Perl regular expressions are more powerful than "mathematical"
> regular expressions, because they feature conveniences like
> backreferences (`\1' and its ilk), they still aren't powerful enough --
> with the possible exception of bizarre and experimental features in the
> development-track releases of Perl. You still need to use non-regex
> techniques to parse balanced text, such as the text enclosed between
> matching parentheses or braces, for example.
>
> An elaborate subroutine (for 7-bit ASCII only) to pull out balanced and
> possibly nested single chars, like ``' and `'', `{' and `}', or `(' and
> `)' can be found in
> http://www.perl.com/CPAN/authors/id/TOMC/scripts/pull_quotes.gz .
>
> The C::Scan module from CPAN contains such subs for internal usage, but
> they are undocumented.
>
> -
>
> Documents such as this have been called "Answers to Frequently
> Asked Questions" or FAQ for short. They represent an important
> part of the Usenet tradition. They serve to reduce the volume of
> redundant traffic on a news group by providing quality answers to
> questions that keep comming up. If you are some how irritated by
> seeing these postings you are free to ignore them or add the sender
> to your killfile. If you find errors or other problems with these
> postings please send corrections or comments to the posting email
> address.
>
> If you are not able to find this or other Perl documentation from
> your installation you may access it via the web by following the
> appropriate links from one of the addresses listed below.
>
> http://theoryx5.uwinnipeg.ca/mod_perl/cpan-search
> http://www.perldoc.com
> http://www.cpan.org
> http://www.perl.com
>
> Answers to questions about LOTS of other stuff, mostly not related to
> Perl, can be found at
>
> news:news.answers
>
> and in the many thousands of other useful Usenet news groups.
>
> The perlfaq manual pages contain the following copyright notice.
>
> AUTHOR AND COPYRIGHT
>
> Copyright (c) 1997-1999 Tom Christiansen and Nathan
> Torkington. All rights reserved.
>
> When included as an integrated part of the Standard
> Distribution of Perl or of its documentation (printed or
> otherwise), this work is covered under Perl's Artistic
> License. For separate distributions of all or part of
> this FAQ outside of that, see the perlfaq manpage.
>
> Irrespective of its distribution, all code examples here
> are public domain. You are permitted and encouraged to
> use this code and any derivatives thereof in your own
> programs for fun or for profit as you see fit. A simple
> comment in the code giving credit to the FAQ would be
> courteous but is not required.
>
> --
> This space intentionally left blank
--
Terrence Brannon
Carter's Compass...
I know I'm on the right track when by deleting code I'm adding
functionality.
------------------------------
Date: Mon, 01 Jan 2001 05:34:49 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: FAQ 6.11: Can I use Perl regular expressions to match balanced text?
Message-Id: <ZFU36.554$B9.190377472@news.frii.net>
In article <lbsnn3q4ff.fsf@lnc.usc.edu>,
Terrence Brannon <brannon@lnc.usc.edu> wrote:
>this doesnt recommend Text::Balanced
>
>> +
>> Can I use Perl regular expressions to match balanced text?
>>
Write up changes to the perlfaq6.pod and mail the diffs to
perlfaq-suggestions@perl.com
thanks
chris
--
This space intentionally left blank
------------------------------
Date: Mon, 01 Jan 2001 06:13:13 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: FAQ 6.11: Can I use Perl regular expressions to match balanced text?
Message-Id: <x7ae9bajgo.fsf@home.sysarch.com>
>>>>> "CF" == Chris Fedde <cfedde@fedde.littleton.co.us> writes:
CF> In article <lbsnn3q4ff.fsf@lnc.usc.edu>,
CF> Terrence Brannon <brannon@lnc.usc.edu> wrote:
>> this doesnt recommend Text::Balanced
>>
>>> +
>>> Can I use Perl regular expressions to match balanced text?
>>>
CF> Write up changes to the perlfaq6.pod and mail the diffs to
CF> perlfaq-suggestions@perl.com
<to the OP)
and don't jeopardy quote the entire faq for a one line comment. that is also
the worst quoting ratio you can have. a simple one line post CC'ed to
the poster would suffice.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 30 Dec 2000 16:40:21 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: FAQ 6.21: What's wrong with using grep or map in a void context?
Message-Id: <92l35l$d8o$1@bob.news.rcn.net>
John Lin <johnlin@chttl.com.tw> wrote:
> "Bart Lateur" wrote:
>> map() and grep() are not loops. They do something to each item, but
>> theoretically there's no garantee that it will be in the "natural"
>> order. Execution order might just as well be shuffled.
> I doubt that. If the execution order is not defined, the operation would
> have different possible results, which is difficult to use.
> grep /^b/,'good','better','best';
> could returns
> ('better','best') or ('best','better')
> map {$_? ('a','b'): 'c'} 0,1;
> could returns
> ('c','a','b') or ('a','b','c')
Not necessarily. There's no reason why the *return* order, which as you
point out needs to be defined, has to correspond to the *execution*
order. In principle, grep or map could evaluate its arguments in reverse
order and prepend the results to its output list.
------------------------------
Date: 30 Dec 2000 13:06:45 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: FAQ 6.21: What's wrong with using grep or map in a void context?
Message-Id: <m3zohd6ax6.fsf@mumonkan.sunstarsys.com>
ebohlman@omsdev.com (Eric Bohlman) writes:
> John Lin <johnlin@chttl.com.tw> wrote:
> > "Bart Lateur" wrote:
>
> >> map() and grep() are not loops. They do something to each item, but
> >> theoretically there's no garantee that it will be in the "natural"
> >> order. Execution order might just as well be shuffled.
>
> > I doubt that. If the execution order is not defined, the operation would
> > have different possible results, which is difficult to use.
>
> > grep /^b/,'good','better','best';
> > could returns
> > ('better','best') or ('best','better')
>
> > map {$_? ('a','b'): 'c'} 0,1;
> > could returns
> > ('c','a','b') or ('a','b','c')
>
> Not necessarily. There's no reason why the *return* order, which as you
> point out needs to be defined, has to correspond to the *execution*
> order. In principle, grep or map could evaluate its arguments in reverse
> order and prepend the results to its output list.
>
To clarify ?
map(`cd $_`, split |/|, "relative/path/to/deep/directory") ;
@array = (1,2);
@array = map { $_ + shift(@array) } @array;
Although these will (currently) do what you want,
the documentation for map & grep does cover this
type of usage. Indeed, under certain circumstances,
it might be preferable for the implementors of map &
grep to construct the output list in a "non-natural"
order (as you point out).
--
Joe Schaefer
------------------------------
Date: 30 Dec 2000 13:08:50 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: FAQ 6.21: What's wrong with using grep or map in a void context?
Message-Id: <m3u27l6atp.fsf@mumonkan.sunstarsys.com>
Joe Schaefer <joe+usenet@sunstarsys.com> writes:
>
> To clarify ?
>
> map(`cd $_`, split |/|, "relative/path/to/deep/directory") ;
>
> @array = (1,2);
> @array = map { $_ + shift(@array) } @array;
>
> Although these will (currently) do what you want,
> the documentation for map & grep does cover this
^
NOT !
> type of usage. Indeed, under certain circumstances,
> it might be preferable for the implementors of map &
> grep to construct the output list in a "non-natural"
> order (as you point out).
Sorry about that!
--
Joe Schaefer
------------------------------
Date: Sun, 31 Dec 2000 11:51:21 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: FAQ 6.21: What's wrong with using grep or map in a void context?
Message-Id: <slrn94t0o9.6lr.mgjv@martien.heliotrope.home>
On 30 Dec 2000 13:08:50 -0500,
Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
> Joe Schaefer <joe+usenet@sunstarsys.com> writes:
>
>>
>> To clarify ?
>>
>> map(`cd $_`, split |/|, "relative/path/to/deep/directory") ;
>>
>> @array = (1,2);
>> @array = map { $_ + shift(@array) } @array;
>>
>> Although these will (currently) do what you want,
>> the documentation for map & grep does cover this
> ^
> NOT !
>> type of usage. Indeed, under certain circumstances,
>> it might be preferable for the implementors of map &
>> grep to construct the output list in a "non-natural"
>> order (as you point out).
There have been discussions about this in the past. Since Perl is not a
formal language, and has no formal language specification, it isn't
really valid to say that something that isn't documented can therefore
just change. The specification for Perl exists both as the
documentation, and as the implementation. If perl does things certain
ways, in many cases that is seen to be as valid a specification as the
more formal documented features. Especially things that perl does in a
certain way right now, and that can have side effects, are very unlikely
to ever change. If there is a reasonable chance that currently running
programs will break by changing behaviour in perl, there is a strong
drive to not change that behaviour. map() and grep() both can be used
with side-effects, since they accept a code block.
#!/usr/local/bin/perl -wl
use strict;
my (@a, @b, @c) = (1, 2, 3, 4);
@b = map { push @c, $_ } @a;
print join ":", @b;
print join ":", @c;
@b = @c = ();
@b = grep { push @c, $_ } @a;
print join ":", @b;
print join ":", @c;
__END__
1:2:3:4
1:2:3:4
1:2:3:4
1:2:3:4
Both map() and grep() evaluate their arguments, and process their
arguments in the order they go in. Any other order probably would be
less efficient anyway.
These two particular builtins are most unlikely to change, since they
have behaved like this for a long time, and changing their behaviour
would probably break many things.
If, on the other hand, Perl would be more formally specified, as has
been done for for example C, C++ and Java, then that documentation would
be the only source of information, and any implementation could choose
to implement any feature any way they liked, as long as it follows the
specification. If the spec would not talk about evaluation order of the
arguments to map, then the implementers are free to choose another
order. Since, however, there is only one implementation, and no formal
specification, the terms 'undefined behaviour', or 'unspecified
behaviour', or 'implementation-specific behaviour' just are not
relevant. The behaviour is as perl implements it, until there is a
formal specification. As long as there is no formal standard, perl is
authoritative.
However, as Abigail will testify, that doesn't guarantee that no
features or behaviour will ever change. It just makes it harder for the
implementers to change behaviour that is in use.
A formal standard for the language would be nice. It could be used to
resolve debates like this, just as any debate on C can be resolved by a
discussion of the wording in the standard (or not :)). I doubt it will
happen any time soon, though.
Martien
--
Martien Verbruggen |
Interactive Media Division | life ain't fair, but the root
Commercial Dynamics Pty. Ltd. | password helps. -- BOFH
NSW, Australia |
------------------------------
Date: Tue, 02 Jan 2001 00:04:47 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: FAQ 6.5: How do I substitute case insensitively on the LHS, but preserving case on the RHS?
Message-Id: <zW846.563$B9.189435904@news.frii.net>
In article <x7zohh9mmb.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "JL" == John Lin <johnlin@chttl.com.tw> writes:
>
> JL> s{(\Q$old\E)}
>
> do an email reply to the OP so that can get fixed.
>
I'm beginning to think that I should rephrase the preamble to the FAQ
section so that it recommends mailing fixes to the OP.
But, who am I kidding... Better to just follow the reply postings and
trap the results there.
chris
--
This space intentionally left blank
------------------------------
Date: 30 Dec 2000 02:37:55 -0500
From: Nevin Kapur <kapur@mts.jhu.edu>
Subject: Re: FAQ 7.14: How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?
Message-Id: <m3hf3mgy0c.fsf@fermat.mts.jhu.edu>
On Sat, 30 Dec 2000, PerlFAQ Server wrote:
> How can I pass/return a {Function, FileHandle, Array, Hash,
> Method, Regex}?
[...]
> If you're planning on generating new filehandles, you could
> do this:
>
> sub openit {
> my $name = shift;
> local *FH;
> return open (FH, $path) ? *FH : undef;
> }
> $fh = openit('< /etc/motd');
> print <$fh>;
>
Is there a typo in this code? The sub open it shifts $name and then
doesn't use it. It uses $path instead.
-Nevin
------------------------------
Date: Sat, 30 Dec 2000 22:19:37 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: FAQ 7.14: How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?
Message-Id: <x7ofxta6x2.fsf@home.sysarch.com>
>>>>> "NK" == Nevin Kapur <kapur@mts.jhu.edu> writes:
>>
>> sub openit {
>> my $name = shift;
>> local *FH;
>> return open (FH, $path) ? *FH : undef;
>> }
>> $fh = openit('< /etc/motd');
>> print <$fh>;
>>
NK> Is there a typo in this code? The sub open it shifts $name and then
NK> doesn't use it. It uses $path instead.
looks like one. email it back to the faqserver.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Thu, 4 Jan 2001 10:55:12 -0500
From: victor@eijkhout.net (Victor Eijkhout)
Subject: Re: FAQ 7.8: How do I declare/create a structure?
Message-Id: <1emphqr.14vdbth9fb0hsN%victor@eijkhout.net>
PerlFAQ Server <faq@denver.pm.org> wrote:
> How do I declare/create a structure?
>
> In general, you don't "declare" a structure. Just use a (probably
> anonymous) hash reference. See the perlref manpage and the perldsc
> manpage for details. Here's an example:
>
> $person = {}; # new anonymous hash
> $person->{AGE} = 24; # set field AGE to 24
> $person->{NAME} = "Nat"; # set field NAME to "Nat"
Why use a reference? What's the difference with just using a hash?
--
Victor Eijkhout
"the time comes for everyone to do deliberately what
he used to do by mistake" [Quentin Crisp]
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 5228
**************************************