[24409] in Perl-Users-Digest
Perl-Users Digest, Issue: 6597 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 22 14:05:41 2004
Date: Sat, 22 May 2004 11:05:06 -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 Sat, 22 May 2004 Volume: 10 Number: 6597
Today's topics:
Re: 2-1/2 regexp questions <mgjv@tradingpost.com.au>
Re: 2-1/2 regexp questions <jkrugman345@yahbitoo.com>
HTML form to MS Access? <jm@home.com>
Join-command misuse ? (Alexander Oberhuber)
Re: Join-command misuse ? <nospam@bigpond.com>
Re: Join-command misuse ? (Anno Siegel)
Re: Join-command misuse ? <perl@my-header.org>
output data to audio (Alx)
Re: Password scheme/Persistent session... (krakle)
Re: Password scheme/Persistent session... (Anno Siegel)
Re: Password scheme/Persistent session... (krakle)
Re: Password scheme/Persistent session... (krakle)
Re: Password scheme/Persistent session... <jurgenex@hotmail.com>
Re: Perl vs PHP <perl@my-header.org>
Re: Perl vs PHP <perl@my-header.org>
Re: Perl vs PHP <usenet@morrow.me.uk>
Re: Perl vs PHP (krakle)
Re: Perl work? (krakle)
Re: Problem installing modules <tpsX@vr-web.de>
Re: Sockets: receiving data <someone@somewhere.com>
Re: String search/match question (Anno Siegel)
Re: String search/match question (Kevin Potter)
When is $#- != $#+ ? When is $-[$i] undef ? <nomail_please@nomail.org>
Re: When is $#- != $#+ ? When is $-[$i] undef ? <rwxr-xr-x@gmx.de>
Re: When is $#- != $#+ ? When is $-[$i] undef ? <usenet@morrow.me.uk>
Re: When is $#- != $#+ ? When is $-[$i] undef ? (Jay Tilton)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 22 May 2004 17:55:39 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: 2-1/2 regexp questions
Message-Id: <slrncau1rr.nqd.mgjv@martien.heliotrope.home>
On Sat, 22 May 2004 01:07:37 +0000 (UTC),
Irving Kimura <nomail_please@nomail.org> wrote:
>
>
> In <slrncaskp3.ct.abigail@alexandra.abigail.nl> Abigail <abigail@abigail.nl> writes:
>> my $re = qr /($r)(?{print "(", $- [-1], ", ", $+ [-1] - $- [-1], ")",
>> " --> '$^N'\n"})(?!)/;
>
> I assume that "$- [-1]" and "$+ [-1]" refer to elements of some
> special arrays @- and @+ , but I have not been able to find anything
> on these arrays by grepping through the online documentation.
>
> Where in the Perl documentation are @- and @+ explained?
All special variables are documented in the perlvar documentation; this
includes @- and @+.
Martien
--
|
Martien Verbruggen | There are only 10 types of people in the
| world; those who understand binary and those
| who don't.
------------------------------
Date: Sat, 22 May 2004 17:29:46 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Re: 2-1/2 regexp questions
Message-Id: <c8o2ma$b52$1@reader2.panix.com>
First I want to give thanks for all the great replies to my post;
I learned a lot from them. (Not least of them being that, even
though once upon a time a slogged through the 2nd Edition of
Programming Perl, I really should slog through the 3rd Edition.
Too bad O'Reilly never published a Delta edition.)
In <slrncaskp3.ct.abigail@alexandra.abigail.nl> Abigail <abigail@abigail.nl> writes:
> use re 'eval';
> my $s = '1a21b4xy';
> my $r = '\d+';
> my $re = qr /($r)(?{print "(", $- [-1], ", ", $+ [-1] - $- [-1], ")",
> " --> '$^N'\n"})(?!)/;
> $s =~ $re;
I realize that the (?!) at the end of $re's definition is necessary
to get the right results, but I don't understand why. I figure it
has to do with getting the regexp engine to move to the right state,
but I really have no clue...
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: Sat, 22 May 2004 17:47:21 GMT
From: "Jason Miles" <jm@home.com>
Subject: HTML form to MS Access?
Message-Id: <JmMrc.105007$0qd.39215@twister01.bloor.is.net.cable.rogers.com>
Hi,
I have a site which uses a form. I would like to be able to export the data
from the form to MS Access. Some of the fields may contain commas, which I
think may be a problem.
Can someone show me how to take the info from the form and export it to MS
Access?
Thanks,
Jason
------------------------------
Date: Sat, 22 May 2004 09:35:02 GMT
From: aloh@x-mail.net (Alexander Oberhuber)
Subject: Join-command misuse ?
Message-Id: <a9Frc.146594$O9.122052@news.chello.at>
Hello World :-)
I just digged some interesting Perl code and would like to know wheter you
consider this a kosher programming or not:
open file, $f_in;
binmode file;
$data = join("", <file>);
close file;
Interesting use of using "join" to read a file, isn't it?
How would one do this more properly? "-s" to get filesize and READ whole file
in a buffer, I suppose?
Does this code work automagically on (nightmare!) all sort of hardware
architectures (32bit, 16bit, LSB/MSB bytes etc.)?
------------------------------
Date: Sat, 22 May 2004 20:02:39 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Join-command misuse ?
Message-Id: <1410694.TCaMDS1Qca@GMT-hosting-and-pickle-farming>
Alexander Oberhuber wrote:
> Hello World :-)
>
> I just digged some interesting Perl code and would like to know wheter you
> consider this a kosher programming or not:
>
> open file, $f_in;
> binmode file;
> $data = join("", <file>);
> close file;
>
> Interesting use of using "join" to read a file, isn't it?
> How would one do this more properly? "-s" to get filesize and READ whole
> file in a buffer, I suppose?
> Does this code work automagically on (nightmare!) all sort of hardware
> architectures (32bit, 16bit, LSB/MSB bytes etc.)?
Nothing unusual. <file> as an rvalue slurps the file into an array.
functional composition with join just concatenates the array elements.
gtoomey
------------------------------
Date: 22 May 2004 10:42:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Join-command misuse ?
Message-Id: <c8napr$kh2$1@mamenchi.zrz.TU-Berlin.DE>
Gregory Toomey <nospam@bigpond.com> wrote in comp.lang.perl.misc:
> Alexander Oberhuber wrote:
>
> > Hello World :-)
> >
> > I just digged some interesting Perl code and would like to know wheter you
> > consider this a kosher programming or not:
> >
> > open file, $f_in;
> > binmode file;
> > $data = join("", <file>);
> > close file;
> >
> > Interesting use of using "join" to read a file, isn't it?
> > How would one do this more properly? "-s" to get filesize and READ whole
> > file in a buffer, I suppose?
> > Does this code work automagically on (nightmare!) all sort of hardware
> > architectures (32bit, 16bit, LSB/MSB bytes etc.)?
>
> Nothing unusual. <file> as an rvalue slurps the file into an array.
> functional composition with join just concatenates the array elements.
It may not be unusual, but it isn't the most economic way to slurp a
file. "<file>" in list context reads the contents into a list of
lines, then "join" packs them together in a single string. So the
file content is held in memory twice.
OP has hinted at a different approach: "read( file, $buffer, -s file)"
reads the contents directly, but this fails when the file is a pipe or
terminal or anything that doesn't have a size.
The most common idiom is probably "do { local $/; <file> }", which locally
undefines the input record terminator, so the next "line" goes all the
way to eof.
There is also a module on CPAN that handles file slurping, unsurprisingly
called File::Slurp.
Anno
------------------------------
Date: Sat, 22 May 2004 12:52:50 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: Join-command misuse ?
Message-Id: <tkbua0l835eg8alsii9i7n7lt1tb0452m5@4ax.com>
X-Ftn-To: Alexander Oberhuber
aloh@x-mail.net (Alexander Oberhuber) wrote:
>I just digged some interesting Perl code and would like to know wheter you
>consider this a kosher programming or not:
>
>open file, $f_in;
>binmode file;
>$data = join("", <file>);
>close file;
>
>Interesting use of using "join" to read a file, isn't it?
>How would one do this more properly? "-s" to get filesize and READ whole file
>in a buffer, I suppose?
You can tell perl to slurp whole file at once if you set global $/ to undef,
my $data;
{ local $/; $data = <FILE> }
You can change $/ to anything you like,
{
local $/ = '<!--separator-->';
#get all records and erase trailing separator
chomp(my @records = <FILE>);
}
--
Secure and instant E-pay for web shops
http://www.ouroboros.hr/?e-placanje
------------------------------
Date: 22 May 2004 09:51:13 -0700
From: nenamiele@libero.it (Alx)
Subject: output data to audio
Message-Id: <38d4c7d4.0405220851.3b8921@posting.google.com>
I was playing around yesterday, and I came out with a Perlish version
of a simple Cellular Automata.
Apart from visualizing the result (thank you, GD), I wanted to
"listen" the result of the evolution of the automata as an audio file.
After a day browsing CPAN, I say that I'm a little disappointed: I
didn't find any <simple> way to output data (e.g. some @CA=(numbers,
numbers, numbers,...) in .wav or other format.
Yes, there is a ton of Audio::... modules.
Yes, there are Audio::Wav and Audio::Data.
Yet, for a simple layman as me who does not recognize a bitrate from
some other beast, the docs of those modules are really hard to master.
Do you know of some other way to do it?
Thanks!
Alessandro Magni
------------------------------
Date: 21 May 2004 21:53:13 -0700
From: krakle@visto.com (krakle)
Subject: Re: Password scheme/Persistent session...
Message-Id: <237aaff8.0405212053.296e7c2e@posting.google.com>
Jim Gibson <jgibson@mail.arc.nasa.gov> wrote in message news:<210520041247195176%jgibson@mail.arc.nasa.gov>...
> In article <237aaff8.0405202019.6ffc3e47@posting.google.com>, krakle
> <krakle@visto.com> wrote:
>
> > "John W. Kennedy" <jwkenne@attglobal.net> wrote in message
> > news:<_55rc.106204$MH.21799388@news4.srv.hcvlny.cv.net>...
> > > krakle wrote:
> > > > The question IS ontopic to this group.
> > >
> > > No, it is not. You are asking a question about how the web works, not
> > > how Perl works.
> >
> > I never asked how the web works or any sort of question to that
> > nature. It was a question pertaining to sessions in mod_perl. Yes it
> > will be used for a web site obviously but it DOESN'T make sense to ask
> > a PERL question in a regular newsgroup dealing with the web that
> > doesn't relate to PERL... Why is this so hard for you guys to
> > understand...
>
> Because we are morons.
So it seems!
------------------------------
Date: 22 May 2004 08:28:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Password scheme/Persistent session...
Message-Id: <c8n2vs$g10$1@mamenchi.zrz.TU-Berlin.DE>
krakle <krakle@visto.com> wrote in comp.lang.perl.misc:
> "John W. Kennedy" <jwkenne@attglobal.net> wrote in message
> news:<G0rrc.9423$cz5.1816627@news4.srv.hcvlny.cv.net>...
> > We understand perfectly. You are asking a question about how the web
> > works in a Perl group.
>
> OR I asked how can you mantain state in Perl to make a session with
> out the use of cookies. That's not a question asking how the web
> works. It's a Perl question. To say such a thing just proves your
> ignorance after I repeatedly asked the question. Wow...unbelievable.
Well, Krakle, it looks like you and clpm just don't go together.
Remember your last stint? I do, and it was a shouting match quite
indistinguishable from this one.
So this place is full of idiots who don't know what Perl is and
what it isn't. Draw your conclusions and go away. AND STAY AWAY!
Anno
------------------------------
Date: 22 May 2004 08:39:13 -0700
From: krakle@visto.com (krakle)
Subject: Re: Password scheme/Persistent session...
Message-Id: <237aaff8.0405220739.70dd8a9f@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c8n2vs$g10$1@mamenchi.zrz.TU-Berlin.DE>...
> Well, Krakle, it looks like you and clpm just don't go together.
> Remember your last stint? I do, and it was a shouting match quite
> indistinguishable from this one.
I don't remember such a thing...
>
> So this place is full of idiots who don't know what Perl is and
> what it isn't. Draw your conclusions and go away. AND STAY AWAY!
I'm here to stay. Have been for the last 4 years. So why should I stay
away? One thing this newsgroup has to learn is you can scream "This
post doesn't belong in this group" to EVERY question. You can also
redirect them to another newsgroup where you will get the same
response. That's usenet for you. 1 person helps you and 25 write books
on how they won't waste their keystrokes on helping you...
I just find it humorous that if my single post was indeed offtopic
then what do you call the 30 something replies (such as your post)...
On topic? :)
------------------------------
Date: 22 May 2004 08:42:58 -0700
From: krakle@visto.com (krakle)
Subject: Re: Password scheme/Persistent session...
Message-Id: <237aaff8.0405220742.12678da4@posting.google.com>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message news:<rRxrc.3090$ZQ.411@nwrddc03.gnilink.net>...
> Again: Perl has states, Perl maintains the program state during program
> execution, there are many ways to preserve the state of a Perl program
> between different program executions. None of this has anything to do with
> your problem, YOU DO NOT HAVE A PERL PROBLEM.
None of that had anything to do with my question. Not only did you
waste your keystrokes and valuable(?) time but you went offtopic...
Let's see if we can get 25 more people to write books on why my post
was offtopic. This makes this whole group look like fools.
------------------------------
Date: Sat, 22 May 2004 17:48:12 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Password scheme/Persistent session...
Message-Id: <wnMrc.5395$No1.237@nwrddc02.gnilink.net>
krakle wrote:
> Let's see if we can get 25 more people to write books on why my post
> was offtopic. This makes this whole group look like fools.
I think this is the proto-typical definition of trolling.
Luckily there is an easy remedy:
*PLONK*
jue
------------------------------
Date: Sat, 22 May 2004 12:54:03 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: Perl vs PHP
Message-Id: <hl9ua0556tc4e3votgv3l7hfs8ioduu8hu@4ax.com>
X-Ftn-To: Jürgen Exner
"Jürgen Exner" <jurgenex@hotmail.com> wrote:
>>> It seems that CGI stands for many things, apples and oranges are
>> probably ok, but how one could describe a very common "CGI ==
>> perl_script"?
>
>How do you call the opposite of a tautology (i.e always false)?
A liar? :)
--
Secure and instant E-pay for web shops
http://www.ouroboros.hr/?e-placanje
------------------------------
Date: Sat, 22 May 2004 12:54:04 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: Perl vs PHP
Message-Id: <4p9ua094bm1upik9daj8cvqff1an59rmq2@4ax.com>
X-Ftn-To: Tad McClellan
Tad McClellan <tadmc@augustmail.com> wrote:
>>>somewhat off, as PHP is a programming language and CGI is an interface.
>>>Apples and oranges, you know. :-)
>>
>> It seems that CGI stands for many things, apples and oranges are probably
>> ok, but how one could describe a very common "CGI == perl_script"?
>
>I think many people use "CGI" as short for "CGI program", which
>many other people object to because then you are talking about
>the Interface rather than a program that conforms to the Interface.
Yes, and that comes very close to Pythons sketch where all man are called
Bruce, for some other name could bring confusion among them. ;)
--
Secure and instant E-pay for web shops
http://www.ouroboros.hr/?e-placanje
------------------------------
Date: Sat, 22 May 2004 13:09:38 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Perl vs PHP
Message-Id: <c8njei$rng$1@wisteria.csv.warwick.ac.uk>
Quoth Matija Papec <perl@my-header.org>:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote:
> >>>
> >>> It seems that CGI stands for many things, apples and oranges are
> >> probably ok, but how one could describe a very common "CGI ==
> >> perl_script"?
> >
> >How do you call the opposite of a tautology (i.e always false)?
>
> A liar? :)
A Cretan.
Epimenides ...err, Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces molit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: 22 May 2004 08:45:57 -0700
From: krakle@visto.com (krakle)
Subject: Re: Perl vs PHP
Message-Id: <237aaff8.0405220745.16f59f0d@posting.google.com>
"David H. Adler" <dha@panix2.panix.com> wrote in message news:<slrncasn5g.980.dha@panix2.panix.com>...
> On 2004-05-21, krakle <krakle@visto.com> wrote:
> >
> > If I had to start all over and select a language to learn from scratch
> > FOR the web I'd use PHP because 1. It's easier 2. More convienent and
> > 3. faster than CGI.
>
> For the sake of accuracy, I just want to point out that #3 seems
> somewhat off, as PHP is a programming language and CGI is an interface.
> Apples and oranges, you know. :-)
Since we are talking about Perl here I assumed the reader had enough
brains to figure out CGI in this case was programmed in Perl
(Obviously since this is PHP vs Perl). In this case yes PHP would be
faster.
------------------------------
Date: 22 May 2004 08:49:30 -0700
From: krakle@visto.com (krakle)
Subject: Re: Perl work?
Message-Id: <237aaff8.0405220749.2841ba62@posting.google.com>
John Bokma <postmaster@castleamber.com> wrote in message news:<40ad609d$0$201$58c7af7e@news.kabelfoon.nl>...
> I am looking for freelance Perl work. I already found jobs.perl.org. But
> I am wondering if there are more sites that list freelance perl projects.
>
> I did some Google searches, but only found bidding sites where people
> want a $5 / hour Perl programmer, and people offer to do it $ 2 / hour :-(
They are called bottom feeders. Usually teenage twips looking to make
a few bucks. Noone in their right mind should offer (or accept) a job
dealing with programming that pays $2-$5/hour. But if you pay burger
king money you get burger king work.
------------------------------
Date: Sat, 22 May 2004 14:22:52 +0200
From: Thomas Schweikle <tpsX@vr-web.de>
Subject: Re: Problem installing modules
Message-Id: <2h8v2bFa4ccrU1@uni-berlin.de>
J. Gleixner wrote:
> Can be found at http://theoryx5.uwinnipeg.ca/ppms/AppConfig.ppd
OK! Thanks! This worked. But now I am missing four additional packages:
CGI --- I need v2.93 the repository only has 2.81
Date::Format --- not found
Template --- not found
Chart::Base --- not found
Where can I find them, or, how can I build my own working ppm-module
installable via ActivePerl PPM?
--
Thomas
------------------------------
Date: Sat, 22 May 2004 07:58:44 GMT
From: "Bigus" <someone@somewhere.com>
Subject: Re: Sockets: receiving data
Message-Id: <39ee9c03a3a99dd4501c8c963726a4be@news.teranews.com>
"Jim Gibson" <jgibson@mail.arc.nasa.gov> wrote in message
news:210520041329166224%jgibson@mail.arc.nasa.gov...
> In article <c8kurh$169i@newton.cc.rl.ac.uk>, Bigus
> <someone@somewhere.com> wrote:
>
> > > > my $email = 'my@email.address'
> > >
> > > Missing semi-colon at the end of the line above. Is this the code you
> > > actually ran?
> >
> > No.. I had to change that line when copying it into the post, lest I be
> > spammed to eternity.
> >
> > > > my $cmd = "review LISTNAME msg pw=password";
> > > >
> > > > # --- Connect to Listserv --- #
> > > >
> > > > use IO::Socket;
> > > > my $lsv = IO::Socket::INET->new(
> > > > Proto => "tcp",
> > > > PeerAddr => "localhost",
> > > > PeerPort => '2306')
> > > > or die print "Connection problem :$!";
> > >
> > > You create a TCP socket here.
> > > ...
> > >
> > > > # send command header
> > > > print $lsv "1B".$bin;
> > > > recv($lsv, my $ans, 100, 0);
> > > > if($ans !~ /^250/){print "Failed because $ans\n"; exit;}
> > >
> > > recv is for UDP.
> >
> > Oh. Sounds kind of fudnamental.. it works for smaller amounts of data
> > though. The main reason I am using that is because there's an example
script
> > in C that does what I'm trying to do here. I don't understand half of
it,
> > but it does use the recv command and is definitely over TCP, since the
> > interface is called TCPGUI. Maybe C is different in the way it handles
> > sockets or something.
>
> Perl calls the socket functions in the C library for your platform, so
> the behavior should be the same. Perl recv calls C recvfrom, and is
> definitely a UDP function.
>
> Stick to the object-oriented versions of the socket functions. E.g.,
> use $lsv->recv(...) instead of recv(...) (although as you have
> discovered you should be using read instead of recv). You are calling
> the basic Perl recv function with a reference to an IO::Socket::INET
> object instead of a file handle as the first argument. That may or may
> not work.
OK, I've done that now. What's the advantage of referencing the object when
calling a function? Is it something to do with error-trapping?
Thanks
Bigus
------------------------------
Date: 22 May 2004 14:21:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: String search/match question
Message-Id: <c8nnkl$ran$1@mamenchi.zrz.TU-Berlin.DE>
Tore Aursand <tore@aursand.no> wrote in comp.lang.perl.misc:
> On Fri, 21 May 2004 13:12:09 -0700, Kevin Potter wrote:
> > The problem is, I need to find the first occurance of this character
> > that is not enclosed in brackets "[]" in this string.
>
> 1. Remove all the characters within brackets.
> 2. Use 'index'.
Removing won't do, you must replace them. Matija has proposed a a solution
based on that. One small but relevant problem is that we must use a
character other than the one we want to find. chr( ( 1 + ord $char) % 256)
should do, but it ain't pretty.
The standard solution is in the pertinent FAQ
How can I split a [character] delimited string except when inside
[character]?
found through "perldoc -q 'except'". It points to a number of modules,
most of them standard, that can be used.
For an ad-hoc solution, this may be one of the rare cases where
character-wise processing is indicated in Perl. It leads to simple
code that covers nested "[]":
$_ =
"abcdefg[extra]hijklmn[texas]opqrstuvwxYZabc[tex]defghijklmnopqrstuvwxyz";
my $char = 'x';
my ( $pos, $nest) = 0;
for ( split // ) {
$nest ++ if $_ eq '[';
$nest -- if $_ eq ']';
last if $_ eq $char and not $nest;
$pos ++;
}
print "$pos (", substr( $_, $pos), ")\n" if $pos < length;
I'd like to note that the seemingly random string "abcdefg[extra]hi..."
is a quite well thought-out bit of test data. It contains a few cases
of "[]"-enclosed "x", which helps explain the intent, as well as two
cases of un-enclosed "x". The one that matters is marked with the only
two upper-case letters, so it's easy to find. Otherwise, it is
uncluttered, the only non-alphabetics being the relevant "[]".
We get to see such a lot of ill-prepared test data, this seems worth
mentioning.
Anno
------------------------------
Date: 22 May 2004 09:11:26 -0700
From: krpotter@co.douglas.or.us (Kevin Potter)
Subject: Re: String search/match question
Message-Id: <64f69747.0405220811.1e1f2bb1@posting.google.com>
All EXCELLENT suggestions! Thanks for the help! This will get me going!
-Kevin-
------------------------------
Date: Sat, 22 May 2004 12:02:24 +0000 (UTC)
From: Irving Kimura <nomail_please@nomail.org>
Subject: When is $#- != $#+ ? When is $-[$i] undef ?
Message-Id: <c8nfgg$65s$1@reader2.panix.com>
The documentation for @- in perlvar says
One can use "$#-" to find the last matched subgroup in the last
successful match. Contrast with $#+, the number of subgroups
in the regular expression.
...which suggests that it is possible for $#- and $#+ to be different,
but I have not been able to produce an example in which they are
actually different. In fact, later in the documentation for @-,
perlvar says
After a match against some variable $var:
$` is the same as "substr($var, 0, $-[0])"
$& is the same as "substr($var, $-[0], $+[0] - $-[0])"
$' is the same as "substr($var, $+[0])"
$1 is the same as "substr($var, $-[1], $+[1] - $-[1])"
$2 is the same as "substr($var, $-[2], $+[2] - $-[2])"
$3 is the same as "substr $var, $-[3], $+[3] - $-[3])"
...which implies that $-[n] is defined if and only if $+[n] is
defined, meaning that $#- and $#+ should always be equal. What
gives?
In addition, the above quote suggests that all elements of @- are
defined (if some element of @- were undefined, the corresponding
substr expression would be nonsensical), but the docs say that
there are cases in which some elements of @- are undefined. Although
I've managed to come up with examples in which, for some n, $-[n]
and $+[n] are equal (implying an "empty submatch"), I have not been
able to produce an example in which @- has undefined elements.
But more important than an example is the answer to this question:
which regexps can produce empty submatches (both $-[n] and $+[n]
are defined and equal), and which can produce "undefined" ones
(both $-[n] and $+[n] are undefined)? Can the same parenthesized
group in a regexp produce either an empty submatch or an undefined
one depending on the input string?
Thanks!
Irv
------------------------------
Date: 22 May 2004 13:13:41 GMT
From: Lukas Mai <rwxr-xr-x@gmx.de>
Subject: Re: When is $#- != $#+ ? When is $-[$i] undef ?
Message-Id: <c8njm5$l5$1@wsc10.lrz-muenchen.de>
Irving Kimura schrob:
> The documentation for @- in perlvar says
> One can use "$#-" to find the last matched subgroup in the last
> successful match. Contrast with $#+, the number of subgroups
> in the regular expression.
> ...which suggests that it is possible for $#- and $#+ to be different,
> but I have not been able to produce an example in which they are
> actually different.
[...]
Here's an example where they're different:
$ perl -wle '"a" =~ /a|(x)/; print "$#- $#+"'
0 1
And here's an example with undefined elements in @-:
$ perl -MData::Dumper -we '"x" =~ /(a)|(x)|(b)/; print "$#- $#+\n", Dumper(\@-, \@+)'
2 3
$VAR1 = [
'0',
undef,
'0'
];
$VAR2 = [
'1',
undef,
'1',
undef
];
HTH, Lukas
--
perl -eval "-MPerlIO=via;printf'Just another Perl hacker%c '=>44"
------------------------------
Date: Sat, 22 May 2004 13:19:51 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: When is $#- != $#+ ? When is $-[$i] undef ?
Message-Id: <c8nk1n$rng$2@wisteria.csv.warwick.ac.uk>
Quoth Irving Kimura <nomail_please@nomail.org>:
> In fact, later in the documentation for @-,
> perlvar says
<schtuff>
> ...which implies that $-[n] is defined if and only if $+[n] is
> defined, meaning that $#- and $#+ should always be equal. What gives?
>
<snip>
> I have not been able to produce an example in which @- has undefined
> elements.
A paren group which matches the empty string produces equal elements of
@+ and @-. A paren group which is not matched at all produces undefined
elements, or in the case of final elements of @-, no element at all.
Consider
$ perl -le'"foo" =~ /(bar)|fo()o|(baz)/;
print join ",", map { defined $_ ? $_ : "(undef)" } @-, ":", @+'
0,(undef),2,:,3,(undef),2,(undef)
. I think that's got all the cases... :)
Ben
--
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
ben@morrow.me.uk (Kate Rusby)
------------------------------
Date: Sat, 22 May 2004 13:32:22 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: When is $#- != $#+ ? When is $-[$i] undef ?
Message-Id: <40af52da.59040595@news.erols.com>
Irving Kimura <nomail_please@nomail.org> wrote:
: The documentation for @- in perlvar says
:
: One can use "$#-" to find the last matched subgroup in the last
: successful match. Contrast with $#+, the number of subgroups
: in the regular expression.
:
: ...which suggests that it is possible for $#- and $#+ to be different,
: but I have not been able to produce an example in which they are
: actually different.
[...]
: the docs say that
: there are cases in which some elements of @- are undefined. Although
: I've managed to come up with examples in which, for some n, $-[n]
: and $+[n] are equal (implying an "empty submatch"), I have not been
: able to produce an example in which @- has undefined elements.
An example that demonstrates both phenomena:
#!perl
use Data::Dumper;
'foo' =~ /(x)|(foo)|(y)/;
print Dumper \@-, \@+;
outputs:
$VAR1 = [
'0',
undef,
'0'
];
$VAR2 = [
'3',
undef,
'3',
undef
];
------------------------------
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 6597
***************************************