PerlX::Let - Syntactic sugar for lexical constants
version v0.2.1
use PerlX::Let; let $x = 1, $y = "string" { if ( ($a->($y} - $x) > ($b->{$y} + $x) ) { something( $y, $x ); } }
This module allows you to define lexical constants using a new let keyword, for example, code such as
let
if (defined $arg{username}) { $row->update( { username => $arg{username} ); }
is liable to typos. You could simplify it with
let $key = "username" { if (defined $arg{$key}) { $row->update( { $key => $arg{$key} ); } }
This is roughly equivalent to using
use Const::Fast; { const $key => "username"; if (defined $arg{$key}) { $row->update( { $key => $arg{$key} ); } }
However, if the value does not contain a sigil, and the variable is a scalar, or you are using Perl v5.28 or later, this uses state variables so that the value is only set once.
The parsing of assignments is rudimentary, and may fail when assigning to another variable or the result of a function.
Because this modifies the source code during compilation, the line numebrs may be changed.
Const::Fast
Keyword::Simple
Robert Rothenberg <rrwo@cpan.org>
This software is Copyright (c) 2019 by Robert Rothenberg.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install PerlX::Let, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PerlX::Let
CPAN shell
perl -MCPAN -e shell install PerlX::Let
For more information on module installation, please visit the detailed CPAN module installation guide.