Showing posts with label perl. Show all posts
Showing posts with label perl. Show all posts

22 Dec 2010

Download youtube videos - Perl

Perl one-liner to download youtube videos

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")'

Use it as following:

$ perl ... http://www.youtube.com/watch?v=ID

It will save the video to a file named "ID.flv".

It was written by Peteris Krumins (peter@catonmat.net).
His blog is at http://www.catonmat.net -- good coders code, great reuse.

2 Dec 2010

Perl Best practices - Coding

Ten Essential Coding Practices by Damien conway in PBP book

1. Always use strict and use warnings.

2. Use grammatical templates when forming identifiers.

3. Use lexical variables, not package variables.

4. Label every loop that is exited explicitly, and every next, last, or redo.

5. Don’t use bareword filehandles; use indirect filehandles.

6. In a subroutine, always unpack @_ first, using a hash of named arguments if
there are more than three parameters.

7. Always return via an explicit return.

8. Always use the /x ,/m , and /s flags, and the \A and \z anchors.

9. Use capturing parentheses in regexes only when deliberately capturing, then give
the captured substrings proper names.

10. Never make variables part of a module’s interface.

Perl Best practices - Development

Ten Essential Development Practices



1. Design the module’s interface first.

2. Write the test cases before the code.

3. Create standard POD templates for modules and applications.

4. Use a revision control system.

5. Create consistent command-line and configuration interfaces.

6. Agree upon a coherent layout style and automate it with perltidy.

7. Code in commented paragraphs.

8. Throw exceptions instead of returning special values or setting flags.

9. Add new test cases before you start debugging.

10. Don’t optimize code—benchmark it.