[22265] in Perl-Users-Digest
Perl-Users Digest, Issue: 4486 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 30 06:05:51 2003
Date: Thu, 30 Jan 2003 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, 30 Jan 2003 Volume: 10 Number: 4486
Today's topics:
Re: alarm() implemented? <Peter.Dintelmann@dresdner-bank.com>
Re: array slicing (Anno Siegel)
Re: hash ordering. (Graham Patterson)
Re: How to search a file (newbie) <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: How to search a file (newbie) <josef.moellers@fujitsu-siemens.com>
Re: loop-array question <goldbb2@earthlink.net>
Re: Need help with sendmail routine <file attachments> <me@privacy.net>
Net::NNTP Can't call method "list" on an undefined valu <Etan@none.com>
Re: Net::NNTP Can't call method "list" on an undefined <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: Net::NNTP Can't call method "list" on an undefined (Anno Siegel)
Re: Newbie questions <tassilo.parseval@localhost.localhost>
Re: Next problem. <krahnj@acm.org>
Re: Next problem. (Alan Barclay)
Re: Next problem. <jurgenex@hotmail.com>
Re: Next problem. <me@privacy.net>
Re: Next problem. <krahnj@acm.org>
Re: Next problem. <spikey-wan@bigfoot.com>
Re: perl data structure question (Hemuda)
POSIX::sigaction() - how to get sa_sigaction semantic ? <billy@arnis-bsl.com>
Re: Possible flock/POSIX::close/__END__ bug in 5.8.0 <cees@sitesuite.net>
Re: Premature end of script headers errors <rcook@pcug.org.au>
Regular expression and capturing (Hemuda)
Re: Regular expression and capturing <abigail@abigail.nl>
Re: Regular expression and capturing <bigj@kamelfreund.de>
Search a text <dmuren@start.no>
Re: Search a text <simon.oliver@nospam.umist.ac.uk>
Re: Tie::IxHash <spikey-wan@bigfoot.com>
Re: Use and Require - Perl Modules <me@privacy.net>
Re: wondering why this doesn't work (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 30 Jan 2003 10:09:53 +0100
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: alarm() implemented?
Message-Id: <b1ap2i$j9u402@news-1.bank.dresdner.net>
Hik
"spark" <spark@dcwis.nodurnspam.com> schrieb im Newsbeitrag
news:MPG.18a1bbf086a3da8a989695@news-central.giganews.com...
> Is alarm() implemented for Win32 in the latest version of Perl?
perl -MConfig -le 'print $Config{d_alarm}'
(use "" on Win32) shows, wether alarm() is available.
HTH,
Peter Dintelmann
------------------------------
Date: 30 Jan 2003 08:26:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: array slicing
Message-Id: <b1ankb$bpo$1@mamenchi.zrz.TU-Berlin.DE>
Thens <thens@nospam.com> wrote in comp.lang.perl.misc:
> On 29 Jan 2003 17:26:17 GMT
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>
> > Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in comp.lang.perl.misc:
[...]
> > > "!defined" is not an attempt to reset the operator. I would have
> > > used "0" or "''" instead of "!defined" if the range operator didn't
> > > insist in comparing a constant against $. I wanted a non-constant
> > > expression that returns false, and nothing simpler came to mind. In
> > > fact, it returns false only most of the time :)
> >
> > I guess "do { 0 }" is what I was looking for.
> >
> > print "@{[grep { $_ eq 'THREE' .. do { 0 } } @$_]}\n";
> >
>
> Can you explain how this works or can you point me to any section of
> perldoc that will explain this??
The core of it is
my @numbers = ( 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE' );
my @tail = grep { $_ eq 'THREE' .. do { 0 } } @numbers;
which assigns "THREE" and the following elements to @tail. This is
just an application of the range operator ".." in scalar context.
Basically, it becomes true when its left operand is true (that is,
when an element of @numbers is "THREE", and it stays true until the
right operand becomes true (which won't happen). So grep collects
"THREE" and everything that follows. Why the second operand is
"do { 0 }" instead of simply "0" I have explained above. Look up
"range operator" in perlop for the details.
The whole thing is wrapped up in "@{[ ... ]}\n" for print. This
is a standard trick to interpolate a list expression in a string.
Anno
------------------------------
Date: 30 Jan 2003 01:02:17 -0800
From: gpatterson@opec.org (Graham Patterson)
Subject: Re: hash ordering.
Message-Id: <7dfc2de8.0301300102.65c1c64c@posting.google.com>
> Is there any way to force a hash to be in the same order as you defined it?
You could always search.cpan.org for Tie::IxHash
Cheers, GP
------------------------------
Date: Thu, 30 Jan 2003 08:19:50 +0100
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: How to search a file (newbie)
Message-Id: <ufkh3v4v5vtp9ng0iplhv17plbsoigv9h4@4ax.com>
On Wed, 29 Jan 2003 13:01:35 -0600, "Eric J. Roode"
<REMOVEsdnCAPS@comcast.net> wrote:
>"David K. Wall" <usenet@dwall.fastmail.fm> wrote in
>news:Xns931284999E67Adkwwashere@216.168.3.30:
>
>> Ben Morrow <mauzo@ux-ma160-13.csv.warwick.ac.uk> wrote on 29 Jan 2003:
>>
>>> The English abbreviation for 'for example' is 'e.g.'.
>>
>> I thought it was Latin, "exempli gratia". :-)
>>
>
>It is. But nobody uses "f.ex." in English.
Don't call Helgi a nobody! ;-)
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Thu, 30 Jan 2003 08:43:29 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: How to search a file (newbie)
Message-Id: <3E38D7A1.FE2CABEC@fujitsu-siemens.com>
Bernard El-Hagin wrote:
> =
> On Wed, 29 Jan 2003 13:01:35 -0600, "Eric J. Roode"
> <REMOVEsdnCAPS@comcast.net> wrote:
> =
> >"David K. Wall" <usenet@dwall.fastmail.fm> wrote in
> >news:Xns931284999E67Adkwwashere@216.168.3.30:
> >
> >> Ben Morrow <mauzo@ux-ma160-13.csv.warwick.ac.uk> wrote on 29 Jan 200=
3:
> >>
> >>> The English abbreviation for 'for example' is 'e.g.'.
> >>
> >> I thought it was Latin, "exempli gratia". :-)
> >>
> >
> >It is. But nobody uses "f.ex." in English.
> =
> Don't call Helgi a nobody! ;-)
Isn't Helgi's _real_ name Mario Girotti, aka Terence Hill? So ...
BTW I think meta-discussions are below the members of this group.
SCNR,
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Thu, 30 Jan 2003 00:37:48 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: loop-array question
Message-Id: <3E38BA2C.DECAFB4E@earthlink.net>
patric wrote:
>
> What is the best way for me to proceed through a loop, find an item in
> an array that matches a condition, delete it and then proceed to the
> next match without having to go back to the beginning of the array and
> re-loop?
Try this:
my @data = qw(foo bar baz quux);
my $i = 0;
for my $item (@data) {
next if condition($item);
$data[$i++] = $item;
}
$#data = $i - 1; # or splice @data, $i;
Or, if some of the things in @data are blessed references, and want
their DESTROY methods called asap, then perhaps something like this will
do:
my $i = 0;
for my $item (@data) {
my $x = $item; $item = undef;
next if condition($x);
$data[$i++] = $x;
}
$#data = $i - 1; # or splice @data, $i;
I'm not sure how much difference there is between shortening the array
by assigning to $#{array name}, or shortening with splice.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Thu, 30 Jan 2003 20:03:35 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Need help with sendmail routine <file attachments>
Message-Id: <b1appa$111l1c$1@ID-172104.news.dfncis.de>
"Tara" <tararse@hotmail.com> wrote in message
news:27eb673f.0301290052.c026466@posting.google.com...
> Hello, I have this simple script that is submitted from a form that I
> want to add file attachments too. How can I work in this process
> under the sub SendSubmission routine? I know it has something to do
> with encode_base64, but I have no idea on how to implement this. Can
> someone please help?
[snip of cargo cult code]
Use the MIME::Lite module. Simple to install and use.
------------------------------
Date: Thu, 30 Jan 2003 10:14:28 GMT
From: "Etan" <Etan@none.com>
Subject: Net::NNTP Can't call method "list" on an undefined value
Message-Id: <8W6_9.2161034$%W4.312436@news.easynews.com>
I have a script the gets the list of newsgroups and article counts off of a
news server. It worked fine on the previous host. I changed hosts, and now
I get the error message "Can't call method "list" on an undefined value."
What is wrong? What value is undefined? I reduced the code to its simplest
as follows, and still get the error message:
#!/usr/bin/perl
use Net::NNTP;
$nntp = Net::NNTP->new("news.xxxx.com");
my $grpsref = $nntp->list();
------------------------------
Date: Thu, 30 Jan 2003 10:20:23 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Net::NNTP Can't call method "list" on an undefined value
Message-Id: <Xns931372BB398EBelhber1lidotechnet@62.89.127.66>
Etan wrote:
> I have a script the gets the list of newsgroups and article counts off
> of a news server. It worked fine on the previous host. I changed
> hosts, and now I get the error message "Can't call method "list" on an
> undefined value." What is wrong? What value is undefined? I reduced
There's only one place in your code where you're trying to call list().
> the code to its simplest as follows, and still get the error message:
>
> #!/usr/bin/perl
> use Net::NNTP;
> $nntp = Net::NNTP->new("news.xxxx.com");
> my $grpsref = $nntp->list();
^^^^
So $nntp is undefined. Did you make sure that the connection didn't fail
and that $nntp actually has a sensible value?
--
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: 30 Jan 2003 10:28:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Net::NNTP Can't call method "list" on an undefined value
Message-Id: <b1aunm$fed$1@mamenchi.zrz.TU-Berlin.DE>
Etan <Etan@none.com> wrote in comp.lang.perl.misc:
> I have a script the gets the list of newsgroups and article counts off of a
> news server. It worked fine on the previous host. I changed hosts, and now
> I get the error message "Can't call method "list" on an undefined value."
> What is wrong? What value is undefined? I reduced the code to its simplest
> as follows, and still get the error message:
>
> #!/usr/bin/perl
> use Net::NNTP;
> $nntp = Net::NNTP->new("news.xxxx.com");
> my $grpsref = $nntp->list();
Apparently the NNTP server (represented by "news.xxxx.com") doesn't
give you access. Net::NNTP->new() returns a false value in this case.
Catch the error:
my $nntp = Net::NNTP->new( 'news.xxxx.com') or die "no connection: $!";
Anno
------------------------------
Date: 30 Jan 2003 10:12:00 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@localhost.localhost>
Subject: Re: Newbie questions
Message-Id: <slrnb3hujb.fm8.tassilo.parseval@localhost.localhost>
Also sprach Tad McClellan:
> Kwan <ckkwan@my-deja.com> wrote:
>> my ($bstr) = "";
>> my (@Lines) = split '\n';
>
>
> 1) you haven't put anything in $_, so splitting it won't be very useful.
>
> 2) you are splitting on the two-character sequence: backslash, "n".
> If you meant to split on a newline, then:
>
> split /\n/;
Actually he is splitting on newline alright:
ethan@localhost:~$ perl -MData::Dumper
$_ = "hallo\ntest";
print Dumper [ split '\n' ];
__END__
$VAR1 = [
'hallo',
'test'
];
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Thu, 30 Jan 2003 05:16:31 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Next problem.
Message-Id: <3E38B52E.1ACA00E4@acm.org>
"Jürgen Exner" wrote:
>
> Ben Morrow wrote:
> >
> > But then
> > my $var = shift || $ENV{PARAM} || 'default';
> > wouldn't work.
>
> I see your point. Seems || has a dual nature. It can be used as a boolean
> operator. And it can be used as a kind of selector for text.
> Maybe that's the root of the problem and we need a different || for
> selecting text? Just like you got == for numbers and eq for text?
I think you are confusing the | boolean operator with the || logical
operator. :-)
John
--
use Perl;
program
fulfillment
------------------------------
Date: 30 Jan 2003 04:56:06 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Next problem.
Message-Id: <1043902566.586944@elaine.furryape.com>
In article <slrnb3gisk.cp1.abigail@alexandra.abigail.nl>,
Abigail <abigail@abigail.nl> wrote:
>Richard S Beckett (spikey-wan@bigfoot.com) wrote on MMMCDXXXVIII
>September MCMXCIII in <URL:news:b18vsl$pbt$1@newshost.mot.com>:
>::
>:: I _always_ use strict and warnings.
>
>
>Then you wouldn't be able to write modules like Exporter or Memoize.
You're assuming that he would be able to even if he hadn't used
strict and warnings.
------------------------------
Date: Thu, 30 Jan 2003 06:50:54 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Next problem.
Message-Id: <iX3_9.3092$cu4.1538@nwrddc02.gnilink.net>
John W. Krahn wrote:
> "Jürgen Exner" wrote:
>>
>> Ben Morrow wrote:
>>>
>>> But then
>>> my $var = shift || $ENV{PARAM} || 'default';
>>> wouldn't work.
>>
>> I see your point. Seems || has a dual nature. It can be used as a
>> boolean operator. And it can be used as a kind of selector for text.
>> Maybe that's the root of the problem and we need a different || for
>> selecting text? Just like you got == for numbers and eq for text?
>
> I think you are confusing the | boolean operator with the || logical
> operator. :-)
You seem to be confusing boolean and bitwise ;-)
jue
------------------------------
Date: Thu, 30 Jan 2003 20:09:16 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Next problem.
Message-Id: <b1aq40$117mlt$1@ID-172104.news.dfncis.de>
"Richard S Beckett" <spikey-wan@bigfoot.com> wrote in message
news:b18mi5$lal$1@newshost.mot.com...
> Thanks, folks.
For what?
Quote some context. Read the posting guidelines for this group. Read the
general guides on how to use Usenet.
------------------------------
Date: Thu, 30 Jan 2003 09:34:26 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Next problem.
Message-Id: <3E38F198.AE1BD7D8@acm.org>
"Jürgen Exner" wrote:
>
> John W. Krahn wrote:
> >
> > I think you are confusing the | boolean operator with the || logical
> > operator. :-)
>
> You seem to be confusing boolean and bitwise ;-)
Oops. :-)
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 30 Jan 2003 09:47:13 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: Next problem.
Message-Id: <b1ascp$k8p$1@newshost.mot.com>
"Tintin" <me@privacy.net> wrote in message
news:b1aq40$117mlt$1@ID-172104.news.dfncis.de...
> > Thanks, folks.
>
> For what?
Well, if you'd read the smegging thread, you'd know! And if you didn't read
the thread, then why on Earth did you post this?
Or are you just looking to flame for the fun of it?
If we accomodated this request, then every post in a thread would contain
all previous posts, so that if a plonker like you comes along, and only
reads one of the posts, he can follow the thread. That's a good idea, isn't
it! (NOT!).
Mind you, with a name like 't i'n't in I can see why you'd be grumpy.
R.
------------------------------
Date: 30 Jan 2003 01:04:20 -0800
From: hemuda@yahoogroups.com (Hemuda)
Subject: Re: perl data structure question
Message-Id: <20d93d09.0301300104.390d4f96@posting.google.com>
With $type, $name, $size etc. as undef, here are the perl internals...
DB<10> p Dumper( \@DirEnts )
$VAR1 = [
{
'w' => undef,
'n' => undef,
'r' => undef,
'a' => undef,
'm' => undef,
's' => undef,
'u' => undef,
'g' => undef,
'f' => undef,
't' => undef
}
];
You can see its a array, with only one element.
Regards,
Hemant
------------------------------
Date: Thu, 30 Jan 2003 12:59:38 +0200
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: POSIX::sigaction() - how to get sa_sigaction semantic ?
Message-Id: <b1b0iq$11klm0$1@ID-33095.news.dfncis.de>
Hi All ,
While experimenting with POSIX::sigaction() I found that
even if I specify the SA_SIGINFO flag, the signal handler
is called using the sa_handler semantic (only the signal
number is passed to the handler), there is no way to force
the sa_sigaction behaviour (with three arguments passed to
the signal handler).
Here is the sample script:
#!/usr/bin/perl -w
use strict;
use POSIX;
my $sigset = POSIX::SigSet->new;
my $sigact = POSIX::SigAction->new( 'main::handler', $sigset,
&POSIX::SA_SIGINFO );
POSIX::sigaction(SIGINT, $sigact) or die "cannot sigaction: $!\n";
sleep(100) while(1);
sub handler
{
print "handler called with ", scalar(@_), " arguments\n";
}
I also looked at the POSIX.xs source and really found that the
the signal handler is always installed as sa_handler.
And my Perl questions ;-) is:
Is the above right ? Or maybe I missed something ?
Some hidden knowledge ?
The reason I'm asking is that in the POSIX::RT::MQ module
(POSIX message queues) I'd like to implement the full support
for mq_notify(), with struct sigevent.
However even if I'd implement this feature it will be _useless_
without the ability to install the 3-argument signal handler
with sa_sigaction semantic.
Also, I got the idea to implement some more perl bindings to
POSIX Realtime Extension (like, say, sigqueue() etc., or maybe
AIO if I'll have enough spare time).
But again - these extensions use Realtime signals, which, in turn,
require sa_sigaction support to be usefull.
Maybe I could roll my own POSIX::RT::sigaction(), but I'm not sure
how it would coexist with the present POSIX::sigaction() ...
... and yes, maybe I'm too lazy ;-)
BRGDS
--
Ilja
------------------------------
Date: Thu, 30 Jan 2003 00:24:15 -0500
From: Cees Hek <cees@sitesuite.net>
Subject: Re: Possible flock/POSIX::close/__END__ bug in 5.8.0
Message-Id: <aN2_9.66757$lj.2616951@read1.cgocable.net>
Benjamin Goldberg wrote:
> Cees Hek wrote:
> [snip]
>> use strict;
>> use warnings;
>> use Fcntl qw(:DEFAULT :flock);
>> use POSIX;
>>
>> POSIX::close(3);
>
> This closes the DATA filehandle, which is created by having an __END__
> or a __DATA__ token in your file.
That explains a lot.
>>
>> {
>> sysopen FH, '/tmp/test.pl.pid', O_RDWR|O_CREAT
>> || die "Cannot open pid file '/tmp/test.pl.pid': $!\n";
>
> This opens FH, using the next available filedescriptor, which, since
> you've closed #3, and 0, 1, 2 (STD{IN,OUT,ERR}) are still open, is 3,
> the same fd as the DATA filehandle was at.
>
> But since you didn't directly *close* the DATA filehandle, only the
> underlying filedescriptor, perl thinks that the DATA handle is still
> open, and that the FH and DATA handles are aliases to each other.
>
>> flock FH, LOCK_EX;
>> my ($pid) = <FH> =~ /^(\d+)/;
>> # flock FH, LOCK_UN; # Should be automatic on close FH
>> close FH;
>
> Some versions of perl perform refcounting on filedescriptors, so that to
> get the underlying fd to *really* close, then number of handles which
> are open to it has to go to zero. I'd be willing to bet that a
> 'close(DATA)' at this point in the program will make the deadlock later
> on go away.
>
> [PS: This is all OTTOMH, so might be complete and utter BS. Does strace
> show a close(3) occuring around here?]
I think you have it. The strace of the original code results in the
following:
1: fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
2: close(3) = 0
3: open("/tmp/test.pl.pid", O_RDWR|O_CREAT|O_LARGEFILE, 0666) = 3
4: ioctl(3, SNDCTL_TMR_TIMEBASE, 0xbffff560) = -1 ENOTTY (Inappropriate
ioctl for device)
5: _llseek(3, 0, [0], SEEK_CUR) = 0
6: fstat64(3, {st_mode=S_IFREG|0666, st_size=5, ...}) = 0
7: fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
8: flock(3, LOCK_EX) = 0
9: brk(0) = 0x825b000
10: brk(0x825c000) = 0x825c000
11: read(3, "3681\n", 4096) = 5
12: open("/tmp/test.pl.pid", O_RDWR|O_CREAT|O_LARGEFILE, 0666) = 4
13: ioctl(4, SNDCTL_TMR_TIMEBASE, 0xbffff560) = -1 ENOTTY (Inappropriate
ioctl for device)
14: _llseek(4, 0, [0], SEEK_CUR) = 0
15: fstat64(4, {st_mode=S_IFREG|0666, st_size=5, ...}) = 0
16: fcntl64(4, F_SETFD, FD_CLOEXEC) = 0
17: flock(4, LOCK_EX <unfinished ...>
(line numbers added by me)
Notice that after the read(3, ...) on line 11 there should be a close(3)
(since my code does a close(FH), but it never happens. The next open then
uses the next available fd which is 4.
If I add the close(DATA) at that spot like you mentioned, the program
finishes correctly and the strace shows a close(3) at that spot:
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
close(3) = 0
open("/tmp/test.pl.pid", O_RDWR|O_CREAT|O_LARGEFILE, 0666) = 3
ioctl(3, SNDCTL_TMR_TIMEBASE, 0xbffff560) = -1 ENOTTY (Inappropriate ioctl
for device)
_llseek(3, 0, [0], SEEK_CUR) = 0
fstat64(3, {st_mode=S_IFREG|0666, st_size=5, ...}) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
flock(3, LOCK_EX) = 0
brk(0) = 0x825b000
brk(0x825c000) = 0x825c000
read(3, "3709\n", 4096) = 5
close(3) = 0
open("/tmp/test.pl.pid", O_RDWR|O_CREAT|O_LARGEFILE, 0666) = 3
ioctl(3, SNDCTL_TMR_TIMEBASE, 0xbffff560) = -1 ENOTTY (Inappropriate ioctl
for device)
_llseek(3, 0, [0], SEEK_CUR) = 0
fstat64(3, {st_mode=S_IFREG|0666, st_size=5, ...}) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
flock(3, LOCK_EX) = 0
_llseek(3, 0, [0], SEEK_SET) = 0
ftruncate64(3, 0) = 0
write(3, "3713\n", 5) = 5
close(3) = 0
exit_group(0) = ?
>
> [snip]
>> Can someone confirm that this is a bug, or explain to me what I am
>> doing wrong... I am asking here first, because that's what the
>> perl5-porters FAQ says to do :)
>
> I suppose that it's a bug in that perl can't distinguish between:
> open( A, ">x" );
> open( B, ">=&A" ); # fileno(A) == fileno(B)
> close B; # shouldn't cause fileno(A) to get closed.
> and:
> open( A, ">x" );
> POSIX::close(fileno(A));
> # A still appears to be open, even though it's fd is closed.
> open( B, ">x" );
> # Now that the fd is reused, perl doesn't know that A ought to
> # be considered closed. Oh, and fileno(B) == fileno(A)
> close B; # should this cause fileno(A) to get closed?
>
> If you try to fix the behavior of the latter situation, there's a good
> chance that you'll break the behavior of the former situation.
Thank you for the insight. It is making more sense to me now.
Here is a simpler example of what is happening that doesn't use the magic
of the __DATA__ file handle:
----------------------
#!/usr/bin/perl
use strict;
use warnings;
use POSIX;
open (TEST, "+> /tmp/output");
print TEST "testing\n";
POSIX::close(3);
print TEST "testing\n";
----------------------------------
Perl will not complain about this code, but nothing gets written to the
file. the first print is buffered, and using POSIX::close on the file
descriptor will not trigger a flush of the buffer. The second print also
doesn't cause perl to complain, but if you look at the strace you can see
the problems with this:
read(3, "", 4096) = 0
close(3) = 0
open("/tmp/output", O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
ioctl(3, SNDCTL_TMR_TIMEBASE, 0xbffff580) = -1 ENOTTY (Inappropriate ioctl
for device)
_llseek(3, 0, [0], SEEK_CUR) = 0
fstat64(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
close(3) = 0
write(3, "testing\ntesting\n", 16) = -1 EBADF (Bad file descriptor)
close(3) = -1 EBADF (Bad file descriptor)
exit_group(0) = ?
By the way, with this program I get the same results with perl 5.6.1 and
perl 5.8.0.
So does this just mean that POSIX::close should only ever be used with
files that are opened with POSIX::open? A note in the POSIX docs regards
to this would have helped a great deal. Also, I guess I will have to talk
to the maintainer of Proc::Daemon to come up with a workaround to using
POSIX::close to clean up any open file handles.
Thanks for your help.
Cees
------------------------------
Date: Thu, 30 Jan 2003 05:45:41 GMT
From: Owen Cook <rcook@pcug.org.au>
Subject: Re: Premature end of script headers errors
Message-Id: <Pine.GSO.4.21.0301301642100.3242-100000@supreme.pcug.org.au>
On 29 Jan 2003, Chumley the Walrus wrote:
> I have all my files chmoded correctly, but I keep getting an internal
> server error when trying to access my perl script/ page. In my error
> logs, I get a:
>
> Premature end of script headers
>
> ...which tells me little or nothing.
>
> Any ideas? Thanks for help
If the permissions are correct, you could have incorrect newline
characters. If the script was written in a MS or windows program, then you
need to fix that.
Did you upload the script to a server, did you do an ASCII transfer or
send it up as binary? That can cause problems also
Owen
------------------------------
Date: 30 Jan 2003 00:29:40 -0800
From: hemuda@yahoogroups.com (Hemuda)
Subject: Regular expression and capturing
Message-Id: <20d93d09.0301300029.438b1239@posting.google.com>
Hello All,
I am reasonably good in perl. I am looking for a better way of doing
the following. My actual problem is quite complex and I am just
reproducing the problem in the following code. Any help or pointers in
improving the efficiency is appreciated.
The string "s" is the start sequence (^s in regex) and "e" the end
sequence (e$ in regex). I need to extract components a b c and d which
are seperated by , and there can be a variable number of these. (Think
of a b c d , as some sequence and I will replace corresponding regex).
@list = ( "sa,b,c,de" =~ m/^s(?:(\w),)+(\w)e$/ );
The above reqex matches the string but the capturing (@list) only
receives (c, d). Capturing parenthesis for $1 gets overwritten and
finally has just c. Currently to get all the components I have to
store "a,b,c,d" in some variable and then have to use split which is
costly.
How can I get the list ("a", "b", "c", "d") with just one regex match?
Is there any simple way to do it?
How to do it by embedding perl code witin the regular expression using
(??{ code }) ? Examples to its usage is also appriciated.
Thanks,
Hemant
------------------------------
Date: 30 Jan 2003 08:57:07 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Regular expression and capturing
Message-Id: <slrnb3hq73.mvb.abigail@alexandra.abigail.nl>
Hemuda (hemuda@yahoogroups.com) wrote on MMMCDXXXIX September MCMXCIII in
<URL:news:20d93d09.0301300029.438b1239@posting.google.com>:
** Hello All,
**
** I am reasonably good in perl. I am looking for a better way of doing
** the following. My actual problem is quite complex and I am just
** reproducing the problem in the following code. Any help or pointers in
** improving the efficiency is appreciated.
**
** The string "s" is the start sequence (^s in regex) and "e" the end
** sequence (e$ in regex). I need to extract components a b c and d which
** are seperated by , and there can be a variable number of these. (Think
** of a b c d , as some sequence and I will replace corresponding regex).
**
** @list = ( "sa,b,c,de" =~ m/^s(?:(\w),)+(\w)e$/ );
**
** The above reqex matches the string but the capturing (@list) only
** receives (c, d). Capturing parenthesis for $1 gets overwritten and
** finally has just c. Currently to get all the components I have to
** store "a,b,c,d" in some variable and then have to use split which is
** costly.
**
** How can I get the list ("a", "b", "c", "d") with just one regex match?
You can't.
** Is there any simple way to do it?
Not if you insist on doing it all in one regex. But it's easy to do
it in two:
@list = do {"sa,b,c,de" =~ m/^s((?:\w,)+\w)e$/ && $1 =~ /(\w)/g};
Abigail
--
:;$:=~s:
-:;another Perl Hacker
:;chop
$:;$:=~y:;::d;print+Just.$:
------------------------------
Date: Thu, 30 Jan 2003 10:02:03 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Regular expression and capturing
Message-Id: <pan.2003.01.30.08.22.35.432893@kamelfreund.de>
On Thu, 30 Jan 2003 00:29:40 +0000, Hemuda wrote:
> The string "s" is the start sequence (^s in regex) and "e" the end
> sequence (e$ in regex). I need to extract components a b c and d which
> are seperated by , and there can be a variable number of these. (Think
> of a b c d , as some sequence and I will replace corresponding regex).
>
> @list = ( "sa,b,c,de" =~ m/^s(?:(\w),)+(\w)e$/ );
>
> The above reqex matches the string but the capturing (@list) only
> receives (c, d). Capturing parenthesis for $1 gets overwritten and
> finally has just c. Currently to get all the components I have to
> store "a,b,c,d" in some variable and then have to use split which is
> costly.
>
> How can I get the list ("a", "b", "c", "d") with just one regex match?
> Is there any simple way to do it?
I would use a combination of substr and split:
my @list = split /,/, substr "sa,b,c,de", 1, -1;
Greetings,
Janek
------------------------------
Date: Thu, 30 Jan 2003 09:52:20 +0100
From: "Djm" <dmuren@start.no>
Subject: Search a text
Message-Id: <8J5_9.21813$Rc7.306417@news2.e.nsc.no>
I need some help to search a text. I have read in some of the perl faqs, but
since I am a newbie I do not understand how I can solve this.
I want to search the bible. For those of you who are familiar with the bible
knows that it is build by books, chapters and verses. Now, I want to search
for e.g. gen2:3. The text can be found on several lines so I need to extract
the text between gen2:3 and gen2:4. I also have to have in mind that
somewhere down the line the books change.
Anyone know how to deal with this "problem"?
I need help because I´ve started to learn perl 3 days ago.
Djm
------------------------------
Date: Thu, 30 Jan 2003 10:52:38 +0000
From: Simon Oliver <simon.oliver@nospam.umist.ac.uk>
Subject: Re: Search a text
Message-Id: <3E3903F6.90706@nospam.umist.ac.uk>
Djm wrote:
> I need some help to search a text. I have read in some of the perl
faqs, but
> since I am a newbie I do not understand how I can solve this.
What format is your bible in? Is it a database, or a plain text file?
The Project Gutenberg EBook version of the King James Bible has the format:
01:001:001 In the beginning God created the heaven and the earth.
01:001:002 And the earth was without form, and void; and darkness was
upon the face of the deep. And the Spirit of God moved upon
the face of the waters.
You could use unpack, substr or a regexp to seperate the index from the
text and then read-on untill you find a line of white space.
One solution would be to convert the bible to a DBM and use the tied
hash interface to quickly locate a verse.
--
Simon Oliver
--
Simon Oliver
------------------------------
Date: Thu, 30 Jan 2003 10:02:58 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: Tie::IxHash
Message-Id: <b1ataa$kmb$1@newshost.mot.com>
"Brian McCauley" <nobull@mail.com> wrote
> > I read perldoc -q remember the order
> > It told me that:
> >
> > tie(%myhash, Tie::IxHash);
> > Bareword "Tie::IxHash" not allowed while "strict subs" in use at v06b.pl
> > line 101.
> >
> > As usual I bet it's me that did something wrong, but I have no idea
what.
> Actually you have found an error in the FAQ. The FAQ should not
> include example code that only compiles without strict subs.
>
> And your prize for finding the error is that you get to report it to
> the FAQ maintainer. This means that you'll be able to say from now on
> that you are a contributor to Perl (albeit a contributor of only two
> characters).
WAY HAAAAAAAAAAAAAAAAAAAAAYYYYY!
My life is worthwhile, now!! :-D
R.
------------------------------
Date: Thu, 30 Jan 2003 20:07:32 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Use and Require - Perl Modules
Message-Id: <b1aq0n$10pg9i$1@ID-172104.news.dfncis.de>
"Richard Byers" <richardbyers@talk21.com> wrote in message
news:22a01626.0301290409.e4dedf@posting.google.com...
> Many thanks for your assistance.
Why are you talking to yourself?
>
> You been most helpful - which is what these internet groups are all about!
I certainly haven't. Who is "you"?
BTW, this is a Usenet group, not Internet group.
------------------------------
Date: 30 Jan 2003 10:39:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: wondering why this doesn't work
Message-Id: <b1avcl$fed$2@mamenchi.zrz.TU-Berlin.DE>
Andrew Perrin (CLists) <clists@perrin.socsci.unc.edu> wrote in comp.lang.perl.misc:
> swen <swen@news.com> writes:
>
> [snip]
>
> > require B;
>
> That's because there's a standard B.pm which is part of the perl package:
>
> aperrin@perrin:~$ perldoc B
>
> B(3) User Contributed Perl Documentation B(3)
>
>
>
> NAME
> B - The Perl Compiler
>
> SYNOPSIS
> use B;
>
>
> Summary: use a different name (not B.pm).
...or put "use lib '.'" ahead of the "use ..." statements. This will
make it search the current directory before everything else, so your
B.pm will be used.
Anno
------------------------------
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 4486
***************************************