[21997] in Perl-Users-Digest
Perl-Users Digest, Issue: 4219 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 5 06:05:41 2002
Date: Thu, 5 Dec 2002 03:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 5 Dec 2002 Volume: 10 Number: 4219
Today's topics:
A beginner's question <vefatica@syr.edu>
Re: A beginner's question (Anno Siegel)
Re: A beginner's question <vefatica@syr.edu>
Re: A beginner's question <jurgenex@hotmail.com>
Re: any cool script site??? <tassilo.parseval@post.rwth-aachen.de>
Re: child signal (Villy Kruse)
Re: child signal (Villy Kruse)
dns query with specified nameserver <bastian.zacher@aspect-onlin.de>
Re: dns query with specified nameserver <michi@nuddelaug.jackal-net.at>
Flat file databases >> mysql databases <bubba@wubba.com>
Re: Flat file databases >> mysql databases <palladium@spinn.net>
Re: Future of Perl as an application server language? <joe+usenet@sunstarsys.com>
Is there a better way of doing this? (Jimbo)
Re: Is there a better way of doing this? <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: Is there a better way of doing this? <tassilo.parseval@post.rwth-aachen.de>
Re: Is there a better way of doing this? <fxn@hashref.com>
Re: Is there a better way of doing this? btam01@ccsf.edu
Re: Newbie: Translation from PHP to Perl <anthony.heuveline@wanadoo.fr>
OLE: InternetExplorer - how do i set proxy server (NiCC)
Re: passing data between perl scripts and a module: pro (benrog)
Re: Re FAQ: How can I capture STDERR from an external c <palladium@spinn.net>
Re: read from a process(open a pipe both to and from a <sunil_franklin@hotmail.com>
split - more parts than expected <jNoOh.lSePbAeMk@gmx.de>
Re: split - more parts than expected <pinyaj@rpi.edu>
Re: split - more parts than expected <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: split - more parts than expected <dave@dave.org.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 05 Dec 2002 05:10:36 GMT
From: Vincent Fatica <vefatica@syr.edu>
Subject: A beginner's question
Message-Id: <qsntuu4b27ddoavius7l3o2iv6pt9cvpse@4ax.com>
Sorry if this is often-asked. In ActivePerl/Windows, both of these do
something useful:
($name, $alias, $type, $length, @addrs) = gethostbyname("...");
$address = gethostbyname("...");
... the first, filling the @addrs list with multiple ips, and the second
just putting the first ip into $address.
Are they both "kosher"? Is this behavior (a function behaving in two
ways) typical of perl ... is it peculiar to gethostbyname()? Is this
behavior documented anywhere? Thanks.
--
- Vince
------------------------------
Date: 5 Dec 2002 05:52:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: A beginner's question
Message-Id: <asmpi7$imr$1@mamenchi.zrz.TU-Berlin.DE>
According to Vincent Fatica <vefatica@syr.edu>:
> Sorry if this is often-asked. In ActivePerl/Windows, both of these do
> something useful:
>
> ($name, $alias, $type, $length, @addrs) = gethostbyname("...");
> $address = gethostbyname("...");
>
> ... the first, filling the @addrs list with multiple ips, and the second
> just putting the first ip into $address.
>
> Are they both "kosher"? Is this behavior (a function behaving in two
> ways) typical of perl ... is it peculiar to gethostbyname()?
The first call assigns to a list, and hence calls gethostbyname() in
list context. The second call is in scalar context. Both are correct.
Context-dependent behavior is typical for Perl, and many (though not all)
Perl functions show it. You can also make your own subroutines behave
differently depending on context.
> Is this
> behavior documented anywhere? Thanks.
Of course it is documented with each Perl function if its behavior
depends on context. For the particular case, see "perldoc -f gethostbyname".
Anno
------------------------------
Date: Thu, 05 Dec 2002 05:59:50 GMT
From: Vincent Fatica <vefatica@syr.edu>
Subject: Re: A beginner's question
Message-Id: <5pqtuugmbn421ttgqniddivlosspmi4o8t@4ax.com>
Thank you.
On 5 Dec 2002 05:52:07 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
wrote:
>According to Vincent Fatica <vefatica@syr.edu>:
>> Sorry if this is often-asked. In ActivePerl/Windows, both of these do
>> something useful:
>>
>> ($name, $alias, $type, $length, @addrs) = gethostbyname("...");
>> $address = gethostbyname("...");
>>
>> ... the first, filling the @addrs list with multiple ips, and the second
>> just putting the first ip into $address.
>>
>> Are they both "kosher"? Is this behavior (a function behaving in two
>> ways) typical of perl ... is it peculiar to gethostbyname()?
>
>The first call assigns to a list, and hence calls gethostbyname() in
>list context. The second call is in scalar context. Both are correct.
>
>Context-dependent behavior is typical for Perl, and many (though not all)
>Perl functions show it. You can also make your own subroutines behave
>differently depending on context.
>
>> Is this
>> behavior documented anywhere? Thanks.
>
>Of course it is documented with each Perl function if its behavior
>depends on context. For the particular case, see "perldoc -f gethostbyname".
>
>Anno
------------------------------
Date: Thu, 05 Dec 2002 06:15:57 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: A beginner's question
Message-Id: <xaCH9.14137$361.12353@nwrddc04.gnilink.net>
Vincent Fatica wrote:
> Sorry if this is often-asked. In ActivePerl/Windows, both of these do
> something useful:
Please see my answer in "the other newsgroup".
And PLEASE do not multi-post!
jue
------------------------------
Date: 5 Dec 2002 07:59:35 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: any cool script site???
Message-Id: <asn117$8ul$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Palladium Solutions:
> "Palladium Solutions" <palladium@spinn.net> wrote in message
> news:uutj2u5fbraiff@corp.supernews.com...
>> Had anyone noticed I was being facetious....And sorry for the top post...I
>> was using a new usenet reader....my bad....
>>
>>
> Did I do that again....sorry...Think I will switch readers ...
You do know that even with the clumsiest newsreader you can set the
cursor to a custom position, don't you? Also, newsreaders typically
allow for deletion of text as you should have done here. Your article
contains quite an amount of trailing text you are not referring to.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: 05 Dec 2002 08:48:06 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: child signal
Message-Id: <slrnauu4m6.1q1.vek@station02.ohout.pharmapartners.nl>
On 04 Dec 2002 16:02:30 GMT,
ctcgag@hotmail.com <ctcgag@hotmail.com> wrote:
>"Lois" <lois@hotmail.com> wrote:
>> Hi all,
>>
>> I have fork() some children to do some processings and I want to quit the
>> whole program when the first child finishes.
>
>> what's the correct way to do this?
>
>Here is a way to do it:
>
>$SIG{CHLD} = \&zombie;
>sub zombie
>{
> kill -15, $$;
>}
>
>By sending the negative signal, it gets sent to the whole "process
>group". As far as I can tell, a "process group" consists of a process and
>all of it's decendents. So here, the parent process kills itself and all
>of it's children.
>
You first, however, need to call setpgrp to set up the process group
and make the process the process group leader. Otherwise the current
pid (the $$) won't be the same as the process group id and nothing will
be killed. If you get the current process group id using getpgid you
will kill more processes than you intended to. The shell may or may
not have already set up the process in its own process group as part
of its job control system.
Villy
------------------------------
Date: 05 Dec 2002 08:54:08 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: child signal
Message-Id: <slrnauu51g.1q1.vek@station02.ohout.pharmapartners.nl>
On 5 Dec 2002 00:12:22 GMT,
Walter Roberson <roberson@ibd.nrc.ca> wrote:
>
> Most historical implementations do not queue signals; i.e., a process's
> signal handler is invoked once, even if the signal has been generated
> multiple times before it is delivered. A notable exception to this
> is SIGCLD, which, in System V, is queued. The queueing of signals is
> neither required nor prohibited by POSIX.1. See 3.3.1.2. It is expected
> that a future realtime extension to POSIX.1 will address the issue
> of reliable queueing of event notification.
>
This is not correct (with respect to System V SIGCLD signals being queued).
What realy happens is that when a SIGCLD signal handler reinstalls the SIGCLD
handler a SIGCLD signal will be generated if a zombie process is pending.
Villy
------------------------------
Date: Thu, 05 Dec 2002 09:41:06 +0100
From: Bastian Zacher <bastian.zacher@aspect-onlin.de>
Subject: dns query with specified nameserver
Message-Id: <asn3h0$2kmv$1@news.f.de.plusline.net>
Hello,
I want to create a perlscript which sends a query to specified
nameserver(s). With Net::DNS I'm able to send queries but I can't
specify the nameserver(s). perldoc got no answer.
Any ideas ?
Thanx,
Bastian
------------------------------
Date: Thu, 5 Dec 2002 10:24:45 +0000 (UTC)
From: Michael Lang <michi@nuddelaug.jackal-net.at>
Subject: Re: dns query with specified nameserver
Message-Id: <slrnauuaa3.64k.michi@nuddelaug.jackal-net.at>
In article <asn3h0$2kmv$1@news.f.de.plusline.net>, Bastian Zacher wrote:
> Hello,
>
> I want to create a perlscript which sends a query to specified
> nameserver(s). With Net::DNS I'm able to send queries but I can't
> specify the nameserver(s). perldoc got no answer.
> Any ideas ?
use Net::DNS;
$dns = new Net::DNS::Resolver;
$dns->searchlist("127.0.0.1");
$dns->tcp_timeout(2);
$dns->retry(1);
>
> Thanx,
>
> Bastian
>
--
Michael Lang System Engineer
EUnet-AG EDV und Internetdienstleistungen Tel: +43 1 89933118
Diefenbachgasse 35, 1150 Wien Fax: +4318991110118
http://www.eunet-ag.at Michael.Lang@eunet-ag.at
------------------------------
Date: Thu, 05 Dec 2002 06:14:12 GMT
From: "Bubba" <bubba@wubba.com>
Subject: Flat file databases >> mysql databases
Message-Id: <U8CH9.24099$K64.930431@news2.west.cox.net>
Are there any good resources I can get a hold of that deal with having Perl
scripts interface with mysql databases? I have a series of scripts that run
well with flat file databases, but I anticipate data becoming cumbersome
soon
------------------------------
Date: Wed, 4 Dec 2002 23:27:28 -0700
From: "Palladium Solutions" <palladium@spinn.net>
Subject: Re: Flat file databases >> mysql databases
Message-Id: <uuttrr58bgs4d2@corp.supernews.com>
"Bubba" <bubba@wubba.com> wrote in message
news:U8CH9.24099$K64.930431@news2.west.cox.net...
> Are there any good resources I can get a hold of that deal with having
Perl
> scripts interface with mysql databases? I have a series of scripts that
run
> well with flat file databases, but I anticipate data becoming cumbersome
> soon
>
>
http://search.cpan.org/modlist/Database_Interfaces
Look for DBI and MySql
I like
http://mysql.turbolift.com/DBD_3.21.X.php3
But there are many many resources on the net..
Check out google for perl mysql
Results 1 - 10 of about 1,630,000. Search took 0.15 seconds
HTH,
Rodney
------------------------------
Date: 05 Dec 2002 00:24:32 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Future of Perl as an application server language?
Message-Id: <m3hedt3unj.fsf@mumonkan.sunstarsys.com>
simonf@simonf.com (Simon) writes:
[...]
> I have picked up on this just from the few days of the conference, as
> I did not know much about server-side Java before (and I will get into
> it now). I am sure someone more familiar with various Java tools will
> be able to give many more examples.
Then be sure to check out Jakarta: <URL:http://jakarta.apache.org/>.
They've got a bunch of cool projects to build on, and they could
use some fresh new Perl blood injected into their community. ;-)
[...]
> Perhaps this is a wrong group to bring up these issues. I will
> appreciate suggestions for a more appropriate forum.
p5ee at perl.org (it's a mailing list).
[...]
> If one language has standard frameworks supporting software
> engineering concepts, and another one does not, guess which one will
> be more viable?
Common Lisp. Always and Forever.
--
Joe Schaefer "... when Truth and Error have fair Play, the former is always
an overmatch for the latter" -- Ben Franklin
------------------------------
Date: Thu, 05 Dec 2002 09:21:20 GMT
From: nobody@nobody.com (Jimbo)
Subject: Is there a better way of doing this?
Message-Id: <kUEH9.29890$vj1.7201862@amsnews02.chello.com>
Create an empty array:
my @empty;
push ( @empty, undef ) foreach ( 1 .. 100 );
------------------------------
Date: Thu, 5 Dec 2002 09:26:43 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Is there a better way of doing this?
Message-Id: <asn64j$6fm$1@korweta.task.gda.pl>
In article <kUEH9.29890$vj1.7201862@amsnews02.chello.com>, Jimbo wrote:
> Create an empty array:
>
> my @empty;
> push ( @empty, undef ) foreach ( 1 .. 100 );
my @entry;
$#entry = 99;
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: 5 Dec 2002 09:29:08 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Is there a better way of doing this?
Message-Id: <asn694$gfo$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Jimbo:
> Create an empty array:
>
> my @empty;
> push ( @empty, undef ) foreach ( 1 .. 100 );
Depends on what you want. Is it essential that your array initially
contains 100 undefined elements? If so, this is probably quicker:
my @empty;
$#empty = 99;
It sets the initial capacity to 100 (by specifying the index of the last
element to 99). Elements will be undef then.
Still, I am quite sure you don't need this kind of initialization at
all. Perl's data-types are completely dynamic.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Thu, 5 Dec 2002 10:47:54 +0000 (UTC)
From: Xavier Noria <fxn@hashref.com>
Subject: Re: Is there a better way of doing this?
Message-Id: <slrnauubsq.1r6.fxn@conway.localdomain>
In article <kUEH9.29890$vj1.7201862@amsnews02.chello.com>, Jimbo wrote:
> my @empty;
> push ( @empty, undef ) foreach ( 1 .. 100 );
Besides what others have said, the x operator rules if you want to set
initial values to some other thing:
my @initialized_with_ones = (1) x 100;
-- fxn
------------------------------
Date: Thu, 5 Dec 2002 02:57:03 -0800
From: btam01@ccsf.edu
Subject: Re: Is there a better way of doing this?
Message-Id: <Pine.HPX.4.44.0212050256240.24143-100000@hills.ccsf.cc.ca.us>
On Thu, 5 Dec 2002, Jimbo wrote:
> Create an empty array:
>
> my @empty;
> push ( @empty, undef ) foreach ( 1 .. 100 );
This easily clears out your array.
my @isFull = ();
-Bill
------------------------------
Date: Thu, 5 Dec 2002 10:48:23 +0100
From: "Anthony" <anthony.heuveline@wanadoo.fr>
Subject: Re: Newbie: Translation from PHP to Perl
Message-Id: <asn7br$ett$1@news-reader12.wanadoo.fr>
Thank you for your help...
Maybe I forgot some important details...
My aim isn't to force the person who opens this Perl program to download the
PDF file but only to display the save as dialog of its browser instead of
having the PDF automatically open in the browser.
That's why after this two lines...
print "Content-type: application/force-download\n";
print "Content-Disposition: attachment; filename=downloaded.pdf\n\n";
... I just want to open to the file and make it available for download when
the user clicks the save button.
And I don't know how to do that with a PDF file.
Anthony.
"Alan J. Flavell" <flavell@mail.cern.ch> a écrit dans le message de news:
Pine.LNX.4.40.0212041948550.22227-100000@lxplus074.cern.ch...
> On Dec 4, Tassilo v. Parseval inscribed on the eternal scroll:
>
> > The guy on the right, is that John von Neumann? Or wasn't he yet born by
> > the time this picture was taken? ;-)
>
> Just for the record - the "machine" was already obsolete when I met it
> in 1958, it had been cast-out by Harwell and offered to an institution
> who would give it a good home - Wolverhampton won the prize, see
> http://www.scit.wlv.ac.uk/university/scit/history/timeline.html
>
------------------------------
Date: 5 Dec 2002 02:25:03 -0800
From: mail@dominicneumann.de (NiCC)
Subject: OLE: InternetExplorer - how do i set proxy server
Message-Id: <887ed4b5.0212050225.77975a16@posting.google.com>
which property is the one where i can set the proxy server for my
controlled ie window?
how can i set it?
and: how can i deleted the cookies for a specific site?
------------------------------
Date: 4 Dec 2002 23:29:10 -0800
From: ben.rogers@escalate.com (benrog)
Subject: Re: passing data between perl scripts and a module: probably a basic question
Message-Id: <1da5d446.0212042329.40366c8e@posting.google.com>
This advice was very helpful. The ideas and resources taught me quite
a bit and I'll send a summary later on.
Anyway, I solved my last problem by realizing that I defined $database
= "db2.dat"; in a sub and therefore none of the other subs could see
it and open the file.
Thanks again. I'm a beginner, but these responses extended my
capabilities another notch.
ben
------------------------------
Date: Thu, 5 Dec 2002 00:03:39 -0700
From: "Palladium Solutions" <palladium@spinn.net>
Subject: Re: Re FAQ: How can I capture STDERR from an external command?
Message-Id: <uutvvi470hkh47@corp.supernews.com>
"Peter J. Acklam" <pjacklam@online.no> wrote in message
news:fe4612a5.0212040226.4aba4e19@posting.google.com...
> > 8.25: How can I capture STDERR from an external command?
> >
> > [...]
> >
> > 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");
>
> That's what I need, except I need cycling of the output files,
> like what is done with /var/adm/messages (at least on Solaris).
>
> (By "cycling" I mean that when the size of the first set of output
> files (one for each of stdout and stderr) has reached a certain
> limit, then I close the "program.stdout", shift the list of files,
> so that the old "program.0.stdout" becomes "program.1.stdout", and
> "program.stdout" becomes "program.0.stdout". etc., and then I open
> "program.stdout" for writing again.)
>
> How about if I create two FIFO files and let the output files be
> the two FIFOs? Then, my Perl program can read from the two FIFOs
> and write to the output files and also handle the cycling of the
> regular output files.
>
> What are the dangers and disadvantages of this approach compared
> to using IPC::Open3. To me, using FIFO files seems much cleaner,
> but since no-one else seems to have suggested it, I'm afraid there
> are some disadvantages that I have missed... :-)
>
> Comments, anyone?
>
> Peter
The Logfile::Rotate Module might work for you. If you are closing the file
handle, then reopening it.
Rodney
------------------------------
Date: Thu, 5 Dec 2002 16:08:57 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: Re: read from a process(open a pipe both to and from a command) - Portably Issues
Message-Id: <j4GH9.2$Td5.25@news.oracle.com>
All,
The routine I am writing is supposed to work on Win2000, WinNT and
Solaris.
I have used open SQLP, "|sqlplus ..." even though it looks like
http://www.perldoc.com/perl5.6.1/pod/perlport.html does not recommend it.
It works fine in Win2000. Do you see me running into any issues.
Thanks,
Sunil.
"Brian McCauley" <nobull@mail.com> wrote in message
news:u9hedtvadk.fsf@wcl-l.bham.ac.uk...
> "Sunil" <sunil_franklin@hotmail.com> writes:
>
> > Subject: read from a process
>
> Actually a better way to phrase what you are tring to ask would be:
>
> "How can I open a pipe both to and from a command?"
>
> And that, indeed, is exactly how it is phrased when this question
> appears in the FAQ.
>
> Unfortunately the FAQ is not necessarily the full answer in this case.
>
> > I would like the results of this script to be available in my
program
> > (may be in an array). is this possible. How can I read from this?
> > I can redirect the output to a file by using
> > open SQLP, "|sqlplus -s /nolog > output.log" or die "cannot
open
> > sqlplus\n";
> > But I may not always be having write permissions on the dir.
> >
> > Any Ideas?
>
> Redirect the output to somewhere to which you will always have write
> permissions.
>
> One neat way to do this is to open a temporary file with
IO::File->new_tmpfile
>
> my $tempfile = IO::File->new_tmpfile or die $!;
> open SQLP, "|sqlplus -s /nolog >&" . fileno($tempfile) or die $!;
> seek($tempfile,0,0);
>
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
------------------------------
Date: Thu, 28 Nov 2002 20:27:23 +0100
From: "Johannes Lebek" <jNoOh.lSePbAeMk@gmx.de>
Subject: split - more parts than expected
Message-Id: <asmqg6$1uf$02$1@news.t-online.com>
Hello,
I am a newbie to Perl and I experienced a - in my eyes - strange behaviour
of "split".
my $digits = "12345678";
my @twodigits = split(/(\d\d)(\d\d)(\d\d)(\d\d)/, $digits);
foreach my $member (@twodigits) {
print "[$member]\n";
}
In my script I expected as result of "split" an array of 4 two-letter
strings ("12", "34", "56", and "78"). Indeed, an array consisting of 5
members is returned:
Output:
=====
[]
[12]
[34]
[56]
[78]
Do you have any idea, where the first array entry comes from and how to
suppress it? (I suppose, it has to do with my regular expression...)
Any help appreciated,
Johannes
------------------------------
Date: Thu, 5 Dec 2002 01:44:47 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Johannes Lebek <joh.lebek@gmx.de>
Subject: Re: split - more parts than expected
Message-Id: <Pine.A41.3.96.1021205014318.84048A-100000@cortez.sss.rpi.edu>
[posted & mailed]
On Thu, 28 Nov 2002, Johannes Lebek wrote:
>I am a newbie to Perl and I experienced a - in my eyes - strange behaviour
>of "split".
>
>my $digits = "12345678";
>
>my @twodigits = split(/(\d\d)(\d\d)(\d\d)(\d\d)/, $digits);
You're not using split() properly. You usually split on something you
DON'T want in the output:
my @numbers = split /,/ => "123,84,11108,7575784";
In your case, you probably want to use:
my @two_digits = $digits =~ /\d\d/g;
--
Jeff "japhy" Pinyan RPI Acacia Brother #734 2002 Acacia Senior Dean
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Thu, 5 Dec 2002 07:49:34 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: split - more parts than expected
Message-Id: <asn0ee$9io$1@korweta.task.gda.pl>
In article <asmqg6$1uf$02$1@news.t-online.com>, Johannes Lebek wrote:
> Hello,
>
> I am a newbie to Perl and I experienced a - in my eyes - strange behaviour
> of "split".
>
> my $digits = "12345678";
>
> my @twodigits = split(/(\d\d)(\d\d)(\d\d)(\d\d)/, $digits);
>
> foreach my $member (@twodigits) {
> print "[$member]\n";
> }
>
> In my script I expected as result of "split" an array of 4 two-letter
> strings ("12", "34", "56", and "78"). Indeed, an array consisting of 5
> members is returned:
You are using split when you should be using m//. Observe:
my @twodigits = $digits =~ /(\d\d)(\d\d)(\d\d)(\d\d)/;
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Thu, 05 Dec 2002 08:32:12 +0000
From: "Dave Cross" <dave@dave.org.uk>
Subject: Re: split - more parts than expected
Message-Id: <pan.2002.12.05.08.32.11.538998@dave.org.uk>
On Thu, 28 Nov 2002 20:27:23 +0100, Johannes Lebek wrote:
> Hello,
>
> I am a newbie to Perl and I experienced a - in my eyes - strange
> behaviour of "split".
>
> my $digits = "12345678";
>
> my @twodigits = split(/(\d\d)(\d\d)(\d\d)(\d\d)/, $digits);
>
> foreach my $member (@twodigits) {
> print "[$member]\n";
> }
> }
> In my script I expected as result of "split" an array of 4 two-letter
> strings ("12", "34", "56", and "78"). Indeed, an array consisting of 5
> members is returned:
>
> Output:
> =====
> []
> [12]
> [34]
> [56]
> [78]
>
> Do you have any idea, where the first array entry comes from and how to
> suppress it? (I suppose, it has to do with my regular expression...)
Others have explained what you should be doing to get the results that you
want, but I haven't yet seen an explaination of why you're seeing what
you're seeing.
The first argument to split is a regular expression which defines the
separator that you want to split on. In normal circumstances, that
separator is not returned in the resulting list. There is, however, a
special case where the separator data is also returned. If you include
capturing parentheses in your regular expression then whatever is captured
will also be included in the list returned by split. Each set of
parentheses will become a separate element in the returned list.
In your original code you have defined a rather long regular expression as
your separator. In fact, your separator matches your whole string - and it
is all captured in parentheses. Therefore your returned list includes all
of the data in your string. Note, however, that Perl is still seeing your
regex as a _separator_. This means that the first occurance of the
separator must _follow_ the first item in the list. There is nothing in
your string before the first (and only) occurance of the separator,
therefore Perl (very reasonably) assumes that the first item in your list
should be an empty string - so that's what it gives you.
hth,
Dave...
--
"Don't you boys know any _nice_ songs?"
------------------------------
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.
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 4219
***************************************