You can now run tests for I<x> seconds instead of guessing the right
number of tests to run.
+Keeps better time.
+
=item Carp
Carp has a new function cluck(). cluck() warns, like carp(), but also adds
Cwd::cwd is faster on most platforms.
-=item Benchmark
-
-Keeps better time.
-
=back
=head1 Utility Changes
debugger at all. To demonstrate, here's a simple script with a problem:
#!/usr/bin/perl
-
+
$var1 = 'Hello World'; # always wanted to do that :-)
$var2 = "$varl\n";
-
+
print $var2;
exit;
Now when you run it, perl complains about the 3 undeclared variables and we
get four error messages because one variable is referenced twice:
-
+
Global symbol "$var1" requires explicit package name at ./t1 line 4.
Global symbol "$var2" requires explicit package name at ./t1 line 5.
Global symbol "$varl" requires explicit package name at ./t1 line 5.
#!/usr/bin/perl
use strict;
-
+
my $var1 = 'Hello World';
my $varl = '';
my $var2 = "$varl\n";
-
+
print $var2;
exit;
Looks OK, after it's been through the syntax check (perl -c scriptname), we
run it and all we get is a blank line again! Hmmmm.
-
+
One common debugging approach here, would be to liberally sprinkle a few print
statements, to add a check just before we print out our data, and another just
after:
print "done: '$data{$key}'\n";
And try again:
-
+
> perl data
All OK
-
+
done: ''
After much staring at the same piece of code and not seeing the wood for the
DB<1> q
>
-
+
That's it, you're back on home turf again.
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.
-
+
More confusing options than you can shake a big stick at! It's not as bad as
it looks and it's very useful to know more about all of it, and fun too!
DM<3>X ~err
FileHandle(stderr) => fileno(2)
-
+
Remember we're in our tiny program with a problem, we should have a look at
where we are, and what our data looks like. First of all let's have a window
on our present position (the first line of code in this case), via the letter
At line number 4 is a helpful pointer, that tells you where you are now. To
see more code, type 'w' again:
-
+
DB<4> w
8 'welcome' => q(Hello World),
9 'zip' => q(welcome),
DB<4> l 5
5: my %data = (
-
+
In this case, there's not much to see, but of course normally there's pages of
stuff to wade through, and 'l' can be very useful. To reset your view to the
line we're about to execute, type a lone period '.':
DB<5> .
main::(./data_a:4): my $key = 'welcome';
-
+
The line shown is the one that is about to be executed B<next>, it hasn't
happened yet. So while we can print a variable with the letter 'B<p>', at
this point all we'd get is an empty (undefined) value back. What we need to
do is to step through the next executable statement with an 'B<s>':
-
+
DB<6> s
main::(./data_a:5): my %data = (
main::(./data_a:6): 'this' => qw(that),
DB<8> c 13
All OK
main::(./data_a:13): print "$data{$key}\n";
-
+
We've gone past our check (where 'All OK' was printed) and have stopped just
before the meat of our task. We could try to print out a couple of variables
to see what is happening:
DB<9> p $data{$key}
-
+
Not much in there, lets have a look at our hash:
-
+
DB<10> p %data
Hello Worldziptomandwelcomejerrywelcomethisthat
DB<11> p keys %data
Hello Worldtomwelcomejerrythis
-
+
Well, this isn't very easy to read, and using the helpful manual (B<h h>), the
'B<x>' command looks promising:
cont: {'col' => 'black', 'things' => [qw(this that etc)]}}, 'MY_class')
And let's have a look at it:
-
+
DB<2> x $obj
0 MY_class=HASH(0x828ad98)
'attr' => HASH(0x828ad68)
of code or regexes until the cows come home:
DB<3> @data = qw(this that the other atheism leather theory scythe)
-
+
DB<4> p 'saw -> '.($cnt += map { print "\t:\t$_\n" } grep(/the/, sort @data))
atheism
leather
1: $obj = bless({'unique_id'=>'123', 'attr'=>
{'col' => 'black', 'things' => [qw(this that etc)]}}, 'MY_class')
DB<5>
-
+
And if you want to repeat any previous command, use the exclamation: 'B<!>':
DB<5> !4
> temp -c0.72
33.30 f
-
+
> temp -f33.3
162.94 c
-
+
Not very consistent! We'll set a breakpoint in the code manually and run it
under the debugger to see what's going on. A breakpoint is a flag, to which
the debugger will run without interruption, when it reaches the breakpoint, it
will stop execution and offer a prompt for further interaction. In normal
use, these debugger commands are completely ignored, and they are safe - if a
little messy, to leave in production code.
-
+
my ($in, $out) = ($num, $num);
$DB::single=2; # insert at line 9!
if ($deg eq 'c')
...
-
+
> perl -d temp -f33.3
Default die handler restored.
main::(temp:10): if ($deg eq 'c') {
Followed by a window command to see where we are:
-
+
DB<1> w
7: my ($deg, $num) = ($1, $2);
8: my ($in, $out) = ($num, $num);
We can put another break point on any line beginning with a colon, we'll use
line 17 as that's just as we come out of the subroutine, and we'd like to
pause there later on:
-
+
DB<2> b 17
-
+
There's no feedback from this, but you can see what breakpoints are set by
using the list 'L' command:
DB<6> p (5 * $f - 32 / 9)
162.944444444444
-
+
DB<7> p 5 * $f - (32 / 9)
162.944444444444
-
+
DB<8> p (5 * $f) - 32 / 9
162.944444444444
-
+
DB<9> p 5 * ($f - 32) / 9
0.722222222222221
return out of the sub with an 'r':
DB<10> $c = 5 * ($f - 32) / 9
-
+
DB<11> r
scalar context return from main::f2c: 0.722222222222221
-
+
Looks good, let's just continue off the end of the script:
DB<12> c
Actions, watch variables, stack traces etc.: on the TODO list.
a
-
+
W
-
+
t
-
+
T
Ever wanted to know what a regex looked like? You'll need perl compiled with
the DEBUGGING flag for this one:
-
+
> perl -Dr -e '/^pe(a)*rl$/i'
Compiling REx `^pe(a)*rl$'
size 17 first at 2
B<ptkdb> perlTK based wrapper for the built-in debugger
B<ddd> data display debugger
-
+
B<PerlDevKit> and B<PerlBuilder> are NT specific
NB. (more info on these and others would be appreciated).
# is still an experimental feature. It is here to stop people
# from deploying threads in production. ;-)
#
-
+
and another known thread-related warning is
pragma/overload......Unbalanced saves: 3 more saves than restores
There is no builtin C<import> function. It is just an ordinary
method (subroutine) defined (or inherited) by modules that wish to export
names to another module. The C<use> function calls the C<import> method
-for the package used. See also L</use()>, L<perlmod>, and L<Exporter>.
+for the package used. See also L</use>, L<perlmod>, and L<Exporter>.
=item index STR,SUBSTR,POSITION
=item listen SOCKET,QUEUESIZE
Does the same thing that the listen system call does. Returns true if
-it succeeded, false otherwise. See the example in L<perlipc/"Sockets: Client/Server Communication">.
+it succeeded, false otherwise. See the example in
+L<perlipc/"Sockets: Client/Server Communication">.
=item local EXPR
%hash = map { ("\L$_", 1) } @array # this also works
%hash = map { lc($_), 1 } @array # as does this.
%hash = map +( lc($_), 1 ), @array # this is EXPR and works!
-
+
%hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
or to force an anon hash constructor use C<+{>
=item break source.c:xxx
Tells the debugger that we'll want to pause execution when we reach
-either the named function (but see L</Function names>!) or the given
+either the named function (but see L<perlguts/Internal Functions>!) or the given
line in the named source file.
=item step
(gdb) break Perl_pp_add
Breakpoint 1 at 0x46249f: file pp_hot.c, line 309.
-Notice we use C<Perl_pp_add> and not C<pp_add> - see L<perlguts/Function Names>.
+Notice we use C<Perl_pp_add> and not C<pp_add> - see L<perlguts/Internal Functions>.
With the breakpoint in place, we can run our program:
(gdb) run -e '$b = "6XXXX"; $c = 2.3; $a = $b + $c'
warning.
use warnings ;
-
+
time ;
-
+
{
use warnings FATAL => qw(void) ;
length "abc" ;
}
-
+
join "", 1,2,3 ;
-
+
print "done\n" ;
When run it produces this output
localeconv() takes no arguments, and returns B<a reference to> a hash.
The keys of this hash are variable names for formatting, such as
C<decimal_point> and C<thousands_sep>. The values are the
-corresponding, er, values. See L<POSIX (3)/localeconv> for a longer
+corresponding, er, values. See L<POSIX/localeconv> for a longer
example listing the categories an implementation might be expected to
provide; some provide more and others fewer. You don't need an
explicit C<use locale>, because localeconv() always observes the
=head1 SEE ALSO
-L<POSIX (3)/isalnum>, L<POSIX (3)/isalpha>, L<POSIX (3)/isdigit>,
-L<POSIX (3)/isgraph>, L<POSIX (3)/islower>, L<POSIX (3)/isprint>,
-L<POSIX (3)/ispunct>, L<POSIX (3)/isspace>, L<POSIX (3)/isupper>,
-L<POSIX (3)/isxdigit>, L<POSIX (3)/localeconv>, L<POSIX (3)/setlocale>,
-L<POSIX (3)/strcoll>, L<POSIX (3)/strftime>, L<POSIX (3)/strtod>,
-L<POSIX (3)/strxfrm>.
+L<POSIX/isalnum>, L<POSIX/isalpha>, L<POSIX/isdigit>,
+L<POSIX/isgraph>, L<POSIX/islower>, L<POSIX/isprint>,
+L<POSIX/ispunct>, L<POSIX/isspace>, L<POSIX/isupper>,
+L<POSIX/isxdigit>, L<POSIX/localeconv>, L<POSIX/setlocale>,
+L<POSIX/strcoll>, L<POSIX/strftime>, L<POSIX/strtod>,
+L<POSIX/strxfrm>.
=head1 HISTORY
=head1 DESCRIPTION
-=head1 Declaration and Access of Arrays of Arrays
+=head2 Declaration and Access of Arrays of Arrays
The simplest thing to build an array of arrays (sometimes imprecisely
called a list of lists). It's reasonably easy to understand, and
But you cannot do so for the very first one if it's a scalar containing
a reference, which means that $ref_to_AoA always needs it.
-=head1 Growing Your Own
+=head2 Growing Your Own
That's all well and good for declaration of a fixed data structure,
but what if you wanted to add new elements on the fly, or build
In fact, that wouldn't even compile. How come? Because the argument
to push() must be a real array, not just a reference to such.
-=head1 Access and Printing
+=head2 Access and Printing
Now it's time to print your data structure out. How
are you going to do that? Well, if you want only one
}
}
-=head1 Slices
+=head2 Slices
If you want to get at a slice (part of a row) in a multidimensional
array, you're going to have to do some fancy subscripting. That's
Variables beginning with underscore used to be forced into package
main, but we decided it was more useful for package writers to be able
to use leading underscore to indicate private variables and method names.
-$_ is still global though. See also L<perlvar/"Technical Note on the
-Syntax of Variable Names">.
+$_ is still global though. See also
+L<perlvar/"Technical Note on the Syntax of Variable Names">.
C<eval>ed strings are compiled in the package in which the eval() was
compiled. (Assignments to C<$SIG{}>, however, assume the signal
some of which require a C compiler to build. Major categories of
modules are:
-=over
+=over 4
=item *
Registered CPAN sites as of this writing include the following.
You should try to choose one close to you:
-=over
+=over 4
=item Africa
=item *
The U/WIN environment for Win32,
-<http://www.research.att.com/sw/tools/uwin/
+http://www.research.att.com/sw/tools/uwin/
-=item Build instructions for OS/2, L<perlos2>
+=item *
+Build instructions for OS/2, L<perlos2>
=back
with the next one (if it exists).
For a discussion of issues surrounding file permissions and B<-i>,
-see L<perlfaq5/Why does Perl let me delete read-only files? Why
-does -i clobber protected files? Isn't this a bug in Perl?>.
+see L<perlfaq5/Why does Perl let me delete read-only files? Why does -i clobber protected files? Isn't this a bug in Perl?>.
You cannot use B<-i> to create directories or to strip extensions from
files.
=item Step-by-step: Making the module
Start with F<h2xs>, Use L<strict|strict> and L<warnings|warnings>, Use
-L<Carp|Carp>, Use L<Exporter|Exporter> - wisely!, Use L<plain old
-documentation|perlpod>, Write tests, Write the README
+L<Carp|Carp>, Use L<Exporter|Exporter> - wisely!,
+Use L<plain old documentation|perlpod>, Write tests, Write the README
=item Step-by-step: Distributing your module
(here the optional C<IN> keyword is omitted).
The C<IN_OUT> parameters are identical with parameters introduced with
-L<The & Unary Operator> and put into the C<OUTPUT:> section (see L<The
-OUTPUT: Keyword>). The C<IN_OUTLIST> parameters are very similar, the
-only difference being that the value C function writes through the
+L<The & Unary Operator> and put into the C<OUTPUT:> section (see
+L<The OUTPUT: Keyword>). The C<IN_OUTLIST> parameters are very similar,
+the only difference being that the value C function writes through the
pointer would not modify the Perl parameter, but is put in the output
list.
HV * rh;
STRLEN l;
char * fn = SvPV(*av_fetch((AV *)SvRV(paths), n, 0), l);
-
+
i = statfs(fn, &buf);
if (i != 0) {
av_push(results, newSVnv(errno));
continue;
}
-
+
rh = (HV *)sv_2mortal((SV *)newHV());
-
+
hv_store(rh, "f_bavail", 8, newSVnv(buf.f_bavail), 0);
hv_store(rh, "f_bfree", 7, newSVnv(buf.f_bfree), 0);
hv_store(rh, "f_blocks", 8, newSVnv(buf.f_blocks), 0);
hv_store(rh, "f_ffree", 7, newSVnv(buf.f_ffree), 0);
hv_store(rh, "f_files", 7, newSVnv(buf.f_files), 0);
hv_store(rh, "f_type", 6, newSVnv(buf.f_type), 0);
-
+
av_push(results, newRV((SV *)rh));
}
RETVAL = newRV((SV *)results);