joharr
joharr

Reputation: 535

conflict between use IO::Tee & an END block

This script, IOTee.pl, reports it took 0 seconds to run:

#!/usr/bin/perl

use IO::Tee

# create a time check:
END { print "This Perl program ran for ", time() - $^T, " seconds.\n"}

but it also reports:

Can't locate object method "END" via package "1" (perhaps you forgot to load "1"?) at IOTee.pl line 6.
BEGIN failed--compilation aborted at IOTee.pl line 6.

- why?

Upvotes: 0

Views: 47

Answers (1)

user3967089
user3967089

Reputation:

You forgot the semicolon after "use IO::Tee".

So the END { print ... } is being used as the import list to pass to IO::Tee::import. And that syntax is like print { expression-giving-a-filehandle } output-stuff; what's in the {} (which is 1, because that's what a successful print returns) is an object to call the END method on.

Upvotes: 2

Related Questions