CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
General Strawberry questions

 



Wildcard
Novice

Oct 11, 2017, 2:34 PM

Post #1 of 4 (1637 views)
General Strawberry questions Can't Post

Hello there everyone, I hope somone can clarify this little problem I have :)

Well, I am on Windows 10, and so I have now Strawberry installed, and strucked to 2 problems I would like to have answered, if you please..

1 ) How does the CPAN module works? I wanted to use the getOpt for command line parameters, so tried to run the "CPAN Client", I clicked on it, a breaksecond of a command window apperad, and then nothing.

2) how do you debug? Maybe it seems strange that I never debuged before, I always used strict and warnings, that was enough. But now I intentionaly invoked a code, which doesn't work:

Code
my $x = <>;  
my $y = fak($x);

print "$x $y \n";
exit(0);

sub fak
{
my $p = shift;
return ($p * fak($p - 1));
}


How do I prompt a debug? I tried "-d" in the Strawberry command line, but with no prevail. I hope somebody have some insight concerning this. Thanks in advance!


Laurent_R
Veteran / Moderator

Oct 11, 2017, 3:02 PM

Post #2 of 4 (1634 views)
Re: [Wildcard] General Strawberry questions [In reply to] Can't Post

Try to use it from the command line (when on Windows, I use the cmd window prompt, but I guess it should also work on the powershell command line).

Then, something like "cpan module_name" should probably work.

And, to debug, also try from the cmd prompt, with the "-d" command line option:


Code
perl -d my_program.pl


(Then, use "h" to view the available commands in the help menu.)


Chris Charley
User

Oct 12, 2017, 11:51 AM

Post #3 of 4 (1616 views)
Re: [Wildcard] General Strawberry questions [In reply to] Can't Post

A note on your program (finding a factorial).

It needs a condition to stop the recursion.


Code
#!/usr/bin/perl 
use strict;
use warnings;

my $x = <>;
my $y = fak($x);

print "$x $y \n";

sub fak {
my $p = shift;
return 1 if $p == 0;
return ($p * fak($p - 1));
}



Wildcard
Novice

Oct 12, 2017, 1:31 PM

Post #4 of 4 (1611 views)
Re: [Chris Charley] General Strawberry questions [In reply to] Can't Post

First of all, thanks again for the answers, much abliged.
And yeah, I know about that stop condition, that's why I wanted to run a debug through that code, this is the whole point of it :)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives