Perl Forum for Beginners

Re: Debugging and tests

Jul 9, 2009 1:36 am
Steve Bertrand

> On Wed, Jul 8, 2009 at 10:16, Steve Bertrand<steve@ibctech.ca> wrote:

>> %hash = map { my $x = $_; $_ =~ s/h_/hello_/;$_, $hash{$x} } keys %hash;
> snip
>
> The following bits of advice are stylistic in nature, so you can
> ignore them, but there really are good reasons not to.
>
> As name, $x does not really mean anything in this context. A better
> name is $k for key, especially if you use $k often to mean key.
>
> The fat comma (=>) is better than the normal comma in this case. They
> will function the same way, but the fat comma makes it clear that
> there is a key/value pair being created.

Apparently, my webmail application (Squirrelmail) decides that it's best
to snip out credit for the most recent quote, so I apologize for that,
Chas.

Thanks for the style tips. I really do appreciate those, because who knows
who will read my code in the future.

While coding, I don't use unnamed, hard-to-understand vars such as $x. Now
I know the importance of not using such in q&d test scripts as well ;)

I'm glad that you pointed out the importance of using => when dealing with
a hash. I left out some things in the line that I wrote, mostly for
brevity, so it would fit nicely within email standard width.

However, I did not realize that I could use => in place of , wherever a
list is present (even though I know I've read over it in the Cookbook).
That is handy.

I'm so appreciative of this list, and everyone on it. I'm also
appreciative of the people who have written the books. It's clear to me
that teaching Perl is their ultimate goal.

Cheers to all of those who read this list and just 'fit in' when necessary,

Steve




>
>
> --
> Chas. Owens
> wonkden.net
> The most important skill a programmer can have is the ability to read.
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>




Previous Thread: Sorting a hash to user needs
Next Thread: Is there a well-written threading TCP server module for perl?

Related Forum Topics
Re: Debugging and tests
On Wed, Jul 8, 2009 at 09:31, Steve Bertrand<steve@ibctech.ca> wrote:
snip
> my %newhash = map { $_ =~ s/h_/hello_/; ($_, $hash{$_}) } keys %hash;
snip

That will still have a problem: $_ is changed, so it won't reference
the correct thing in %hash. Try this instead:

my %newhash = map {...
Writing tests for module utility scripts
Hi all,

I've got a module that has a significant number of unit tests for each
sub, each within its own file:

acct-dev: ISP-RADIUS % ls t | grep daily
07-aggregate_daily.t

Within the overall package, I've included a few utility scripts that are
installed into the OS path that utilize...
Debugging code that freezes
In another list, I am baffled by the instability of a Perl script that free=
zes after some time for a user. What can be done to run a Perl script in a =
debug like mode such that all system calls could be logged so that one coul=
d see what was attempted for execution by the script as it...
MIME::Lite debugging
I am trying to modify an existing script that uses MIME::Lite->send

I am trying to take any debug output and send it through a Debug
function which goes to a log file so I can see if there is an error.
Am I doing this correctly?:

I'm not using die because I think that sends it to stdout. ...
How to complete the loop while debugging.
--001636457c405003090478943878
Content-Type: text/plain; charset=UTF-8

Hi All,

It happens so many times that while debugging I come inside a loop which
doesn't contain the issue which I am debugging.

And as I am not aware of a method to complete the loop while debugging - I
manually...
Debugging a PERL Web Application
--001636283e78d46d7c0497c97d3a
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I have started working with Perl since 3 days.
I would like to debug an existing perl-web application and have already
found a few links on how to use eclipse and EPIC.
Here I am stuck though and I hope...
File::Find with chmod trouble debugging

The script below is my first usage of perls `chmod', but it appears to
be in keeping with the info at perldoc -f chmod.

But somehow in the print of $mode it turns into 493... even though it
is set to 755. Its just the print though... the actual chmod appears
to be working as...