CINXE.COM
PerlMonks - The Monastery Gates
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- Took this out for IE6ites "http://www.w3.org/TR/REC-html40/loose.dtd" --> <html lang="en"> <head id="stdcontainer"> <title> PerlMonks - The Monastery Gates </title> <link rel="canonical" href="https://www.perlmonks.org/?node_id=131" /> <!-- Theme : Web safe blue PerlMonks Theme --> <script language="javascript" type="text/javascript" src="?node=list%20replies%20toggle%20javascript" integrity="sha384-6jdBZxT7udN82vOTryPaLwqMohSfDF3HXv3M32KAZ7dOREMdAkYh9ZhoaKCgCXcr" crossorigin="anonymous"></script> <link rel="stylesheet" href="/css/common.css" type="text/css" /> <link rel="stylesheet" href="?node_id=204962" type="text/css" /> <!-- No CSS Link in Display Settings --> <!-- No CSS Data in Display Settings --> <link rel="icon" href="/favicon.ico" /> <meta name = "description" content = "A community committed to sharing Perl knowledge and coding tips. The site contains questions and answers, useful snippets, and a library of code." /> <meta name = "keywords" content = "perl, mod_perl, regular expressions, regexp, CGI, programming, learning, tutorials, questions, answers, examples, node, experience, votes, code" /> </head> <body id="id-131"> <!-- monktainer --> <!-- monkbar2001 --> <table id="monkbar" width="100%" border="0" cellpadding="0" cellspacing="0"> <tr class="bannerrow"> <td align="left" width="100%"> <a href="http://pair.com"> <img src="//promote.pair.com/i/pair-banner-current.gif" height = "60" width = "468" alt = "Beefy Boxes and Bandwidth Generously Provided by pair Networks" /> </a> </td> <td rowspan="2" align="right" valign="bottom"> <!-- Monk Pic Turned Off In User Settings --> </td> </tr> <tr class="monkquip"> <td class="monkquip" valign="bottom" width="100%" > good chemistry is complicated,<br />and a little bit messy -LW </td> </tr> <tr class="titlebar"> <td class="titlebar"> <form method="get" action="?" enctype="application/x-www-form-urlencoded" > <input type="text" name="node" id="search_text" size="20" maxlength="300" /> <input class="titlebar" type="submit" value="Search" /> </form> </td> <td class="titlebar" id="mb2001titlebar" align="right" > <a class="titlebar" href="?">PerlMonks</a> </td> </tr> </table> <!-- /monkbar2001 --> <!-- Begin title bar --> <table width="98%" align="center" id="titlebar-top"> <tbody> <tr> <td valign="middle" class="titlechooser"> <!-- node_info_string: (h3)Title and (span)Author --> <h3 class="superdoc">The Monastery Gates</h3> <!-- /node_info_string --> </td> <td valign="top" align="right" class="monktitlebar"> <!-- monktitlebar --> <ul class="topnavmenu inline-list"> <li><a href="?node_id=109">Log in</a></li><li><a href="?node_id=101">Create a new user</a></li> <li><a href="?">The Monastery Gates</a></li> <li><a href="?node=Seekers%20of%20Perl%20Wisdom">Seekers of Perl Wisdom</a></li> <li><a href="?node=Meditations">Meditations</a></li> <li><a href="?node=Cool%20Uses%20for%20Perl">Cool Uses For Perl</a></li> <li><a href="?node=Obfuscated%20Code">Obfuscation</a></li> <li><a href="?node=Tutorials">Tutorials</a></li> <li><a href="?node=Perl%20Poetry">Poetry</a></li> <li><a href="?node=Illuminations">Illuminations</a></li> <li><a href="?node=Reviews">Reviews</a></li> <li><a href="?node=Perl%20News">Perl News</a></li> <li><a href="?node=Recently%20Active%20Threads">Recent Threads</a></li> <li><a href="?node=Newest%20Nodes">Newest Nodes</a></li> <li><a href="?node=Super%20Search">Super Search</a></li> <li><a href="?node=Perl%20Monks%20Discussion">PerlMonks Discussion</a></li> <li><a href="?node=Tidings">What's New</a></li> </ul> <!-- args=(monktitlebar sitedoclet -TOPNAV_SPECIAL <li><a href="?node_id=109">Log in</a></li><li><a href="?node_id=101">Create a new user</a></li>) NODE.title = The Monastery Gates NODE.owner = 485628 N.title = monktitlebar sitedoclet N.owner = 17342 --> <!-- /monktitlebar --> </td> </tr> </tbody> </table> <table width="98%" align="center" id="titlebar-bottom"> <tbody> <tr> <td valign="middle" class="titlechooser"> <!-- node_info_string: (span)Date and (span)Links --> <span class="addlinks">( <a href="?node_id=131">[id://131]</a>=<a href="?node_id=14">superdoc</a>: <a rel="nofollow" href="?node_id=131;displaytype=print">print</a> <a rel="nofollow" href="?replies=1;displaytype=print;node_id=131">w/replies</a>, <a href="?displaytype=xml;node_id=131">xml</a> )</span> <!-- /node_info_string --> </td> <td valign="middle" align="right" class="monktitlebar"> <a href="?node=PerlMonks%20FAQ">Need Help??</a> </td> </tr> </tbody> </table> <!-- End title bar --> <!-- Begin main (monktainer) --> <center> <table width="98%"> <tr> <td width="80%" valign="top" class="main_content"> <!--contained stuff--> <!-- BEGIN general container --> <p align='center'><i>New here?</i> ⇒ <a href="?node_id=17974">I want to ask a question of the Perl Monks. Where do I start?</a></p> <div class="link-back"><b><a href="?node=Offering%20Plate">Donations gladly accepted</a></b></div> <!-- <a href="https://plus.google.com/110429821816504715800" rel="publisher">Google+</a> --> <!-- args=() NODE.title = The Monastery Gates NODE.owner = 485628 N.title = The Monastery Gates sitedoclet N.owner = 17342 --> <blockquote> </blockquote> <p style="text-align:center">If you're new here, please read <a href="?node=PerlMonks%20FAQ">PerlMonks FAQ</a><br /> and <a href="?node=Create%20a%20new%20user">Create a new user</a>!</p><table width="100%" cellpadding="0" cellspacing="0"> <tr class="section_title" width="100%" border="1"> <td class="section_title" width="100%"> Quests </td> </tr> <tr> <td> <table width="100%" border="0" cellpadding="2" cellspacing="0"> <tr width="100%" class="highlight"><td> <a href="?node_id=11163477">poll ideas quest 2025</a><br /> Starts at: Jan 01, 2025 at 00:00<br /> Ends at: Dec 31, 2025 at 23:59<br /> Current Status: Active </td> <td valign="top"> <a href="?node_id=11163477">1 reply</a> </td> <td valign="top"> by <a href="?node_id=275323">pollsters</a> </td> </tr> <tr><td> <ul>First, read <a href="?node=How%20do%20I%20create%20a%20Poll%3F">How do I create a Poll?</a>. Then suggest your poll here. Complete ideas are more likely to be used. <p> Note that links may be used in choices but not in the title.</ul> </td></tr> </table> </td> </tr> </table> <!-- BEGIN listapproved default outer container --> <table width="100%" cellpadding="0" cellspacing="0"> <tr class="section_title" width="100%" border="1"> <td class="section_title" width="100%"> Perl News </td> </tr> <tr> <td> <table width="100%" border="0" cellpadding="2" cellspacing="0"> <!-- BEGIN embed node container --> <TR class="highlight"><TD><a href="?node_id=11164086">CPANSec is now CNA!</a> <BR> on Feb 26, 2025 at 04:05 </TD> <TD valign=top> <a href="?node_id=11164086">0 replies</a> </TD> <TD valign=top> by <a href="?node_id=200365">Tux</a> </TD> </TR> <TR><TD> <ul><p>Years ago, a few people decided during the Perl Toolchain Summit (PTS) that it would be a good idea to join forces, ideas and knowledge and start a group to monitor vulnerabilities in the complete perl ecosystem form core to the smallest CPAN release. The goal was to follow legislation and CVE reports, and help authors in taking actions on not being vulnerable anymore.</p> <p>That group has grown stable over the past years and is now known as <a href="https://security.metacpan.org">CPANSec</a></p> <p>The group has several focus areas, and one of them is channeling CVE vulnerability issues.</p> <p>In that specific goal, a milestone has been reached:</p> <p><a href="https://security.metacpan.org/2025/02/25/cpansec-is-cna-for-perl-and-cpan.html">CPANSec has just been authorized as a CVE Numbering Authority (CNA) for Perl and modules on CPAN</a> 📣🎉🥳👌</p> <hr /> <p>The CPAN Security Group was <a href="https://www.cve.org/Media/News/item/news/2025/02/25/CPAN-Security-Group-Added-as-CNA">authorized by the CVE Program</a> as a CVE Numbering Authority (CNA) on Feb 25, 2025. A CNA assigns and manages CVE identifiers for projects in their scope.</p> <p>Our scope is vulnerabilities in Perl and CPAN Modules (including End-of-Life Perl versions) found at <a href="https://perl.org/">perl.org</a>, <a href="https://cpan.org/">cpan.org</a> or <a href="https://metacpan.org/">metacpan.org</a>, excluding distributions of Perl or CPAN Modules maintained by third-party redistributors.</p> <p>CVE is an international, community-based effort to identify, define and catalog publicly disclosed software vulnerabilities. To learn more about the CVE program, visit <a href="https://www.cve.org">www.cve.org</a>.</p> <h2>Report Vulnerability</h2> <p>Vulnerabilities should be reported according to the security policy of the affected project.</p> <p>For more details, see our guide on how to <a href="https://security.metacpan.org/docs/report.html">Report a Security Issue</a> in Perl and the CPAN ecosystem.</p> <h2>Contact Us</h2> <p>To request a CVE identifier, or to update a CVE we have issued, please send an email to <a href="mailto:cve-request@security.metacpan.org">cve-request@security.metacpan.org</a>.</p> <p>Subscribe to the <a href="https://lists.security.metacpan.org/cve-announce/">cve-announce mailing list</a> to be notified of new CVEs published by us.</p> <p>For questions, disputes or other CNA related queries please use <a href="mailto:cna@security.metacpan.org">cna@security.metacpan.org</a>. Disputes are handled according to the <a href="https://www.cve.org/ResourcesSupport/AllResources/CNARules">CNA rules</a>.</p> <h2>Links</h2> <ul> <li><a href="https://www.cve.org/Media/News/item/news/2025/02/25/CPAN-Security-Group-Added-as-CNA">CVE.org: CPAN Security Group added as CVE Numbering Authority (CNA)</a></li> <li><a href="https://www.cve.org/PartnerInformation/ListofPartners/partner/CPANSec">CVE.org: Partner Information - CPAN Security Group</a></li> <li><a href="https://www.cve.org/ResourcesSupport/AllResources/CNARules">CVE.org: CVE Numbering Authority (CNA) Operational Rules</a></li> <li><a href="https://security.metacpan.org/docs/report.html">Report Security Issue</a></li> <li><a href="https://lists.security.metacpan.org/cve-announce/">cve-announce mailing list</a></li> <li><a href="https://security.metacpan.org/docs/cna-disclosure-policy.html">CNA Disclosure Policy</a></li> </ul> <!-- Node text goes above. Div tags should contain sig only --> <div class="pmsig"><div class="pmsig-200365"> <br /> Enjoy, Have FUN! H.Merijn </div></div></ul> </TD></TR> <!-- END embed node container --> <!-- BEGIN embed node container --> <TR class="highlight"><TD><a href="?node_id=11164084">PDL::Stats 0.854 released</a> <BR> on Feb 25, 2025 at 14:11 </TD> <TD valign=top> <a href="?node_id=11164084">0 replies</a> </TD> <TD valign=top> by <a href="?node_id=1068773">etj</a> </TD> </TR> <TR><TD> <ul>Significant changes in recent times: <ul> <li><a href="https://rt.cpan.org/Ticket/Display.html?id=97925">https://rt.cpan.org/Ticket/Display.html?id=97925</a> has been fixed: now anova_rptd works with mixed-model designs <li>There's now a demo at <a href="https://pdl.perl.org/?page=demos/stats">https://pdl.perl.org/?page=demos/stats</a> <li>The plotting functions now use <a href="https://metacpan.org/pod/PDL%3A%3AGraphics%3A%3ASimple">PDL::Graphics::Simple</a> (which facilitates generating the above) <li>The plotting functions have also had a tidy-up, and now include plotting categorical anova data with stripcharts <li>It uses the new PDL 2.096+ "lib/*.pd" format so it builds quicker </ul> Any problems, please let us know by opening a GitHub issue, joining the IRC channel (both linked on the <a href="https://metacpan.org/pod/PDL%3A%3AStats">PDL::Stats</a> page) or emailing the pdl-general list.</ul> </TD></TR> <!-- END embed node container --> </table> </td> </tr> </table> <!-- END listapproved default outer container --> <table width="100%" cellpadding="0" cellspacing="0"> <tr class="section_title" width="100%" border="1"> <td class="section_title" width="100%"> Supplications </td> </tr> <tr> <td> <table width="100%" border="0" cellpadding="2" cellspacing="0"> <!-- 1 reply --> <!-- Begin Post --> <!-- embed node with vote container --> <tr class="post-head post_head"> <td valign="top" style="padding-left:.2em"> <!-- TITLE --> <a id ="post-head-id11164097" name="post-head-id11164097" href="?node_id=11164097" >schwartzian transform problem - Solved</a> <br/> <!-- REPLIES --> 1 direct reply — <a href="?node_id=11164097">Read more / Contribute</a> </td> <td valign="top" align="right" style="padding-right:.2em"> <!-- AUTHOR --> by <a href="?node_id=421781">Cristoforo</a> <br/> <!-- DATE --> on Feb 27, 2025 at 14:37 </td> </tr> <tr class="post-voterep"> <td colspan="2" class="voterep"> </td> </tr> <tr class="post-body post_body"> <td colspan="2"> <ul>I wonder if someone could tell me why this code is not working. It is to sort the records from highest percent to lowest. (I edited the regexp in split) Found one error. the <tt class='inlinecode'>mao{$_[0]}</tt> should be <tt class='inlinecode'>map {$_->[0]}</tt> and the split needed a newline (\n) at the end of the pattern <tt class='inlinecode'>split(/(?<=workspace\/data)\n/, $s)</tt> Now, I'm getting the correct sorted output. <pre class="code"><div class='codeblock'><tt class='codetext'>C:\Old_Data\perlp>perl try3.pl >>> prd1702 Filesystem Size Used Avail Use% Moun<span class="line-breaker"> <font color="red">+</font></span>ted on /workspace 3.9T 746G 3.1T 23% /wor<span class="line-breaker"> <font color="red">+</font></span>kspace/data >>> prd1703 Filesystem Size Used Avail Use% Moun<span class="line-breaker"> <font color="red">+</font></span>ted on /workspace 3.9T 687G 3.2T 18% /wor<span class="line-breaker"> <font color="red">+</font></span>kspace/data >>> prd1701 Filesystem Size Used Avail Use% Moun<span class="line-breaker"> <font color="red">+</font></span>ted on /workspace 3.9T 887G 3.0T 13% /wor<span class="line-breaker"> <font color="red">+</font></span>kspace/data </tt></div><div class='embed-code-dl'><a href="?abspart=1;displaytype=displaycode;node_id=11164097;part=4">[download]</a></div></pre> (Below, the code before fixes noted above) <pre class="code"><div class='codeblock'><tt class='codetext'>#!/usr/bin/perl use strict; use warnings; use feature 'say'; #https://stackoverflow.com/questions/79472778/sorting-the-content-of-a<span class="line-breaker"> <font color="red">+</font></span>-file my $s = <<EOF; >>> prd1701 Filesystem Size Used Avail Use% Moun<span class="line-breaker"> <font color="red">+</font></span>ted on /workspace 3.9T 887G 3.0T 13% /wor<span class="line-breaker"> <font color="red">+</font></span>kspace/data >>> prd1702 Filesystem Size Used Avail Use% Moun<span class="line-breaker"> <font color="red">+</font></span>ted on /workspace 3.9T 746G 3.1T 23% /wor<span class="line-breaker"> <font color="red">+</font></span>kspace/data >>> prd1703 Filesystem Size Used Avail Use% Moun<span class="line-breaker"> <font color="red">+</font></span>ted on /workspace 3.9T 687G 3.2T 18% /wor<span class="line-breaker"> <font color="red">+</font></span>kspace/data EOF my @data = map {$_[0]} sort {$b->[1] <=> $a->[1]} map {[$_, /\s(\d+)%/]} split(/(?<=workspace\/data)/, $s); </tt></div><div class='embed-code-dl'><a href="?part=5;abspart=1;displaytype=displaycode;node_id=11164097">[download]</a></div></pre> It is printing error as: <pre class="code"><div class='codeblock'><tt class='codetext'>C:\Old_Data\perlp>perl try3.pl Use of uninitialized value in numeric comparison (<=>) at try3.pl line<span class="line-breaker"> <font color="red">+</font></span> 23. Use of uninitialized value in numeric comparison (<=>) at try3.pl line<span class="line-breaker"> <font color="red">+</font></span> 23. </tt></div><div class='embed-code-dl'><a href="?part=6;displaytype=displaycode;node_id=11164097;abspart=1">[download]</a></div></pre> </ul> </td> </tr> <!-- End Post --> <!-- 1 reply --> <!-- Begin Post --> <!-- embed node with vote container --> <tr class="post-head post_head"> <td valign="top" style="padding-left:.2em"> <!-- TITLE --> <a id ="post-head-id11164056" name="post-head-id11164056" href="?node_id=11164056" >what should be in PERL5LIB after installing from source the 5.40.1 version on MacOS (am64)</a> <br/> <!-- REPLIES --> 1 direct reply — <a href="?node_id=11164056">Read more / Contribute</a> </td> <td valign="top" align="right" style="padding-right:.2em"> <!-- AUTHOR --> by <a href="?node_id=486996">kwolcott</a> <br/> <!-- DATE --> on Feb 21, 2025 at 23:28 </td> </tr> <tr class="post-voterep"> <td colspan="2" class="voterep"> </td> </tr> <tr class="post-body post_body"> <td colspan="2"> <ul><p> I'm really confused and frustrated about how to get my PERL5LIB environment variable set correctly. </p> <p> I'm on MacOS Sequoia, aarch64, running zsh, installed Perl 5.40.1 from source, into the /opt/perl_5.40.1 directory. </p> <p> I already have a Perl 5.38.2, also built from source, located in the /opt/perl directory. </p> <p> I have a MacPorts version of Perl installed (5.34.3). I removed an additional MacPorts Perl version 5.38.3 that I had installed recently. </p> <p> I was reading in the Programming Perl book about PERL5LIB...I don't understand the order of the paths that should be in the PERL5LIB. </p> <p> I've installed MANY Perl modules from CPAN using cpanm, specifying -L path respective to each version of Perl. </p> <p> I have a section in my ~/.zshrc for Perl that looks like this: <p> <div class='readmore-link'><a href="?node_id=11164056">Read more...</a><span class='readmore-size'> (3 kB)</span></div> </p> <p> I'm not using homebrew and I'm not using perlbrew. </p> <p> I was using Sidef (installing manually as a standalone executable, not as a Perl Module) for some while, then things went bonkers when I installed Perl 5.38.3 from MacPorts (I think). Now Sidef fails, and many Perl programs fail that require modules (some work, some fail). </p> <pre class="code"><div class='codeblock'><tt class='codetext'>./wagstaff_primes.pl Can't locate local/lib.pm in @INC (you may need to install the local::<span class="line-breaker"> <font color="red">+</font></span>lib module) (@INC entries checked: /opt/perl_5.40.1/lib/site_perl/5.4<span class="line-breaker"> <font color="red">+</font></span>0.1/darwin-2level /opt/perl_5.40.1/lib/site_perl/5.40.1 /opt/perl_5.4<span class="line-breaker"> <font color="red">+</font></span>0.1/lib/5.40.1/darwin-2level /opt/perl_5.40.1/lib/5.40.1) at ./wagsta<span class="line-breaker"> <font color="red">+</font></span>ff_primes.pl line 4. BEGIN failed--compilation aborted at ./wagstaff_primes.pl line 4. </tt></div><div class='embed-code-dl'><a href="?node_id=11164056;displaytype=displaycode;abspart=1;part=2">[download]</a></div></pre> <p> The aforementioned is a script from Rosetta Code. </p> <pre class="code"><div class='codeblock'><tt class='codetext'>find /opt/perl_5.40.1/lib -type f -name lib.pm /opt/perl_5.40.1/lib/5.40.1/darwin-2level/lib.pm /opt/perl_5.40.1/lib/lib/perl5/local/lib.pm </tt></div><div class='embed-code-dl'><a href="?part=3;node_id=11164056;displaytype=displaycode;abspart=1">[download]</a></div></pre> </ul> </td> </tr> <!-- End Post --> <!-- 1 reply --> <!-- Begin Post --> <!-- embed node with vote container --> <tr class="post-head post_head"> <td valign="top" style="padding-left:.2em"> <!-- TITLE --> <a id ="post-head-id11164052" name="post-head-id11164052" href="?node_id=11164052" >Existing module for PerlX::Maybe except for hash existence?</a> <br/> <!-- REPLIES --> 1 direct reply — <a href="?node_id=11164052">Read more / Contribute</a> </td> <td valign="top" align="right" style="padding-right:.2em"> <!-- AUTHOR --> by <a href="?node_id=5348">Corion</a> <br/> <!-- DATE --> on Feb 21, 2025 at 11:51 </td> </tr> <tr class="post-voterep"> <td colspan="2" class="voterep"> </td> </tr> <tr class="post-body post_body"> <td colspan="2"> <ul><p>I'm quite fond of using <a href="https://metacpan.org/pod/PerlX%3A%3AMaybe">PerlX::Maybe</a> to pass parameters to subroutines if they are there:</p> <pre class="code"><div class='codeblock'><tt class='codetext'> GetOptions( 'f' => \my $filename, 'bar' => \my $bar, 'bruce' => \my $batman, 'u' => \my $universe, ); foo( file => $filename, maybe bar => $bar, maybe baz => $batman, maybe universe => $universe, ) </tt></div><div class='embed-code-dl'><a href="?part=1;abspart=1;node_id=11164052;displaytype=displaycode">[download]</a></div></pre> <p>The above will invoke <tt class='inlinecode'>foo()</tt> with only the hash keys that have a defined value. This is better in the sense that this allows <tt class='inlinecode'>foo()</tt> to make a difference between <i>parameter was not passed at all</i> and <i>parameter was passed, but was <tt class='inlinecode'>undef</tt></i>:</p> <pre class="code"><div class='codeblock'><tt class='codetext'>sub foo( %options ) { if( ! exists $options{ baz } ) { $options{ baz } = 'Superman'; }; ... } </tt></div><div class='embed-code-dl'><a href="?part=5;abspart=1;node_id=11164052;displaytype=displaycode">[download]</a></div></pre> <p>Now, I'd like to have something similar(ish) to <tt class='inlinecode'>maybe</tt> on the receiving side for subroutines and objects, but I'm lacking a good name and a good syntax for it. The idea is to only set a value in a hash if the key does not exist yet. This is different from the <tt class='inlinecode'>//</tt> operator, because that one only checks for defined-ness, not for existence.</p> <p>If we already had <a href="https://www.nntp.perl.org/group/perl.perl5.porters/2019/11/msg256680.html">full-grown subroutine keyword parameters</a>, this could be written in a declarative way as:</p> <pre class="code"><div class='codeblock'><tt class='codetext'>sub foo( :$baz = 'Superman', :$bar, :$file, :$universe='DC' ) { } </tt></div><div class='embed-code-dl'><a href="?abspart=1;node_id=11164052;displaytype=displaycode;part=8">[download]</a></div></pre> <p>(actually, I'm not sure if the above is correct for an invocation <tt class='inlinecode'>foo( baz => undef )</tt>).</p> <p>But we don't have named parameters in the syntax yet, so we have to deparse the parameters ourselves:</p> <pre class="code"><div class='codeblock'><tt class='codetext'>sub foo( %options ) { ... } </tt></div><div class='embed-code-dl'><a href="?part=10;node_id=11164052;displaytype=displaycode;abspart=1">[download]</a></div></pre> <p>Let's assume that <tt class='inlinecode'>option</tt> is a good name for this (I'm not convinced):</p> <pre class="code"><div class='codeblock'><tt class='codetext'>sub option ( $key, $def, $options ) { if( !exists $options->{ $key } ) { $options->{ $key } = $def; } return $options } </tt></div><div class='embed-code-dl'><a href="?part=12;abspart=1;node_id=11164052;displaytype=displaycode">[download]</a></div></pre> <p>Then we could have a syntax like this:</p> <pre class="code"><div class='codeblock'><tt class='codetext'>sub foo( %options ) { option baz => 'Superman', option universe => 'DC', \%options; return \%options } </tt></div><div class='embed-code-dl'><a href="?node_id=11164052;displaytype=displaycode;abspart=1;part=13">[download]</a></div></pre> <p>But I'm not entirely happy with this approach for two reasons:</p> <ol> <li>It doesn't strike me as overly elegant. I'm happy with it being not overly elegant, but there are some warts: <ul> <li>We pass in and modify the <tt class='inlinecode'>%options</tt> hash by reference. Alternatively we could do <tt class='inlinecode'>%options = option foo => 'bar', %options;</tt>, but that copies the whole hash a lot of times</li> <li>We eagerly evaluate the default values, which might be costly in the case of function calls: <pre class="code"><div class='codeblock'><tt class='codetext'> option files => [glob('~/*')], option html => $user_agent->get('https://example.com'), </tt></div><div class='embed-code-dl'><a href="?part=16;abspart=1;node_id=11164052;displaytype=displaycode">[download]</a></div></pre> </li> </ul> </li> <li>There must be something like this on CPAN already</li> </ol> <p>Test file:</p> <p> <div class='readmore-link'><a href="?node_id=11164052">Read more...</a><span class='readmore-size'> (3 kB)</span></div> </p></ul> </td> </tr> <!-- End Post --> </table> </td> </tr> </table> <!-- END general container --> <!--/contained stuff--> </td> <!--nodelet handling code (monktainer)--> <td width="20%" valign="top" align="right" class="nodelets"> <!-- Begin nodelets --> <table class='nodelet_container' id='nodelet_container'> <!-- Nodelet Break --> <tbody class="nodelet" id="Log_In"> <tr><th class="nodelet_head"> <span class="title">Log In</span><a href="?node=About The Log In Nodelet" class="nodelethead-annot"><sup>?</sup></a> </th></tr> <tr><td class="nodelet_body"> <form method="post" action="?" enctype="multipart/form-data" name="login"> <span><input type="hidden" name="node_id" value="109" ></input></span> <input type="hidden" name="op" value="login" /> <input type="hidden" name="lastnode_id" value="131" /> <table border="0"><tr><td> Username:</td><td> <input type="text" name="user" size="10" maxlength="34" /> </td></tr><tr><td> Password:</td><td> <input type="password" name="passwd" size="10" maxlength="10" /> </td></tr></table> <label><input type="checkbox" name="expires" value="+10y" />remember me</label> <input type="submit" name="login" value="Login" /> <br /> <a href="?node_id=2513">What's my password?</a> <br /> <a href="?node_id=101">Create A New User</a> </form> </td></tr> </tbody> <!-- Nodelet Break --> <tbody class="nodelet" id="Domain_Nodelet"> <tr><th class="nodelet_head"> <span class="title">Domain Nodelet</span><a href="?node=About The Domain Nodelet" class="nodelethead-annot"><sup>?</sup></a> </th></tr> <tr><td class="nodelet_body"> <p class='domain_link' align='center'><a class='wwwdomainlink' href="http://www.perlmonks.com/index.pl?node_id=131">www</a>.<a class='domainlink' href="http://perlmonks.com/index.pl?node_id=131">com</a> | <a class='wwwdomainlink' href="http://www.perlmonks.net/index.pl?node_id=131">www</a>.<a class='domainlink' href="http://perlmonks.net/index.pl?node_id=131">net</a> | <a class='wwwdomainlink' href="http://www.perlmonks.org/index.pl?node_id=131">www</a>.<span class='currentdomain'>org</span></p> </td></tr> </tbody> <!-- Nodelet Break --> <tbody class="nodelet" id="Chatterbox"> <tr><th class="nodelet_head"> <span class="title">Chatterbox</span><a href="?node=About The Chatterbox Nodelet" class="nodelethead-annot"><sup>?</sup></a> </th></tr> <tr><td class="nodelet_body"> <form method="get" action="?" enctype="multipart/form-data"> <span><input type="hidden" name="node_id" value="131" ></input></span><i>and the web crawler heard nothing...</i> <input type="submit" name="foo" value="Refresh" /> </form> <i><br /> <a href="?node=ChatterBox%20FAQ">How do I use this?</a> • <a href="?node=last%20hour%20of%20cb">Last hour</a> • <a href="?node_id=20842">Other CB clients</a></i> </td></tr> </tbody> <!-- Nodelet Break --> <tbody class="nodelet" id="Other_Users"> <tr><th class="nodelet_head"> <span class="title">Other Users</span><a href="?node=About The Other Users Nodelet" class="nodelethead-annot"><sup>?</sup></a> </th></tr> <tr><td class="nodelet_body"> <span class="other-users-text">Others <span class="other-users-blurb">avoiding work at</span> the Monastery:</span> (5)<br /><ul class="spacey-list"><li><span class='even-row'><span class='item-000'><span class='user-level-24'><span class='user-832495'><a title="choroba's home node. Level 24. Member of: pmdev" href="?node_id=832495">choroba</a></span></span></span></span></li> <li><span class='odd-row'><span class='item-001'><span class='user-level-20'><span class='user-200365'><a href="?node_id=200365" title="Tux's home node. Level 20">Tux</a></span></span></span></span></li> <li><span class='even-row'><span class='item-002'><span class='user-level-20'><span class='user-174111'><a href="?node_id=174111" title="Discipulus's home node. Level 20. Member of: janitors">Discipulus</a></span></span></span></span></li> <li><span class='odd-row'><span class='item-003'><span class='user-level-17'><span class='user-399498'><a title="erix's home node. Level 17" href="?node_id=399498">erix</a></span></span></span></span></li> <li><span class='even-row'><span class='item-004'><span class='user-level-1'><span class='user-11155664'><a title="chatterbot's home node. Level 1" href="?node_id=11155664">chatterbot</a></span></span></span></span></li> </ul><span class='update-time'><small>As of 2025-02-28 08:07 GMT</small></span> </td></tr> </tbody> <!-- Nodelet Break --> <tbody class="nodelet" id="Sections"> <tr><th class="nodelet_head"> <span class="title">Sections</span><a href="?node=About The Sections Nodelet" class="nodelethead-annot"><sup>?</sup></a> </th></tr> <tr><td class="nodelet_body"> <ul class="spacey-list"> <li><a href="?node=Seekers%20of%20Perl%20Wisdom">Seekers of Perl Wisdom</a></li> <li><a href="?node=Cool%20Uses%20for%20Perl">Cool Uses for Perl</a></li> <li><a href="?node=Meditations">Meditations</a></li> <li><a href="?node=Perl%20Monks%20Discussion">PerlMonks Discussion</a></li> <li><a href="?node=Categorized%20Questions%20and%20Answers">Categorized Q&A</a></li> <li><a href="?node=Tutorials">Tutorials</a></li> <li><a href="?node=Obfuscated%20Code">Obfuscated Code</a></li> <li><a href="?node=Perl%20Poetry">Perl Poetry</a></li> <li><a href="?node=Perl%20News">Perl News</a></li> <li><a href="?node_id=483086">about</a></li> </ul> <!-- args=(Sections) NODE.title = The Monastery Gates NODE.owner = 485628 N.title = Sections sitedoclet N.owner = 17342 --> </td></tr> </tbody> <!-- Nodelet Break --> <tbody class="nodelet" id="Information"> <tr><th class="nodelet_head"> <span class="title">Information</span><a href="?node=About The Information Nodelet" class="nodelethead-annot"><sup>?</sup></a> </th></tr> <tr><td class="nodelet_body"> <ul class="spacey-list"> <li><a href="?node=PerlMonks%20FAQ">PerlMonks FAQ</a></li> <li><a href="?node=the%20Perl%20Monks%20guide%20to%20the%20Monastery">Guide to the Monastery</a></li> <li><a href="?node=Tidings">What's New at PerlMonks</a></li> <li><a href="?node=Voting%2FExperience%20System">Voting/Experience System</a></li> <li><a href="?node=Tutorials">Tutorials</a></li> <li><a href="?node=Reviews">Reviews</a></li> <li><a href="?node=Library">Library</a></li> <li><a href="?node=perlman%3Aperlfaq">Perl FAQs</a></li> <li><a href="?node=Where%20can%20I%20find%20more%20information%20on...">Other Info Sources</a></li> </ul> <!-- args=(Information sitedoclet -TIDINGS_NEW ) NODE.title = The Monastery Gates NODE.owner = 485628 N.title = Information sitedoclet N.owner = 17342 --> </td></tr> </tbody> <!-- Nodelet Break --> <tbody class="nodelet" id="Find_Nodes"> <tr><th class="nodelet_head"> <span class="title">Find Nodes</span><a href="?node=About The Find Nodes Nodelet" class="nodelethead-annot"><sup>?</sup></a> </th></tr> <tr><td class="nodelet_body"> <ul class="spacey-list"> <li><a href="?node_id=6364;user=961">Nodes You Wrote</a></li> <li><a href="?node=My%20Watched%20Nodes">My Watched Nodes</a></li> <li><a href="?node=Super%20Search">Super Search</a></li> <li><a href="?node=Perl%20Monks%20User%20Search">List Nodes By Users</a></li> <li><a href="?node=Newest%20Nodes">Newest Nodes</a></li> <li><a href="?node=Recently%20Active%20Threads">Recently Active Threads</a></li> <li><a href="?node=Selected%20Best%20Nodes">Selected Best Nodes</a></li> <li><a href="?node=Best%20Nodes">Best Nodes</a></li> <li><a href="?node=Worst%20Nodes">Worst Nodes</a></li> <li><a href="?node=Saints%20in%20our%20Book">Saints in our Book</a></li> <li><a href="?op=randomnode">Random Node</a></li> </ul> <!-- args=(Find Nodes sitedoclet -USER 961) NODE.title = The Monastery Gates NODE.owner = 485628 N.title = Find Nodes sitedoclet N.owner = 17342 --> </td></tr> </tbody> <!-- Nodelet Break --> <tbody class="nodelet" id="Leftovers"> <tr><th class="nodelet_head"> <span class="title">Leftovers</span><a href="?node=About The Leftovers Nodelet" class="nodelethead-annot"><sup>?</sup></a> </th></tr> <tr><td class="nodelet_body"> <ul class="spacey-list" id="user"></ul> <ul class="spacey-list" id="internal"> <li><a href="?node=The%20St.%20Larry%20Wall%20Shrine">The St. Larry Wall Shrine</a></li> <li><a href="?node=Offering%20Plate">Offering Plate</a></li> <li><a href="?node=Awards">Awards</a></li> <li><a href="?node=Quests">Quests</a></li> </ul> <ul class="spacey-list" id="external"> <li><a href="http://www.perl.org/">Perl</a></li> <li><a href="http://blogs.perl.org/">Perl Blogs</a></li> <li><a href="http://perl.com/">Perl.com</a></li> <li><a href="https://perl.theplanetarium.org/">Planet Perl</a></li> <li><a href="http://perlweekly.com/">Perl Weekly</a></li> <li><a href="http://jobs.perl.org/">Perl Jobs</a></li> <li><a href="http://www.pm.org/">Perl Mongers</a></li> <li><a href="http://perldoc.perl.org/">Perl documentation</a></li> <li><a href="https://metacpan.org/">MetaCPAN</a></li> <li><a href="http://cpan.perl.org/">CPAN</a></li> <li><a href="https://raku.org/">Raku</a></li> </ul> <!-- args=(Leftovers sitedoclet -USER_LINKS -TIL <span class="wikilink"><a href="?node_id=11156813">Today I Learned</a></span>) NODE.title = The Monastery Gates NODE.owner = 485628 N.title = Leftovers sitedoclet N.owner = 17342 --> </td></tr> </tbody> <!-- Nodelet Break --> <tbody class="nodelet" id="Voting_Booth"> <tr><th class="nodelet_head"> <span class="title">Voting Booth</span><a href="?node=About The Voting Booth Nodelet" class="nodelethead-annot"><sup>?</sup></a> </th></tr> <tr><td class="nodelet_body"> <p>No recent polls found<br /> </td></tr> </tbody> </table> <!-- End nodelets --> </td> <!--/nodelet handling code (monktainer)--> </tr> </table> </center> <!-- End main (monktainer)--> <br /> <br /> <div id="footer"> PerlMonks lovingly hand-crafted by <a href="?node=vroom">Tim Vroom</a>.<br/> PerlMonks was recently assimilated by <a href="http://www.perlfoundation.org">The Perl Foundation</a>. <a href="?node=Offering%20Plate">Donate</a> to TPF!<br /> Wonderful Web Servers and Bandwidth Generously Provided by <a href="http://promote.pair.com/direct.pl?perlmonks.org"> pair Networks</a> <br/>Built with the <a href="http://perl.org">Perl programming language</a>. </div> <!-- /monktainer --> </body> </html>