Perl for Newbies - Part 3 - Modules and ObjectsObjects in PerlObject Use

4.2. Object Use

Let's demonstrate the object use cycle on a very useful Perl class called Data::Dumper. This class accepts a set of perl data structures, and renders them into a string which is an easy-to-read Perl representation of them.

Here's a program that uses it to display a perl data structure on the screen:


use strict;
use warnings;

# Import the Data::Dumper class
use Data::Dumper;

# Define a sample data structure
$data =

"a" => [
3 ],

"hello" =>

"yes" =>

"r" =>

# Construct a Data::Dumper instance that is associated with this data
$dumper = Data::Dumper->new([
$data], [
data" ]);

# Call its method that renders it into a string.

Written by Shlomi Fish