snipt

Ctrl+h for KB shortcuts

Perl

CPAN for proxy

1
2
3
#Configure CPAN for proxy
cpan> o conf init /proxy/
#and then follow the prompts
https://snippets.siftie.com/embed/298172733eee72bcda1acfcad146819d/
/raw/298172733eee72bcda1acfcad146819d/
298172733eee72bcda1acfcad146819d
perl
Perl
3
2019-03-17T21:04:19
True
False
False
/api/public/snipt/3812/
cpan-for-proxy
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">#Configure CPAN for proxy</span> </span><span id="L-2"><a name="L-2"></a><span class="n">cpan</span><span class="o">&gt;</span> <span class="n">o</span> <span class="n">conf</span> <span class="n">init</span> <span class="sr">/proxy/</span> </span><span id="L-3"><a name="L-3"></a><span class="c1">#and then follow the prompts</span> </span></pre></div> </td></tr></table>
cpan, perl

Perl

Log messages based on debug level in log4perl

1
2
3
4
5
6
# Cheap in non-debug mode!
if($logger->is_debug()) {
    for (@super_long_array) {
        $logger->debug("Element: $_\n");
    }
}
https://snippets.siftie.com/embed/9a99084454f780a291db54dacc334011/
/raw/9a99084454f780a291db54dacc334011/
9a99084454f780a291db54dacc334011
perl
Perl
6
2019-02-27T17:37:02
True
False
False
/api/public/snipt/3810/
log-messages-based-on-debug-level-in-log4perl
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># Cheap in non-debug mode!</span> </span><span id="L-2"><a name="L-2"></a><span class="k">if</span><span class="p">(</span><span class="nv">$logger</span><span class="o">-&gt;</span><span class="n">is_debug</span><span class="p">())</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">for</span> <span class="p">(</span><span class="nv">@super_long_array</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$logger</span><span class="o">-&gt;</span><span class="n">debug</span><span class="p">(</span><span class="s">&quot;Element: $_\n&quot;</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">}</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
perl

Perl

calculate elapsed time (in ms) in Perl code

1
2
3
4
5
use Time::HiRes;

my $t_start = [Time::HiRes::gettimeofday];
my $t_end = [Time::HiRes::gettimeofday];
print Time::HiRes::tv_interval ($t_start, $t_end) . "\n";
https://snippets.siftie.com/embed/a8fafdd82bee992cfa9efc11737e4019/
/raw/a8fafdd82bee992cfa9efc11737e4019/
a8fafdd82bee992cfa9efc11737e4019
perl
Perl
5
2019-03-16T09:51:44
True
False
False
/api/public/snipt/3772/
calculate-elapsed-time-in-ms-in-perl-code
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">use</span> <span class="nn">Time::</span><span class="n">HiRes</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">my</span> <span class="nv">$t_start</span> <span class="o">=</span> <span class="p">[</span><span class="nn">Time::HiRes::</span><span class="n">gettimeofday</span><span class="p">];</span> </span><span id="L-4"><a name="L-4"></a><span class="k">my</span> <span class="nv">$t_end</span> <span class="o">=</span> <span class="p">[</span><span class="nn">Time::HiRes::</span><span class="n">gettimeofday</span><span class="p">];</span> </span><span id="L-5"><a name="L-5"></a><span class="k">print</span> <span class="nn">Time::HiRes::</span><span class="n">tv_interval</span> <span class="p">(</span><span class="nv">$t_start</span><span class="p">,</span> <span class="nv">$t_end</span><span class="p">)</span> <span class="o">.</span> <span class="s">&quot;\n&quot;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
hires, perl, time