Returns the current time. Example:
use Benchmark;
- $t0 = new Benchmark;
+ $t0 = Benchmark->new;
# ... your code here ...
- $t1 = new Benchmark;
+ $t1 = Benchmark->new;
$td = timediff($t1, $t0);
print "the code took:",timestr($td),"\n";
Enables or disable debugging by setting the C<$Benchmark::Debug> flag:
- debug Benchmark 1;
+ Benchmark->debug(1);
$t = timeit(10, ' 5 ** $Global ');
- debug Benchmark 0;
+ Benchmark->debug(0);
=item iters
=head1 SYNOPSIS
use DirHandle;
- $d = new DirHandle ".";
+ $d = DirHandle->new(".");
if (defined $d) {
while (defined($_ = $d->read)) { something($_); }
$d->rewind;
use Symbol;
sub new {
- @_ >= 1 && @_ <= 2 or croak 'usage: new DirHandle [DIRNAME]';
+ @_ >= 1 && @_ <= 2 or croak 'usage: DirHandle->new( [DIRNAME] )';
my $class = shift;
my $dh = gensym;
if (@_) {
=head1 SYNOPSIS
use Dumpvalue;
- my $dumper = new Dumpvalue;
+ my $dumper = Dumpvalue->new;
$dumper->set(globPrint => 1);
$dumper->dumpValue(\*::);
$dumper->dumpvars('main');
A new dumper is created by a call
- $d = new Dumpvalue(option1 => value1, option2 => value2)
+ $d = Dumpvalue->new(option1 => value1, option2 => value2)
Recognized options:
use FileHandle;
- $fh = new FileHandle;
+ $fh = FileHandle->new;
if ($fh->open("< file")) {
print <$fh>;
$fh->close;
}
- $fh = new FileHandle "> FOO";
+ $fh = FileHandle->new("> FOO");
if (defined $fh) {
print $fh "bar\n";
$fh->close;
}
- $fh = new FileHandle "file", "r";
+ $fh = FileHandle->new("file", "r");
if (defined $fh) {
print <$fh>;
undef $fh; # automatically closes the file
}
- $fh = new FileHandle "file", O_WRONLY|O_APPEND;
+ $fh = FileHandle->new("file", O_WRONLY|O_APPEND);
if (defined $fh) {
print $fh "corge\n";
undef $fh; # automatically closes the file
use I18N::Collate;
setlocale(LC_COLLATE, 'locale-of-your-choice');
- $s1 = new I18N::Collate "scalar_data_1";
- $s2 = new I18N::Collate "scalar_data_2";
+ $s1 = I18N::Collate->new("scalar_data_1");
+ $s2 = I18N::Collate->new("scalar_data_2");
=head1 DESCRIPTION
#
# Usage: use I18N::Collate;
# setlocale(LC_COLLATE, 'locale-of-your-choice'); # 4)
-# $s1 = new I18N::Collate "scalar_data_1";
-# $s2 = new I18N::Collate "scalar_data_2";
+# $s1 = I18N::Collate->("scalar_data_1");
+# $s2 = I18N::Collate->("scalar_data_2");
#
# now you can compare $s1 and $s2: $s1 le $s2
# to extract the data itself, you need to deref: $$s1
use SelectSaver;
{
- my $saver = new SelectSaver(FILEHANDLE);
+ my $saver = SelectSaver->new(FILEHANDLE);
# FILEHANDLE is selected
}
# previous handle is selected
{
- my $saver = new SelectSaver;
+ my $saver = SelectSaver->new;
# new handle may be selected, or not
}
# previous handle is selected
use Symbol;
sub new {
- @_ >= 1 && @_ <= 2 or croak 'usage: new SelectSaver [FILEHANDLE]';
+ @_ >= 1 && @_ <= 2 or croak 'usage: SelectSaver->new( [FILEHANDLE] )';
my $fh = select;
my $self = bless \$fh, $_[0];
select qualify($_[1], caller) if @_ > 1;
=head1 SYNOPSIS
use Term::ReadLine;
- my $term = new Term::ReadLine 'Simple Perl calc';
+ my $term = Term::ReadLine->new('Simple Perl calc');
my $prompt = "Enter your arithmetic expression: ";
my $OUT = $term->OUT || \*STDOUT;
while ( defined ($_ = $term->readline($prompt)) ) {
All the supported functions should be called as methods, i.e., either as
- $term = new Term::ReadLine 'name';
+ $term = Term::ReadLine->new('name');
or as
...
package main;
- $a = new SomeThing 57;
+ $a = SomeThing->new( 57 );
$b=5+$a;
...
if (overload::Overloaded $b) {...}
one may need to I<explicitly unlink> other values which references the
same value:
- $a = new Data 23;
+ $a = Data->new(23);
...
$b = $a; # $b is "linked" to $a
...
Note that overloaded access makes this transparent:
- $a = new Data 23;
+ $a = Data->new(23);
$b = $a; # $b is "linked" to $a
$a += 4; # would unlink $b automagically
However, it would not make
- $a = new Data 23;
+ $a = Data->new(23);
$a = 4; # Now $a is a plain 4, not 'Data'
preserve "objectness" of $a. But Perl I<has> a way to make assignments
Use it as follows:
require two_face;
- my $seven = new two_face ("vii", 7);
+ my $seven = two_face->new("vii", 7);
printf "seven=$seven, seven=%d, eight=%d\n", $seven, $seven+1;
print "seven contains `i'\n" if $seven =~ /i/;
Now one can access an object using both the array and hash syntax:
- my $bar = new two_refs 3,4,5,6;
+ my $bar = two_refs->new(3,4,5,6);
$bar->[2] = 11;
$bar->{two} == 11 or die 'bad hash fetch';
provide any usual overloaded operators, instead it provides the L<Last
Resort> operator C<nomethod>. In this example the corresponding
subroutine returns an object which encapsulates operations done over
-the objects: C<new symbolic 3> contains C<['n', 3]>, C<2 + new
-symbolic 3> contains C<['+', 2, ['n', 3]]>.
+the objects: C<< symbolic->new(3) >> contains C<['n', 3]>, C<< 2 +
+symbolic->new(3) >> contains C<['+', 2, ['n', 3]]>.
Here is an example of the script which "calculates" the side of
circumscribed octagon using the above package:
require symbolic;
my $iter = 1; # 2**($iter+2) = 8
- my $side = new symbolic 1;
+ my $side = symbolic->new(1);
my $cnt = $iter;
while ($cnt--) {
Use this module like this:
require symbolic;
- my $iter = new symbolic 2; # 16-gon
- my $side = new symbolic 1;
+ my $iter = symbolic->new(2); # 16-gon
+ my $side = symbolic->new(1);
my $cnt = $iter;
while ($cnt) {
to the package C<symbolic>. After this change one can do
- my $a = new symbolic 3;
- my $b = new symbolic 4;
+ my $a = symbolic->new(3);
+ my $b = symbolic->new(4);
my $c = sqrt($a**2 + $b**2);
and the numeric value of $c becomes 5. However, after calling