Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Modules to reduce syntax?

by perlfan (Vicar)
on Dec 27, 2021 at 16:11 UTC ( #11139940=note: print w/replies, xml ) Need Help??


in reply to Modules to reduce syntax?

Util::H2O will take this,
my $ref = { foo => $bar => 'baz' }; printf "%s\n", $ref->{'foo'}{$bar};
And let you do this:
use Util::H2O qw/h2o/; my $ref = h2o -recurse, { foo => $bar => 'herp' }; printf "%s\n", $ref->foo->$bar;
If you use a lot hash references, it can remove a significant amount of typing and cruft simply by doing away with the curly braces. The reduction in typing and file size from these 2 characters quickly adds up. enjoy!

Replies are listed 'Best First'.
Re^2: Modules to reduce syntax?
by LanX (Sage) on Dec 27, 2021 at 17:49 UTC
    > it can remove a significant amount of typing

    That's a Pyrrhic victory from level two onwards.

    Curlies {} are "spared" for mandatory arrows -> for the price of init and OO overhead.

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

      >Pyrrhic victory

      perhaps a tad hyperbolic? OP asked for reduction in syntax (I read it as more readable) - not even "less typing"; but the only thing I can assuredly tell you is that I tend to use this module a lot nowadays. And it is true that eliminating a paired set of curlies in exchange for some dereference syntax is worth it to me; and "overhead" (whatever that means to the reader) is generally never something I even look at. My optimizations happen on the algorithmic or complexity level; IOW I avoid nesting loops in favor of ... hashes (and references to such) :-) In any case, I should have added a YMMV.
        > perhaps a tad hyperbolic?

        well you said

        > > > The reduction in typing and file size from these 2 characters quickly adds up.

        and that's not the case from the second level on.

        This can be easily overlooked, hence my remark.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11139940]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2022-05-28 21:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?