Global symbol "$buffer" requires explicit package name at ...
Global symbol "@output" requires explicit package name at ...
Global symbol "%states" requires explicit package name at ...
####
my ($buffer, @output, %states);
####
our ($buffer, @output, %states);
####
package DFA;
sub new {
my $dfa = {};
bless $dfa, shift; # associates $dfa with the current package
$dfa->{buffer} = '';
$dfa->{output} = []; # note: output is now an array reference
$dfa->{states} = {}; # note: states is now a hash ref
$dfa; # return the new object
}
...
####
sub argout {
my $dfa = shift; # $dfa here is equivalent to 'this' in Java
my $temp = { type => 'ARG', value => $dfa->{buffer} };
$dfa->{buffer} = '';
push(@{$dfa->{output}}, $temp);
}
# example of constructing a DFA object and calling argout:
my $dfa = DFA->new();
$dfa->argout();