Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

naChoZ

by naChoZ (Curate)
on Jun 12, 2001 at 05:17 UTC ( [id://87699]=user: print w/replies, xml ) Need Help??

Monks I know:

Useful nodes:

TVSET

Check out his page on getting the most out of using vim for editing your perl.

You can take a look at my vim configuration in my scratchpad.

While I'm on vim, also check out gmax's post Editing features for advanced users, as well as a couple more nodes on editors in general, [here] and [here]

Aristotle
Lots of good reading at his node.

turnstep
Very useful information here. Especially Important is the Posting FAQ.

PerlMonks Related Information:

Items of Interest:

Important Reference Material:

Perl
Database Stuff
Misc

Perl Idioms Explained

Useful s‎crip‎ts and snippets

Sigs around the monastery I've enjoyed:

crouchingpenguin

----
"Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."

licking9Volts

Well, no sig, but that handle makes me laugh.

EvdB

--tidiness is the memory loss of environmental mnemonics

dash2

A massive flamewar beneath your chosen depth has not been shown here

jepri

I didn't believe in evil until I dated it.

Tomte

Hlade's Law:
If you have a difficult task, give it to a lazy person -- they will find an easier way to do it

erikharrison

Light a man a fire, he's warm for a day. Catch a man on fire, and he's warm for the rest of his life. - Terry Pratchet

Jenda

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
-- Rick Osborne

LazerRed

Driver carries > $20 in ammo at all times.

and another quote from him...

Whip me, Beat me, Make me use Y-ModemG.

Petras

Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
-Howard Aiken

stefan k

you begin bashing the string with a +42 regexp of confusion

Obligatory geek code:

-----BEGIN PERL GEEK CODE BLOCK-----
Version: 0.01
P++>++++$c?>---P6-> R+>++++M >++O >++MA >++E--PU->+++BD
C+>++D++$S+++$X->++WP+>+++MO >+PP!n+CO-->-PO >+o
>++G!>+A--OL!Ee---Ev++uB++>+++$uS+++w-- >!m!
------END PERL GEEK CODE BLOCK------
[ decode ]

Great Perl Modules

Catalyst
Very slick looking MVC development framework for creating web apps.
Class::DBI
One of the most useful modules to come along. This can save you a tremendous amount of time with your database s‎crip‎ts.
Data::Dumper
I use this all the time while coding. I like turning it into a method available through all of my objects.
DBM::Deep
Very useful when you need to work with extremely large arrays and hashes.
WWW::Mechanize
Makes web s‎crip‎ts super easy.
HTTP::Recorder
Use this in conjunction with WWW::Mechanize and your web s‎crip‎ts will almost create themselves.

Useful tips.

Perlmonks
Collapsable Nodelets

Stuff this javas‎crip‎t somewhere in your Free Nodelet somewhere. I know it's crap. It's the first javas‎crip‎t I wrote from scratch, but it works.

function nodeletExpandCollapse () { var bodyId = arguments[0]; var showCustom = arguments[1]; var hideCustom = arguments[2]; var whichcustom = document.getElementById(bodyId); if (whichcustom.className==showCustom) { whichcustom.className=hideCustom; } else { whichcustom.className=showCustom; } } function nodeletObject ( text, headId, bodyId, defaultState ) { this.text = text; this.headId = headId; this.bodyId = bodyId; this.defaultState = defaultState; } function replaceNodeletHeadings () { var cpan = new nodeletObject( 'CPAN nodelet', 'nodelet_head_ro +w_CPAN_nodelet', 'nodelet_body_row_CPAN_nodelet', 'hide' ); var chat = new nodeletObject( 'Chatterbox', 'nodelet_head_ro +w_Chatterbox', 'nodelet_body_row_Chatterbox', 'hide' ); var vote = new nodeletObject( 'Voting Booth', 'nodelet_head_ro +w_Voting_Booth', 'nodelet_body_row_Voting_Booth', 'hide' ); var info = new nodeletObject( 'Information', 'nodelet_head_ro +w_Information', 'nodelet_body_row_Information', 'hide' ); var pers = new nodeletObject( 'Personal Nodelet', 'nodelet_head_ro +w_Personal_Nodelet', 'nodelet_body_row_Personal_Nodelet', 'hide' ); var free = new nodeletObject( 'Free Nodelet', 'nodelet_head_ro +w_Free_Nodelet', 'nodelet_body_row_Free_Nodelet', 'show' ); var myxp = new nodeletObject( 'XP Nodelet', 'nodelet_head_ro +w_XP_Nodelet', 'nodelet_body_row_XP_Nodelet', 'show' ); var time = new nodeletObject( 'Tick tock', 'nodelet_head_ro +w_Tick_tock', 'nodelet_body_row_Tick_tock', 'show' ); var nodeList = new Array( cpan, chat, vote, info, pers, free, myxp +, time ); for ( var index in nodeList ) { var nodeletObj = document.getElementById( nodeList[ind +ex].headId ); //+ "\n<a href=\"javas‎crip‎t:nodeletExpand +Collapse('" + nodeletTargetIdList[index] + "', 'nodelet_body_row', 'h +ideblock')\" onMouseOver=\"ExpandOnly('" + nodeletTargetIdList[index] + + "', 'nodelet_body_row')\">" var newInnerHTML = "\n<th class=\"nodehead\">\n" + "\n<a href=\"javas‎crip‎t:nodeletExpand +Collapse('" + nodeList[index].bodyId + "', 'nodelet_body_row', 'hideb +lock')\">" + nodeList[index].text + "</a>\n" + "\n</th>\n"; nodeletObj.innerHTML = newInnerHTML; if ( nodeList[index].defaultState == 'hide' ) { nodeletExpandCollapse(nodeList[index].bodyId, "nodelet_bod +y_row", "hideblock"); } } } function init(){ replaceNodeletHeadings(); } window.onload=init;

CLI
perl -lane

Use the -a command-line option to make perl behave like awk. Instead of using $1, $2, etc like awk uses, perl uses the @F array.

Useful usage:

Of all the editors in the FreeBSD ports tree, show which ones you have installed:
/usr/ports/Tools/s‎crip‎ts/portsearch -p editors | grep Port: | perl \ -lane 'print $F[1] if qx(pkg_info -E $F[1])'
FreeBSD - Show bsdpan-* ports with no ORIGIN field. (one liner)

ls -1 /var/db/pkg/bsdpan-*/+CONTENTS | perl \ -ne 'while (<>) { my $filename = $_; \ open( CUR, "<" . $filename); my $origin_p; \ for (<CUR>) { $origin_p++ if m/ORIGIN/; } \ print $filename unless $origin_p}'

Misc
Viewing the code in a perlmonks posting

Here's a little trick I often use when viewing someone's code from a perlmonks node, usually when the coding style is bad or just difficult for me to read, to tidy it up and look at it in vim (or gvim) so I get syntax highlighting also.

Right-click on the little [download] link and copy the url. Then, pass it to wget by pasting it with quotes:

wget -O - "http://perlmonks.org/?abspart=1;displaytype=displaycode;nod +e_id=663850;part=1" | perltidy | view "+set filetype=perl" -
Unrecognized character \xE2 at /home/forda/bin/send_to_mms line 6.

Back in this thread, I responded to someone getting the above error message when copying and pasting code from a perldoc to use in a s‎crip‎t.

I'd run into it before and after spending at least 45 full seconds looking at the perldoc manpage and the Pod:: module docs, I posted the tiny perl s‎crip‎t I originally used to fix this annoying problem myself.

I later updated that s‎crip‎t to make it a little smarter plus added a convenient way to identify the "wide" characters like the curled quotation mark. This is the result:

#!/usr/bin/perl -n #use strict; #use warnings; use charnames (); use encoding "utf8"; $|++; my $chars = { 'HYPHEN' => '-', # \x{2010} 'SOFT HYPHEN' => '-', #­ \x{00AD} 'MINUS SIGN' => '-', # \x{2212} 'FIGURE DASH' => '-', # \x{2012} 'ACUTE ACCENT' => "'", # \x{00B4} 'GRAVE ACCENT' => "'", # \x{0060} 'LEFT SINGLE QUOTATION MARK' => "'", # \x{2018} 'RIGHT SINGLE QUOTATION MARK' => "'", # \x{2019} 'LEFT DOUBLE QUOTATION MARK' => '"', # \x{201C} 'RIGHT DOUBLE QUOTATION MARK' => '"', # \x{201D} 'BOX DRAWINGS LIGHT VERTICAL' => '|', # \x{2502} 'MULTIPLICATION SIGN' => '*', # \x{00D7} }; # If the first character is an equal sign, skip it and # display the identity of each remaining character. # if (/^=/) { chomp; for my $index ( 1 .. length($_) - 1 ) { my $char = substr( $_, $index++, 1 ); print $char . " " . sprintf( "\\x{%04X}", ord($char) ) . "\" = '" . charnames::viacode( ord($char) ) . "'\n" ; } } else { for my $cname ( keys %$chars ) { my $char = chr( charnames::vianame($cname) ); s/$char/$chars->{$cname}/g; } print; }

I gathered the list of characters I defined simply by browsing some random perldocs and man pages, at least ones I thought most likely to contain odd characters that I might want to translate after a copy and paste action. If you have any more suggestions, please let me know.

pmlocate My::Foo

You can set up the same functionality for perl modules as the common locate command available in most Unices.

First, put the pmdesc s‎crip‎t on your system.

Second, add a line to your crontab, usually right alongside the entry for updating the regular locatedb.

20 4 * * *  /usr/local/bin/pmdesc.pl | /usr/libexec/locate.mklocatedb > /var/db/pmlocatedb 2>&1

Now just create a little wrapper s‎crip‎t.

/usr/local/bin/pmlocate: #!/bin/sh # change path if needed LOCATE="locate" LOCATEDB_PATH="/var/db/pmlocatedb" $LOCATE -d $LOCATEDB_PATH $1
Commandline completion for perldoc

You can set up automatic commandline completion so that when you type perldoc perl<TAB> it will autocomplete based on pod documents starting with 'perl', for example.

Create this little s‎crip‎t to generate the list of pods. You could put this in crontab or simply run it on occasion. It would really only need to be updated after installing perl modules. This s‎crip‎t leaves a lot to be desired and I'm sure there's a better way of generating this list, especially one that uses the perldoc command itself, but this way is much, much faster than I found when I tried to use the perldoc command to look for valid perldoc in files.

/usr/local/bin/podlist.sh #!/bin/sh PODLIST=/tmp/podlist.txt PERLPATHS="/usr/perl5 /usr/lib/perl5 /usr/local/perl5 /usr/local/lib/p +erl5" [ -f ${PODLIST} ] && [ ! -w ${PODLIST} ] && echo "Permission problem on ${PODLIST}" && exit 1 [ -f ${PODLIST} ] && rm ${PODLIST} for DIR in ${PERLPATHS} ; do if [ -d "${DIR}" ] ; then FINDPATH=${DIR} break fi done find ${FINDPATH} -type f -name '*.pod' -o -name '*.pm' | xargs egrep -h -A3 '^=head.*NAME' | egrep -v '^X<' | egrep -v '=head' | egrep -v -- '--' | sort -u | dos2unix | egrep -v '^$' | egrep ' - ' | awk -F' - ' '{print $1}' | tr -d '^ ' | sed 's/^README[.]/perl/' \ > ${PODLIST} echo "${PODLIST} generation complete..."

For tcsh commandline completion, add this to your .tcshrc file:

if ( -f /tmp/podlist.txt ) then set podcomplete = ( 'n@*@`\cat /tmp/podlist.txt`@' ) else foreach d ( /usr/perl5 /usr/lib/perl5 /usr/local/perl5 /usr/lo +cal/lib/perl5 /mc/apps/perl/lib ) if ( -d "$d" ) then set podcomplete=( 'n@*@`\ls -1 '$d'/5.*/pod | sed s%\\ +.pod.\*\$%%`@' ) break endif end if ( -z "$podcomplete" ) then set podcomplete=( 'n@*@`\ls -1 /usr/lib/perl5/5.*/pod | se +d s%\\.pod.\*\$%%`@' ) endif endif complete perldoc "${podcomplete}"

I don't know how to do bash completions, but if anyone wants to submit it to me, I'll include it here.

Personal stuff:

Married, five chirruns, three dogs, house in the country.

Long time systems engineer doing broadband ISP work.

aharrison→← & gmail com

AHinMaine
$Id: perlmonkbio.html,v 1.29 2012/01/11 03:46:08 aharrison Exp aharrison $
uploaded with hup.pl

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found