Skip to content

Instantly share code, notes, and snippets.

@ktnyt
Created December 15, 2014 04:01
Show Gist options
  • Save ktnyt/467bc5f2c850a8a77598 to your computer and use it in GitHub Desktop.
Save ktnyt/467bc5f2c850a8a77598 to your computer and use it in GitHub Desktop.
Polish Notation
use strict;
use warnings;
print p([@ARGV]), "\n";
sub p {
my $e = shift;
my $s = shift @{$e};
return p($e) + p($e) if $s eq "+";
return p($e) - p($e) if $s eq "-";
return p($e) * p($e) if $s eq "*";
return p($e) / p($e) if $s eq "/";
return $s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment