This is largely because of the huge boost that Perl received when it was adopted as the de facto language for creating content on the world wide web. Some people even believe that Perl was designed for use CGI programming. This is clearly wrong as Perl was, in fact , written long before before the design of the CGI protocol. This book, then, is not about writing CGI scripts, but about another of the computing tasks for which Perl is particularly well suited—data munging. Data munging encompasses all of those boring , everyday tasks to which most programmers devote a good deal of their time. The task of converting data form one format into another.
|Published (Last):||7 February 2015|
|PDF File Size:||19.75 Mb|
|ePub File Size:||18.98 Mb|
|Price:||Free* [*Free Regsitration Required]|
The references can also be objects. The content of each variable is output in a single Perl statement. Handles self-referential structures correctly.
The return value can be eval ed to get back an identical copy of the original reference structure. You should set the Purity flag to 1 to get additional statements that will correctly fill in these references.
Moreover, if eval ed when strictures are in effect, you need to ensure that any variables it accesses are previously declared. In the extended usage form, the references to be dumped can be given user-specified names. Output of names will be avoided where possible if the Terse flag is set. In many cases, methods that are used to set the internal state of the object will return the object itself, so method calls can be conveniently chained together. Several styles of output are possible, all controlled by setting the Indent flag.
See Configuration Variables or Methods below for details. The first argument is an anonymous array of values to be dumped. The optional second argument is an anonymous array of names for the values. Data::Dumper will catalog all references encountered while dumping the values. Cross-references in the form of names of substructures in perl syntax will be inserted at all possible points, preserving any structural interdependencies in the original set of values. Structure traversal is depth-first, and proceeds in order from the first supplied value to the last.
In a list context, it returns a list of strings corresponding to the supplied values. The second form, for convenience, simply calls the new method on its arguments before dumping the object immediately. You must use Reset to explicitly clear the table if needed. Such references are not dumped; instead, their names are inserted wherever they are encountered subsequently. This is useful especially for properly dumping subroutine references. Same rules apply for names as in new.
Otherwise, returns the object itself. When called without arguments, returns the values as a list. When called with a reference to an array of replacement values, returns the object itself. When called with any other type of argument, dies. When called without arguments, returns the names. When called with an array of replacement names, returns the object itself.
If the number of replacement names exceeds the number of values to be named, the excess names will not be used. If the number of replacement names falls short of the number of values to be named, the list of replacement names will be exhausted and remaining values will not be renamed.
Functions Dumper LIST Returns the stringified form of the values in the list, subject to the configuration options below. Will return a list of strings in a list context. Configuration Variables or Methods Several configuration variables can be used to control the kind of output generated when using the procedural interface.
These variables are usually local ized in a block so that other parts of the code are not affected by the change. These variables determine the default state of the object created by calling the new method, but cannot be used to alter the state of the object thereafter.
The equivalent method names should be used instead to query or set the internal state of the object. The method forms return the object itself when called with arguments, so that they can be chained together nicely. Style 0 spews output without any newlines, indentation, or spaces between list items. It is the most compact format possible that can still be called valid perl. Style 1 outputs a readable form with newlines but no fancy indentation each level in the structure is simply indented by a fixed amount of whitespace.
Style 2 the default outputs a very readable form which takes into account the length of hash keys so the hash value lines up. Style 3 is like style 2, but also annotates the elements of arrays with their index but the comment is on its own line, so array output consumes twice the number of lines. Style 2 is the default. Even when true, no comma is added between the last element of an array or hash and a closing bracket when they appear on the same line.
The default is false. Setting it to 1 will output additional perl statements that will correctly recreate nested references. The default is 0. Empty string by default. The default is "VAR". Data::Dumper will invoke that method via the object before attempting to stringify it. This method can alter the contents of the object if, for instance, it contains data allocated from C , and even rebless it in a different package. The client is responsible for making sure the specified method can be called via the object, and that the object ends up containing only perl data types after the method has been called.
Defaults to an empty string. If the method dies a warning will be generated. The client is responsible for making sure the method can be called via the object, and that it returns a valid object. Cross-referencing will then only be done when absolutely essential i.
Default is 0. A defined false value will avoid quoting hash keys when it looks like a simple string. Default is 1, which will always enclose hash keys in quotes. A function with the specified name should exist, and should accept the same arguments as the builtin.
Default is Since the XS version is much faster, it will always be used if possible. This option lets you override the default behavior, usually for testing purposes only. Default is 0, which means the XS implementation will be used if possible. Can also be set to a subroutine reference which will be called for each hash that is dumped. In this case Data::Dumper will call the subroutine once for each hash, passing it the reference of the hash.
The purpose of the subroutine is to return a reference to an array of the keys that will be dumped, in the order that they should be dumped. Using this feature, you can control both the order of the keys, and which keys are actually used. In other words, this subroutine acts as a filter by which you can exclude certain keys from being dumped. Default is 0, which means that hash keys are not sorted. If set to a true value, B::Deparse will be used to get the source of the code reference.
In older versions, using this option imposed a significant performance penalty when dumping parts of a data structure other than code references, but that is no longer the case. Caution : use this option only if you know that your coderefs will be properly reconstructed by B::Deparse. This is very expensive. This seen hash is necessary to support and even just detect circular references. It is exposed to the user via the Seen call both for writing and reading.
If you, as a user, do not need explicit access to the "seen" hash, then you can set the Sparseseen option to allow Data::Dumper to eschew building the "seen" hash for scalars that are known not to possess more than one reference. This speeds up serialization considerably if you use the XS implementation. Note: If you turn on Sparseseen , then you must not rely on the content of the seen hash since its contents will be an implementation detail! When you are through with these examples, you may want to add or change the various configuration variables described above, to see their behavior.
See the testsuite in the Data::Dumper distribution for more examples.
Welcome to Manning India!
The references can also be objects. The content of each variable is output in a single Perl statement. Handles self-referential structures correctly. The return value can be eval ed to get back an identical copy of the original reference structure. You should set the Purity flag to 1 to get additional statements that will correctly fill in these references. Moreover, if eval ed when strictures are in effect, you need to ensure that any variables it accesses are previously declared.
It will teach you systematic and powerful techniques using Perl. There are no discussion topics on this book yet. You will learn how to decouple the various stages of munging programs, how to design data structures, how to emulate the Unix filter model, etc. Want to Read Currently Reading Read.