tag:blogger.com,1999:blog-62853693969820984422024-03-13T20:15:17.321-07:00Perl4EverythingThis blog will have articles on how to use Perl for various tasks and integrations.perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.comBlogger27125tag:blogger.com,1999:blog-6285369396982098442.post-4901331957563323192011-09-22T04:23:00.000-07:002013-09-25T23:09:16.323-07:00Net::LDAP::Security<script src="//platform.linkedin.com/in.js" type="text/javascript">
lang: en_US
</script>
<script type="IN/Share" data-url="http://perl4everything.blogspot.in/2011/09/netldapsecurity.html" data-counter="top"></script>
<br><br>
<b>Net::LDAP::Security</b>
<br><br>
LDAP servers are vulnerable to LDAP query injection and DNS hijacking may lead to your query landing on the attacker's server. Attacker can sniff your username/password through your LDAP connection. Hacker may sniff your confidential information through LDAP connection. <br><br>
So, How to prevent this? You can use Net::LDAPS and LDAP over TLS. <br><br>
To know more about various security threats on LDAP and how to overcome those, read the document at <a href= 'http://search.cpan.org/~gbarr/perl-ldap-0.43/lib/Net/LDAP/Security.pod'>Net::LDAP::Security </a>
perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com1Bengaluru, Karnataka, India12.9715987 77.594562712.724026199999999 77.2787057 13.2191712 77.910419699999991tag:blogger.com,1999:blog-6285369396982098442.post-21453447706860149502011-09-20T01:51:00.000-07:002011-09-20T01:51:38.047-07:00Security Issues in Perl Scripts<b>Security Issues in Perl Scripts</b><br />
<br />
<b>system() and exec()</b><br />
<br />
system() and exec() are potentially vulnerable to parameter tampering threat. Suppose if you have a CGI application which reads the the username parameter and displays the file he created. If you directly pass the parameter input to the system call it is a biggest security threat. <br />
<br />
$user = param("user");<br />
@out = system("cat /usr/upload/$user");<br />
<br />
Imagine if some attacker is changing the param from "foe" to "test; cat /etc/passwd", your script will output the content of the user file along with the contents of /etc/passwd<br />
<br />
As far as security is concerned, everything stated above with regard to the system() function applies to exec() too.<br />
<br />
<b>setuid scripts</b><br />
<br />
Normally a Perl program runs with the privileges of the user who executed it. By making a script setuid, its effective user ID can be set to one that has access to resources to which the actual user does not (viz., to the owner ID of the file containing the program). The passwd program for example uses setuid to acquire writing permission to the system password file, thus allowing users to change their own passwords. Since programs that are executed via a CGI interface run with the privileges of the user who runs the web server (usually this is user 'nobody', who has very limited privileges), CGI programmers are often tempted to use the setuid technique to let their scripts perform tricks that they otherwise couldn't. This can be useful, but it can also be very dangerous. For one thing, if an attacker finds a way to exploit a weakness in the script, they won't only gain access to the system, but they will also have it with the privileges of the effective UID of that script (often the 'root' UID).<br />
<br />
To avoid this, Perl programs should set the effective UID and GID to the real UID and GID of the process before any file manipulations:<br />
<br />
<br />
$> = $< # set effective user ID to real UID.<br />
$) = $( # set effective group ID to real GID.<br />
<br />
and CGI scripts should always run with the lowest possible privilege.<br />
<br />
Beware that just being careful in what you do inside your setuid script doesn't always solve the problem. Some operating systems have bugs in the kernel that make setuid scripts inherently insecure. For this, and other reasons, Perl automatically switches to a special security mode (taint mode) when it runs setuid or setgid scripts. We will discuss taint mode in our next article.<br />
<br />
<b>rand()</b><br />
Generating random numbers on deterministic machines is a nontrivial problem. In security critical applications, random numbers are used intensely for many important tasks ranging from password generation to cryptography. For such purposes, it is vital that the generated numbers are as close to truly random as possible, making it difficult (but never impossible) for an attacker to predict future numbers generated by the algorithm. The Perl rand() function simply calls the corresponding rand(3) function from the standard C library. This routine is not very secure. The C rand() function generates a sequence of pseudorandom numbers based on some initial value called the seed. Given the same seed, two different instances of a program utilizing rand() will produce the same random values. In many implementations of C, and in all version of Perl before 5.004, if a seed is not explicitly specified, it is computed from the current value of the system timer, which is anything but random. Having some information about values produced by rand() at a given point and a sufficient amount of time, any self-respecting cracker can accurately predict the sequence of numbers that rand() will generate next, thus obtaining key knowledge necessary to compromise a system.<br />
<br />
One (partial) solution to the rand() problem is to use one of the built-in random number generators on Linux systems -- /dev/random and /dev/urandom. Those are better sources of randomness then the standard library rand() function, but like anything else, they have their own imperfections. The difference between the two devices is that /dev/random stops supplying random numbers when its entropy pool runs out of randomness while /dev/urandom uses cryptography to generate new numbers when the entropy pool runs out. Another solution is to use a secure implementation of one of the more complicated cryptographic random number generators such as Yarrow.perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-15788901023229000062011-09-13T21:52:00.000-07:002011-09-13T21:52:23.291-07:00Perl 5.10 - Switch<span style="font-size: x-large;"> Perl 5.10 - Switch</span><br />
<br />
Perl 5.10 introduces a native switch statement into the language. Like
other features in Perl 5.10, we can enable it with the <code>use feature</code>
pragma.<br />
<pre> use feature qw(switch);</pre>
It's also possible to enable all Perl 5.10 features with any of
the following:<br />
<pre> use feature qw(:5.10);
use 5.10.0; # Requires perl v5.10.0 or later.
use 5.010; # Same, with nicer errors on older versions.</pre>
Perl's new <code>switch</code> feature is best demonstrated with an example.
Let's take the classic guessing game, where the computer picks a number
and our user needs to try and guess it.<br />
<pre> use strict;
use warnings;
use feature qw(switch say);</pre>
<pre> # Pick our random number between 1 and 100
my $secret = int(rand 100)+1;</pre>
<pre> # An array of numbers guessed thus far
my @guessed;</pre>
<pre> say "Guess my number between 1-100";</pre>
<pre> # Get each guess from the user
while (my $guess = <STDIN>) {
chomp $guess;</pre>
<pre> # Check their guess using given/when
given($guess) {
when (/\D/) { say "Give me an integer"; }
when (@guessed) { say "You've tried that"; }
when ($secret) { say "Just right!"; last; }
when ($_ < $secret) { say "Too low"; continue; }
when ($_ > $secret) { say "Too high"; continue; }</pre>
<pre> # record the guess they've made
push(@guessed,$_);
}
}</pre>
The heart of our program is the <code>given</code>/<code>when</code> block, which is
enabled by the use of <code>use feature qw(switch)</code> at the top of our code.
Let's look at each part in detail:<br />
<dl>
<dt><b><code>given($guess)</code></b></dt>
<dd>A <code>given</code> construct marks the start of our switch logic. It
has the effect as assigning <code>$_</code> to <code>$guess</code> for the duration
of our <code>given</code> block. The changes to <code>$_</code> are not visible outside
of the <code>given</code> block (ie, they are lexical in scope).</dd>
<dt><b><code>when (/\D/)</code></b></dt>
<dd><code>when</code> provided with a regular expression checks to see if <code>$_</code>
matches that regular expression. In our case, if our input
contains non-digit characters, then we have something that doesn't
look like an integer, and execute the associated block.</dd><dd>After a successful <code>when</code> match Perl will automatically break out of the
<code>given</code> block unless told otherwise. In our case this repeats the loop asking
the user for another guess.</dd>
<dt><b><code>when (@guessed)</code></b></dt>
<dd>In this second test we're asking whether <code>$guess</code> appears as a value in
the <code>@guessed</code>. If it does we inform the user and go onto their next
guess.</dd>
<dt><b><code>when ($secret)</code></b></dt>
<dd>This is a direct comparison. Is <code>$guess</code> the same value as <code>$secret</code>?.
If so the player has guessed correctly! Using <code>last</code> allows us to break
out of our <code>while</code> loop, ending the game.</dd>
<dt><b><code>when ($_ < $secret)</code> and <code>when ($_ >
$secret)</code></b></dt>
<dd>These final two tests are simple comparisons. Remember that <code>$_</code> contains
the item we were <code>given</code>.<br />
We've used <code>continue</code> for these statements to say that Perl should
not break out of our <code>given</code> block on a successful match. This
means that if the user guesses too low or too high, we will eventually
evaluate the line:<br />
<pre> push(@guesses,$guess);</pre>
which remembers the guess as one we've already seen.</dd></dl>
You can also use <code>when</code> with hashes (is $_ a key in the hash),
subroutines (does the subroutine return true with $_ as an argument)
and strings (tests for string equality). Furthermore, our
given expression need not be merely a number or a string, we can also
compare arrays, and hashes if we want to.<br />
Finally, we can also set a default case, for when nothing has matched,
although we have not shown it in our example.<br />
<br />
<h2>
foreach / when</h2>
If you've enabled <code>use feature qw(switch</code> then you can also use
a <code>foreach/when</code> construct. Here's an example of tallying up
the number of times we see cool things in a list:<br />
<pre> use feature qw(switch);
foreach (@cool_things) {
when (/pirate/) { $pirate++ }
when (/ninja/) { $ninja++ }
when (/robot/) { $robot++ }
say "$_ doesn't look cool...";
}</pre>
If a <code>when</code> is activated, it automatically goes onto the next
iteration of the <code>foreach</code> loop. Just like <code>given/while</code>, we can
use the <code>continue</code> keyword to continue examining later options after
a successful match.<br />
It should be noted that <code>foreach/when</code> only works when using Perl's
default <code>$_</code> variable for iteration.<br />
<br />
<h2>
Lexical $_</h2>
In Perl 5.10 we can write:<br />
<pre> my $_;</pre>
This is allows us to do anything we like with <code>$_</code>, but without the
possibility of changing <code>$_</code> for code outside our current block. It's
strongly recommended for subroutines using <code>$_</code> in Perl 5.10 to
avoid accidentally changing <code>$_</code> for your caller.perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-85015565110179578152011-08-16T22:28:00.000-07:002011-08-19T01:40:30.107-07:00Compare two ldap branches<span style="font-weight:bold;">ldapcmp</span>
<br />
<br />
<br />ldapcmp is the tool which can be used to compare directory branches from two servers. This will compare all the entries in the branch including all the attributes in the branch
<br />
<br /><span style="font-weight:bold;">usage</span>
<br />
<br />
<br />ldapcmp -h hostA -h hostB -s sub -b "branch_path"
<br />
<br />usage: ldapcmp -b basedn [options] [attributes...]
<br />where:
<br /> basedn base dn for search
<br /> (if the environment variable LDAP_BASEDN is set,
<br /> then the -b flag is not required)
<br />options:
<br /> -s scope one of base, one, or sub (default is sub)
<br /> -l timelim time limit (in seconds) for search (default is no limit)
<br /> -z sizelim size limit (in entries) for search (default is no limit)
<br /> -n show what would be done but don't actually do it
<br /> -v run in verbose mode (diagnostics to standard output)
<br /> -h host LDAP server1 name or IP address (default: localhost)
<br /> -p port LDAP server1 TCP port number (default: 389)
<br /> -h host LDAP server2 name or IP address (default: localhost)
<br /> -p port LDAP server2 TCP port number (default: 389)
<br /> -V n LDAP protocol version number (2 or 3; default: 3)
<br /> -ZZ start TLS request
<br /> -ZZZ enforce start TLS request (successful server response required)
<br /> -Z make an SSL-encrypted connection
<br /> -P pathname path to SSL certificate database (default: current directory)
<br /> -N name of certificate to use for SSL client authentication
<br /> -K pathname path to key database to use for SSL client authentication
<br /> (default: path to certificate database provided with -P option)
<br /> -m pathname path to security module database
<br /> -W SSL key password
<br /> -W - prompt for SSL key password
<br /> -I file SSL key password 'file' containing token:password pair/s
<br /> -Q [token][:certificate name] PKCS 11
<br /> -3 check hostnames in SSL certificates
<br /> -D binddn bind dn
<br /> -w passwd bind passwd (for simple authentication)
<br /> -w - prompt for bind passwd (for simple authentication)
<br /> -j file read bind passwd from 'file' (for simple authentication)
<br /> -E ask server to expose (report) bind identity
<br /> -g do not send a password policy request control
<br /> -R do not automatically follow referrals
<br /> -O limit maximum number of referral hops to traverse (default: 5)
<br /> -M manage references (treat them as regular entries)
<br /> -0 ignore LDAP library version mismatches
<br /> -i charset character set for command line input (default taken from locale)
<br /> use '-i 0' to override locale settings and bypass any conversions
<br /> -k do not convert password to utf8 (use default from locale)
<br /> -Y proxyid proxied authorization id,
<br /> e.g, dn:uid=bjensen,dc=example,dc=com
<br /> -H display usage information
<br /> -J controloid[:criticality[:value|::b64value|:
<br />
<br /><span style="font-weight: bold;">Example</span>
<br />
<br />ldapcmp -h exmaple.host.com -h example1.host.com -s sub -b "o=176,ou=grpStructure,o=com"
<br />
<br />o=176,ou=grpStructure,c=com
<br />different: type
<br /> 1: SA 55
<br /> 2: PA 55
<br />
<br />
<br />perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-43874119162219574872011-06-27T22:21:00.000-07:002011-06-27T22:26:28.264-07:00Comment your code with Smart::CommentsNormally we comment our code so that humans (including ourselves) can<br /> understand it later on. However with ``Smart::Comments'' it becomes<br /> possible to have comments which are not only useful in comprehending our<br /> code, but also in *debugging* our code.<br /><br /> With ``Smart::Comments'' enabled, when a special comment sequence is<br /> seen (``###'' by default) debugging output is produced:<br /><br /> use Smart::Comments;<br /><br /> ### [<now>] Running backups...<br /><br /> my $backup_dir = get_backup_host();<br /><br /> ### Backing up files to: $backup_dir<br /><br /> foreach my $file (@manifest) { ### Copying files... % done<br /> backup($file, $backup_dir);<br /> }<br /><br /> ### [<now>] Backup complete...<br /><br /> With ``Smart::Comments'' enabled, output similar to the following would<br /> be seen:<br /><br /> ### [Fri Feb 25 12:14:34 2011] Running backups...<br /><br /> ### Backing up files to: '/mnt/backup'<br /><br /> Copying files........ 64% done<br /><br /> ### [Fri Feb 25 12:17:57 2011] Done...<br /><br /> One of great advantages of ``Smart::Comments'' is that the ``use<br /> Smart::Comments'' line can simply be removed (or commented away) when<br /> done, and all our smart comments are then simply ignored by Perl.<br /> There's no requirement that ``Smart::Comments'' be installed on the<br /> production systems, and no risk that that it may interfere with your<br /> code.<br /><br /> You can read more about ``Smart::Comments'' on the <br /> <a href='http://search.cpan.org/perldoc?Smart::Comments'>CPAN</a> .perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-84134568153689045422011-06-26T23:37:00.000-07:002011-06-26T23:38:15.437-07:00local::lib<span style="font-weight:bold;">Work with local modules via local::lib</span><br /><br /> ``local::lib'' helps solve the problem when a Perl package on your<br /> machine isn't the version you need it to be. It allows you to create<br /> your own directory of Perl packages into your own, or your team's<br /> directory.<br /><br /> use local::lib;<br /><br /> # or<br /><br /> use local::lib '/path/to/team/directory';<br /><br /> ``local::lib'' also sets up some useful shell commands which add our<br /> preferred include directories to ``PERL5LIB'' in our environment. If our<br /> code is not running under taint, we don't even need to add the ``use''<br /> line to our code to use these newly installed modules.perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-34648650181100509472011-06-26T23:35:00.000-07:002011-06-26T23:37:04.394-07:00App::perlbrew<span style="font-weight:bold;">Experimenting with new versions of Perl and modules</span><br /><br /> Many developers have a chicken-and-egg problem when it comes to<br /> upgrading their version of Perl. On one hand, the system version of Perl<br /> cannot be upgraded because it might break existing scripts, on the the<br /> other hand it has been difficult to install your own version of Perl to<br /> see whether an upgrade is safe. The same happens with modules.<br /><br /><br /><span style="font-weight:bold;">Pick your Perl version with App::perlbrew</span><br /><br /> Use ``App::perlbrew'' to install and switch between multiple versions of<br /> Perl. ``perlbrew'' is easy to install, even if you don't have system<br /> administration privileges, and very easy to use. Once you've installed<br /> and initialised it, you can install whichever version of Perl you wish<br /> to use.<br /><br /> perlbrew install perl-5.12.2<br /> perlbrew install perl-5.10.1<br /><br /> ``perlbrew'' will then fetch, compile and install that version of Perl<br /> in your home directory (or other nominated location) and you then you<br /> can just start using that version (``perlbrew'' will do all the path<br /> magic required to make this your default version of Perl).<br /><br /> If you have more than one version of Perl installed by ``perlbrew'' you<br /> can list the verions out:<br /><br /> perlbrew list<br /><br /> and switch between them:<br /><br /> perlbrew switch perl-5.12.2<br /><br /> You can also ask ``perlbrew'' to switch itself off so that you can go<br /> back to using the system Perl.<br /><br /> perlbrew offperl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-20118454609523946462011-06-26T23:32:00.000-07:002011-06-26T23:34:04.218-07:00Maintain your own CPAN with CPAN::MiniIf you wish to have a portable, off-line CPAN mirror, or wish to maintain the state of CPAN exactly as it was at a particular date, then ``CPAN::Mini'' is the way to go:<br /><br /> cpanmini -l ~/local-cpan \<br /> -r http://search.cpan.org/CPAN<br /><br /> We can even use this with ``cpanm'':<br /><br /> cpanm --mirror ~/local-cpan --mirror-only Test::Most<br /><br /> ``cpanmini'' only includes the most recent versions of the CPAN modules<br /> (rather than their whole history) and as a consequence is only a few<br /> Gigabytes big.perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-34920313711989326762011-02-06T14:05:00.000-08:002011-02-06T14:06:22.406-08:00Testing your perl code - Jacinta Richardson - Perltraining.com==== Testing your code ====
<br />
<br /> Testing cannot prove the absence of bugs, although it can help identify
<br /> them for elimination. It's impossible to write enough tests to prove
<br /> that your program is flawless. However, a comprehensive test-plan with
<br /> an appropriate arsenal of tests can assist you in your goal of making
<br /> your program defect free.
<br />
<br />
<br />== Test::Simple ==
<br />
<br /> Writing a test is just like writing regular Perl code, and checking that
<br /> what you got is what you expected. There are a huge number of modules in
<br /> Perl which are designed to make testing that much easier. These are all
<br /> built on ``Test::Harness'' underneath. ``Test::Simple'' comes standard
<br /> with Perl and provides a great starting point.
<br />
<br /> ``Test::Simple'' provides one test routine: ``ok''. You pass it an
<br /> expression, and a description. If the expression, when evaluated, is
<br /> true, the test succeeds, otherwise it fails. For example:
<br />
<br /> use Test::Simple tests => 1;
<br />
<br /> ok( 1 + 1 == 2, 'simple arithmetic works');
<br />
<br /> If we save this into a file, and run that file, we get:
<br />
<br /> 1..1
<br /> ok 1 - simple arithmetic works
<br />
<br /> We can add a failing test too:
<br />
<br /> use Test::Simple tests => 2;
<br />
<br /> ok( 1 + 1 == 2, 'simple arithmetic works');
<br /> ok( 1 + 3 == 2, 'of course, this should fail');
<br />
<br /> and then we get:
<br />
<br /> $ perl testscript.pl
<br /> 1..2
<br /> ok 1 - simple arithmetic works
<br /> not ok 2 - of course, this should fail
<br /> # Failed test 'of course, this should fail'
<br /> # at test.pl line 4.
<br /> # Looks like you failed 1 test of 2.
<br />
<br /> So let's consider this code. First of all we must have a plan. This
<br /> tells ``Test::Simple'' how many tests we intend to run. If we get this
<br /> number wrong, our test suite will not pass; as ``Test::Simple'' cannot
<br /> tell whether we made a mistake in our plan, or if some tests didn't run
<br /> for some other reason.
<br />
<br /> Note that we didn't need to specify test numbers, just how many tests we
<br /> have. ``Test::Simple'' will keep track of the test numbers for us.
<br />
<br />
<br />== Test::More ==
<br />
<br /> ``Test::More'' provides a richer set of functions to make your tests
<br /> even easier to write. For example, ``is'', ``isnt'', ``like'' and
<br /> ``unlike'':
<br />
<br /> use Test::More tests => 8;
<br />
<br /> # Load in my module, fail if it won't load.
<br /> use_ok 'Local::People';
<br />
<br /> # Test if simple addition is working.
<br /> is( (1 + 5), 6, "Simple addition behaves");
<br />
<br /> # Let's not compare apples to oranges.
<br /> isnt( "Malus domestica",
<br /> "Citrus sinensis",
<br /> "Inequal string comparison"
<br /> );
<br />
<br /> # Test that we can create a new person
<br /> my $self;
<br /> eval { $self = Local::People->new(cache_id => 1234) };
<br /> like( $@, undef, 'Correctly created $self' );
<br />
<br /> # Does my name match this regular expression?
<br /> like ( $self->name(), qr/Jacinta/, 'Name contains Jacinta' );
<br />
<br /> # We can also provide a regular expression in a string form:
<br /> like ( $self->hobby(), '/Perl/i', 'Name contains Perl' );
<br />
<br /> # Make sure my favourite foods don't contain broad beans.
<br /> unlike ( $self->favourite_foods(),
<br /> qr/broad beans/i,
<br /> "Don't like icky foods"
<br /> );
<br />
<br /> # Test that languages matches the expected list:
<br /> my @languages = qw/Perl C PHP C++ Bash/;
<br /> is_deeply( [sort $self->languages()],
<br /> [sort @languages],
<br /> 'All the languages are there'
<br /> );
<br />
<br />
<br />== Having a plan ==
<br />
<br /> With ``Test::More'', if you're just starting your test suite, or adding
<br /> an unknown number of extra tests you can tell ``Test::More'' that you
<br /> don't *know* how many tests there will be in total:
<br />
<br /> use Test::More qw(no_plan);
<br />
<br /> Of course, once your test suite has become more stable, you should
<br /> always provide a number of tests. This allows your testing modules to
<br /> tell if your tests have stopped prematurely (which usually indicates
<br /> something has gone wrong).
<br />
<br /> You can also delay defining your plan until later:
<br />
<br /> use Test::More;
<br />
<br /> # ...
<br />
<br /> plan( tests => 3 );
<br />
<br /> This is useful if you won't know how many tests you expect to run until
<br /> some condition is decided at run-time. For example, if you have some
<br /> tests which depend on an environment variable being set, or a module
<br /> being installed. It's a mistake to set a plan, and then change it later.
<br />
<br />
<br />== ok() vs is() ==
<br />
<br /> If you make an error either in your module, or in your test script
<br /> ``ok()'' will only tell you that your test failed. ``is()'' is a lot
<br /> friendlier and will tell you both what you got, and what you said you
<br /> were expecting. For example ``ok()'' might give us:
<br />
<br /> $ perl -I lib/ testprogram.pl
<br /> 1..2
<br /> ok 1 - sum() works properly
<br /> not ok 2 - product() works properly
<br /> # Failed test 'product() works properly'
<br /> # at ok.t line 10.
<br /> # Looks like you failed 1 test of 2.
<br />
<br /> Which doesn't necessarily help us spot what we've done wrong. On the
<br /> other hand, if we change our tests to use ``is()'' we'll get:
<br />
<br /> $ perl -I lib/ testprogram.pl
<br /> 1..2
<br /> ok 1 - sum() works properly
<br /> not ok 2 - product() works properly
<br /> # Failed test 'product() works properly'
<br /> # at ok.t line 10.
<br /> # got: '3628800'
<br /> # expected: '3628880'
<br /> # Looks like you failed 1 test of 2.
<br />
<br /> Here we can see that our error is in the number we said we're expecting
<br /> (we've mistyped it).
<br />
<br />
<br />== Further resources ==
<br />
<br /> There's a whole lot more to testing, and ``Test::More'' does a lot more
<br /> than we've covered here. Many articles on testing in Perl and
<br /> specifically ``Test::More'' have been written, and we recommend these in
<br /> particular:
<br />
<br />: * Building Testing Libraries
<br /> <<a href="http://www.perl.com/pub/a/2004/05/07/testing.html" target="_blank">http://www.perl.com/pub/a/2004/05/07/testing.html</a>>
<br />
<br />: * Introduction to Testing
<br /> <<a href="http://www.perl.com/pub/a/2001/12/04/testing.html?page=1" target="_blank">http://www.perl.com/pub/a/2001/12/04/testing.html?page=1</a>>
<br />
<br />: * Perl Testing: A Developer's Notebook; by Ian Langworth and
<br /> Chromatic; O'Reilly Media, 20005
<br />perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com2tag:blogger.com,1999:blog-6285369396982098442.post-71780398500589873912011-02-06T14:00:00.000-08:002011-02-06T14:01:43.519-08:00Perl Programming Best Practices 2011==== Perl Programming Best Practices 2011 by <span class="email">Jacinta Richardson (perltraining.com)</span> ====<br /><br /> Over the next few tips, we'll be covering current best practices for<br /> programming Perl.<br /><br /><br />== Introduction ==<br /><br /> In 2005, Dr Damian Conway published the very popular "Perl Best<br /> Practices" book which details 256 "best practices" for Perl programming.<br /> While some of these "best practices" have been further improved on in<br /> the ensuing 5 years, many of them remain excellent practices for your<br /> coding. If you have not yet read this book, we strongly recommend that<br /> you do so! In this sequence of Perl tips we will cover a wide selection<br /> of current best practices, taking into account the ideas and<br /> modernisations that Perl has undergone..<br /><br /><br />== Some best practices are obvious ==<br /><br /> use strict;<br /> use warnings;<br /><br /> If you're not already using ``strict'' in all of your scripts, and using<br /> ``warnings'' in almost all of your scripts, you have a lot to learn, and<br /> should probably start with Conway's book.<br /><br /><br />= 10 year old features =<br /><br /> Perl has had scalar filehandles and three-argument open for more than 10<br /> years now:<br /><br /> # Opening a file for reading<br /> open(my $in_fh, "<", $input_file) or die "Failed to open: $!";<br /><br /> # Reading from that filehandle<br /> while(<$in_fh>) {<br /> # do something with $_<br /> }<br /><br /> close $in_fh;<br /><br /> # Opening a file for writing<br /> open(my $out_fh, ">", $output_file) or die "Failed to open: $!";<br /><br /> # Printing to that filehandle<br /> print {$fh} "This text will go into my file.";<br /><br /> close $out_fh;<br /><br /> Three-argument open treats the filename literally, which protects you<br /> from a number of potential security issues that are possible with<br /> two-argument open. Scalar filehandles - because they are just scalars -<br /> can be passed to subroutines, put in arrays, and used as values in<br /> hashes. Additionally, when the scalar goes out of scope before you close<br /> the file, Perl will automatically close the file for you. None of this<br /> is easy with package filehandles.<br /><br /><br />= Coding standards =<br /><br /> Ideally every organisation you work for, or project you work on, has a<br /> pre-established, formalised set of coding standards. While these may not<br /> be as current as you'd like, consistency is a good thing. If you don't<br /> have a coding standard, then now is a good time to develop one. Conway's<br /> book is a great starting place.<br /><br /><br />== Upgrade your version ==<br /><br /> Perl 5.6.1 is almost 10 years old now (2001-Apr-08). Perl 5.8.2 is 7<br /> years old (2003-Nov-05). Perl 5.10.0 is 3 years old (2007-Dec-18). Perl<br /> 5.8.9 is 2 years old (2008-Dec-14). Perl 5.10.1 is 1.5 years old<br /> (2009-Aug-22) Perl 5.12.2 is 4 months old (2010-Sep-06).<br /><br /> Upgrade! At the very, very least, use one of the Perl 5.8.x versions,<br /> but if you can, upgrade to either 5.10.1 or 5.12.2. Why? Because a whole<br /> lot of wonderful, new, awesome and *modern* features have been<br /> incorporated into Perl in the last few years.<br /><br /> To use the features of your modern version of Perl, just specify your<br /> minimum version:<br /><br /> use v5.10.1; # get all the things from Perl 5.10.1<br /><br /><br />= Perl 5.12.x =<br /><br /> By specifying any of the Perl 5.12 versions, ``strict'' is automatically<br /> turned on by default. Thus this:<br /><br /> use v5.12.2;<br /><br /> is the same as saying:<br /><br /> use v5.12.2;<br /> use strict;<br /><br /> This is a great improvement.<br /><br /><br />== New features ==<br /><br /> With Perl 5.10.0 we received a host of new features. Some of these are<br /> mentioned here:<br /><br /><br />= say =<br /><br /> ``say'' gives us ``print'' with an attached newline. Instead of:<br /><br /> print "Hello World!\n";<br /><br /> print "$_\n" foreach @list;<br /><br /> we can write:<br /><br /> say "Hello World!";<br /><br /> say foreach @list;<br /><br /> it's shorter, neater, and gets rid of that ugly $_.<br /><br /><br />= // (defined-or) =<br /><br /> Consider this subroutine:<br /><br /> sub item_sale {<br /> my ($product, $price) = @_;<br /><br /> $price ||= $product->cost;<br /><br /> ...<br /> }<br /><br /> This example is short, neat, and almost correct. But how do we signal<br /> that this item is being provided for free without changing the $product<br /> object? If we pass in zero, then that's a false value, so we're going to<br /> get the full product cost.<br /><br /> We could rewrite this to be:<br /><br /> sub item_sale {<br /> my ($product, $price) = @_;<br /><br /> unless( defined($price) ) {<br /> $price = $product->cost;<br /> }<br /><br /> ...<br /> }<br /><br /> Or, in Perl 5.10.0 and above we can use defined-or. Defined-or works<br /> just like regular OR, except that it tests for whether the value is<br /> defined, rather than true.<br /><br /> sub item_sale {<br /> my ($product, $price) = @_;<br /><br /> $price //= $product->cost;<br /><br /> ...<br /> }<br /><br /><br />= state =<br /><br /> ``state'' allows us to create variables which remember their state.<br /> These are like ``static'' variables in C. Imagine the following code to<br /> ensure that we only show 100 images:<br /><br /> my $images_allowed = 100;<br /><br /> sub view_image {<br /> die "Too many images" unless $images_allowed-- > 0;<br /><br /> ...<br /> }<br /><br /> As it is, other subroutines here could be used to change<br /> $images_allowed. To prevent that, we could wrap it into a closure:<br /><br /> {<br /> my $images_allowed = 100;<br /><br /> sub view_image {<br /> die "Too many images" unless $images_allowed-- > 0;<br /><br /> ...<br /> }<br /> }<br /><br /> Or, we can use a state variable:<br /><br /> sub view_image {<br /> state $images_allowed = 100;<br /> die "Too many images" unless $images_allowed-- > 0;<br /><br /> ...<br /> }<br /><br /><br />= given-when =<br /><br /> There's now a native switch for Perl, except that it's very, very cool.<br /><br /> given ($has) {<br /> when (/ninja/) { $ninjas++; }<br /> when (/pirate/) { $pirates++; }<br /> when (/robot/) { $robots++; }<br /> when (@other) { $other_cool_things++; }<br /> when (%interesting) { $interesting++; }<br /> default { $boring++; }<br /> }<br /><br /> This says smart match the value in $has. If it matches against any of<br /> the first three regular expressions, increment that variable. Otherwise<br /> if it is an element of @other increment ``$other_cool_things++'',<br /> otherwise if it is a key in %interesting increment $interesting. If it<br /> matches none of these comparisons, increment $boring.<br /><br /> The given-when can also be used with ``foreach'':<br /><br /> foreach (@input) {<br /> when (/ninja/) { $ninjas++; }<br /> when (/pirate/) { $pirates++; }<br /> when (/robot/) { $robots++; }<br /> when (@other) { $other_cool_things++; }<br /> when (%interesting) { $interesting++; }<br /> default { $boring++; }<br /> }<br /><br /><br />= New features: smart matching =<br /><br /> given-when uses smart matching to work. Smart match allows us to compare<br /> things to determine if they match, in the most useful way possible:<br /><br /> $foo ~~ undef; # is $foo undefined?<br /><br /> $foo ~~ @array; # is $foo in @array?<br /><br /> $foo ~~ %hash; # is $foo a key in %hash?<br /><br /> $foo ~~ $coderef; # does $coderef->($foo) return true?<br /><br /> $foo ~~ qr{$re}; # does $foo pattern match $re?<br /><br /> $foo ~~ $bar; # does $foo equal $bar?<br /><br /><br />== Next ==<br /><br /> There are many other best practices still to be covered. In our next tip<br /> we'll discuss exception handling, and how you can test a wide variety of<br /> Perl versions from your home directory.perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-52279846159255910092010-12-31T00:43:00.000-08:002010-12-31T00:44:04.988-08:00Perl New year wishperl -le 'print pack "H*","4861707079204e657720596561722032303131"'perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-80965570968287502072010-12-22T02:08:00.000-08:002010-12-22T02:14:53.368-08:00Download youtube videos - Perl<h3>Perl one-liner to download youtube videos</h3>perl -MWWW::Mechanize -e '$m = WWW::Mechanize->new; $_=shift; ($i) = /v=(.+)/; s/%(..)/chr(hex($1))/ge for (($u) = $m->get($_)->content =~ /l_map": .+(?:%2C)?5%7C(.+?)"/); $m->get($u, ":content_file" => "$i.flv")'<br /><br />Use it as following:<br /><br />$ perl ... http://www.youtube.com/watch?v=ID<br /><br />It will save the video to a file named "ID.flv".<br /><br />It was written by Peteris Krumins (peter@catonmat.net).<br />His blog is at <a href="http://www.catonmat.net/">http://www.catonmat.net</a> -- good coders code, great reuse.perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-23713892768278862702010-12-22T01:23:00.000-08:002010-12-22T01:36:51.883-08:00Proc::ProcessTable<h3> Framework for getting process information </h3><br /><br />Find it at: <a href="http://search.cpan.org/search?mode=module&query=Process%3A%3AProcessTable">cpan</a><br /><br /><h4>Description</h4><br />This modules gets the process information <br /><br /><h4>Who should use it?</h4><br />Very useful for sysadmins<br /><br /><h4>Good features: </h4><br />Good to extract process related information and it is very fast<br /><br /><h4>What are the drawbacks or problems?</h4><br />Not working on some Linux flavors<br />There are <a href="https://rt.cpan.org/Public/Dist/Display.html?Name=Proc-ProcessTable">13 open bugs </a><br /><br />Example code:<br /><br /><pre><br />#!/usr/bin/perl -w<br /><br />use strict;<br /><br />print join("\n", &memusage), "\n";<br />exit 0;<br /><br /><br /># memusage subroutine<br />#<br /># usage: memusage [processid]<br />#<br /># this subroutine takes only one parameter, the process id for <br /># which memory usage information is to be returned. If <br /># undefined, the current process id is assumed.<br />#<br /># Returns array of two values, raw process memory size and <br /># percentage memory utilisation, in this order. Returns <br /># undefined if these values cannot be determined.<br /><br />sub memusage {<br /> use Proc::ProcessTable;<br /> my @results;<br /> my $pid = (defined($_[0])) ? $_[0] : $$;<br /> my $proc = Proc::ProcessTable->new;<br /> my %fields = map { $_ => 1 } $proc->fields;<br /> return undef unless exists $fields{'pid'};<br /> foreach (@{$proc->table}) {<br /> if ($_->pid eq $pid) {<br /> push (@results, $_->size) if exists $fields{'size'};<br /> push (@results, $_->pctmem) if exists $fields{'pctmem'};<br /> };<br /> };<br /> return @results;<br />}<br /><br /></pre><br /><a href="http://perlmonks.org/?node_id=115098">Perl monks</a><br /><a href="http://perlmonks.org/?node_id=121674">Perl monks</a>perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-52327945229657418152010-12-07T02:38:00.000-08:002010-12-07T02:44:37.444-08:00Perl - Cheat sheets Collection<a href="http://search.cpan.org/~nwclark/perl-5.8.7/pod/perlcheat.pod">perlcheat - Perl 5 Cheat Sheet [html] (cpan.org)</a><br /><a href="http://juerd.nl/site.plp/perlcheat">Perl Cheat Sheet [html] (juerd.nl)</a><br /><a href="http://johnbokma.com/perl/perl-quick-reference-card.html">Perl Quick Reference Card [pdf] (johnbokma.com)</a><br /><a href="http://refcards.com/refcard/perl-regexp-trusketti">Perl Regular Expressions by Iain Truskett [pdf] (refcards.com)</a><br /><a href="http://www.cheat-sheets.org/saved-copy/PerlQuickRef.pdf">Perl Regular Expression - Quick Reference [pdf]</a><br /><a href="http://www.catonmat.net/blog/perls-special-variable-cheat-sheet/">Perl Predefined Variables (perls special variable cheat sheet) by Peteris Krumins [doc, pdf]</a><br /><a href="http://www.cheat-sheets.org/saved-copy/perl_quickref.pdfPerl">Language Quick Reference by Johan Vromans [pdf] (tiger.la.asu.edu)</a><br /><a href="http://www.digilife.be/quickreferences/QRC/PERL%20Win32%20Quick%20Reference.pdf">PERL Win32 Quick Reference by Jialong He [pdf] (digilife.be)</a><br /><a href="http://encycode.com/wiki/index.php/Perl_Cheat_Sheet">Perl Cheat Sheet [html] (encycode.com)</a><br /><a href="http://users.physik.fu-berlin.de/~goerz/refcards/perl_refcard.pdf">Perl Reference Card by Michael Goerz [pdf, odt] (users.physik.fu-berlin.de/~goerz/)</a>perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-84888466967512165152010-12-05T21:38:00.000-08:002010-12-05T21:43:35.234-08:00Facebook Puzzle - Perl - BreathalyzerFacebook puzzle Breathalyzer can be solved easily using Levenshtein distance calculation Algorthim. More details about this algorithm is here <a href="http://en.wikipedia.org/wiki/Levenshtein_distance">Levenshtein distance</a><br /><br />If you are trying to solve using Perl have a look at Text::Levenshtein<br /><br />This module is available in cpan<a href="'http://search.cpan.org/~jgoldberg/Text-Levenshtein-0.05/Levenshtein.pm'">Text::Levenshtein</a>perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-9804191489265341122010-12-05T20:54:00.000-08:002010-12-05T21:01:11.193-08:00Facebook Puzzle - Perl - hoppityFacebook has added Puzzles section under its careers section. You can follow this procedure to get your test puzzle submission done. <br /><br />1. Save this script in a file hoppity.<br /><br /><pre><br />#!/usr/bin/perl<br /><br />use strict;<br />use warnings;<br /><br />my $fh;<br /><br />my $path = $ARGV[0];<br /><br />die("Missing Filename. Run $0 <filename> \n") if(! $path);<br />die("File not found ") if(! -f $path);<br /><br />open($fh,"<$path") || die("Error reading file");<br />my $number = <$fh>;<br /><br />chomp($number);<br />$number = trim($number);<br /><br />die("Invalid input $number") if($number !~ /\d+/);<br /><br />$\ = "\n";<br />for(my $i=1;$i<=$number;$i++) {<br /> if ($i % 3 == 0 && $i % 5 == 0) {<br /> print "Hop";<br /> } elsif ($i % 3 == 0) {<br /> print "Hoppity";<br /> } elsif ($i % 5 == 0) {<br /> print "Hophop";<br /> }<br />}<br /><br />sub trim {<br /> my ( $str) = @_;<br /> $str =~ s/^\s*//g;<br /> $str =~ s/\s*$//g;<br /> return $str;<br />}<br /></pre><br /><br />2. Send this file to 1051962371@fb.com with the file attached and subject as hoppity<br /><br />3. After four hours facebook puzzle bot will reply you with your submission resultsperl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-11239393534996373812010-12-02T02:43:00.000-08:002010-12-02T02:47:21.387-08:00Perl Best practices - CodingTen Essential Coding Practices by Damien conway in PBP book<br /><br />1. Always use strict and use warnings.<br /><br />2. Use grammatical templates when forming identifiers.<br /><br />3. Use lexical variables, not package variables.<br /><br />4. Label every loop that is exited explicitly, and every next, last, or redo.<br /><br />5. Don’t use bareword filehandles; use indirect filehandles.<br /><br />6. In a subroutine, always unpack @_ first, using a hash of named arguments if<br />there are more than three parameters.<br /><br />7. Always return via an explicit return.<br /><br />8. Always use the /x ,/m , and /s flags, and the \A and \z anchors.<br /><br />9. Use capturing parentheses in regexes only when deliberately capturing, then give<br />the captured substrings proper names.<br /><br />10. Never make variables part of a module’s interface.perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-28501723600375057252010-12-02T02:40:00.000-08:002010-12-02T02:42:49.198-08:00Perl Best practices - Development<h3>Ten Essential Development Practices</h3><br /><br />1. Design the module’s interface first.<br /><br />2. Write the test cases before the code.<br /><br />3. Create standard POD templates for modules and applications.<br /><br />4. Use a revision control system.<br /><br />5. Create consistent command-line and configuration interfaces.<br /><br />6. Agree upon a coherent layout style and automate it with perltidy.<br /><br />7. Code in commented paragraphs.<br /><br />8. Throw exceptions instead of returning special values or setting flags.<br /><br />9. Add new test cases before you start debugging.<br /><br />10. Don’t optimize code—benchmark it.perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-67855444952389539482010-12-02T02:36:00.000-08:002011-08-29T00:48:00.656-07:00vimrc for Perl coding from PBP by damien conwayvim is the desired editor for most of the Perl programmers. This .vimrc is recommended by Damien conway in Perl Best practices book
<br />
<br />set autoindent "Preserve current indent on new lines
<br />set textwidth=78 "Wrap at this column
<br />set backspace=indent, eol, start "Make backspaces delete sensibly
<br />set tabstop=4 "Indentation levels every four columns
<br />set expandtab "Convert all tabs typed to spaces
<br />set shiftwidth=4 "Indent/outdent by four columns
<br />set shiftround "Indent/outdent to nearest tabstop
<br />set matchpairs+=<: > "Allow % to bounce between angles too
<br />"Inserting these abbreviations inserts the corresponding Perl statement. . .
<br />iab phbp #! /usr/bin/perl –w
<br />iab pdbg use Data: : Dumper ' Dumper' ; warn Dumper [ ] ; ^[ hi
<br />iab pbmk use Benchmark qw( cmpthese ); ^Mcmpthese -10, {}; ^[ O
<br />iab pusc use Smart: : Comments; ###
<br />iab putm use Test: : More qw( no_plan );
<br />iab papp ^[ : r ~/. code_templates/perl_application. pl^
<br />iab pmod ^[ : r ~/. code_templates/perl_module. pmperl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-79883453417018955262010-11-29T22:05:00.000-08:002010-11-29T22:10:14.489-08:00Desktop application with PerlEver wondered how to create pretty looking windowing applications without perltk? The answer is wxPerl. wxPerl is a perl module that allows a Perl program to use the wxWidgets GUI toolkit. If you don't know anything about Perl or wxWidgets, you may find a short explanation below. If you want to learn more, go to <a href='http://www.wxwidgets.org/'>wxWidgets</a>. In short wxPerl allows you to write portable GUI applications in Perl, using the wxWidgets object oriented interface. Look at the <a href='http://wxperl.sourceforge.net/sshot01.html'>screenshots</a>.<br /><br /><br /><h3> wxWidgets </h3><br /><br />wxWidgets gives you a single, easy-to-use API for writing GUI applications on multiple platforms. Link with the appropriate library for your platform (Windows/Unix/Mac) and compiler (almost any popular C++ compiler), and your application will adopt the look and feel appropriate to that platform. On top of great GUI functionality, wxWidgets gives you: online help, network programming, streams, clipboard and drag and drop, multithreading, image loading and saving in a variety of popular formats, database support, HTML viewing and printing, and much much more.perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-24701191258653423582010-11-29T21:51:00.000-08:002010-11-29T21:55:08.392-08:00ldapsearch encoding issuesEver wondered why your ldapsearch results are base64 encoded for some values? ldapsearch does a base64 encoding while returning values if there is a space in the end or in the front. It also encodes the value when there is a special character in the value. To get the proper decoded value I would recommend using Net::LDAP which decodes the value while returning via Net::LDAP::Entryperl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com1tag:blogger.com,1999:blog-6285369396982098442.post-89628053767110564492010-11-29T00:23:00.000-08:002010-11-29T00:24:36.335-08:00Perl Monks Head Lines - 29-Nov-2010Perl Monks Head Lines<br /><br />1. <a href="http://perlmonks.org/?node_id=874068">Renaming an image file</a><br /><br />2. <a href="http://perlmonks.org/?node_id=874062">why need my in a foreach loop?</a><br /><br />use strict;<br />use 5.010;<br /><br />foreach my $word (qw(abc def ghi)) {<br /> say $word;<br />}<br /><br /><br />When using strict perl requires to declare even the loop variable of a foreach loop. Why is that? After all the $word v<br /><br />3. <a href="http://perlmonks.org/?node_id=874060">Array values into a database help!</a><br /><br />4. <a href="http://perlmonks.org/?node_id=874052">Get CID inline attachments with MIME::Parser</a><br /><br />I have a postfix server which mailbox_command's into this perl script:<br /><br />#!/usr/bin/perl<br /><br />use MIME::Parser;<br />srand;<br /><br />$parser = new MIME::Parser;<br />$foldername = time().int(rand(10)).int(rand(10)).int(ran<br /><br />5. <a href="http://perlmonks.org/?node_id=874036">default hash name for GetOptions</a><br /><br />I want to use GetOptions('foo','bar'), which provides default variables $opt_foo and $opt_bar.<br /><br />Is there also a default hash provided with this call such as $opts{foo} ?<br />I realise I could do GetOpti<br /><br />6. <a href="http://perlmonks.org/?node_id=874034">Help using Find::File::name</a><br /><br />I'm a perl noob<br />I'm trying to inventory a bunch of file with .wgt extension and store the matches (from some seeded input) in a report at the end. I need the full path that Find::File::name provides<br /><br />7. <a href="http://perlmonks.org/?node_id=874017">removing duplicates from a string list</a><br /><br />8. <a href="http://perlmonks.org/?node_id=874007">URL-String-concatenation within Perl [applying to a loop]</a><br /><br />Hello dear Perl-monks - good evening!<br /><br /><br />well i am currently workin on a parser that should fetch pages: i want to do it with Perl since this is the most pretty way to do it!<br /><br />well - i have to build<br /><br />9. <a href="http://perlmonks.org/?node_id=873999">cookie ssss</a><br /><br />Thank you everyone for all your help<br /><br />Update:<br />This is not a Perl question , but does any one know where to get a Firefox cookie<br />editor for Linux<br /><br />Hello,<br /> Does anyone know where to find good informat<br /><br />10. <a href="http://perlmonks.org/?node_id=873981">Getting range from N..end with list slice</a><br /><br />A friend told me that there is some sort of new list slice range syntax in Perl 5.10 that would allow getting a range starting at some offset continuing thru to the last element in a list - no matter<br /><br />11. <a href="http://perlmonks.org/?node_id=873972">"use 5.10.0" creates weird syntax error on sub named "default"</a><br /><br />Hi Monks,<br /><br />I am running 5.10.0 (on Mac Os), and I get a weird behavior. I wan't able to find any explanation so far, and I am quite puzzled. Before I file a bug report, I would like to seek your imme<br /><br />12. <a href="http://perlmonks.org/?node_id=873945">Strange Behavior with XML::Simple when pulling info out of an XML file</a><br /><br />I'm very lost. I am trying to do the following:<br />I have an XML file from Nagios. Here's the structure:<br /><br /> 1<br /> 2<br /> 3<br /> 4 check_bigip_pool_connection<br /> 5 0<br /> 6 1<br /> 7 cur<br /> 8perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-63295424956437274782010-11-26T00:34:00.001-08:002010-11-26T01:07:08.687-08:00Perl Monks Head Lines - 26-Nov-2010<br /><br />Perl Monks Head Lines<br /><br />1. <a href="http://perlmonks.org/?node_id=873628">Attachments in emails and finding matches and cross referencing</a><br /><br />1st question:<br />Is there a library out there to read SMTP messages (written to disk in text form with attachments still encoded in various ways) and reliably extract the names of any attachments from t<br /><br />2. <a href="http://perlmonks.org/?node_id=873624">Build Perl with glib1 or glib2</a><br /><br />Venerable Monks,<br /><br />I am compiling Perl 5.10.0 and Perl 5.12.2 on Solaris 8 (and later on Solaris 10). To support this, I have downloaded several packages required by GNU C++ (gcc) from www.sunfreewar<br /><br />3. <a href="http://perlmonks.org/?node_id=873620">PAR::Packer fails to find dependencies when executed</a><br /><br />I have encountered an issue which appears to be a bug in the Solaris build of PAR::Packer and may previously have shown up under BSD as well but works fine under Linux<br /><br />Solaris run<br /><br />bash-2.05$ pp -o<br /><br />4. <a href="http://perlmonks.org/?node_id=873599">Calculating cross-correlation</a><br /><br /><br />5. <a href="http://perlmonks.org/?node_id=873590">find & replace a string in perl</a><br /><br />Hi monks, i am struggling with editing a file , Iam opening a file and replacing string with a comment(#) at start of that line for example: i have a test.txt file in that there is string called "te<br /><br />6. <a href="http://perlmonks.org/?node_id=873586">error showing LWP request failed</a><br /><br />7. <a href="http://perlmonks.org/?node_id=873580">Search pattern from end of line</a><br /><br />Hi<br /><br /> I need a perl reg-expression which extracts the pattern as below.<br /><br /><br />Basically we want to parse and extract the rpms from the packages.xml inside RHEL cd hence looking for a pattern which extrac<br /><br />8. <a href="http://perlmonks.org/?node_id=873569">Selenium-rc Perl</a><br /><br />Test::WWW::Selenium<br /><br />Using Selenium I cam log into the wepage and get into home page. But I want to understand if it is possible to do following,<br /><br />In home page When I give the name of third party pro<br /><br />9. <a href="http://perlmonks.org/?node_id=873565">SQL Server parser</a><br /><br /><br />I am following the book "Real World SQL Server<br /> Administration with Perl" by Linchi Shea. He has used<br />5.6.1 from ActiveState.com; Current / latest version<br />available is<br />ActivePerl-5.12.2.1202-MSWi<br /><br />10. <a href="http://perlmonks.org/?node_id=873562">Parsing command line options without knowing what they are</a><br /><br />Greetings monks,<br /><br />This seems like such a simple idea, but I can't seem to find any module that does it. I have a script that needs to take in a bunch of command line options in an open-ended set. I<br /><br />11. <a href="http://perlmonks.org/?node_id=873546">Problems with INET, Select, and Win32</a><br /><br />I have been trying to make the following code work without success. It is a simple thread waiting on a UDP port. I have lots of possible devices that may send packets to the port which are then simpl<br /><br />12. <a href="http://perlmonks.org/?node_id=873533">SOAP::Lite returning a 404-error for a known-good URL</a><br /><br />Hello all,<br />I am trying to convince SOAP::Lite to post to a .NET WCF web service. I expected interop problems, but I'm hitting a wall even sooner than I expected. When I try to POST the request,perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-3653729398791591232010-11-25T03:33:00.000-08:002010-11-25T03:35:56.421-08:00How to extract Headlines from PerlmonksDo you want to visit perlmonks site only when you see an interesting posting? Here is a simple script which gets the headlines from perlmonks and gives corresponding link. <br />If you are interested then just go to the link. This takes .01 sec to get the headlines from perlmonk site. <br /><br />#!/usr/bin/perl<br />use XML::Simple;<br />use LWP::Simple;<br />my $xml = get("http://www.perlmonks.org/headlines.rdf");<br />my $xs = XML::Simple->new();<br />my $ref = $xs->XMLin($xml);<br />my @items = @{$ref->{item}};<br />print "Perl Monks Head Lines \n\n";<br />foreach $item (@items) {<br /> print "$item->{link} - $item->{title}\n";<br />}perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0tag:blogger.com,1999:blog-6285369396982098442.post-38357435873455372122010-11-25T02:46:00.000-08:002010-11-25T03:22:37.372-08:00PerlMonks Headlines - 25-Nov-2010Perl Monks Head Lines<br /><br />1. <a href="http://perlmonks.org/?node_id=873407">[OT] Providing a Windows ppm repo at minimal cost</a><br />2. <a href="http://perlmonks.org/?node_id=873402">Getting element from List box in Perl tk</a><br />3. <a href="http://perlmonks.org/?node_id=873373">how to nullify case sensitivity</a><br />4. <a href="http://perlmonks.org/?node_id=873367">how to find last word match ?</a><br />5. <a href="http://perlmonks.org/?node_id=873353">check which files are open to write/read by another process</a><br />6. <a href="http://perlmonks.org/?node_id=873344">how to read every 10 line from input text file ?</a><br />7. <a href="http://perlmonks.org/?node_id=873336">Poor man's transaction construct</a><br />8. <a href="http://perlmonks.org/?node_id=873332">Apache::ReadConfig and RewriteRules</a><br />9. <a href="http://perlmonks.org/?node_id=873331">Storable.pm - corrupt when saving to non-truncated file</a><br />10. <a href="http://perlmonks.org/?node_id=873317">Find First character of each word in a string</a><br />11. <a href="http://perlmonks.org/?node_id=873314">NET::SSH2 Terminates</a><br />12. <a href="http://perlmonks.org/?node_id=873297">Great learning experience</a>perl_loverhttp://www.blogger.com/profile/02046504289783680080noreply@blogger.com0