Having a method with the same name as a builtin

This example shows how a module can have a method which has the same name as an existing builtin. In this case the module Fruit has a method called read.

package Fruit;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw//;
use warnings;
use strict;

sub new
{
    return bless {};
}


sub Fruit::read
{
    print "OK\n";
}

1;

(download)

Using the qualified name, the module now has a method read:

#!/usr/bin/perl
use warnings;
use strict;
use Fruit;
my $fruit = Fruit->new ();
$fruit->read ("boxes.txt");

(download)


Copyright © Ben Bullock 2009-2019. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer