Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
compare webbrowser
Freenet DSL
Who's Online
9 user(s) are online (9 user(s) are browsing encyclopedia)

Members: 0
Guests: 9

more...
browser tip
Unix Befehle
manual of unix befehle
recommendation!
Sponsored
partner

One-liner program

A one-liner is a computer program or expression (programming) that takes no more than a single line. In practice, one-liners will be entered and executed directly from the command-line. Perl is an excellent language to use when creating one-liners.

Many one-liners are practical. For example, the following Perl one-liner will reverse all the bytes in a file:

perl -0777e print scalar reverse filename

One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.

The following example is a C program (a winning entry in the Best one-liner category of the IOCCC.)

main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return*t-42*s63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}

This one-liner program is a glob pattern matcher. It understands the glob characters `* meaning `zero or more characters and ` meaning exactly one character, just like your unix shell.

Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:

$ prog foo f ; echo $ $ prog best short program st*o**p* ; echo $

=External links=

  • [http://www.rollmop.org/oneliners/perl.html Perl Oneliners], showing off
  • [http://www.unixguide.net/unix/perl_oneliners.shtml Perl One Liners], practical examples
  • [http://sial.org/howto/perl/one-liner/ More Perl One Liners]
  • [http://www.ioccc.org/main.html International Obfuscated C Code Contest], IOCCC