The debugger as a perl shell

Starting a Session (perl -d)

For an example of its simplest usage, start the debugger by giving it something innocuous (like a 0 (zero)) as the evaluation argument to the debugger via the command line:

opx-p1200794This way of invoking the debugger works just as well on Microsoft Windows and Mac OS X as it does on the many flavors of Un*x.

A simple expression (perl -d -e 0)
The “-e” supplies a complete program on the command line for Perl to run –
for more info on this see perlrun

perldb@monkey> B<perl -d -e 0>
Default die handler restored.

Loading DB routines from perl5db.pl version 1.19
Editor support available.

Enter h or `h h’ for help, or `man perldebug’ for more help.

main::(-e:1): 0
DB<1>

Perl stops at the first executable statement. In this example, this is 0,
a perfectly valid (though minimal) Perl expression.

If you continue now, you’ll just fall off the end of the program.

Although this example may not immediately appear to be very useful, at this point you can in fact interact completely with the debugger. You can look at any environment variables (“V”) and you can also check out the help (“h”) page/s, and explore your surroundings.

To get the help page simply type “h” at the command prompt:

C<>
DB<1> B<h>
List/search source lines: Control script execution:
l [ln|sub] List source code         T Stack trace
– or . List previous/current line  s [expr] Single step [in expr]
w [line] List around line            n [expr] Next, steps over subs
f filename View source in file    <CR/Enter> Repeat last n or s
/pattern/ ?patt? Search forw/backw r Return from subroutine
v Show versions of modules     c [ln|sub] Continue until position
Debugger controls: L List break/watch/actions
O […] Set debugger options     t [expr] Toggle trace [trace expr]
<[<]|{[{]|>[>] [cmd] Do pre/post-prompt b [ln|event|sub] [cnd] Set breakpoint
! [N|pat] Redo a previous command d [ln] or D Delete a/all breakpoints
H [-num] Display last num commands a [ln] cmd Do cmd before line
= [a val] Define/list an alias      W expr Add a watch expression
h [db_cmd] Get help on command A or W Delete all actions/watch
|[|]db_cmd Send output to pager ![!] syscmd Run cmd in a subprocess
q or ^D Quit                           R Attempt a restart
Data Examination: expr Execute perl code, also see: s,n,t expr
x|m expr Evals expr in list context, dumps the result or lists methods.
p expr Print expression (uses script’s current package).
S [[!]pat] List subroutine names [not] matching pattern
V [Pk [Vars]] List Variables in Package. Vars can be ~pattern or !pattern.
X [Vars] Same as “V current_package [Vars]”.
For more help, type h cmd_letter, or run man perldebug for all docs.
DB<2>

A perl shell

You can run any Perl code you like in this environment, you can think of it as a form of Perl Shell.

Perhaps you can’t remember whether the results of a regular expression are given in scalar or array context. Instead of looking it up in perlre, you might choose to just try it out.

We’ll use “p”, which is just Perl’s print command in disguise, to see what is happening, first create a string $str.

C<>
DB<2> B<$str = ‘some string’>
DB<3>

Now print $str.

See “p” in examining-data.

C<>
DB<3> B<p $str>
some string
DB<4>

Now use $res to capture the return value of a regex and print the result.

C<>
DB<4> B<$res = $str =~ /(\w+)\s+(\w+)/>
DB<5> B<p $res>
1
DB<6>

Now use @res to capture and print that.

C<>
DB<7> B<@res = $str =~ /(\w+)\s+(\w+)/>
DB<8> B<p @res>
somestring
DB<9>

Use “x” to dump the results to get a clearer picture.

C<>
DB<9> B<x \@res>
0 ARRAY(0x844df5c)
0 ‘some’
1 ‘string’
DB<10>

Extract from the Perl Debugger Pocket Reference book.

Naked at the Gasthof

Occasionally we glimpsed the surrounding peaks getting smaller. After several hours of zig-zagging upwards through the trees, we emerged from the forest onto the ridge and a welcome pause. We were going slowly and stopped for lunch just below the top. We were going slowly and stopped for lunch just below the top, Doug, Mira, mid-p1050335Jacques and Sylvie, then joined us for lunch and then to walk back up to the top of the hill, many people passing us on the fairly busy ridge trail.

Several looked a little surprised to see our group walking naked along the same way as they were, but were all friendly enough, with several smiles and waves exchanged, as one would expect when out on a mountain hike. Continuing along the spine of the alp, we quickly dressed to enter the Hochzelleralm Mountain Gasthof, nestling nicely on the shoulder of the ridge with extensive views of the lower valleys all around. We were just sitting down when Jerome, (organiser of the Brussels WNBR), suggested I ask the staff if it were possible to sit on their terrace naked. Naturally I thought they’d say no, but was happy to ask.

Guests at the Gasthof

The young and friendly waiter looked suitably surprised, but said that it was late in the day, with not many guests, and if the few that were here didn’t mind he had no objection either. So I asked a couple on the nearest table, and they said they didn’t mind, I dutifully fed the response back to the waiter, and he said, “fine, enjoy your drinks on our terrace naked by all means, then”.

We needed no further encouragement and our flimsy wraps and shorts came off, much to the surprise of one other couple, who’d I’d neglected to ask. They however were quite ok with us being naked too, furthermore they were happy to be video interviewed by the naked Gilles as to how they felt about more than 20 plus naked guests sharing their alpine coffee break with them. They seemed pretty comfortable about it all, the lady even removing her jumper to show some solidarity, (or perhaps she was just getting a bit hot).

We chatted for some time, greeting new arrivals with cheerful smiles as usual, and slowly drank our thirst-quenching schorles at this extraordinary well situated alpine Gasthof. The views were stupendous.

Extract from the Naked Hiking book, chapter by Richard Foley

In winter things get complicated

Then clothing. This will be necessary anyway at one time or another, especially at the outset, when the muscles are still stiff and cold. Once you get going, the muscles will soon warm up, then clothes become redundant and can be removed layer by layer. However, unlike shorts in summer which are quickly removed, in winter things get complicated.

I02 avril 2010, Vararey, Chartreuset’s an acrobatic feat to avoid soaking your clothes while undressing in the snow, not to mention dressing again in a hurry. So you need to choose your outfit carefully. In practice, what I find works best are over-trousers worn directly on the skin, which unzip completely at the sides so that you can keep your boots on, worn with polar-grade jackets and vests. In deep snow, gaiters will prevent snow getting into your boots. Heat loss is mainly from the extremities, so gloves and a hat are de rigueur.

Extra dry warm clothes will also be needed in case of sudden changes in temperature. Make sure you have really effective sunglasses, otherwise you will suffer sore eyes, or even snow-blindness. The rest of the gear is that of any winter mountain hike: water, food, warm gore-tex jacket, rescue equipment, including a snow shovel, phone, gps, maps, and camera.

Extract from the Naked Hiking book, chapter by Jacques-Marie Francillon

Naked in a public space

The photographic images presented here tell the tale of the ride itself, as well as a few of its related stories, and each “picture is worth a thousand words”. Indeed, many images from the WNBR are truly excellent and belong in the photo-std-2011_0611wnbr0078-bcdocumentary slot of any comprehensive photographic library purporting to be representative of modern times, and we present a frustratingly small selection of these images for your curiosity here.

However, there are still some people who wish to join the WNBR and yet not take part in the photographic record, which seems to be an untenable position in principle. This is a very naturist kind of outlook, the wanting to be naked and wanting other people to see, but not wanting anyone to take a photograph, for some unspoken, half-guessed at reason. At a WNBR event, this approach just does not wash.

Naked in public

When someone is naked in a public space, and when that person is clearly taking part in a massively advertised protest event, which event is expressly designed to attract the media, photographers and news reporters from all around the world, there is very little credit to be had from complaining when someone takes a photograph. I don’t think anyone would assume this opinion to be valid legal counsel for photographing naked people in public in every country around the world, but certainly anyone who attends a WNBR event has almost certainly voided any reasonable claim to privacy, and it’s almost certain the law courts would take a similar view in any sensible case.

Extract from the World Naked Bike Ride book.

Request Tracker

RT Essentials, co-written by one of the RT’s original core developers, Jesse Vincent, starts off with a quick background opx-p1200796lesson about ticketing systems and then shows you how to install and configure RT.

This comprehensive guide explains how to perform day-to-day tasks to turn your RT server into a highly useful tracking tool. One way it does this is by examining how a company could use RT to manage its internal processes.

Advanced chapters focus on developing add-on tools and utilities using Perl and Mason. There’s also chapter filled with suggested uses for RT inside your organization.

From the reviews on Amazon:

When I first started learning about RT and how to apply the utility to our business, I needed a book that was simple and easy to understand. This taught me all the fundamentals and the examples were easy to follow.

and

Request Tracker (RT) is a great product. I am the only sysadmin at a small company, and having an automated tracking system is going to be an immense benefit for me. I bought “RT Essentials” to help me get up to speed on RT3 really quickly. And, since it was written by the programmer who’s responsible for RT, the book had lots of detail and tips.

Check it out for yourself.

Too close to Nature

I learnt for the first time what it was not just to be amongst nature, but to be part of it. Boots had left me stumbling blindly across the ground, oblivious to what lay on it. mid-image45My clothes had insulated me, not just to the elements, but to the whole environment. Was I really not tough enough to handle a bit of wind, maybe an occasional spot of rain?

And while paths are often rough and gravel strewn did I really need boots for grass strewn slopes? While the climate of Scotland could be harsh, I realised there would always be days when nature welcomed me, when clothes, maybe even boots might not be needed.

Too close

However, you can sometimes get a little too close to nature. One particular example of this takes me back to a hot summer day on the north coast of Scotland. We had thought about finding ourselves a secluded beach to take advantage of the warm Gulf Stream waters, but instead we decided to climb a mountain, Ben Hope, one of the largest of the isolated peaks of the far north. Parked at the bottom of it, the weather seemed so good that for a moment I briefly considered leaving my waterproof jacket behind. But then I remembered this is Scotland, and we have a saying here – “if you don’t like the weather, just try waiting fifteen minutes.”

Extract from the Naked Hiking book, chapter by Stuart Pitsligo

Listing perl code

Using the perl debugger to produce a code listing.

l usage
l [min+incr|min-max|line|subname|$var]

List code within the currently loaded file, in “windowSize” chunks. Note
you can always get back to the current code position with the “.” command
(below).

See options for more information about “windowSize”

opx-p1200794Sometimes the default “windowSize” view of your code just is not
sufficient, and knowing how to modify the view can make the difference
between an easy trouble-shooting session and a hard one.

l
List code from current viewing position

perldb@monkey> B<perl -d linecounter.pl>
<…truncated output…>
main::(linecounter.pl:8): my @args = @ARGV;
DB<1> B<l>
8==> my @args = @ARGV;
9
10 # help requested?
11: my $help = grep(/^-h(elp)*$/i, @args);
12: if ($help) {
13: logg(help());
14: exit 0;
15 }
16
17 # get the pattern to match against.
DB<1>

Now do it again to continue the listing:

C<>
DB<1> B<l>
18: my $REGEX = shift @args || ”;
19
20 # get the files for processing.

21: my @files = grep(!/^-h(elp)*$/i, @args);

22: unless (@files) {

23: push(@files, $0);
24: logg(“using default $0 while no files given”);
25 }
26
27 # loop through the files
DB<1>

l line
List the single line of code at line 11.

C<>
DB<1> B<l 11>
11: my $help = grep(/^-h(elp)*$/i, @args);
DB<2>

l min+incr
List the range of code from line number min and the following incr lines.

C<>
DB<2> B<l 11+3>
11: my $help = grep(/^-h(elp)*$/i, @args);
12: if ($help) {
13: logg(help());
14: exit 0;
DB<3>

l min-max
List the range of code from line number min up to and including line
number max.

C<>
DB<3> B<l 11-14>
11: my $help = grep(/^-h(elp)*$/i, @args);
12: if ($help) {
13: logg(help());
14: exit 0;
DB<4>

l subname
List “windowSize” lines of code of the given subroutine.

C<>
DB<4> B<l report>
56 sub report {
57: my $FH = shift;
58: my $regex = shift;
59: my %report = ();
60: my $i_cnt = 0;
61: while (<$FH>) {
62: $i_cnt++;
63: my $i_match = 0;
64: my $line = $_;
65: if ($line =~ /($regex)/) {
DB<5>

The subroutine may be in any file loaded in %INC.

C<>
DB<5> B<l Carp::croak>
Switching to file ‘/usr/lib/perl5/5.8.0/Carp.pm’.
191: sub croak { die shortmess @_ }
DB<6>

 

Extract from the Perl Debugger Pocket Reference book.

Pro Perl Debugging

Pro Perl Debugging steps in to help resolve the dilemma of application testing and debugging—one of the biggest time commitments in a programmers daily routine.

opx-p1200807What this book will do is rescue you from substandard application testing practices.

The book commences with several chapters that overview the debuggers basic features, then covers common debugging scenarios. The concluding portion examines debugger customization, alternative debugging utilities, and debugging best practices.

From the reviews on Amazon:

I’ve had this book for several weeks and foolishly ignored it. Part of that was because I was busy with a lot of other stuff, but a large part was that I didn’t have much interest: what do I need a perl debugger for? What’s wrong with “print”‘s?

Boy was I wrong. By the second chapter I was kicking myself for being so stupid. Perl’s debugger is a thing of joy – it almost makes me look forward to my next confused Perl program.. well, I’d still rather not have any problem at all, but reading this book gives me a powerful tool to help me figure out where I went wrong.

Try it out for yourself.

Magical zone

The most compelling reason that I have found though for hiking in the nude, is the ease of sliding into that magical zone of existence while naked. As my freehiking buddies and I have all experienced, especially while hiking solo, it is the process of just wandering, and slowly drifting into that zone of existence mid-bb-07where you are acutely sensitive to everything around you, yet deeply calm, and passively observing. On one hike on an early spring day, I nearly tripped over a bright orange newt (a small lizard-like amphibian) amongst the green undergrowth at my feet, if tripping over a newt is possible.

I just had to squat down and stare at it for awhile. That newt was my total existence for that moment. On another hike, I found myself sitting during a rest break, upon a small ledge halfway up a hillside on the Long Trail in Vermont, in the Northeast Kingdom. Overlooking a medium size pond a few hundred feet below me, the water below was framed by clouds and mist boiling and spilling over the mountain tops several hundred feet above me. Sitting in my nakedness, temps in the low 50s , overcast weather, I was acutely aware of my environment, the sound of the rain drifting down through the trees, the lush green smell, the color of the light filtering through the mists above, the texture of the surface of the pond. I was totally at peace with that moment.

Heightened state

Parts of the past few years have been rather wet for hiking here in the northeast US, a blessing in keeping some of the tourists at bay. A relative delight in discovering how comfortable one can be hiking naked during the summer, in the rain that would otherwise have one miserable, soggy and chilled. This has come at the expense of the trails getting very beat up because they have remained so muddy that they cannot support the foot traffic when the sun and crowds do return. There has also been a lot of damage caused by the hurricanes and major storms experienced in my area these past two years.

A side benefit that I have noticed through this adversity though, backpacking sections of both the Long Trail and Appalachian Trail is that because the going is rough and much slower than normal, I have been able to notice many things along the trail that I may have unconsciously walked by under more normal conditions. The slower pace and the heightened state of my senses brought on by my nakedness have allowed me a deeper appreciation of some very special parts of this planet we inhabit. And yes, I have been asked by fellow hikers that I meet in the overnight huts, how it can be that my clothes have spilled out of my pack dry and why my spirits have remained bouyant. And I have been pleased to have been able to share my personal take on simple nudity with an open minded audience.

Extract from the Naked Hiking book, chapter by Dan Kidwell.

Goldfinger

There’s an old myth about body painting being dangerous, as it supposedly doesn’t let your skin breathe, so-called epidermal suffocation. This was the gimmick used in the James Bond (Sean Connery) movie Goldfinger in 1964, when std-2012_0609wnbr20120057-bcthe girl Jill Masterson (Shirley Eaton), was covered in gold paint and apparently died a terrible death from suffocation.

This is an entertaining fantasy, but the skin on the human just does not breathe in the same way we might imagine by comparing this organ with our lungs, and if you can breathe through your mouth, covering your skin in a safe paint will make no difference to you.

Goldfinger myth

I suspect the origin of this myth goes back to the days of the Judy Garland movie, The Wizard of Oz in 1939, when the actor playing the Tin Man (Buddy Ebsen) role became seriously ill and was hospitalized because of inhaling dangerous metal flakes from the unsafe aluminium-based paint make-up, which was used at the time.

Today’s body paint is safe and fun to use, although it’s still worth pointing out that one should of course use body paint made for the purpose, and not just any old paint one happens to have to hand. Kids put paint on for fancy dress parties, and WNBR protest activists wear body paint to both attract attention to the cause and to have fun.

Extract from the World Naked Bike Ride book.