[18101] in Perl-Users-Digest
Perl-Users Digest, Issue: 261 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 9 21:05:35 2001
Date: Fri, 9 Feb 2001 18:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981770712-v10-i261@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 9 Feb 2001 Volume: 10 Number: 261
Today's topics:
[ANNOUNCE] New HPUX::Ioscan module <domi@komarr.grenoble.hp.com>
Re: [OT] What does "newbie" mean? (was Re: This is driv (David H. Adler)
Re: [OT] What other languages do you know? <ldo@geek-central.gen.new_zealand>
Re: a bug in perl-5.6.0? <mischief@velma.motion.net>
Re: A Question on OLE and EXCEL- help please <bart.lateur@skynet.be>
Re: Another XML::Parser Question <bart.lateur@skynet.be>
Re: Can perl define vars dynamically? <bart.lateur@skynet.be>
Re: CFP: Yet Another Perl Conference 2001 (David H. Adler)
Re: Devel DProf and " dprofpp " (John McNamara)
Re: Devel DProf and " dprofpp " <godzilla@stomp.stomp.tokyo>
Re: Devel DProf and " dprofpp " <godzilla@stomp.stomp.tokyo>
Re: Devel DProf and " dprofpp " <bkennedy99@Home.com>
Free Movie Ticket Give-away for solving the basic probl <caramari9@hotmail.com>
Re: Free Movie Ticket Give-away for solving the basic p <joe+usenet@sunstarsys.com>
Re: howto split without regard to white spaces? (Gwyn Judd)
Re: insertion sort algorithm <wells@cedarnet.org>
Re: insertion sort algorithm shogun415@my-deja.com
Re: insertion sort algorithm <kstep@pepsdesign.com>
Makerpm updated : new features + support for RedHat 7.0 throwaway-a2345s@scotclimb.org.uk
Re: newbie regexp <bart.lateur@skynet.be>
Perl & Recursion : Why doesn't this work? <vaton@pacbell.net>
Re: Perl & Recursion : Why doesn't this work? <lincwils@teleport.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 09 Feb 2001 13:53:02 +0100
From: Dominique Dumont <domi@komarr.grenoble.hp.com>
Subject: [ANNOUNCE] New HPUX::Ioscan module
Message-Id: <t8936vcps6pl90@corp.supernews.com>
Hello
I've written an interface module that works on top of the HP-UX
command ioscan. This module is quite basic but it may be interesting
if you need to write administration program on HP-UX.
This module forks a process to run the ioscan command and parses its
STDOUT. The result is returned in a hash.
Note that this module can work ONLY on HP-UX.
Suggested DSLI line :
HPUX
Ioscan bdpf Perl function to handle HPUX ioscan command DDUMONT
The test will skip the actual ioscan command unless you are running on
a HP-UX system as superuser. I guess than you will have to trust me
with this module ... ;-)
This module is already available on CPAN:
http://search.cpan.org/search?mode=module&query=ioscan
Cheers
--
Dominique_Dumont@grenoble.hp.com
------------------------------
Date: 9 Feb 2001 23:56:51 GMT
From: dha@panix2.panix.com (David H. Adler)
Subject: Re: [OT] What does "newbie" mean? (was Re: This is driving me nuts and I need a guru)
Message-Id: <slrn9890u2.e77.dha@panix2.panix.com>
On Fri, 09 Feb 2001 14:32:49 GMT, Tad McClellan <tadmc@augustmail.com> wrote:
>David H. Adler <dha@panix6.panix.com> wrote:
>>On Thu, 08 Feb 2001 23:51:52 GMT, Tad McClellan <tadmc@augustmail.com> wrote:
>>>
>>> You don't (or shouldn't anyway) get flamed here for being
>>> new to Perl. You get flamed here for being new to Usenet.
>>
>>As much as I respect Tad, I need to disagree slightly.
>>
>>Being new to Usenet doesn't get you flamed. Not bothering to find out
>>how one is expected to act on Usenet (and taking that to heart) gets
>>you flamed.
>
>
>We don't disagree at all. I think I didn't make my point clear.
Actually, I was quite sure that we were on the same page. I probably
shouldn't have indicated otherwise... I was intending a clarification,
not a correction.
Fortunately, I'm quite sure that Tad knows that too... :-)
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Well of *course* Perl should not be taught to everyone. It should only
be taught to people who want to like their computers. - Larry Wall
------------------------------
Date: Sat, 10 Feb 2001 12:47:25 +1300
From: Lawrence DčOliveiro <ldo@geek-central.gen.new_zealand>
Subject: Re: [OT] What other languages do you know?
Message-Id: <ldo-4A90CF.12472510022001@news.wave.co.nz>
In article <953t6p$o23$1@nnrp1.deja.com>, Mario <m_ario@my-deja.com>
wrote:
>Just curious to know what other languages are popular in the Perl
>community.
AppleScript!
Perl has much more powerful features built _into_ the language--regular
expressions, hashes--but AppleScript has much more powerful support for
coordinating processing _across_ applications, particularly with all the
AppleScriptable applications already out there.
Pity MacPerl isn't AppleScriptable--it would be handy, sometimes, to use
a quick line or two of Perl in an AppleScript script. Or if it is
scriptable, I haven't been able to figure out how to drive it from
AppleScript...
------------------------------
Date: Sat, 10 Feb 2001 01:54:59 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: a bug in perl-5.6.0?
Message-Id: <t897rjgu7jhs05@corp.supernews.com>
Csaba Raduly <real.email@signature.this.is.invalid> wrote:
> And so it came to pass that Chris Stith <mischief@velma.motion.net>
> on 07 Feb 2001 wrote <t83fcptb9o5u9e@corp.supernews.com>:
> [snip]
>>
>>True. This is because of the behavior in Perl of an assignment
>>returning a value (a Perlism, for sure.. not very common in languages).
> ^^^^^
> Did you mean lvalue ? C/C++ assignment operators return rvalues allright.
Yes, I did.
> Csaba Raduly, Software Developer (OS/2)
What a brave soul, still working on what should have been the
successor to DOS.
> You are in a maze of twisted little minds, all different.
Zork on psychadelics, I like it.
Chris
--
Christopher E. Stith
Product shown enlarged to make you think you're getting more.
------------------------------
Date: Sat, 10 Feb 2001 01:20:06 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: A Question on OLE and EXCEL- help please
Message-Id: <n8598tkshh0bp1fdne08uqi4hjg55b48mp@4ax.com>
dog222@my-deja.com wrote:
>use OLE;
New code should use Win32::OLE instead, I think.
>ERROR MESSAGE!!!!!!
>
>"Cant use and undefined value as a hash reference at line 5."
Here's why:
>$excelobject = CreateObject OLE 'Excel.Sheet';
Apparently CreateObject on this line fails. Don't ask me why, there
ought to be some way to get the error message out of perl, but I don't
use this old module. ;-)
You can get online documentation for using OLE with Perl, here:
perlwin32faq12 - Using OLE with Perl
<http://velocity.activestate.com/docs/ActivePerl/faq/Windows/ActivePerl-Winfaq12.html>
Win32::OLE - OLE Automation extensions
<http://velocity.activestate.com/docs/ActivePerl/site/lib/Win32/OLE.html>
Lots of neat examples, too.
--
Bart.
------------------------------
Date: Fri, 09 Feb 2001 23:46:25 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Another XML::Parser Question
Message-Id: <gb098t0k7htg51q64b4886s7k97kfanuf6@4ax.com>
kumar22@my-deja.com wrote:
>Okay I'm not sure if anyone cares, but I found a simple, if inelegant,
>solution to my own problem:
>s/&/XXXXXXX/g; #before sending the file to the parser
>and
>s/XXXXXXX/&/g; #after it comes back.
>
>Duh.
s/&/&/g;
Let XML::Parser convert it back for you.
;-)
--
Bart.
------------------------------
Date: Sat, 10 Feb 2001 01:02:10 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Can perl define vars dynamically?
Message-Id: <gm498tobhitqqev9ubhb0km2sm3dt26eob@4ax.com>
michael.cambray@wellpoint.com wrote:
>So it sounds like perl can't define or assign a variable "on the fly".
>Correct?
Not correct. Perl CAN do it. However, most experienced perl coders
consider it very bad practise. See "Why it's stupid to `use a variable
as a variable name" in 3 parts at
<http://perl.plover.com/varvarname.html>.
--
Bart.
------------------------------
Date: 10 Feb 2001 00:35:41 GMT
From: dha@panix2.panix.com (David H. Adler)
Subject: Re: CFP: Yet Another Perl Conference 2001
Message-Id: <slrn98936t.kk5.dha@panix2.panix.com>
On Fri, 09 Feb 2001 13:24:32 -0800, Terrence Monroe Brannon
<terrence.brannon@oracle.com> wrote:
>You have posted spam for your conference in a technical newsgroup.
>Long-standing usenet tradition... [[ blah blah blah s/David Adler's
>rant on job postings/conference post/g ]]]
You rant^Hg? :-)
FWIW, I don't see an announcement of a conference that is
*specifically* perl oriented as inappropriate for this forum. It's
not like it was "Microsoft Windows Symposium... oh yeah, and we have a
talk on perl...". :-)
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
I drink to my coming cirrhosis... - Charles Aznavour
------------------------------
Date: Fri, 09 Feb 2001 23:28:31 GMT
From: jmcnamara@cpan.org (John McNamara)
Subject: Re: Devel DProf and " dprofpp "
Message-Id: <3a847c81.2714777@news1.eircom.net>
>> mothra wrote:
>> You are correct, there is no man page for this. However I was able
>> to find the information on the profile format of the tmon.out file.
>> It is located in the DProf.pm file ( I include only a portion of
>> this due to space)
> godzilla@stomp.stomp.tokyo wrote:
> Right. Perl docs claim there is a dprofpp manual. There is
> not.
The documention for dprofpp is contained within the program. Try:
pod2html --infile=dprofpp.bat --outfile=dprofpp.html
John McNamara
--
------------------------------
Date: Fri, 09 Feb 2001 16:49:55 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Devel DProf and " dprofpp "
Message-Id: <3A849033.7FDEF3CC@stomp.stomp.tokyo>
John McNamara wrote:
> >> mothra wrote:
> >> You are correct, there is no man page for this. However I was able
> >> to find the information on the profile format of the tmon.out file.
> >> It is located in the DProf.pm file ( I include only a portion of
> >> this due to space)
> > godzilla wrote:
> > Right. Perl docs claim there is a dprofpp manual. There is
> > not.
> The documention for dprofpp is contained within the program. Try:
> pod2html --infile=dprofpp.bat --outfile=dprofpp.html
Thank you for this information, Mr. McNamara.
I am not having very good luck with any Perl documentation
for DProf, dprofpp and Pod Html. Bothers me a bit to say
this, not having completed my testing for fairness. It does
appear documentation for all three of those devices is in
error. DProf does run and work as it should but its dprofpp
feature does not. I am keeping a fairness factor in mind;
Perl documentation is so poorly written, it could very well
be I cannot correctly decipher these attempts at documentation.
A system search yielded dprofpp.html located at:
apache/html/lib/devel/dprofpp.html
After finding Pod Html documentation, I tried this
syntax provided by Tom Christiansen. It does not work.
My script and resulting errors using syntax provided
by Christiansen are below my signature.
For now, after I feel I have found as much documentation
as possible on DProf and dprofpp, I am going to focus
on Mothra's system syntax and discover if dprofpp can
be successfully run.
Clearly there are a significant amount of very serious
problems with Perl documentation. This is most frustrating.
I've been working on this, researching this for a week now
and have yet to find neither official Perl documentation
nor module documentation which works as presented, related
to the topic of this thread.
Your information has provided another concern for me.
After a system search and locating dprofpp.html, I checked
this file's properties and discovered a last modified date
of late yesterday. I cannot explain this and, this worries
me discovering Perl 'did something' I did not authorize nor
was notified with a message a file is being created or
modified. I ran DProf and tried to get dprofpp to run
yesterday afternoon but I cannot fathom a connection between
this and the modification date for dprofpp.html. This causes
great concern knowing perl core is doing whatever without
my authorization nor command to do so.
Thank you again for your information. A result of your posted
information has led me to closely examine all directories to
discover what is there, I don't know about. I also discovered
several days back, the 'search' feature with Perl documentation
doesn't work, it's screwed up. No problem there, I wrote my own
search script which performs perfectly, now that I have modified
it to recurse deeply into sub-directories. This is how I found
pod2html documentation, at your suggestion, leading to my
discovery of dprofpp.html being created or modified without
my knowledge. If perl core was real, I would punch its lights
out for screwing around like this without my permission.
This is a rather challenging project. There is some enjoyment
in trying to get Perl to operate correctly, sans any viable
or helpful documentation. However, there is a sore note knowing
Perl documentation is seriously flawed; my opinion is the
Big Boys of Perl can do much better than this, I sure would.
However, I am an English professor who expects near perfection
in language usage. Rahhhhly I do, dahhhhling.
Godzilla!
--
TEST SCRIPT:
____________
#!perl
print "Content-type: text/plain\n\n";
use Pod::Html;
pod2html ("--infile=dprofpp.bat", "--outfile=dprofpp.html");
print "program finished";
exit;
APACHE ERROR LOG:
_________________
Bareword found where operator expected at
c:/apache/users//test/test1.pl line 7, near "--outfile"
(Missing operator before outfile?)
Can't modify constant item in predecrement (--) at
c:/apache/users//test/test1.pl line 7, near "infile="
syntax error at c:/apache/users//test/test1.pl line 7, near "--outfile"
Execution of c:/apache/users//test/test1.pl aborted due to compilation errors.
------------------------------
Date: Fri, 09 Feb 2001 17:14:21 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Devel DProf and " dprofpp "
Message-Id: <3A8495ED.8F9F1FC6@stomp.stomp.tokyo>
"Godzilla!" wrote:
> John McNamara wrote:
> > >> mothra wrote:
> > >> You are correct, there is no man page for this. However I was able
> > >> to find the information on the profile format of the tmon.out file.
> > >> It is located in the DProf.pm file ( I include only a portion of
> > >> this due to space)
> > > godzilla wrote:
> > > Right. Perl docs claim there is a dprofpp manual. There is
> > > not.
> > The documention for dprofpp is contained within the program. Try:
> > pod2html --infile=dprofpp.bat --outfile=dprofpp.html
(snippage)
> Your information has provided another concern for me.
> After a system search and locating dprofpp.html, I checked
> this file's properties and discovered a last modified date
> of late yesterday. I cannot explain this and, this worries
> me discovering Perl 'did something' I did not authorize nor
> was notified with a message a file is being created or
> modified....
Oh gosh, do I ever feel stupid, totally duh.
My dprofpp.html which I could not explain, after checking
my system activity log record, I discovered I downloaded
dprofpp.html from our internet, into this directory where
I found it. Perl didn't create it, I did, via download.
* major red face blushing *
Godzilla!
------------------------------
Date: Sat, 10 Feb 2001 02:00:32 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: Devel DProf and " dprofpp "
Message-Id: <4h1h6.43931$49.7758487@news1.rdc2.pa.home.com>
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3A849033.7FDEF3CC@stomp.stomp.tokyo...
> I am not having very good luck with any Perl documentation
> for DProf, dprofpp and Pod Html. Bothers me a bit to say
> this, not having completed my testing for fairness. It does
> appear documentation for all three of those devices is in
> error. DProf does run and work as it should but its dprofpp
> feature does not. I am keeping a fairness factor in mind;
> Perl documentation is so poorly written, it could very well
> be I cannot correctly decipher these attempts at documentation.
I just installed the latest .msi package from www.activestate.com, and in a
cmd box the command "perldoc dprofpp" works fine (I'm not sure what you find
confusing about it). There is also documentation at "perldoc Devel::DProf".
If the perldoc command is not working for you, you should consider checking
your enviromental path variable and/or reinstalling Perl.
--Ben Kennedy
------------------------------
Date: Fri, 9 Feb 2001 18:37:33 -0600
From: "Carmari" <caramari9@hotmail.com>
Subject: Free Movie Ticket Give-away for solving the basic problem on Time:HiRes.pm module
Message-Id: <3a848fb6$0$70817$1dc6e903@news.corecomm.net>
Hi :
I am writing a TIMER program with HiResolution requirement. Basically, we
can get 4.34 double precision seconds from timeofday function ( from
TIME::HiRes) . However, I got problem on the very simple implementation.
Here is the detail:
Please read and let me know what is the problem. Thank you. I will send you
a free movie ticket as reward. Promise!!!
Thanks.
Caramari
+++++++++
Perl system information:
+++++++++
perl: /usr/bin/perl /usr/sbin/perl /usr/sbin/perl5.00502-n32
/usr/sbin/perl5.00502 /usr/sbin/perl5.00404 /usr/lib/perl
/usr/local/bin/perl /usr/freeware/bin/perl /usr/freeware/bin/perl5.00502
+++++++++
program:
+++++++++
#!/usr/bin/perl
use Time::HiRes qw(gettimeofday);
$t0=gettimeofday;
for($i=0;$i<=100;$i++)
{
$y +=$i;
}
$t1=gettimeofday;
$elapsed = $t1-$t0;
print $elapsed;
----------------------
----------------------
perl -c t.cgi
+++++++++
Error message:
+++++++++
Can't locate Time/HiRes.pm in @INC (@INC contains:
/usr/freeware/lib/perl5/5.00502/irix-n32 /usr/freeware/lib/perl5/5.00502
/usr/freeware/lib/perl5/site_perl/5.005/irix-n32
/usr/freeware/lib/perl5/site_perl/5.005
/usr/freeware/lib/perl5/sgi_perl/irix-n32 /usr/freeware/lib/perl5/site_perl
.) at t.cgi line 3.
BEGIN failed--compilation aborted at t.cgi line 3
------------------------------
Date: 09 Feb 2001 20:24:14 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Free Movie Ticket Give-away for solving the basic problem on Time:HiRes.pm module
Message-Id: <m3bssbnxdt.fsf@mumonkan.sunstarsys.com>
"Carmari" <caramari9@hotmail.com> writes:
> perl: /usr/bin/perl /usr/sbin/perl /usr/sbin/perl5.00502-n32
> /usr/sbin/perl5.00502 /usr/sbin/perl5.00404 /usr/lib/perl
> /usr/local/bin/perl /usr/freeware/bin/perl /usr/freeware/bin/perl5.00502
Holy schizo Batman, which perl does /usr/bin/perl point to? Check the
output of
% ls -l /usr/bin/perl /usr/freeware/lib/perl*
If /usr/freeware/lib/perl5/ the correct library tree for /usr/bin/perl,
then it's entirely likely you don't have Time::HiRes installed (it's
not part of the standard installation, IIRC). A quick trip to CPAN
should fix that:
http://www.cpan.org
Do a search for Time::HiRes; download and install it as usual. If
you have the cpan module set up, it's as easy as this:
% perl -MCPAN -e 'install Time::HiRes'
Tickets should be mailed to Pink, c/o the funny farm...
--
Joe Schaefer "Don't be so humble - you are not that great."
--Golda Meir
------------------------------
Date: Sat, 10 Feb 2001 00:42:09 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: howto split without regard to white spaces?
Message-Id: <slrn9893j0.7o0.tjla@thislove.dyndns.org>
I was shocked! How could neutron16@my-deja.com <neutron16@my-deja.com>
say such a terrible thing:
>hi perl gurus, i wish to split a string of numbers i have into an array.
>but it doesn't work with the following code:
>
>#!/usr/local/bin/perl
>$a = " 4822 1.174920e+02 6.944940e+01 4.633870e+00 ";
>@b = split (/[\s]/, $a);
>print "$b[0] $b[1] $b[2] $b[3]\n";
>
>array @b contains only white soaces when i print it out! can anyone help
>me out? thanks in advance!
I think if you do this:
$num_of_items_in_b = @b;
print $num_of_items_in_b;
You might get a big hint. Also:
$" = ')(';
print "(@b)";
Offers a clue.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
BOFH excuse #64:
CPU needs recalibration
------------------------------
Date: Fri, 09 Feb 2001 17:20:29 -0600
From: Steve Wells <wells@cedarnet.org>
Subject: Re: insertion sort algorithm
Message-Id: <3A847B3D.407314C8@cedarnet.org>
Perl arrays are similar to arrays in C in that they start at zero.
One way to fix this would be to put a place holder at the beginning of
your array.
my @A = qw( 0 5 3 1 7 9 2 10 4 8 6 20 18 16 14 12 19 17 15 13 11);
;-) but that would be cheating...
The real problem is that you need to include A[0] in the loop.
Change this:
while( $i > 0 && $A[ $i ] > $key ) {
to this:
while( $i >= 0 && $A[ $i ] > $key ) {
^
and see what happens...
HTH,
STEVE
shogun415@my-deja.com wrote:
>
> I am a complete newbie learning algorithms to add to my arsenal of
> programming skills. I am using Introduction to Algorithms by Cormen,
> Leiserson and Rivest.
>
> I am using PERL of course for the language.
>
> Here is my scenario, I have an @array of 20 integers ranging from 1-20,
> the algo works almost flawlessly EXCEPT that the number 5 is always the
> first number and the rest of the numbers fall into the correct order.
>
> I am enclosing the code, I would appreciate it if someone who knows
> algos could check my code and tell me where the error is in my version
> of the algo...
>
> p.s I know that I am not using strict...
>
> ##---------------------------------
> # code start
> ##---------------------------------
>
> #!/usr/bin/perl -w
>
> my @A = qw( 5 3 1 7 9 2 10 4 8 6 20 18 16 14 12 19 17 15 13 11);
>
> for( $j = 2; $j < scalar( @A ); $j++ ) {
> $key = $A[ $j ];
> $i = $j - 1;
> while( $i > 0 && $A[ $i ] > $key ) {
> $A[ $i + 1] = $A[ $i ];
> $i = ($i - 1);
> }
> $A[ $i + 1] = $key;
> }
>
> print "\n", join "\n", @A, "\n";
>
> ##----------------------------------
> ##----------------------------------
>
> thx in advance,
> -shogun
>
> Sent via Deja.com
> http://www.deja.com/
------------------------------
Date: Sat, 10 Feb 2001 00:20:18 GMT
From: shogun415@my-deja.com
Subject: Re: insertion sort algorithm
Message-Id: <9621fs$vbr$1@nnrp1.deja.com>
Now the 5 is after the 2.
[courtney@uneek algo]$ perl i3.pl
1
2
5
3
4
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
close but no cigar, actually though in a perl example I found on the web
it used the >= operator and it worked! The thing is that his code was
completely different from the book and although it worked I am trying to
stick to the text as much as possible.
Thx Steve,
any other suggestions?
courtney a.k.a shogun
In article <3A847B3D.407314C8@cedarnet.org>,
Steve Wells <wells@cedarnet.org> wrote:
> Perl arrays are similar to arrays in C in that they start at zero.
>
> One way to fix this would be to put a place holder at the beginning of
> your array.
>
> my @A = qw( 0 5 3 1 7 9 2 10 4 8 6 20 18 16 14 12 19 17 15 13 11);
>
> ;-) but that would be cheating...
>
> The real problem is that you need to include A[0] in the loop.
>
> Change this:
> while( $i > 0 && $A[ $i ] > $key ) {
> to this:
> while( $i >= 0 && $A[ $i ] > $key ) {
> ^
>
> and see what happens...
>
> HTH,
> STEVE
>
> shogun415@my-deja.com wrote:
> >
> > I am a complete newbie learning algorithms to add to my arsenal of
> > programming skills. I am using Introduction to Algorithms by Cormen,
> > Leiserson and Rivest.
> >
> > I am using PERL of course for the language.
> >
> > Here is my scenario, I have an @array of 20 integers ranging from
1-20,
> > the algo works almost flawlessly EXCEPT that the number 5 is always
the
> > first number and the rest of the numbers fall into the correct
order.
> >
> > I am enclosing the code, I would appreciate it if someone who knows
> > algos could check my code and tell me where the error is in my
version
> > of the algo...
> >
> > p.s I know that I am not using strict...
> >
> > ##---------------------------------
> > # code start
> > ##---------------------------------
> >
> > #!/usr/bin/perl -w
> >
> > my @A = qw( 5 3 1 7 9 2 10 4 8 6 20 18 16 14 12 19 17 15 13 11);
> >
> > for( $j = 2; $j < scalar( @A ); $j++ ) {
> > $key = $A[ $j ];
> > $i = $j - 1;
> > while( $i > 0 && $A[ $i ] > $key ) {
> > $A[ $i + 1] = $A[ $i ];
> > $i = ($i - 1);
> > }
> > $A[ $i + 1] = $key;
> > }
> >
> > print "\n", join "\n", @A, "\n";
> >
> > ##----------------------------------
> > ##----------------------------------
> >
> > thx in advance,
> > -shogun
> >
> > Sent via Deja.com
> > http://www.deja.com/
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 9 Feb 2001 20:58:15 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: insertion sort algorithm
Message-Id: <96277l$not$1@slb5.atl.mindspring.net>
"Steve Wells" <wells@cedarnet.org> wrote in message
news:3A847B3D.407314C8@cedarnet.org...
> Perl arrays are similar to arrays in C in that they start at zero.
>
> Change this:
> while( $i > 0 && $A[ $i ] > $key ) {
> to this:
> while( $i >= 0 && $A[ $i ] > $key ) {
> ^
You need to correct the array base in both places:
for( $j = 2; $j < scalar( @A ); $j++ ) { # <<< $j starts at the _third_
element
$key = $A[ $j ];
$i = $j - 1;
while( $i > 0 && $A[ $i ] > $key ) { # <<< $i starts at the second
element
$A[ $i + 1] = $A[ $i ];
$i = ($i - 1);
}
$A[ $i + 1] = $key;
}
The corrected code would be
use strict;
use warnings;
my @A = qw( 5 3 1 7 9 2 10 4 8 6 20 18 16 14 12 19 17 15 13 11);
my ($i, $j, $key);
for( $j = 1; $j < scalar( @A ); $j++ ) {
$key = $A[ $j ];
$i = $j - 1;
while( $i >= 0 && $A[ $i ] > $key ) {
$A[ $i + 1] = $A[ $i ];
$i = ($i - 1);
}
$A[ $i + 1] = $key;
}
print "\n", join "\n", @A, "\n";
This is OK if the purpose of the exercise is to implement the textbook code
in Perl, however if you are actually trying to sort some data you should use
the Perl sort() function instead.
(See perldoc -f sort)
my @A = qw( 5 3 1 7 9 2 10 4 8 6 20 18 16 14 12 19 17 15 13 11);
@A = sort {$a <=> $b} @A; # sort @A numerically
print join(',', @A), "\n";
HTH
Kurt Stephens
------------------------------
Date: 9 Feb 2001 23:46:23 GMT
From: throwaway-a2345s@scotclimb.org.uk
Subject: Makerpm updated : new features + support for RedHat 7.0 / RPM 4
Message-Id: <t8936l34lhoj8a@corp.supernews.com>
Keywords: makerpm RPM perl RedHat Linux package
I have released a new version of makerpm. Makerpm is software
designed to turn perl modules into RPMs.
The new version has been tested on RPM 4 systems, and should work on
earlier versions as well.
New features include -
- automatic creation of description information
- possibility to use install scripts
- semi automatic detection of package documentation
This should gradually be making its way round to different CPAN
mirrors worldwide. as
authors/id/M/MI/MIKEDLR/makerpm0.200.tar.gz
P.S. Makerpm is also meant to create PPMs. I don't think I have
broken this, but given that I haven't tested it, I probably have.
Please send 'patch -u's to me if you would like to fix this.
--
<http://www.tardis.ed.ac.uk/~mikedlr/biography.html>
Scottish Climbing Archive: <http://www.tardis.ed.ac.uk/~mikedlr/climbing/>
Linux/Unix clone@ftp://src.doc.ic.ac.uk/packages/linux/sunsite.unc-mirror/docs/
------------------------------
Date: Sat, 10 Feb 2001 01:07:56 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: newbie regexp
Message-Id: <4u498t0vutv1i5d1ct1oo1pq1t3maotta2@4ax.com>
LXQ wrote:
>Im trying to change all words in a file:
>from desk -> table
>from house -> home
>from dog -> cat
> $line = s/desk/table/:
> $line = s/house/home/;
> $line = s/dog/cat/;
Two things. A: use =~ not = . B: add the g modifier.
$line = s/desk/table/g;
And C: it's best to populate a hash, and do all of the substitution in
one go. In case you're wondering why, try replacing "desk" with "house",
"house with "dog", and "dog" with "desk". Use any order you like.
This can do that (provided you adjust the replacement data):
%replace = ( desk => 'table', house => 'home', dog => 'cat' );
s/(desk|house|dog)/$replace{$1}/g;
--
Bart.
------------------------------
Date: Fri, 09 Feb 2001 17:51:14 -0800
From: Robert Shockley <vaton@pacbell.net>
Subject: Perl & Recursion : Why doesn't this work?
Message-Id: <3A849E92.5B7FD9C3@pacbell.net>
I am new to Perl and having problems with recursive routines in Perl.
The following
code produces a 0 instead of 720, as it should, on input 6:
sub factorial{
$number = shift @_;
return 1 if $number == 0;
return ( $number * factorial( $number - 1 ) );
}
print factorial(6) . "\n";
The same algorithm in C works fine (I know - Perl ain't C):
#include <stdio.h>
int factorial(int number){
if(number == 0)
return 1;
else
return ( number * factorial( number - 1 ) );
}
void main(){
int c;
printf("%d\n",factorial(6));
c = getchar();
}
------------------------------
Date: Fri, 9 Feb 2001 18:04:34 -0800
From: "Dennis Wilson" <lincwils@teleport.com>
Subject: Re: Perl & Recursion : Why doesn't this work?
Message-Id: <ti1h6.22$NT1.25726@nntp1.onemain.com>
Try using the pragmas strict and warnings with this code.
They should be place right after the shebang if you are on unix
otherwise on lines 1 and 2.
Do that before you read the rest, please.
Variables are global by default in perl. Without my to make it local your
$number variable is global and that affects the result.
Robert Shockley wrote in message <3A849E92.5B7FD9C3@pacbell.net>...
>I am new to Perl and having problems with recursive routines in Perl.
>The following
>code produces a 0 instead of 720, as it should, on input 6:
>
>sub factorial{
> $number = shift @_;
> return 1 if $number == 0;
> return ( $number * factorial( $number - 1 ) );
>}
>print factorial(6) . "\n";
>
>The same algorithm in C works fine (I know - Perl ain't C):
>
>#include <stdio.h>
>int factorial(int number){
> if(number == 0)
> return 1;
> else
> return ( number * factorial( number - 1 ) );
>}
>
>void main(){
> int c;
> printf("%d\n",factorial(6));
> c = getchar();
>}
>
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 261
**************************************