Apart from the mistake BrowserUk pointed out, there are two more:
- you use overload in package main, so oo_test doesn't have overload included - instead overload binds '""' to main::stringify, which doesn't exist
- to properly invoke the overloaded function, you should print "$test", not invoke stringify as method upon $test
#!/usr/bin/perl
use v5.22;
use Data::Dumper;
package oo_test{
use overload '""' => 'stringify';
sub new{
my $class = shift;
my $self = {};
bless $self, $class;
return $self;
}
sub getter{
my $self = shift;
while( my $line = <main::DATA> ){
print $line;
chomp $line;
$self->{$.} = $line;
}
return $self;
}
sub stringify{
my $self = shift;
return join(" ", values %$self );
}
};
package main;
my $test = oo_test->new();
$test->getter();
print "$test\n";
__DATA__
Hi
How
Are
You
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.