[19689] in Perl-Users-Digest
Perl-Users Digest, Issue: 1884 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 6 14:05:35 2001
Date: Sat, 6 Oct 2001 11:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1002391507-v10-i1884@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 6 Oct 2001 Volume: 10 Number: 1884
Today's topics:
5.6.x: Bug in \B? (was: Goedel JAPH) <lt@toetsch.at>
Re: 5.6.x: Bug in \B? (was: Goedel JAPH) <nospam-abuse@ilyaz.org>
Re: 5.6.x: Bug in \B? <lt@toetsch.at>
Re: Finding the difference between arrays... (JR)
Re: Goedel JAPH <lt@toetsch.at>
Re: Goedel JAPH <lt@toetsch.at>
Re: Goedel JAPH (Martien Verbruggen)
Re: Goedel JAPH <lt@toetsch.at>
Re: How to change date of a file <jurgenex@hotmail.com>
Re: How to have portable email script? (Abigail)
Re: HTTP Binary File Transfer <thomas@baetzler.de>
Re: Nested loops and scoping $_ <bernie@fantasyfarm.com>
one more question about regexps <vvv@vsu.ru>
Re: one more question about regexps <vvv@vsu.ru>
Re: one more question about regexps (Martien Verbruggen)
Re: one more question about regexps <theaney@toadmail.toad.net>
Open Test Failed (Jeff LaPlante)
Re: Perl via metasend (Rodney)
Re: quasi xml to xml (Alan Barclay)
Re: quasi xml to xml <jeff@vpservices.com>
Re: Reformat Chain <thomas@baetzler.de>
Re: resetting variables (rolf deenen)
Re: strangeness (bug?) in regexp handling <vvv@vsu.ru>
Re: Undef ALL arrays? <s.warhurst@rl.ac.uk>
Re: Undef ALL arrays? <s.warhurst@rl.ac.uk>
Re: Undef ALL arrays? <s.warhurst@rl.ac.uk>
waitpid in signal handlers <leo@strike.wu-wien.ac.at>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 6 Oct 2001 15:28:41 +0200
From: Leopold Toetsch <lt@toetsch.at>
Subject: 5.6.x: Bug in \B? (was: Goedel JAPH)
Message-Id: <slrn9ru1o5.16k.lt@toetsch.at>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
Hi, once again:
> $ perl5.6.1 /tmp/foo.pl
> String found where operator expected at (eval 3) line 1, near
> "prInT"JuSt anOtHeR PeRl HaCkEr""
I tested it now with ActivePerl 5.60 on W2K and it gives the same
rubbish.
The difference ist the behaviour of the \B in this line
s/\B./lc$MATCH/eg;
I had earlier the string in lowercase and uppercased it like this:
s/\b./uc$&/eg;
Now the string is in uppercase and I lowercase all but the first
letter of a word, or better I wanted to ;-)
Doc says:
\B Match a non-(word boundary)
but nothing more. So there must be a difference in 5.005 / 5.6.
perldelta seems not to mention the change.
5.6 does lowercase each second letter, which seems br0ken to me.
But may be, I don't understand a 'non-(word boundary)'.
leo
--
Oct 06 15:29:48 lux siggen[10038]: reading next random sig
Oct 06 15:29:48 lux siggen[10038]: warning: this sig is too big
Oct 06 15:29:48 lux siggen[10038]: trying next number /dev/random'ed
Oct 06 15:29:48 lux siggen[10038]: sorry, sig is offending - abandoned!
------------------------------
Date: Sat, 6 Oct 2001 14:33:41 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: 5.6.x: Bug in \B? (was: Goedel JAPH)
Message-Id: <9pn4o5$2hti$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Leopold Toetsch
<lt@toetsch.at>], who wrote in article <slrn9ru1o5.16k.lt@toetsch.at>:
> The difference ist the behaviour of the \B in this line
>
> s/\B./lc$MATCH/eg;
One place where the behaviour of the leading \B could change (but
probably did not :-() is the fact that in some (highly optimized in
the core) substitutions \B (wrongly) operates on a substituted string,
instead of the initial string. But your case is a) not optimized this
way; b) word boundaries do no move during the substution.
Can it be just the fact that Perl has no way to know that $MATCH can
change during the substitution, so it precalculates lc $MATCH?
Probably not...
Ilya
------------------------------
Date: Sat, 6 Oct 2001 19:09:28 +0200
From: Leopold Toetsch <lt@toetsch.at>
Subject: Re: 5.6.x: Bug in \B?
Message-Id: <slrn9ruemk.19s.lt@toetsch.at>
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
>> s/\B./lc$MATCH/eg;
> One place where the behaviour of the leading \B could change (but
> probably did not :-() is the fact that in some (highly optimized in
> the core) substitutions \B (wrongly) operates on a substituted string,
> instead of the initial string. But your case is a) not optimized this
> way; b) word boundaries do no move during the substution.
no optimization and just a fix string:
C:\WINNT>perl -e"$_=q/aaaaaaaaaaaaa aaaa/; s/\B./uc $&/eg; print"
aAaAaAaAaAaAa aAaA
$ perl -le'$_=q/aaaaaaaaaaaa aaa/; s/\B./uc $&/eg; print'
aAAAAAAAAAAA aAA
1. is ActivePerl 5.6 on W2K
2. is Perl 5.005_02 and _03 on Linux
> Ilya
leo
--
Oct 06 19:34:15 lux siggen[18908]: reading next random sig
Oct 06 19:34:15 lux siggen[18908]: quota exceeded on /dev/zero
Oct 06 19:34:15 lux siggen[18908]: no space left on device
Oct 06 19:34:15 lux siggen[18908]: can't write ~/.signature
------------------------------
Date: 6 Oct 2001 11:02:15 -0700
From: tommyumuc@aol.com (JR)
Subject: Re: Finding the difference between arrays...
Message-Id: <319333f5.0110061002.62d9c741@posting.google.com>
abigail@foad.org (Abigail) wrote in message news:<slrn9rrlbl.c4h.abigail@alexandra.xs4all.nl>...
> JR (tommyumuc@aol.com) wrote on MMCMLVII September MCMXCIII in
> <URL:news:319333f5.0110050602.5c0c210e@posting.google.com>:
> }} For the following array examples, how is it possible to determine the
> }} difference? I can't use hashes, because in the actual arrays there
> }} would be many duplicate keys, which aren't allowed in hashes. I can't
> }} just split the fields and do something like "$arrayOne[$_] !=
> }} $arrayTwo[$_]" because, as in the below example, that would return row
> }} 0, 2, and 3. The true difference between the two arrays is:
> }}
> }} 01,001,000,0003 and 01,001,000,0002
> }}
> }} because there are 3 (01,001,000,0003) in @arrayOne and 2 in @arrayTwo
> }} and there is 1 (01,001,000,0002) in @arrayOne and 2 in @arrayTwo.
> }}
> }} My guess is that I need to, in some way, pop, shift, or splice to
> }} remove elements that are compared and found to be equal. The problem
> }} I'm having is how to loop through the arrays, and then delete elements
> }} of those arrays after a match has been found (a runtime error occurs,
> }} usually).
> }}
> }}
> }} @arrayOne @arrayTwo
> }} --------- ---------
> }} 01,001,000,0002 01,001,000,0003
> }} 01,001,000,0003 01,001,000,0003
> }} 01,001,000,0003 01,001,000,0002
> }} 01,001,000,0003 01,001,000,0002
> }} ... ...
> }}
> }} (DESIRED RESULT)
> }} @fallOut
> }} --------
> }} 01,001,000,0003
> }} 01,001,000,0002
> }}
> }} I hope I've explained this problem reasonably well. I would
> }} appreciate any help anyone may have.
>
>
> Actually, you didn't explain a single thing. You gave an example of two
> arrays, each containing 4 elements. Just on one index, the elements are
> the same, so we have 3 places where things differ. Yet, only 2 elements
> are reported. To make thinks more complicated, many elements are repeated,
> and there just 2 values in total.
>
> What is in @fallOut? $arrayTwo [0] and $arrayOne [0]? $arrayTwo [0] and
> $arrayTwo [2]? $arrayOne [3] and $arrayOne [0]?
>
>
> It would help to actually *specify* your problem instead of giving one
> unclear example.
>
>
>
> Abigail
Thank you for taking the time to criticize me, Abigail. Maybe I
didn't do the best job explaining the problem, but I don't think the
problem which I attempted to explain was entirely unclear (and if so,
then your criticism not only affects me, it affects those who tried to
help me with my "one unclear example").
------------------------------
Date: Sat, 6 Oct 2001 12:46:50 +0200
From: Leopold Toetsch <lt@toetsch.at>
Subject: Re: Goedel JAPH
Message-Id: <slrn9rto8m.m6.lt@toetsch.at>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> $ perl5.6.1 /tmp/foo.pl
> $ perl5.6.0 /tmp/foo.pl
> "prInT"JuSt anOtHeR PeRl HaCkEr""
The program uses AFAIK just basic Perl instructions, so this is strange.
It works for me with 5.00503 and 5.00502 on two different Linux
machines. Do you know, what is different in 5.6, that breaks it?
Are there CRs in your file? Ok, I forgot these ;-)
> $ perl5.00405 /tmp/foo.pl
> $
> The last 2 may not be displaying anything, because you're not emitting a
> newline. Let's see..
perl -l emits a newline. But nethertheless, without a newline, still
the output would be printed on program termination.
> $ perl5.00503 /tmp/foo.pl > /tmp/foo.out
> $ echo `cat /tmp/foo.out`
> Just another Perl Hacker
Useless use of echo and cat?
> Martien
leo
--
Oct 06 14:03:07 lux siggen[8628]: reading next random sig
Oct 06 14:03:07 lux siggen[8628]: quota exceeded on /dev/zero
Oct 06 14:03:07 lux siggen[8628]: no space left on device
Oct 06 14:03:07 lux siggen[8628]: can't write ~/.signature
------------------------------
Date: Sat, 6 Oct 2001 14:02:53 +0200
From: Leopold Toetsch <lt@toetsch.at>
Subject: Re: Goedel JAPH
Message-Id: <slrn9rtsnd.m6.lt@toetsch.at>
Corrected version, this should work on Win/Mac too:
#!/usr/bin/perl -lw
use strict;
use English;
## Please note the <spaces> in lines 6, 16 & 17
$_=q!
y[Ao-qBPdghl1] [1];
tr/C\nnH;#/;/;
y[b]{1};
s[y]{1}g;
tr/5/1/d;
y/;//ds;
y[8\}\(.,][1];#-lt
y.\r..d;#cr
tr[12$](111);
tr(01){0}c;#1
s([001]{5}) .pack'b8', "$&010".geoms;
y.YGFBM. ="'$.;
s/\B./lc$MATCH/eg;
s[P](p);
s/A/a/;
!; #'"
eval and eval eval;
leo
--
Oct 06 14:03:07 lux siggen[8628]: reading next random sig
Oct 06 14:03:07 lux siggen[8628]: quota exceeded on /dev/zero
Oct 06 14:03:07 lux siggen[8628]: no space left on device
Oct 06 14:03:07 lux siggen[8628]: can't write ~/.signature
------------------------------
Date: Sat, 6 Oct 2001 22:19:55 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Goedel JAPH
Message-Id: <slrn9rttnb.d6o.mgjv@martien.heliotrope.home>
On Sat, 6 Oct 2001 12:46:50 +0200,
Leopold Toetsch <lt@toetsch.at> wrote:
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>
>> $ perl5.6.1 /tmp/foo.pl
>> $ perl5.6.0 /tmp/foo.pl
>
>> "prInT"JuSt anOtHeR PeRl HaCkEr""
>
> The program uses AFAIK just basic Perl instructions, so this is strange.
> It works for me with 5.00503 and 5.00502 on two different Linux
> machines. Do you know, what is different in 5.6, that breaks it?
Nope. I haven't actually looked at it indepth.
> Are there CRs in your file? Ok, I forgot these ;-)
Nope. Just newlines. Shouldn't make a difference anyway.
>> $ perl5.00405 /tmp/foo.pl
>> $
>
>> The last 2 may not be displaying anything, because you're not emitting a
>> newline. Let's see..
>
> perl -l emits a newline. But nethertheless, without a newline, still
> the output would be printed on program termination.
Depends on the shell, terminal, and some other things. Anything that is
printed without a newline is not guaranteed to be visible. Most shells
will gobble up a line that isn't followed by a newline. I don't exactly
know whether Perl takes extra precautions, but its I/O is built on top
of C stdio, and in C stdio your output has to be followed by a newline
if you want it to show up with any guarantee.
>> $ perl5.00503 /tmp/foo.pl > /tmp/foo.out
>> $ echo `cat /tmp/foo.out`
>> Just another Perl Hacker
>
> Useless use of echo and cat?
Nope. The echo is there to introduce a newline. Could have done it with
Perl as well, but that's not the point. The point was that your output
doesn't have the terminating newline that it should have.
Martien
--
Martien Verbruggen |
Interactive Media Division | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Sat, 6 Oct 2001 15:49:46 +0200
From: Leopold Toetsch <lt@toetsch.at>
Subject: Re: Goedel JAPH
Message-Id: <slrn9ru2vq.16k.lt@toetsch.at>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>> perl -l emits a newline. But nethertheless, without a newline, still
>> the output would be printed on program termination.
> Depends on the shell, terminal, and some other things. Anything that is
> printed without a newline is not guaranteed to be visible.
Ok I see, but you didn't give the -l switch, when testing the program.
First line in my source was:
#!/usr/bin/perl -lw
^^
> Martien
HTH
leo
--
Leopold Toetsch <lt@toetsch.at> http://www.toetsch.at/linux/
-
Dead end
------------------------------
Date: Sat, 6 Oct 2001 07:55:10 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How to change date of a file
Message-Id: <3bbf1b51$1@news.microsoft.com>
<NOSPAM@mail.ru> wrote in message
news:s25rrtkm8s6evrgqpkkgv10lael19a1l9e@4ax.com...
> I need to be able to change date of a file, using a perl script. Have
> no idea of the functions and params to call.
Are you looking for
system ("touch $thisfile");
jue
------------------------------
Date: 6 Oct 2001 13:52:14 GMT
From: abigail@foad.org (Abigail)
Subject: Re: How to have portable email script?
Message-Id: <slrn9ru31h.dc3.abigail@alexandra.xs4all.nl>
BCC (a@b.c) wrote on MMCMLVIII September MCMXCIII in
<URL:news:3BBE572A.85123AE4@b.c>:
Please, do NOT post Jeopardy style. It will make you look clueless, and
appear in many killfiles.
%% The windows machine I have to use is on our ISP and I have no idea what
%% they have installe on it. This is a problem I believe.
It's not a problem for people who can be bothered to read the FAQ.
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
# The Buddha weeps near
# Mount Fuji. A butterfly
# flying. A dog eats.
------------------------------
Date: Sat, 06 Oct 2001 17:39:28 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: HTTP Binary File Transfer
Message-Id: <db9urtkeq9nr2fmi79hk3deppbeg97v4to@4ax.com>
On Fri, 05 Oct 2001 20:08:18 GMT, r1ckey <r1ckey@home.com> wrote:
>Yes, I did look at the file, it's a bunch of binary junk, as it should be.
>Maybe you could point me to the man page you're referring to. I went through
>Google, local man pages and online docs, now I'm here.
Check out the LWP man page. It includes a class overwiew that'll steer
you to the relevant HTTP classes.
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Sat, 06 Oct 2001 07:54:32 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: Nested loops and scoping $_
Message-Id: <3urtrtc6hgp55eppqhovrarv3phm73djun@news.supernews.net>
Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
} Bernie Cosell <bernie@fantasyfarm.com> writes:
}
} > This is, alas, one of the failings of using shallow binding over
} > real dynamic binding...
} ^^^^^^^^^^^^^^^^^^^^
}
} Could you explain this? AFAICT the reason that "local *q = \$_;"
} would actually work is *because* of "shallow binding", not despite it.
} (i.e. "local *q = *_;" will *not* work.)
Sorry, I didn't write clearly. My "This" wasn't referring to the 'local'
hack [which is just ugly, but works] but to the general problem of being
able to mess with _previous_ bindings of a variable and the _necessity_ to
have to explicitly mirror the previous bindings if you want to see them.
Contrast this overall situation with the old Lisp systems that used
stack-based dynamic binding. In those systems you had primitives for
things like "which stack frame did you find this variable in" and "evaluate
this expression beginning <HERE> on the stack". the latter, for example,
would allow you to do things like pass an expression into a function and
have the function be able to evaluate the expression in the context of the
caller.
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: Sat, 06 Oct 2001 16:20:07 +0400
From: Vladimir Volovich <vvv@vsu.ru>
Subject: one more question about regexps
Message-Id: <eyadz5dkp4.fsf@vsu.ru>
Hi,
let $_ be a string, and we know for sure that it has the following
structure:
{<part1>}{<part2>}{<part3>}
i.e. it contains three groups of substrings enclosed in curly braces.
each substring like <part1> can itself contain curly braces, but
always paired.
i'd like to extract those substrings. but the naïve approach like
($part1, $part2, $part3) = m/^\{(.*?)\}\{(.*?)\}\{(.*?)\}$/
will give incorrect results some cases (as it does not know about
paired braces inside parts).
is it possible to achieve this via regexps, or should i write a more
complex parser?
Best,
v.
------------------------------
Date: Sat, 06 Oct 2001 17:17:33 +0400
From: Vladimir Volovich <vvv@vsu.ru>
Subject: Re: one more question about regexps
Message-Id: <eyu1xcdi1e.fsf@vsu.ru>
"VV" == Vladimir Volovich writes:
VV> is it possible to achieve this via regexps, or should i write a
VV> more complex parser?
sorry, -- just noticed a FAQ posting on this matter...
Best,
v.
------------------------------
Date: Sat, 6 Oct 2001 23:12:45 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: one more question about regexps
Message-Id: <slrn9ru0qd.d6o.mgjv@martien.heliotrope.home>
On Sat, 06 Oct 2001 16:20:07 +0400,
Vladimir Volovich <vvv@vsu.ru> wrote:
>
> let $_ be a string, and we know for sure that it has the following
> structure:
>
> {<part1>}{<part2>}{<part3>}
>
> i.e. it contains three groups of substrings enclosed in curly braces.
> each substring like <part1> can itself contain curly braces, but
> always paired.
> is it possible to achieve this via regexps, or should i write a more
> complex parser?
Perl FAQ, part 4, question "How do I find matching/nesting anything?"
Martien
--
Martien Verbruggen |
Interactive Media Division | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd. | selective about its friends.
NSW, Australia |
------------------------------
Date: 06 Oct 2001 10:16:06 -0400
From: Tim Heaney <theaney@toadmail.toad.net>
Subject: Re: one more question about regexps
Message-Id: <87ofnk3lcp.fsf@susie.watterson>
Vladimir Volovich <vvv@vsu.ru> writes:
>
> is it possible to achieve this via regexps, or should i write a more
> complex parser?
I wouldn't do either. Damian Conway has already done the latter. Check
out the Text::Balanced module
http://search.cpan.org/search?dist=Text-Balanced
Something like
use Text::Balanced 'extract_bracketed';
while ( $next = (extract_bracketed($_,'{}'))[0] ) {
push @parts, $next;
}
should do it. I don't see an option to not include the brackets in the
match, but perhaps I'm just missing it. You can just chop them off
when you store the parts in separate scalars, if that's what you
really want
($part1, $part2, $part3) = map { $1 if m/\{(.*)\}/ } @parts;
I hope this helps,
Tim
------------------------------
Date: 6 Oct 2001 07:10:15 -0700
From: jlaplante1@hotmail.com (Jeff LaPlante)
Subject: Open Test Failed
Message-Id: <2bd8abaf.0110060610.211bf482@posting.google.com>
When running a Perl script i get the following error:
open test failed: Value too large for defined data type
Can anyone explain this phenomenon and to possibly fix it.
Thanks,
jeff
------------------------------
Date: 6 Oct 2001 10:03:09 -0700
From: kc5sbj@yahoo.com (Rodney)
Subject: Re: Perl via metasend
Message-Id: <4c772a11.0110060903.5aa4bac8@posting.google.com>
How does one use MIME::Lite do send attachments? I have bee trying
with no success using code in the Summer 1999 PERL Journal. I can get
the mail sent only if I do not attempt attachments.
Bart Lateur <bart.lateur@skynet.be> wrote in message news:<vebkrtgl9cb6nvcbbq0q9kivdf1ae7060r@4ax.com>...
> Donnajeanne Liu wrote:
>
> [snip]
>
> >How do I send 1 email, using metasend, with 2 files attached?
>
> Gee. I think it would be easiest to drop all this, and just use
> Mime::Lite both to construct the mail with attachments, and send it.
------------------------------
Date: 6 Oct 2001 17:32:40 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: quasi xml to xml
Message-Id: <1002389568.7424@elaine.furryape.com>
In article <3BBE4D81.38124B39@vpservices.com>,
Jeff Zucker <jeff@vpservices.com> wrote:
>my $key;
>my %hash;
>my @array;
>while (<DATA>) {
> chomp;
> next if /<start>/;
> last if /<end>/;
> if (/<(.+)>/) {
> $key = $1;
> push @array, $key;
> next;
> }
> $hash{$key} = $_;
>}
>print "<start>\n";
>for $key(@array) {
> print " <$key>$hash{$key}</$key>\n"
>}
>print "<end>\n";
Why the @array?
Seems like it woule be better to use 'for $key (keys %array)'
------------------------------
Date: Sat, 06 Oct 2001 10:52:40 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: quasi xml to xml
Message-Id: <3BBF44E8.EED0B10D@vpservices.com>
Alan Barclay wrote:
>
> In article <3BBE4D81.38124B39@vpservices.com>,
> Jeff Zucker <jeff@vpservices.com> wrote:
> >my $key;
> >my %hash;
> >my @array;
> >while (<DATA>) {
> > chomp;
> > next if /<start>/;
> > last if /<end>/;
> > if (/<(.+)>/) {
> > $key = $1;
> > push @array, $key;
> > next;
> > }
> > $hash{$key} = $_;
> >}
> >print "<start>\n";
> >for $key(@array) {
> > print " <$key>$hash{$key}</$key>\n"
> >}
> >print "<end>\n";
>
> Why the @array?
>
> Seems like it woule be better to use 'for $key (keys %array)'
Because I assumed (perhaps wrongly, but they didn't specify) that the OP
wants to preserve the original order of the keys. If the order is
irrelevant, the array can be ommitted. But if the order is relevant,
your way loses it.
--
Jeff
------------------------------
Date: Sat, 06 Oct 2001 17:44:30 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: Reformat Chain
Message-Id: <4i9urts1rk7ejteesepucmol0ks7a6jvfa@4ax.com>
On Fri, 05 Oct 2001, Benjamin Goldberg <goldbb2@earthlink.net> wrote:
>splice(@something, 0, 1) is another name for shift(@something).
Yup. But then splice is used far too seldom, even it's a pretty cool
command. Usually quickest, too :-)
Cheers,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 6 Oct 2001 07:28:38 -0700
From: rdeenen@mollymail.com (rolf deenen)
Subject: Re: resetting variables
Message-Id: <5b51a4e6.0110060628.12c1907@posting.google.com>
> Did you see my previous contribution to this thread?
Well NoBull,
I Did, but you must have miunderstood me. I am not using cgi.pm (in
fact I don't even know what it is ). I just am rying to learn perl and
in the process i try to write a litte script that i can use in daily
life. The script is supposed to store hyperlinks, like "bookmarks" but
independend of the machine i work on. So it takes input (name, url,
comment) and appends this to a file which is than layed out and
printed to screen. The problem is that when i add a line via a form
and i refresh this form, it adds the line again (which is logical, but
not what i want...)
Rolf
------------------------------
Date: Sat, 06 Oct 2001 16:02:44 +0400
From: Vladimir Volovich <vvv@vsu.ru>
Subject: Re: strangeness (bug?) in regexp handling
Message-Id: <eyelohdli3.fsf@vsu.ru>
"TB" == Thomas Bätzler writes:
TB> You could first map all HTML entities to their "real" characters
TB> and then capture a match from the start of the line up to the
TB> first semicolon.
by "real" characters you mean characters from iso-8859-1 charset? but
some entities could refer to unicode characters which are not present
in iso-8859-1.
TB> You certainly can't use negative lookback because that would've
TB> to be fixed width.
(i do not understand what do you mean here)
TB> Thanks for the explanation!
Thank you for explanation!
Best,
v.
------------------------------
Date: Sat, 6 Oct 2001 16:09:37 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: Undef ALL arrays?
Message-Id: <9pn6rj$n4q@newton.cc.rl.ac.uk>
"Bernard El-Hagin" <bernard.el-hagin@lido-tech.net> wrote in message
news:slrn9rqodj.8li.bernard.el-
> You realise, of course, that resetting 'A-Z' will undef
> variables like %ENV, @ARGV, @INC?
Yes, that's OK.. I don't use them in this program.
Regards
Spencer
------------------------------
Date: Sat, 6 Oct 2001 16:13:36 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: Undef ALL arrays?
Message-Id: <9pn730$18ni@newton.cc.rl.ac.uk>
"Uri Guttman" <uri@sysarch.com> wrote in message
news:x7hete8raa.fsf@home.sysarch.com...
> if you need to do that, then your program probably needs a major
> redesign. it may mean you have too many globals. put more of them in
> scopes and let them get initialized to undef upon entry to the
> scopes. put more of the vars into hashes or lists and reduce the number
> of declared vars. many other software engineering techniques would help
> too but i have no idea what your program is like. but doing a global
> reset is a very weak answer to a more fundamental problem.
It probably could be better designed but there are alot of stats & variables
to hold them in being used in the program.. I needed to do a one off loop,
which I've done now & reset worked nicely :)
Regards
Spencer
------------------------------
Date: Sat, 6 Oct 2001 16:16:28 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: Undef ALL arrays?
Message-Id: <9pn78c$18ho@newton.cc.rl.ac.uk>
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:fqtqrt8dihb5i2k283hb3e988f6gt3ec84@4ax.com...
> For globals, use
>
> use vars qw/$var @var %var/;
>
> or
>
> our($var, @var, %var); # only 5.6.0 and later
>
> and local'ise them in the loop block:
>
> local($var);
>
> if you change them. You can do
>
> local(%ENV) = %ENV;
>
> to initialise them to their initial, outer value every time.
>
> p.s. If you RUN the program again instead of looping, there shouldn't
> even be a problem.
Thanks. I probably ought to use local scope variables!
Regartds
Spencer
------------------------------
Date: Sat, 06 Oct 2001 18:25:22 +0200
From: Alexander Bergolth <leo@strike.wu-wien.ac.at>
Subject: waitpid in signal handlers
Message-Id: <3BBF3072.3B9C9561@strike.wu-wien.ac.at>
Hi!
I've written a small test-script (see below) that dumps core because
of a seg-fault on many systems when the signal handler is called while
there is memory is allocated in the main program. The signal handler
doesn't use or modify any variable, it's only:
$SIG{'CHLD'} = sub {
while (waitpid(-1,&WNOHANG) > 0) { }
};
It looks like Perls waitpid uses malloc. :(
I've tested this with perl-5.6.0 on AIX-4.2.1 and AIX-4.3.3 and
with perl-5.005_03 on linux-2.2.19.
The test-script and the stack backtrace is attached below...
(The random- and delay-parameters are optimised for a crash on
slower machines.)
I've found a similar thread in this group on Google two years ago...
http://groups.google.com/groups?th=73e147d4f576ae40
... but I couldn't find a workaround for this. (Setting preinitialised
flags and calling waitpid outside the signal-handler is not possible
for my application.)
Any hints?
Thanks,
--leo
---------- snipp! ----------
#!/usr/local/bin/perl
use strict;
use POSIX ":sys_wait_h";
my $RAND1= 2000;
my $RAND2= 2000;
my $DELAY_MAIN = 0.2;
my $DELAY_CHILD = 2;
$SIG{'CHLD'} = sub {
while (waitpid(-1,&WNOHANG) > 0) { }
};
my $CHILD_PID = 0;
srand();
$|= 1;
my $i;
for ($i = 1; $i < 200; $i++) {
print "fork $i\n";
# allocate some memory
my ($i, $r1, $r2, @buf);
$r1= rand($RAND1);
for ($i= 1; $i <= $r1; $i++) {
$r2= rand($RAND2);
$buf[$i] = "x" x $r2;
}
my $pid;
if ($pid = fork) {
# parent
select(undef, undef, undef, rand($DELAY_MAIN));
print " Child $pid ready\n";
next;
} elsif (defined $pid) {
# child
$SIG{'CHLD'} = 'DEFAULT';
print " Child $$ ready\n";
select (undef, undef, undef, rand($DELAY_CHILD));
print " Child $$ exit\n";
exit(0);
}
else {
print "Fork error: $!\n";
return;
}
}
print "Done\n";
---------- snipp! ----------
perl-5.6.0 on Linux-2.2.19:
---------------------------
#0 chunk_alloc (ar_ptr=0x40141d40, nb=16) at malloc.c:2814
#1 0x400ac5ae in malloc () at malloc.c:2181
#2 0x807bbe5 in Perl_safemalloc ()
#3 0x808abb6 in Perl_sv_grow ()
#4 0x808cb10 in Perl_sv_setsv ()
#5 0x808ebf5 in Perl_sv_mortalcopy ()
#6 0x8087d8a in Perl_pp_leave ()
#7 0x80b49ad in Perl_runops_standard ()
#8 0x8059a01 in perl_call_sv ()
#9 0x8081cb8 in Perl_sighandler ()
#10 0x40071c48 in __restore () at
../sysdeps/unix/sysv/linux/i386/sigaction.c:127
#11 0x400ac5ae in malloc () at malloc.c:2181
#12 0x807bbe5 in Perl_safemalloc ()
#13 0x808abb6 in Perl_sv_grow ()
#14 0x808cb10 in Perl_sv_setsv ()
#15 0x808533b in Perl_pp_sassign ()
#16 0x80b49ad in Perl_runops_standard ()
#17 0x8059338 in perl_run ()
#18 0x80577e1 in main ()
#19 0x4006b9cb in __libc_start_main () at
../sysdeps/generic/libc-start.c:122
perl-5.6.0 on AIX-4.2.1:
------------------------
malloc_y.malloc_y(??) at 0xd02656c8
malloc.malloc(??) at 0xd0262f10
Perl_safesysmalloc() at 0x100313e4
Perl_sv_grow() at 0x10027550
Perl_sv_setsv() at 0x10024e08
Perl_pp_sassign() at 0x1007d1b8
Perl_runops_standard() at 0x1006340c
S_run_body() at 0x100007c4
perl_run() at 0x100068d0
main() at 0x100003cc
------------------------------
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 1884
***************************************