++ed by:
PERLANCAR
Author image Brian Szymanski

NAME

bare.pm - scalars without sigils

SYNOPSIS

  use bare qw(foo bar);

  foo=3; bar=4;
  print foo+bar; #7

  foo=bar=3;
  print foo=5,foo+bar #58

  # Note that foo and $foo are aliased, eg:
  die unless foo==$foo;
  die unless bar==$bar;
  print "foo: $foo, bar: $bar"; #foo: 3, bar: 3

DESCRIPTION

Everyone knows that Perl looks like line noise. Not anymore! bare.pm lets you access scalar variables without a leading sigil.

BUGS AND LIMITATIONS

Note carefully that these are not lexical variables. You can only have one variable foo, which is aliased to the package variable $foo. You can, however, localize such a variable like so:

  use bare 'foo';
  foo=3;
  {
    local $foo = 7;
    die unless foo==7;
  }
  die unless foo==3;

There are various other cases where you will have to use a sigil, eg:

  To interpolate a bare in a string:
    use bare 'x'; print "x=$x"

  For use on a loop variable, eg:
    use bare 'x'; for $x (0..20) { ... }

bares are implemented as subs, so sigil-less access is quite a bit slower than "native" scalars that use sigils. For code where performance is important, you'll have to use sigils.

LICENSE AND COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Brian Szymanski