in reply to Re^2: How to Intercept Variable Access
in thread How to Intercept Variable Access

Your welcome, have fun experimenting with tied variables.

FWIW, your use case is not something I would solve with tie but just a function CD()

Even the CD="/tmp" syntax can be achieved with an attribute :lvalue see perlsub

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^4: How to Intercept Variable Access
by Corion (Patriarch) on Sep 16, 2024 at 12:43 UTC

    The real fun starts with local:

    sub do_stuff { local $CD = tempdir(); croak "No Makefile found in $CD" unless -f 'Makefile'; croak "No .git directory in $CD" unless -d '.git'; ... }
      Well yes if you want the full syntactic sugar of variables, including interpolation, localization and ...

      Though I'd probably prefer a module exporting both. A cd function and a magic $CD

      I haven't checked, but I seem to remember that shell languages like bash provide both too°.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery

      Edit

      °) well almost

      > PWD A pathname of the current working directory echo "$PWD"