in reply to RE: Operator overloading question

Apart from the mistake BrowserUk pointed out, there are two more:

#!/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'

Replies are listed 'Best First'.
Re^3: Operator overloading question
by lonewolf28 (Beadle) on Oct 26, 2015 at 13:19 UTC

    Thank you shmen. You showed me a better way to do it.