[26490] in Perl-Users-Digest
Perl-Users Digest, Issue: 8651 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 10 03:05:25 2005
Date: Thu, 10 Nov 2005 00:05:06 -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, 10 Nov 2005 Volume: 10 Number: 8651
Today's topics:
Re: how to do this job using perl? <MrReallyVeryNice.RemoveNoSPAM@yahoo.RemoveNoSPAM.com>
Re: How to get array item directly from split result? <huajian.luo@bsd.world>
Re: just because is a tiger robic0
Re: Need workaround for regex bug in 5.8.6 <sisyphus1@nomail.afraid.org>
Re: The Evil American Corprotocracy robic0
Re: The Evil American Corprotocracy robic0
Re: The Evil American Corprotocracy robic0
Re: Why my code doesn't look Perl-ish? robic0
Re: Why my code doesn't look Perl-ish? robic0
Re: Why my code doesn't look Perl-ish? robic0
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 09 Nov 2005 18:36:13 -0800
From: MrReallyVeryNice <MrReallyVeryNice.RemoveNoSPAM@yahoo.RemoveNoSPAM.com>
Subject: Re: how to do this job using perl?
Message-Id: <kcGdnWMUgLRzLO_eRVn-uA@comcast.com>
sonet wrote:
> #items parent
> 01.attr 0
> 02.attr 0
> 04.attr 01.attr
> 03.attr 01.attr
> 06.attr 02.attr
> 07.attr 03.attr
> 08.attr 03.attr
> 09.attr 07.attr
> =========================================
> transform to this form
> ps: The order must follow above
> =========================================
> 01.attr
> 04.attr
> 03.attr
> 07.attr
> 09.attr
> 08.attr
> 02.attr
>
>
>
Hello,
I believe that the following code should fit the bill. It is a bit long
but it also performs some minimum data validation (you will notice that
I added to your data set).
use strict;
use warnings;
my %tree;
my $initialK;
my $K;
my $V;
my $MaxDepth = 10;
my $depth;
while (<DATA>)
{
my ($dt1,$dt2) = /(.*) (.*)/ or die;
$tree{$dt1} = $dt2;
}
sub modifyValue
{
if ($depth >= $MaxDepth )
{
$tree{$initialK} = "XXXXXXXXXXX: Following $initialK leads a Depth >
$MaxDepth\n";
}
else
{
if(!exists $tree{$V} and $V ne "0")
{
$tree{$initialK} = "YYYYYYYYYYY " . $tree{$initialK};
}
elsif ($V ne "0" )
{
$depth = $depth + 1;
$K = $V;
$V = $tree{$K};
$tree{$initialK} = $V . " " . $tree{$initialK};
modifyValue();
}
}
}
foreach my $key (sort hashValueDescendingNum(keys(%tree)))
{
$initialK = $key;
$K = $key;
$V = $tree{$key};
$depth = 0;
modifyValue;
$tree{$initialK} = $tree{$initialK} . " " . $initialK;
}
foreach my $key (sort hashValueAscendingNum(keys(%tree)))
{
if (substr($tree{$key},0,11) eq "XXXXXXXXXXX")
{
print "\nData set problem: $key may be nested to more than $MaxDepth
level deep!" ;
}
elsif (substr($tree{$key},0,11) eq "YYYYYYYYYYY")
{
print "\nData set problem: $key or one of its ancestor may not
have a root!" ;
}
else
{
my @spaces =split(/ /,$tree{$key});
print (" "x($#spaces-1) . $key . "\n");
}
}
sub hashValueDescendingNum
{
$tree{$b} cmp $tree{$a};
}
sub hashValueAscendingNum
{
$tree{$a} cmp $tree{$b};
}
__DATA__
01.attr 0
02.attr 0
04.attr 01.attr
03.attr 01.attr
06.attr 02.attr
07.attr 03.attr
08.attr 03.attr
09.attr 07.attr
10.attr 11.attr
a.attr 0
b.attr a.attr
c.attr b.attr
d.attr c.attr
e.attr d.attr
f.attr e.attr
g.attr f.attr
h.attr g.attr
i.attr h.attr
j.attr i.attr
k.attr j.attr
l.attr k.attr
Would that work for you?
MrReallyVeryNice
------------------------------
Date: Thu, 10 Nov 2005 05:36:03 +0000 (UTC)
From: Huajian Luo<huajian.luo@bsd.world>
Subject: Re: How to get array item directly from split result?
Message-Id: <dkum83$rq4$1@news1nwk.SFbay.Sun.COM>
"John W. Krahn" <krahnj@telus.net> writes:
> That should be:
>
> for my $line ( @lines ) {
> if ( $line =~ /mb_setno/ ) {
> my $100th_fld = ( split ' ', $line )[ 99 ];
> }
> }
>
>
> Or if you want to save some typing:
>
> for ( @lines ) {
> if ( /mb_setno/ ) {
> my $100th_fld = ( split )[ 99 ];
> }
> }
Yes, that's what I'm looking for and I just wanna save typing
and machine memory, Thanks everyone for the response.
--
Thanks,
Huajian Luo.
------------------------------
Date: Wed, 09 Nov 2005 23:41:46 -0800
From: robic0
Subject: Re: just because is a tiger
Message-Id: <2au5n15s983rja5tq6akv495plsgqtlcao@4ax.com>
On Fri, 4 Nov 2005 13:20:41 +0100, "Dr.Ruud" <rvtol+news@isolution.nl>
wrote:
>Anno Siegel:
>
>> Pedantic educative questions instead of getting on with
>> whatever you were doing. You had it coming.
>
>It's just me.
Wheres the original thread?
Why don't you email each others, ahhh whatever it is
lovers do.
------------------------------
Date: Thu, 10 Nov 2005 14:35:47 +1100
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Need workaround for regex bug in 5.8.6
Message-Id: <4372c051$0$25857$afc38c87@news.optusnet.com.au>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
news:Xns9709CEB53E8BEasu1cornelledu@127.0.0.1...
> "Sisyphus" <sisyphus1@nomail.afraid.org> wrote in
> news:43729c0e$0$32020$afc38c87@news.optusnet.com.au:
>
> >
> > "A. Sinan Unur"
> > .
> > .
> >>
> >> D:\Home\asu1\UseNet\clpmisc> cat r.pl
> >> use strict;
> >> use warnings;
> >>
> >> my($s)= ' ' x 100000 ; # 15880 is fine, but 15881 crashes
> >> $s=~ /(.|ab)*/ ; # dies here with no warning
> >>
> >> D:\Home\asu1\UseNet\clpmisc> perl r.pl
> >> Complex regular subexpression recursion limit (32766) exceeded at
> >> r.pl line 5.
> >>
> >
> > I get the same on Windows 2000, perl5.8.4 - but on Windows 2000,
> > perl5.8.7 all I get is an "Unknown software exception ..." WIndows
> > popup - which in the past has usually meant that the stack overflowed.
> > On linux, perl 5.8.7, it just outputs "Segmentation fault". Seems that
> > somewhere along the way, perl has lost the capability of handling the
> > error, and it's now left up to the operating system to deal with.
> >
> > Something else has changed, too. On my Win32 box, using perl 5.8.7,
> > the "Unknown sopftware exception..." occurs with just 5207 spaces
> > assigned to $s. Using perl 5.8.4 (on the same box/os) there's no
> > problem until at least 32767 spaces are assigned to $s (when the perl
> > error occurs).
>
> Interesting because I am using AS Perl 5.8.7 on Windows, and I cannot
> observe the behavior.
>
Aaah ... my perl 5.8.7 was built using gcc (MinGW port), whereas my perl
5.8.4 is AS build 810. So it looks like the compiler used has a bearing.
In fact, I also have a perl 5.8.7 built using MSVC++ 7.0 (.NET), and I now
find it exhibits the same behaviour as my perl 5.8.4 (and your AS perl
5.8.7).
That's notable in that I can't recall ever coming across a situation where
the compiler used to build a native Win32 perl has had such a marked effect
as we're seeing here.
Cheers,
Rob
------------------------------
Date: Wed, 09 Nov 2005 22:36:31 -0800
From: robic0
Subject: Re: The Evil American Corprotocracy
Message-Id: <u3p5n115jt82acmpfochdi15e09ohai622@4ax.com>
On Sun, 06 Nov 2005 21:14:53 -0800, fishfry <fishfry@your-mailbox.com>
wrote:
>In article <trtam1hlo9gp4t1vg7kv8jpcgpuc2sqj58@4ax.com>,
> robic0@yahoo.com wrote:
>
>>
>> To be continued...
>
>Can you imagine a union programming shop? One guy would do all the for
>loops and another worker would do the while loops. They wouldn't be
>allowed to do each other's jobs.
The way it is now:
The new guy has to guy has to read/resolve 100,000 lines of code to go
to the one line of code that burned up the space shuttle .....
a while loop.
Be careful what you trivialize.
>
>If there ever was a time for programmers to unionize, it was about 20 or
>maybe 30 years ago. Way too late now. Bits flow over wires.
Your light switch flows over wires, electricians didn't wait 20 or
30 years.
> Bitstreams will be created where it's cheapest to create them.
Water will flow downhill until its dammed up. Engineers are taught
from day 1 technical discipline analagies that put all science in
perspective. Last I heard "bits" were nothing but a JK flip-flop
floating on the engineers semi-conductor gating train, known
as a transistor. Maybe you believe bitstreams are something like
from the astronomical heavens, something you think will
provide amunition and arm yourself with witt and wittisisms to
throw like a weapon against your foes or half-witts.
There's always the web and its forums for the intellectuals
such as yourself.
------------------------------
Date: Wed, 09 Nov 2005 22:44:21 -0800
From: robic0
Subject: Re: The Evil American Corprotocracy
Message-Id: <vrq5n15tev5oetl8u3pkfus6er25l57sho@4ax.com>
On 7 Nov 2005 06:13:42 GMT, John Bokma <john@castleamber.com> wrote:
>robic0@yahoo.com wrote:
>
>> something over 15 million lines of code. I've been a paid
>> proffesional programmer (mostly I designed and programmed) since
> ^^^^^
^^^^^ huh? syntax?
>
>Funny :-D
>
>> To be continued...
>
>Hopefully a very short summary of your point :-D.
Just skimming the forums or did you have a particular
question or thought on what you didn't read?
------------------------------
Date: Wed, 09 Nov 2005 22:47:42 -0800
From: robic0
Subject: Re: The Evil American Corprotocracy
Message-Id: <u4r5n119dt2g3go7vmakqo3vakm3sha8bq@4ax.com>
On Sun, 30 Oct 2005 20:52:34 -0800, Percival John Hackworth
<pjh@mps.com> wrote:
>In article <trtam1hlo9gp4t1vg7kv8jpcgpuc2sqj58@4ax.com>,
> robic0@yahoo.com wrote:
>
>> Been at this for 25 years (since writing assemblers on
>>
>>[brain bilge deleted]
never enterred you brain, lobotomy is not necessary
>>
>> To be continued...
>
>someone needs to take their meds and shouldn't be in the day room using
>computers while unsupervised.
I'm holding your reds, anytime your ready for them back, let me know
------------------------------
Date: Wed, 09 Nov 2005 23:16:34 -0800
From: robic0
Subject: Re: Why my code doesn't look Perl-ish?
Message-Id: <2ns5n19sh0e72j34n58hadiahjn3in0kn8@4ax.com>
On Sat, 5 Nov 2005 09:34:40 +0100, "Tassilo v. Parseval"
<tassilo.von.parseval@rwth-aachen.de> wrote:
>Also sprach robic0@yahoo.com:
>
>> On Fri, 04 Nov 2005 23:09:06 -0800, robic0@yahoo.com wrote:
>
>>>In my opinion, Perl is NOT good for stream parsing of
>>>strings because the only powerful tool in Perl for that
>>>is Regular Expressions (filters/pattern matching).
>>>Though with RE's you do have mechanism's of
>>>of capturing the non-matching in-stream characters,
>>>but it usually is, if you have multiple paterns,
>>>very slow and itterative as opposed to a very robust
>>>C++ class like CString. You however, are doing
>>>stream parsing and not pattern matching. And,
>>>given you are keying on a single escape character
>>>(although it could be others combined, as well)
>>>I believe your method is "better" than the regex
>>>suggested by others. The reason being that your
>>>methid is infinetly expandable which would leave
>>>regex methods far behind when it comes to stream
>>>parsing.
>>>
>>>Well done!
>> Just want to add that sometimes in Perl it would
>> be nice to be able to index and adress, ie:
>> change and modify a single character in a string,
>> known only by its position in the array of
>> characters. Or embed a string in a string, or
>> delete the same. To "index" a character in
>> would be heaven. Maybe this can be done without
>> having to turn a string into an array of characters
>> then back into a string. I haven't seen it.
>> It would be nice to have the power to index a
>> string even if Perl doesen't know pointers.
>> Makes you wonder if "substr" is an intrinsic.
>
>substr() is exactly the tool for that. And it's often overlooked that
>substr returns a lvalue:
>
> my $str = "abc";
> my $c = \substr $str, 1, 1;
> $$c = uc($$c);
^^ ^^
oop, oop, not allowed, not allowed
Hehe, Tassilo I will have to read (slowly and check)
all your replies as always (no time now, have to revisit! thx)
> print $str;
> __END__
> aBc
>
>That translates quite easily into C:
>
> #include <ctype.h>
> #include <stdio.h>
>
> ...
>
> char str[] = "abc";
> char *c = str + 1;
> *c = toupper(*c);
> printf("%s", str);
>
>That's not quite as convenient as doing
>
> str[1] = toupper(str[1]);
>
>but behold this:
>
> substr($str, 1, 1) =~ tr/a-z/A-Z/;
>
>The string may even grow when using substr():
>
> my $str = "abc";
> substr($str, 1, 1, "bbb");
> print $str;
> __END__
> abbbc
>
>Or even:
>
> my $str = "abc";
> substr($str, 1, 1) .= "bb";
> print $str;
> __END__
> abbbc
>
>Try that in C. ;-)
>
>Perl could even be made to look more like C with a little overload trickery:
>
> package StrArray;
>
> use overload '""' => sub { return join '', @{+shift} };
>
> sub import {
> shift;
> overload::constant q => sub {
> return "\n" if $_[0] eq '\n';
> return bless [ split //, shift ] => __PACKAGE__;
> };
> }
> 1;
> __END__
>
>And now:
>
> use StrArray;
> my $str = "abc";
>
> for my $i (0 .. length($str) - 1) {
> print $str->[$i], "\n";
> }
>
> splice @$str, 1, 0, qw/d e f/;
> print $str, "\n";
> __END__
> a
> b
> c
> adefbc
>
>I'd never recommend using that in production code but it's a nice
>showcase for some of Perl's abilities.
>
>Tassilo
------------------------------
Date: Wed, 09 Nov 2005 23:19:58 -0800
From: robic0
Subject: Re: Why my code doesn't look Perl-ish?
Message-Id: <nvs5n1drl9c5msjq2f1csj1qeqj1dgpggt@4ax.com>
On Sat, 05 Nov 2005 18:44:00 -0600, "Fred@fred.net" <Fred@fred.net>
wrote:
>On Fri, 04 Nov 2005 23:35:32 -0800, robic0@yahoo.com wrote:
>
>>On Fri, 04 Nov 2005 23:09:06 -0800, robic0@yahoo.com wrote:
>>
>>>On 4 Nov 2005 19:57:36 +0100, "V S Rawat" <VSRawat@Invalid.none>
>>>wrote:
>>>
>>>>
>>>>I have developed a program that reads one string having several
>>>>codes in octal, decimal and/or hex; and/or has the characters.
>>>>
>>>>say, input: "ab\o081xy\d66z\\x\x81\aqwer";
>>>>
>>>>it interprets above as "ab (\o081) xy (\d66) z (\\) x (\x81)
>>>>(\a) qwer";
>>>>
>>>>then, it converts the o, d, h codes to chars, and returns the
>>>>entire string.
>>>>
>>>>\o, \d and \x can be followed by any no. of qualifying
>>>>digits/chars for that coding. \ bypasses the next char, and the
>>>>next char could be \ itself.
>>>>
>>>>it is working. The main module is the following:
>>>>========START
>>>>sub get_chrs {
>>>> $TmpElementIn = shift(@_); # input string passed on to sub
>>>> $TmpElementOut = ""; # string to go back to the caller
>>>> $TmpIndexMax = length($TmpElementIn);
>>>> $TmpIndexCurr = 0;
>>>> $TmpIndexNext = 0;
>>>> while ( $TmpIndexCurr < $TmpIndexMax ) {
>>>> $TmpIndexNext = index( $TmpElementIn, "\\",
>>>>$TmpIndexCurr);
>>>> if ( $TmpIndexNext < $TmpIndexCurr ) { # not found
>>>> $TmpElementOut =
>>>>$TmpElementOut.substr($TmpElementIn, $TmpIndexCurr);
>>> ^^^^^^^
>>>Funny, this is a cat, but almost looks like a C++ like
>>>member function for the "scalar" class.
>>>Maybe $TmpElementOut is just a CString.
>>>
>>>In my opinion, Perl is NOT good for stream parsing of
>>>strings because the only powerful tool in Perl for that
>>>is Regular Expressions (filters/pattern matching).
>>>Though with RE's you do have mechanism's of
>>>of capturing the non-matching in-stream characters,
>>>but it usually is, if you have multiple paterns,
>>>very slow and itterative as opposed to a very robust
>>>C++ class like CString. You however, are doing
>>>stream parsing and not pattern matching. And,
>>>given you are keying on a single escape character
>>>(although it could be others combined, as well)
>>>I believe your method is "better" than the regex
>>>suggested by others. The reason being that your
>>>methid is infinetly expandable which would leave
>>>regex methods far behind when it comes to stream
>>>parsing.
>>>
>>>Well done!
>>Just want to add that sometimes in Perl it would
>>be nice to be able to index and adress, ie:
>>change and modify a single character in a string,
>>known only by its position in the array of
>>characters. Or embed a string in a string, or
>>delete the same. To "index" a character in
>>would be heaven.
><snip>
>>Maybe this can be done without
>>having to turn a string into an array of characters
>>then back into a string. I haven't seen it.
></snip>
>
>Aren't we talking about the same beast, but different ends? Split your
>string iteratively and use it. Dosen't matter what "form" it takes, if
>you want an index into a set of strings use a hash. And for what it's
>worth, a string is an array of characters.
Yes your right! I guess I just miss the old C pointer arithmatic.
Thx Fred.
>
>Fred
>
>>It would be nice to have the power to index a
>>string even if Perl doesen't know pointers.
>>Makes you wonder if "substr" is an intrinsic.
------------------------------
Date: Wed, 09 Nov 2005 23:36:12 -0800
From: robic0
Subject: Re: Why my code doesn't look Perl-ish?
Message-Id: <jit5n1dg3vktilf1ch9nh0om4onomj6ptg@4ax.com>
On Sat, 5 Nov 2005 09:34:40 +0100, "Tassilo v. Parseval"
<tassilo.von.parseval@rwth-aachen.de> wrote:
>Also sprach robic0@yahoo.com:
>
>> On Fri, 04 Nov 2005 23:09:06 -0800, robic0@yahoo.com wrote:
>
>>>In my opinion, Perl is NOT good for stream parsing of
>>>strings because the only powerful tool in Perl for that
>>>is Regular Expressions (filters/pattern matching).
>>>Though with RE's you do have mechanism's of
>>>of capturing the non-matching in-stream characters,
>>>but it usually is, if you have multiple paterns,
>>>very slow and itterative as opposed to a very robust
>>>C++ class like CString. You however, are doing
>>>stream parsing and not pattern matching. And,
>>>given you are keying on a single escape character
>>>(although it could be others combined, as well)
>>>I believe your method is "better" than the regex
>>>suggested by others. The reason being that your
>>>methid is infinetly expandable which would leave
>>>regex methods far behind when it comes to stream
>>>parsing.
>>>
>>>Well done!
>> Just want to add that sometimes in Perl it would
>> be nice to be able to index and adress, ie:
>> change and modify a single character in a string,
>> known only by its position in the array of
>> characters. Or embed a string in a string, or
>> delete the same. To "index" a character in
>> would be heaven. Maybe this can be done without
>> having to turn a string into an array of characters
>> then back into a string. I haven't seen it.
>> It would be nice to have the power to index a
>> string even if Perl doesen't know pointers.
>> Makes you wonder if "substr" is an intrinsic.
>
>substr() is exactly the tool for that. And it's often overlooked that
>substr returns a lvalue:
>
> my $str = "abc";
> my $c = \substr $str, 1, 1;
> $$c = uc($$c);
> print $str;
> __END__
> aBc
>
>That translates quite easily into C:
>
> #include <ctype.h>
> #include <stdio.h>
>
> ...
>
> char str[] = "abc";
> char *c = str + 1;
> *c = toupper(*c);
> printf("%s", str);
>
>That's not quite as convenient as doing
>
> str[1] = toupper(str[1]);
>
>but behold this:
>
> substr($str, 1, 1) =~ tr/a-z/A-Z/;
>
>The string may even grow when using substr():
>
> my $str = "abc";
> substr($str, 1, 1, "bbb");
> print $str;
> __END__
> abbbc
>
>Or even:
>
> my $str = "abc";
> substr($str, 1, 1) .= "bb";
> print $str;
> __END__
> abbbc
>
>Try that in C. ;-)
>
>Perl could even be made to look more like C with a little overload trickery:
>
> package StrArray;
>
> use overload '""' => sub { return join '', @{+shift} };
>
> sub import {
> shift;
> overload::constant q => sub {
> return "\n" if $_[0] eq '\n';
> return bless [ split //, shift ] => __PACKAGE__;
> };
> }
> 1;
> __END__
>
>And now:
>
> use StrArray;
> my $str = "abc";
>
> for my $i (0 .. length($str) - 1) {
> print $str->[$i], "\n";
> }
>
> splice @$str, 1, 0, qw/d e f/;
> print $str, "\n";
> __END__
> a
> b
> c
> adefbc
>
>I'd never recommend using that in production code but it's a nice
>showcase for some of Perl's abilities.
>
>Tassilo
Yeah, I will revisit this one. You pass through to the Perl source.
I'll post my C++ intrinsic type overloads tommorrow, ie:
double, float, int, string and all possible operators. From back in
the days when I didn't know what Perl was and had to do it all in
C++. Its bad though now, shifting to Perl has lessened my C++.
I think its syntax and style has erroded my skills for the
other languages I "think" are still in my head (C++). Man o man...
------------------------------
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 8651
***************************************