Lexical readonly state variables with PerlX::Let

I’ve released a new module PerlX::Let that adds a new “let” keyword so that you can do the following:

let $x = 1,
     $y = "string" {

  if ( ($a->($y} - $x) > ($b->{$y} + $x) )
  {
    something( $y, $x );
  }

}

with this, you can have lexical readonly variables, and avoid bugs due to typos.

A nice feature of this is that it uses state variables if the assigned value is a constant, and the value is a scalar (for Perls older than 5.28).

Leave a comment

About Robert Rothenberg

user-pic I was born on the Moon but kidnapped by astronauts and raised in the suburbs of Grumman. Eventually, I drifted along the Gulf Stream to Northern Europe. Blogs about Perl, Puppet, Linux, programming, and whatever etc.