$boo = [ 1, [], "abcd", \*foo,
{1 => 'a', 023 => 'b', 0x45 => 'c'},
\\"p\q\'r", $foo, $fuz];
-
+
########
# simple usage
########
$Data::Dumper::Useqq = 1; # print strings in double quotes
print Dumper($boo);
-
-
+
+
########
# recursive structures
########
-
+
@c = ('c');
$c = \@c;
$b = {};
$b->{b} = $a->[1];
$b->{c} = $a->[2];
print Data::Dumper->Dump([$a,$b,$c], [qw(a b c)]);
-
-
+
+
$Data::Dumper::Purity = 1; # fill in the holes for eval
print Data::Dumper->Dump([$a, $b], [qw(*a b)]); # print as @a
print Data::Dumper->Dump([$b, $a], [qw(*b a)]); # print as %b
-
-
+
+
$Data::Dumper::Deepcopy = 1; # avoid cross-refs
print Data::Dumper->Dump([$b, $a], [qw(*b a)]);
-
-
+
+
$Data::Dumper::Purity = 0; # avoid cross-refs
print Data::Dumper->Dump([$b, $a], [qw(*b a)]);
-
+
########
# deep structures
########
-
+
$a = "pearl";
$b = [ $a ];
$c = { 'b' => $b };
$Data::Dumper::Maxdepth = 3; # no deeper than 3 refs down
print Data::Dumper->Dump([$f], [qw(f)]);
-
+
########
# object-oriented usage
########
-
+
$d = Data::Dumper->new([$a,$b], [qw(a b)]);
$d->Seen({'*c' => $c}); # stash a ref without printing it
$d->Indent(3);
print $d->Dump;
$d->Reset->Purity(0); # empty the seen cache
print join "----\n", $d->Dump;
-
-
+
+
########
# persistence
########
-
+
package Foo;
sub new { bless { state => 'awake' }, shift }
sub Freeze {
$s->{state} = 'asleep';
return bless $s, 'Foo::ZZZ';
}
-
+
package Foo::ZZZ;
sub Thaw {
my $s = shift;
$s->{state} = 'awake';
return bless $s, 'Foo';
}
-
+
package Foo;
use Data::Dumper;
$a = Foo->new;
print $c;
$d = eval $c;
print Data::Dumper->Dump([$d], ['d']);
-
-
+
+
########
# symbol substitution (useful for recreating CODE refs)
########
-
+
sub foo { print "foo speaking\n" }
*other = \&foo;
$bar = [ \&other ];
non-zero value only if C<$!> is set to that value. For example:
use Errno;
-
+
unless (open(FH, "/fangorn/spouse")) {
if ($!{ENOENT}) {
warn "Get a wife!\n";
Copyright (c) 1989, 1993 The Regents of the University of California.
All rights reserved.
-
+
This code is derived from software contributed to Berkeley by
Guido van Rossum.
$lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080);
$sel = new IO::Select( $lsn );
-
+
while(@ready = $sel->can_read) {
foreach $fh (@ready) {
if($fh == $lsn) {
configuration method of the package for that domain, See below.
NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
-
+
As of VERSION 1.18 all IO::Socket objects have autoflush turned on
by default. This was not the case with earlier releases.
NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
-
+
As of VERSION 1.18 all IO::Socket objects have autoflush turned on
by default. This was not the case with earlier releases.
use IPC::SysV qw(IPC_PRIVATE S_IRWXU S_IRWXG S_IRWXO);
use IPC::Msg;
-
+
$msg = new IPC::Msg(IPC_PRIVATE, S_IRWXU | S_IRWXG | S_IRWXO);
-
+
$msg->snd(pack("L a*",$msgtype,$msg));
-
+
$msg->rcv($buf,256);
-
+
$ds = $msg->stat;
-
+
$msg->remove;
=head1 DESCRIPTION
use IPC::SysV qw(IPC_PRIVATE S_IRWXU IPC_CREAT);
use IPC::Semaphore;
-
+
$sem = new IPC::Semaphore(IPC_PRIVATE, 10, S_IRWXU | IPC_CREAT);
-
+
$sem->setall( (0) x 10);
-
+
@sem = $sem->getall;
-
+
$ncnt = $sem->getncnt;
-
+
$zcnt = $sem->getzcnt;
-
+
$ds = $sem->stat;
-
+
$sem->remove;
=head1 DESCRIPTION
The file format used for save/restore is identical to that used by the
Whitehead Genome Center's data exchange format "Boulderio", and can be
manipulated and even databased using Boulderio utilities. See
-
+
http://stein.cshl.org/boulder/
for further details.
use CGI qw(-no_debug :standard);
restore_parameters(join('&',@ARGV));
-
+
See the section on debugging for more details.
=item -private_tempfiles
"Open a new frame");
<A HREF="fred.html",TARGET="_new">Open a new frame</A>
-
+
You may dispense with the dashes in front of the attribute names if
you prefer:
attribute argument was the same as providing undef. However, this has
changed in order to accommodate those who want to create tags of the form
<IMG ALT="">. The difference is shown in these two pieces of code:
-
+
CODE RESULT
img({alt=>undef}) <IMG ALT>
img({alt=>''}) <IMT ALT="">
$query = new CGI;
$query->autoEscape(undef);
-
+
=head2 CREATING AN ISINDEX TAG
startform() will return a <FORM> tag with the optional method,
action and form encoding that you specify. The defaults are:
-
+
method: POST
action: this script
enctype: application/x-www-form-urlencoded
print $query->checkbox_group(-name=>'group_name',
-values=>['eenie','meenie','minie','moe'],
-rows=2,-columns=>2);
-
+
checkbox_group() creates a list of checkboxes that are related
by the same name.
=item 2. Specify the destination for the document in the HTTP header
You may provide a B<-target> parameter to the header() method:
-
+
print $q->header(-target=>'ResultsWindow');
This will tell the browser to load the output of your script into the
for debugging purposes:
print $query->dump
-
+
Produces something that looks like:
=over 4
=item multipart_init()
-
+
multipart_init(-boundary=>$boundary);
Initialize the multipart system. The -boundary argument specifies
#!/usr/local/bin/perl
-
+
use CGI;
-
+
$query = new CGI;
print $query->header;
&do_work($query);
&print_tail;
print $query->end_html;
-
+
sub print_prompt {
my($query) = @_;
-
+
print $query->startform;
print "<EM>What's your name?</EM><BR>";
print $query->textfield('name');
print $query->checkbox('Not my real name');
-
+
print "<P><EM>Where can you find English Sparrows?</EM><BR>";
print $query->checkbox_group(
-name=>'Sparrow locations',
-values=>[England,France,Spain,Asia,Hoboken],
-linebreak=>'yes',
-defaults=>[England,Asia]);
-
+
print "<P><EM>How far can they fly?</EM><BR>",
$query->radio_group(
-name=>'how far',
-values=>['10 ft','1 mile','10 miles','real far'],
-default=>'1 mile');
-
+
print "<P><EM>What's your favorite color?</EM> ";
print $query->popup_menu(-name=>'Color',
-values=>['black','brown','red','yellow'],
-default=>'red');
-
+
print $query->hidden('Reference','Monty Python and the Holy Grail');
-
+
print "<P><EM>What have you got there?</EM><BR>";
print $query->scrolling_list(
-name=>'possessions',
'A Sword','A Ticket'],
-size=>5,
-multiple=>'true');
-
+
print "<P><EM>Any parting comments?</EM><BR>";
print $query->textarea(-name=>'Comments',
-rows=>10,
-columns=>50);
-
+
print "<P>",$query->reset;
print $query->submit('Action','Shout');
print $query->submit('Action','Scream');
print $query->endform;
print "<HR>\n";
}
-
+
sub do_work {
my($query) = @_;
my(@values,$key);
print join(", ",@values),"<BR>\n";
}
}
-
+
sub print_tail {
print <<END;
<HR>
In a scalar context, fetch() returns a hash reference, which may be more
efficient if you are manipulating multiple cookies.
-
+
CGI.pm uses the URL escaping methods to save and restore reserved characters
in its cookies. If you are trying to retrieve a cookie set by a foreign server,
this escaping method may trip you up. Use raw_fetch() instead, which has the
=head1 SEE ALSO
L<CGI::Carp>, L<CGI>
-
+
=cut
=head1 SEE ALSO
L<CGI::Carp>, L<CGI>
-
+
=cut
h1('testing'),
"This page called $counter times";
}
-
+
sub my_last_page {
header(-refresh=>'5; URL=http://somewhere.else/finished.html',
-type=>'text/html'),
=head1 DESCRIPTION
No user-serviceable parts inside.
-
+
=cut
# This package is heavily used. Be small. Be fast. Be good.
package CLIENT;
use DB;
@ISA = qw(DB);
-
+
# these (inherited) methods can be called by the client
-
+
CLIENT->register() # register a client package name
CLIENT->done() # de-register from the debugging API
CLIENT->skippkg('hide::hide') # ask DB not to stop in this package
# These methods will be called at the appropriate times.
# Stub versions provided do nothing.
# None of these can block.
-
+
CLIENT->init() # called when debug API inits itself
CLIENT->stop(FILE,LINE) # when execution stops
CLIENT->idle() # while stopped (can be a client event loop)
=head1 DESCRIPTION
No user-serviceable parts inside.
-
+
=cut
#
# We go to a lot of trouble not to 'require Carp' at file scope,
=head1 SYNOPSIS
require 5.004;
-
+
# override CORE::glob in current package
use File::DosGlob 'glob';
-
+
# override CORE::glob in ALL packages (use with extreme caution!)
use File::DosGlob 'GLOBAL_glob';
@perlfiles = glob "..\\pe?l/*.p?";
print <..\\pe?l/*.p?>;
-
+
# from the command line (overrides only in main::)
> perl -MFile::DosGlob=glob -e "print <../pe*/*p?>"
use File::Find;
finddepth(\&wanted, '/foo', '/bar');
sub wanted { ... }
-
+
use File::Find;
find({ wanted => \&process, follow => 1 }, '.');
The command line options are taken from array @ARGV. Upon completion
of GetOptions, @ARGV will contain the rest (i.e. the non-options) of
the command line.
-
+
Each option specifier designates the name of the option, optionally
followed by an argument specifier.
=head1 SYNOPSIS
use Math::Trig;
-
+
$x = tan(0.9);
$y = acos(3.7);
$z = asin(2.4);
-
+
$halfpi = pi/2;
$rad = deg2rad(120);
details like for example how to display complex numbers. For example:
print asin(2), "\n";
-
+
should produce something like this (take or leave few last decimals):
1.5707963267949-1.31695789692482i
$radians = deg2rad($degrees);
$radians = grad2rad($gradians);
-
+
$degrees = rad2deg($radians);
$degrees = grad2deg($gradians);
-
+
$gradians = deg2grad($degrees);
$gradians = rad2grad($radians);
sleep(1);
}
$p->close();
-
+
$p = Net::Ping->new("tcp", 2);
while ($stop_time > time())
{
sleep(300);
}
undef($p);
-
+
# For backward compatibility
print "$host is alive.\n" if pingecho($host);
use strict;
use Socket;
use Net::netent;
-
+
@ARGV = ('loopback') unless @ARGV;
-
+
my($n, $net);
-
+
for $net ( @ARGV ) {
-
+
unless ($n = getnetbyname($net)) {
warn "$0: no such net: $net\n";
next;
}
-
+
printf "\n%s is %s%s\n",
$net,
lc($n->name) eq lc($net) ? "" : "*really* ",
$n->name;
-
+
print "\taliases are ", join(", ", @{$n->aliases}), "\n"
if @{$n->aliases};
-
+
# this is stupid; first, why is this not in binary?
# second, why am i going through these convolutions
# to make it looks right
shift @a while @a && $a[0] == 0;
printf "\taddr is %s [%d.%d.%d.%d]\n", $n->net, @a;
}
-
+
if ($n = getnetbyaddr($n->net)) {
if (lc($n->name) ne lc($net)) {
printf "\tThat addr reverses to net %s!\n", $n->name;
package FOOBAR;
use SelfLoader;
-
+
... (initializing code)
-
+
__DATA__
sub {....
package NewArray;
use Tie::Array;
@ISA = ('Tie::Array');
-
+
# mandatory methods
sub TIEARRAY { ... }
sub FETCH { ... }
sub FETCHSIZE { ... }
-
+
sub STORE { ... } # mandatory if elements writeable
sub STORESIZE { ... } # mandatory if elements can be added/deleted
sub EXISTS { ... } # mandatory if exists() expected to work
sub DELETE { ... } # mandatory if delete() expected to work
-
+
# optional methods - for efficiency
sub CLEAR { ... }
sub PUSH { ... }
package NewStdArray;
use Tie::Array;
-
+
@ISA = ('Tie::StdArray');
# all methods provided by default
package NewHandle;
require Tie::Handle;
-
+
@ISA = (Tie::Handle);
-
+
sub READ { ... } # Provide a needed method
sub TIEHANDLE { ... } # Overrides inherited method
-
-
+
+
package main;
-
+
tie *FH, 'NewHandle';
=head1 DESCRIPTION
package NewScalar;
require Tie::Scalar;
-
+
@ISA = (Tie::Scalar);
-
+
sub FETCH { ... } # Provide a needed method
sub TIESCALAR { ... } # Overrides inherited method
-
-
+
+
package NewStdScalar;
require Tie::Scalar;
-
+
@ISA = (Tie::StdScalar);
-
+
# All methods provided by default, so define only what needs be overridden
sub FETCH { ... }
-
-
+
+
package main;
-
+
tie $new_scalar, 'NewScalar';
tie $new_std_scalar, 'NewStdScalar';
and timegm_nocheck() functions.
use Time::Local 'timelocal_nocheck';
-
+
{
# The 365th day of 1999
print scalar localtime timelocal_nocheck 0,0,0,365,0,99;
filetest - Perl pragma to control the filetest permission operators
=head1 SYNOPSIS
-
+
$can_perhaps_read = -r "file"; # use the mode bits
{
use filetest 'access'; # intuit harder
my $iter = 1; # 2**($iter+2) = 8
my $side = new symbolic 1;
my $cnt = $iter;
-
+
while ($cnt--) {
$side = (sqrt(1 + $side**2) - 1)/$side;
}
my $iter = new symbolic 2; # 16-gon
my $side = new symbolic 1;
my $cnt = $iter;
-
+
while ($cnt) {
$cnt = $cnt - 1; # Mutator `--' not implemented
$side = (sqrt(1 + $side**2) - 1)/$side;
=head1 DESCRIPTION
-I<S2p> takes a sed script specified on the command line (or from
+I<s2p> takes a sed script specified on the command line (or from
standard input) and produces a comparable I<perl> script on the
standard output.
=head1 ENVIRONMENT
-S2p uses no environment variables.
+s2p uses no environment variables.
=head1 AUTHOR
=head1 SEE ALSO
perl The perl compiler/interpreter
-
+
a2p awk to perl translator
=head1 DIAGNOSTICS