Archive for the ‘perl’ tag
Read and learn – part 1: Perl
It’s about time I post something useful again over here.
That’s why I’m posting a series of links to pages where you can actually learn things. *insert awkward silence*
Anyway, I’m starting of with a couple of pages where you can either learn a new programming language OR increase your productivity looking at your current environment.
We will start the series with a document written for the purpose of learning Perl, written by Sam Hughes
Perl is a dynamic, dynamically-typed, high-level, scripting (interpreted) language most comparable with PHP and Python. Perl’s syntax owes a lot to ancient shell scripting tools, and it is famed for its overuse of confusing symbols, the majority of which are impossible to Google for. Perl’s shell scripting heritage makes it great for writing glue code: scripts which link together other scripts and programs. Perl is ideally suited for processing text data and producing more text data. Perl is widespread, popular, highly portable and well-supported. Perl was designed with the philosophy “There’s More Than One Way To Do It” (TMTOWTDI) (contrast with Python, where “there should be one – and preferably only one – obvious way to do it”).
Go check out: Learn Perl in about 2 hours 30 minutes
ack, much like grep, only better
Tipped bij martijn!
ack is a tool like grep, aimed at programmers with large trees of heterogeneous source code.
ack is written purely in Perl, and takes advantage of the power of Perl’s regular expressions.
Top 10 reasons to use ack instead of grep:
- It’s blazingly fast because it only searches the stuff you want searched.
- ack is pure Perl, so it runs on Windows just fine.
- The standalone version uses no non-standard modules, so you can put it in your ~/bin without fear.
- Searches recursively through directories by default, while ignoring .svn, CVS and other VCS directories.
Which would you rather type?
- $ grep pattern $(find . -type f | grep -v ‘\.svn’)
- $ ack pattern
- ack ignores most of the crap you don’t want to search
- VCS directories
- blib, the Perl build directory
- backup files like foo~ and #foo#
- binary files, core dumps, etc
- Ignoring .svn directories means that ack is faster than grep for searching through trees.
- Lets you specify file types to search, as in –perl or –nohtml.
Which would you rather type?
- $ grep pattern $(find . -name ‘*.pl’ -or -name ‘*.pm’ -or -name ‘*.pod’ | grep -v .svn)
- $ ack –perl pattern
- Note that ack’s –perl also checks the shebang lines of files without suffixes, which the find command will not.
- File-filtering capabilities usable without searching with ack -f. This lets you create lists of files of a given type.
- $ ack -f –perl > all-perl-files
- Color highlighting of search results.
- Uses real Perl regular expressions, not a GNU subset.
- Allows you to specify output using Perl’s special variables
- Example: ack ‘(Mr|Mr?s)\. (Smith|Jones)’ –output=’$&’
- Many command-line switches are the same as in GNU grep:
- -w does word-only searching
- -c shows counts per file of matches
- -l gives the filename instead of matching lines
- etc.
- Command name is 25% fewer characters to type! Save days of free-time! Heck, it’s 50% shorter compared to grep -r.
Check it out: http://betterthangrep.com/