Having learned Perl syntax as a 2nd language, I still have problems making expressions and statements more concise. For example, in a recent (still developing) script for comparing Active Directory accounts to an employee list, I needed to make a function that would take an employee name (Smith, John), and convert it to the AD nomenclature (JSmith). This is the code I used, and I'm sure it's not as brief or concise as it could be. I was hoping for enlightenment, and how you managed to overcome this hurdle if Perl wasn't your [0]th language.
for ($i = 0; $i <= $#sortedNames; $i++) {
@temp = split/,/, $sortedNames[$i][0];
$temp[1] = reverse $temp[1];
$x = chop($temp[1]);
$toOutput = reverse $temp[0];
$toOutput .= $x;
$output = reverse $toOutput;
print NEWFILE "$output\n";
}
I would include the rest of the script, but it looks so bad that I wouldn't want to burn your eyes.
Any comments are welcome. (Yes, I didn't
use strict;. Yes, I should
use strict;). This is only part of the script, I could include the rest, though I'd have to 'clean' it up, as it looks far worse than the above snippet.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.