Hi Fellow Monks, I was playing around with OO perl and i wanted to test if i could replicate __str__ operator method in python with Perl OO. So i created a trivial code to test it out. The code doesn't throw any error, however, i don't get any output either.
#!/usr/bin/perl use v5.22; use overload '""' => 'stringify'; use Data::Dumper; package oo_test{ sub new{ my $class = shift; my $self = {}; bless $self, $class; return $self; } sub getter{ my $self = shift; while( my $line = <DATA> ){ 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->stringify; __DATA__ Hi How Are You
I'm sure that i'm making some mistakes. I'd like to admit that my OO perl is bit shaky.
In reply to RE: Operator overloading question by lonewolf28
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |