Why'd I post these, because I couldn't find any snippets (i saw all 456 of 'em), and even though it was relatively easy, someone might find it useful (since this is the 5th time I created some from scratch).
Also, there was some golf potential ;)(gotta start somewhere)
Reading material (if you don't know how it works):
perlfunc:printf,perlop,perlrun,perldata
update:# style: what i like (my latest first two attempts) perl -e"printf('%4s: %s',++$a,$_)while(<>)" file perl -e"printf'%4s: %s',++$a,$_ while<>" file # then i did a lot of searching, and ran accross clemburg's solution # (which was 'broken' like the craft version, see end) perl -pe "s/^/++$i.' 'x4/e" file # then i remembered -p and broke it down to ### which is by far my favorite (the one i use) perl -pe "printf'%4s: ',++$a" file # style: merlyn (as featured in WebTechniques) perl -pe"printf'%6s ','='.++$a.'='" file # or more acurately perl -pe"printf'%-6s ','='.++$a.'='" file # or most accurately (since his output looks like' =2= code +') perl -pe"printf'%8s%-8s ','','='.++$a.'='" file # style: [craft] (craft doesn't handle 3digits well) # you can always change the 2 into 3 to handle 3 digit nums perl -pe"printf'%-2s: ',++$a" file
########## my favorite (never forget perlvar, thanks davorg) perl -pe "printf'%4u: ',$." file # or to prevent 'overflow' perl -pe "printf'%4.4s: ',$." file
In reply to numbered sourcecode listing (oneliners) by crazyinsomniac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |