[26462] in Perl-Users-Digest
Perl-Users Digest, Issue: 8631 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 4 18:05:37 2005
Date: Fri, 4 Nov 2005 15:05:07 -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 Fri, 4 Nov 2005 Volume: 10 Number: 8631
Today's topics:
FAQ 5.33 How do I close a file descriptor by number? <comdog@pair.com>
FAQ 9.2 My CGI script runs from the command line but no <comdog@pair.com>
How to get html help of ActivePerl <VSRawat@Invalid.none>
Re: How to get html help of ActivePerl <1usa@llenroc.ude.invalid>
Re: How to get html help of ActivePerl <1usa@llenroc.ude.invalid>
Re: How to get html help of ActivePerl <1usa@llenroc.ude.invalid>
Re: Permutations xhoster@gmail.com
Re: Permutations <MrReallyVeryNice.RemoveNoSPAM@yahoo.RemoveNoSPAM.com>
Re: Permutations <MrReallyVeryNice.RemoveNoSPAM@yahoo.RemoveNoSPAM.com>
Re: s///x <rvtol+news@isolution.nl>
Re: s///x <stan.remove@bremove.lz.hmrprint.com>
Re: s///x <abigail@abigail.nl>
The Purpose of the Precious Swich in PPM3 (Newbie) <vtatila@mail.student.oulu.fi>
Why my code doesn't look Perl-ish? <VSRawat@Invalid.none>
Re: Why my code doesn't look Perl-ish? <1usa@llenroc.ude.invalid>
www.vivepc.com Tu tienda de ordenadores discos duros im maria@yafqhvet.ca
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 4 Nov 2005 17:03:00 +0000 (UTC)
From: PerlFAQ Server <comdog@pair.com>
Subject: FAQ 5.33 How do I close a file descriptor by number?
Message-Id: <dkg484$gp2$1@reader2.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
5.33: How do I close a file descriptor by number?
This should rarely be necessary, as the Perl close() function is to be
used for things that Perl opened itself, even if it was a dup of a
numeric descriptor as with MHCONTEXT above. But if you really have to,
you may be able to do this:
require 'sys/syscall.ph';
$rc = syscall(&SYS_close, $fd + 0); # must force numeric
die "can't sysclose $fd: $!" unless $rc == -1;
Or, just use the fdopen(3S) feature of open():
{
local *F;
open F, "<&=$fd" or die "Cannot reopen fd=$fd: $!";
close F;
}
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Fri, 4 Nov 2005 23:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@pair.com>
Subject: FAQ 9.2 My CGI script runs from the command line but not the browser. (500 Server Error)
Message-Id: <dkgpb5$4ae$1@reader2.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
9.2: My CGI script runs from the command line but not the browser. (500 Server Error)
Several things could be wrong. You can go through the "Troubleshooting
Perl CGI scripts" guide at
http://www.perl.org/troubleshooting_CGI.html
If, after that, you can demonstrate that you've read the FAQs and that
your problem isn't something simple that can be easily answered, you'll
probably receive a courteous and useful reply to your question if you
post it on comp.infosystems.www.authoring.cgi (if it's something to do
with HTTP or the CGI protocols). Questions that appear to be Perl
questions but are really CGI ones that are posted to comp.lang.perl.misc
are not so well received.
The useful FAQs, related documents, and troubleshooting guides are
listed in the CGI Meta FAQ:
http://www.perl.org/CGI_MetaFAQ.html
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: 4 Nov 2005 19:57:39 +0100
From: "V S Rawat" <VSRawat@Invalid.none>
Subject: How to get html help of ActivePerl
Message-Id: <xn0e9csox1kgbf001@xananews>
I have downloaded and installed 5.8 Activeperl.
My previous Perl for Win32 had beautiful html based help
documentations of commands and functions of Perl that I could
fetch anything by clicking at links and finding in browser.
It seems that ActivePerl does not have that feature. I need to
go to command prompt and type perldoc and then cribble through
"more".
Is there any free add-on for ActivePerl that would give me html
based documentation for it?
TIA.
--
Rawat
------------------------------
Date: Fri, 04 Nov 2005 19:07:35 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to get html help of ActivePerl
Message-Id: <Xns97048FB4B3B41asu1cornelledu@127.0.0.1>
"V S Rawat" <VSRawat@Invalid.none> wrote in news:xn0e9csox1kgbf001
@xananews:
> It seems that ActivePerl does not have that feature.
Start -> All Programs -> ActivePerl 5.8.7 Build 813 -> Documentation
You might want to ponder whether programming is your thing.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Fri, 04 Nov 2005 19:44:51 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to get html help of ActivePerl
Message-Id: <Xns970496065150Aasu1cornelledu@127.0.0.1>
John Bokma <john@castleamber.com> wrote in
news:Xns970489BEC8D81castleamber@130.133.1.4:
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:
>
>> "V S Rawat" <VSRawat@Invalid.none> wrote in news:xn0e9csox1kgbf001
>> @xananews:
>>
>>> It seems that ActivePerl does not have that feature.
>>
>> Start -> All Programs -> ActivePerl 5.8.7 Build 813 -> Documentation
>>
>> You might want to ponder whether programming is your thing.
>
> The pain... the pain >:->
>
> Related question: is it available in chm format? :-D.
http://htmlhelp.berlios.de/books/chm.php
;-)
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Fri, 04 Nov 2005 20:19:08 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to get html help of ActivePerl
Message-Id: <Xns97049BD6D29D6asu1cornelledu@127.0.0.1>
John Bokma <john@castleamber.com> wrote in
news:Xns97049113B91Fcastleamber@130.133.1.4:
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:
>
>> John Bokma <john@castleamber.com> wrote in
>> news:Xns970489BEC8D81castleamber@130.133.1.4:
...
>>> Related question: is it available in chm format? :-D.
>>
>> http://htmlhelp.berlios.de/books/chm.php
>
> Thanks, now that I see the URL I remember that I have seen it before,
> maybe even asked before. :-D
I remember bookmarking the page in when I saw in:
http://groups.google.com/group/comp.lang.perl.misc/browse_thread/thread/c6c8362f81643345/
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 04 Nov 2005 16:53:20 GMT
From: xhoster@gmail.com
Subject: Re: Permutations
Message-Id: <20051104115320.290$Q6@newsreader.com>
Bertilo Wennergren <bertilow@gmail.com> wrote:
> As part of an application I had to solve a permutations problem
> that gave me much more trouble than I had anticipated.
...
>
> Here's what I want to do:
>
> #!/usr/bin/perl -w
> use strict;
>
> my @numbers = (
> [ 1, 2, 3, ],
> [ 4, 5, ],
> [ 6, 7, ],
> );
>
...
> The print result should be this exciting bunch of numbers:
>
> 1 4 6
> 1 4 7
> 1 5 6
> 1 5 7
Those aren't really permuations, because the order is not varied.
I think it would be more of combinatorics, but that also might not
be exactly right. In databases, it would be cartesian join.
> Any ideas on how to do that in a better way? The major issue is
> speed since the number of permutations rise quickly when there
> are lots of groups with lots of numbers.
That being the case, I would think that memory usage would be much
more of an issue than speed. Your code is building the entire set in
memory.
A couple years ago I posted a module here that does what you want as an
iterator, so it doesn't hog memory. (There may be something on CPAN that
does this, too, but it is easier for me to google my own code).
http://groups.google.com/group/comp.lang.perl.misc/browse_frm/thread/b83886
616f90cc8c
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Fri, 04 Nov 2005 09:51:06 -0800
From: MrReallyVeryNice <MrReallyVeryNice.RemoveNoSPAM@yahoo.RemoveNoSPAM.com>
To: Bertilo Wennergren <bertilow@gmail.com>
Subject: Re: Permutations
Message-Id: <436B9F8A.6080708@yahoo.RemoveNoSPAM.com>
Bertilo Wennergren wrote:
> As part of an application I had to solve a permutations problem
> that gave me much more trouble than I had anticipated. I did
> solve the problem, but I have a very strong feeling that my
> solution is very far from the best one. It seems very cumbersome
> and inefficient. If anyone has any ideas on how to do this in a
> better way, I'd be glad for some input.
>
> Here's what I want to do:
>
DELETED CODE
>
> The print result should be this exciting bunch of numbers:
>
> 1 4 6
> 1 4 7
> 1 5 6
> 1 5 7
> 2 4 6
> 2 4 7
> 2 5 6
> 2 5 7
> 3 4 6
> 3 4 7
> 3 5 6
> 3 5 7
>
> As you can see the program lists all possible permutations of
> picking one number from each group of numbers in the array
> "@numbers". The problem for me was that the subroutine
> "CreatePermutations" must work for any number of groups, and for
> any number of numbers in each group (at least one group though,
> and at least one number in each group).
>
> Here's my working but probably very inefficient version of the
> subroutine:
>
DELETED CODE
> }
>
> Any ideas on how to do that in a better way? The major issue is
> speed since the number of permutations rise quickly when there
> are lots of groups with lots of numbers.
>
I did not benchmark my code or yours and I did not test my code fully. I
believe that my code would require less memory because it is not storing
anything in an array before printing the results. It seems that the
following would meet your requirements:
use strict;
use warnings;
my $string1 = '123';
my $string2 = '45';
my $string3 = '67';
for ("000" .. "999")
{
my $s1 = substr($_,0,1);
my $s2 = substr($_,1,1);
my $s3 = substr($_,2,1);
if ( grep(/$s1/, $string1) && grep(/$s2/, $string2) && grep(/$s3/,
$string3))
{
print $s1 . " " . $s2 . " " . $s3 ."\n";
}
}
This code assumes that:
1. you only have numbers in your "permutation" ($string1 = '1A23'; would
not work in the sense that it would ignore the character 'A')
2. it ignores strings with the same number listed more than once
($string1 = '1231114';) I think that the result should ignore these
repetitive characters but I'm not really sure what you mean by
'permutations'.
Expanding my code for any number of groups, any numbers in each group
should not be too difficult.
MrReallyVeryNice
------------------------------
Date: Fri, 04 Nov 2005 09:51:39 -0800
From: MrReallyVeryNice <MrReallyVeryNice.RemoveNoSPAM@yahoo.RemoveNoSPAM.com>
To: Bertilo Wennergren <bertilow@gmail.com>
Subject: Re: Permutations
Message-Id: <436B9FAB.5000501@yahoo.RemoveNoSPAM.com>
Bertilo Wennergren wrote:
> As part of an application I had to solve a permutations problem
> that gave me much more trouble than I had anticipated. I did
> solve the problem, but I have a very strong feeling that my
> solution is very far from the best one. It seems very cumbersome
> and inefficient. If anyone has any ideas on how to do this in a
> better way, I'd be glad for some input.
>
> Here's what I want to do:
>
DELETED CODE
>
> The print result should be this exciting bunch of numbers:
>
> 1 4 6
> 1 4 7
> 1 5 6
> 1 5 7
> 2 4 6
> 2 4 7
> 2 5 6
> 2 5 7
> 3 4 6
> 3 4 7
> 3 5 6
> 3 5 7
>
> As you can see the program lists all possible permutations of
> picking one number from each group of numbers in the array
> "@numbers". The problem for me was that the subroutine
> "CreatePermutations" must work for any number of groups, and for
> any number of numbers in each group (at least one group though,
> and at least one number in each group).
>
> Here's my working but probably very inefficient version of the
> subroutine:
>
DELETED CODE
> }
>
> Any ideas on how to do that in a better way? The major issue is
> speed since the number of permutations rise quickly when there
> are lots of groups with lots of numbers.
>
I did not benchmark my code or yours and I did not test my code fully. I
believe that my code would require less memory because it is not storing
anything in an array before printing the results. It seems that the
following would meet your requirements:
use strict;
use warnings;
my $string1 = '123';
my $string2 = '45';
my $string3 = '67';
for ("000" .. "999")
{
my $s1 = substr($_,0,1);
my $s2 = substr($_,1,1);
my $s3 = substr($_,2,1);
if ( grep(/$s1/, $string1) && grep(/$s2/, $string2) && grep(/$s3/,
$string3))
{
print $s1 . " " . $s2 . " " . $s3 ."\n";
}
}
This code assumes that:
1. you only have numbers in your "permutation" ($string1 = '1A23'; would
not work in the sense that it would ignore the character 'A')
2. it ignores strings with the same number listed more than once
($string1 = '1231114';) I think that the result should ignore these
repetitive characters but I'm not really sure what you mean by
'permutations'.
Expanding my code for any number of groups, any numbers in each group
should not be too difficult.
MrReallyVeryNice
------------------------------
Date: Fri, 4 Nov 2005 18:22:18 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: s///x
Message-Id: <dkg9cj.1hc.1@news.isolution.nl>
John Bokma:
> Dr.Ruud:
>> Is there an efficient way to use constants in regexes? Maybe not
>> useful when constants are actually subs.
>
> using qr//?
>
> "Since Perl may compile the pattern at the moment of execution of qr()
> operator, using qr() may have speed advantages in some situations,
> notably if the result of qr() is used standalone:"
>
> {perlop)
Thanks John. Abigail already mentioned it, but I didn't look into it
right away and then I just didn't, so now at last I did.
$re{'A01'}[SRCH] = 'some regex, grouping allowed';
$re{'A01')[REPL] = 'some replacement, backtracking allowed';
$re{'A01'}[MODS] = 'xsg';
:
:
$re{'A01'}[QREX] = qr/(?$re{'A01'}[MODS])$re{'A01'}[SRCH]/; #
qompiled regex
:
:
s/$re{'A01'}[QREX]/$re{'A01')[REPL]/;
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Fri, 4 Nov 2005 10:19:41 -0800
From: "Stan R." <stan.remove@bremove.lz.hmrprint.com>
Subject: Re: s///x
Message-Id: <1131128551_1603@spool6-east.superfeed.net>
Abigail wrote:
[...]
> My advice is to *never* use /o. There's no point in using it for
> speed, and when it matters for speed, the effect may not be what you
> want - and even if you want it, it may confuse anyone else looking at
> the code.
>
> for (qw /foo bar/) {
> print /$_/ ? "Yes 1\n" : "No 1\n";
> print /$_/o ? "Yes 2\n" : "No 2\n";
> }
> __END__
> Yes 1
> Yes 2
> Yes 1
> No 1
I get "No 2" on the end, not "No 1"
$ perl -e 'for (qw /foo bar/) {
print /$_/ ? "Yes 1\n" : "No 1\n";
print /$_/o ? "Yes 2\n" : "No 2\n";
}'
Yes 1
Yes 2
Yes 1
No 2
I guess you didn't actually run the code you posted, or you typed from
memory :-P
--
Stan
------------------------------
Date: 04 Nov 2005 22:16:28 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: s///x
Message-Id: <slrndmnnds.pgk.abigail@alexandra.abigail.nl>
Stan R. (stan.remove@bremove.lz.hmrprint.com) wrote on MMMMCDXLVIII
September MCMXCIII in <URL:news:1131128551_1603@spool6-east.superfeed.net>:
"" Abigail wrote:
"" [...]
"" > My advice is to *never* use /o. There's no point in using it for
"" > speed, and when it matters for speed, the effect may not be what you
"" > want - and even if you want it, it may confuse anyone else looking at
"" > the code.
"" >
"" > for (qw /foo bar/) {
"" > print /$_/ ? "Yes 1\n" : "No 1\n";
"" > print /$_/o ? "Yes 2\n" : "No 2\n";
"" > }
"" > __END__
"" > Yes 1
"" > Yes 2
"" > Yes 1
"" > No 1
""
"" I get "No 2" on the end, not "No 1"
Indeed.
""
"" $ perl -e 'for (qw /foo bar/) {
"" print /$_/ ? "Yes 1\n" : "No 1\n";
"" print /$_/o ? "Yes 2\n" : "No 2\n";
"" }'
"" Yes 1
"" Yes 2
"" Yes 1
"" No 2
""
"" I guess you didn't actually run the code you posted, or you typed from
"" memory :-P
Oh, I ran it. Then copied into my posting. Then modified it, and typed the
last line by hand instead of using the mouse.
Abigail
--
perl -wle'print"Êõóô áîïôèåò Ðåòì Èáãëåò"^"\x80"x24'
------------------------------
Date: Fri, 4 Nov 2005 23:12:04 +0200
From: "Veli-Pekka Tätilä" <vtatila@mail.student.oulu.fi>
Subject: The Purpose of the Precious Swich in PPM3 (Newbie)
Message-Id: <dkgirg$af4$1@news.oulu.fi>
Hi,
I really like PPM because it makes trying out pacages a breeze. I ran Linux
for a while and tend to think of PPM as the Perl equivalent of apt-get. BOth
get the job done with minimal user-involvement which is mostly about choices
which I'd rather leave to someone else.
One aspect of PPM I have just recently gotten into is updating packages with
the upgrade command. But I'm puzzled as to what the -precious switch in ppm3
actually does. Put another way, which packages might get updated that
otherwise are not when you run upgrade -install -precious?
As I have happily downloaded and used a number of PPM packages and things
still work fine, I thought I'd ask before I try the precious swich. I've
noticed that doing something you don't understand can be quite risky in
computing, especially in programming. My reasoning is as follows: if the
precious switch is totally safe or recommended, it would be on by default.
So I'd better leav it alone until I know more.
I've looked at the PPM built-in docs which give a rather circular
definition:
Quote:
There are several modifiers to the upgrade command:
-install
Installs, rather than lists, available upgrades
-precious
Allows upgrading of "precious" packages
<snip>
End of quote.
I've checked various Perl FAQs, Active State's Using PPM page and Googled
the Web and news with words like ppm3 perl and precious. I even had a quick
glance at the ppm3-bin source but still feel I'm no wiser.
If I were to guess, I'd say that some packages are marked as precious and
considered to be part of core Perl. But is this list version dependent and
should I really update these packages, in order to fix bugs, make it faster
or add some new functionality? I wouldn't want to use packages that are
considered to be in testing or unstable to borrow some apt-get terminology.
I reckon the Perl interpreter itself is not updated via ppm at any rate, is
it?
I'm runing Windows XP Pro SP2 and Active State Perl 5.8.6.
Is the only way of updating the Perl interpreter to install the latest
Active State Perl distro over the current one?
On a silly side-note, I guess it is just me, but when-ever I hear the word
precious spoken by my current speech synth, I cannot help thinking of how
Gollum says it in LOTR, oh well. The fact that I'm not a native English
Speaker, like LOTR, and rarely use the word precious myself might affect
matters, though. But this is certainly not the only LOTr reference, though
likely unintentional, that I've seen used about Unix-like things.
--
With kind regards Veli-Pekka Tätilä (vtatila@mail.student.oulu.fi)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/
------------------------------
Date: 4 Nov 2005 19:57:36 +0100
From: "V S Rawat" <VSRawat@Invalid.none>
Subject: Why my code doesn't look Perl-ish?
Message-Id: <xn0e9csmc1gpbt000@xananews>
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);
$TmpIndexCurr = $TmpIndexMax;
}
elsif ( $TmpIndexNext > $TmpIndexCurr ) { # found after
the current position
$TmpElementOut =
$TmpElementOut.substr($TmpElementIn, $TmpIndexCurr,
$TmpIndexNext - $TmpIndexCurr );
$TmpIndexCurr = $TmpIndexNext;
}
else { # found right at the current position
$Coding = lc( substr( $TmpElementIn, $TmpIndexCurr +
1, 1) );
if ( $Coding eq "o" || $Coding eq "d" || $Coding eq
"x" ) {
$TmpChar = "";
$TmpCharsOut = "";
while ( $TmpIndexNext + 2 < $TmpIndexMax ) {
$TmpChar = substr($TmpElementIn,
$TmpIndexNext + 2, 1);
if ( ( $Coding eq "o" && $TmpChar ge "0" &&
$TmpChar le "7") ||
( $Coding eq "d" && $TmpChar ge "0" &&
$TmpChar le "9") ||
( $Coding eq "x" && ( $TmpChar ge "0" &&
$TmpChar le "9") ||
( ( lc($TmpChar) ge "a"
) && ( lc($TmpChar) le "f" ) ) ) ) {
$TmpCharsOut = $TmpCharsOut.$TmpChar;
$TmpIndexNext += 1;
}
else {
last;
}
}
$TmpIndexCurr = $TmpIndexCurr + 2 +
length($TmpCharsOut);
if ( $Coding eq "o" ) {
$TmpElementOutTmp = chr(oct($TmpCharsOut));
}
elsif ( $Coding eq "d" ) {
$TmpElementOutTmp = chr($TmpCharsOut);
}
elsif ( $Coding eq "x" ) {
$TmpElementOutTmp = chr(hex($TmpCharsOut));
}
$TmpElementOut =
$TmpElementOut.$TmpElementOutTmp;
}
elsif ( $Coding eq "\\" ) { # \\
$TmpElementOut = $TmpElementOut."\\";
$TmpIndexCurr = $TmpIndexCurr + 2;
}
else { # \ and some character, which is in $Coding
$TmpElementOut = $TmpElementOut.$Coding;
$TmpIndexCurr = $TmpIndexCurr + 2;
}
}
}
return $TmpElementOut;
} # End get_chrs
========END
The problem is that it is looking so much like Foxpro that it
does not give me satisfaction of having developed something in
perl. there is no s///, no tr =~, no ::, no ->, no >><<, no (
... ), no [ ][ ][ ], no +=, no pack, whatever that I find so
fascinating in the snippets posted by you.
So there. Could you veterans please help me:
1. In shortening these loooong code-lines which are so
unilike-perl.
2. in suggesting advanced methods of achieving the same thing,
so that I can explore those commands/ functions/ ..., and my
learning goes on.
Thanks in Advance.
--
V S Rawat at gmail dot com
------------------------------
Date: Fri, 04 Nov 2005 19:16:12 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Why my code doesn't look Perl-ish?
Message-Id: <Xns9704912B44ABBasu1cornelledu@127.0.0.1>
"V S Rawat" <VSRawat@Invalid.none> wrote in news:xn0e9csmc1gpbt000
@xananews:
>
> 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.
...
> ========START
> sub get_chrs {
> $TmpElementIn = shift(@_); # input string passed on to sub
> $TmpElementOut = ""; # string to go back to the caller
This is crazy and I give you some credit for realizing it is crazy.
Maybe you can use the method shown in
http://groups.google.com/group/comp.lang.perl.misc/msg/5864457a0d00f1ca
and generalize it.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Fri, 04 Nov 2005 20:26:28 GMT
From: maria@yafqhvet.ca
Subject: www.vivepc.com Tu tienda de ordenadores discos duros impresoras memorias, Lo + barato . B43L
Message-Id: <UtPaf.284414$o8.59862@twister.auna.com>
---
Mese yisef mitot caligobem kewocisox cicis pabevave gubicep .
------------------------------
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 8631
***************************************