Snipeti-snapeti

Adds commas to long numbers. Eg.

$_ = 1111123456789; 
s/(\d)(\d{3})$/$1,$2/; 
s/(\d)(\d{3}),/$1,$2,/ while (m/\d{4}\,/); 
print;
Result:
1,111,123,456,789

Counts hours from a file where time is formatted H:MM. (I never worked over nine hours a day, lucky me.)

cat tuntilista_07.txt | perl -e '
foreach (<>) { next if (length $_ < 4); m/(\d):(\d\d)/; $a += $1; $b += $2; 
if ($b >= 60) { $a++; $b -= 60 } } print "$a:$b\n";'
Result:
123:45

Perl vs. Ruby
Perl:

$_ = "abcdefg";$a.=$1 while(s/(.)$//);print $a
Result:
gfedcba
Ruby:
"abcdefg".reverse
Result:
gfedcba

Small C snippet called trigraphs.c. Use the following command to compile:

gcc -o trigraphs -pedantic -g -trigraphs -std=c99 -Wextra trigraphs.c
Code:
#include <stdio.h>

int main() {
  int a = 0;
  printf("Why am I a complete %d?\n", a);
  // Let's cheer up variable 'a', won't we??/
  a++;
  if (a) {
    printf("Yay, finally I'm %d\n", a);
  } else {
    printf("Why am I still a %d?\n", a);  
    printf("Can you help variable 'a'? You can change only one character.\n");
  }
}
Result:
$ ./trigraphs 
Why am I a complete 0?
Why am I still a 0?
Can you help variable 'a'? You can change only one character.

C CLI, ex:

$ echo -e '#include \nint main(void) { int a = 1; for (int i = 6; i > 3; i--) { printf("%d\\n", a); a++ ;} }'|gcc -o jee -std=c99 -x c -;/tmp/jee
Result:
1
2
3

No pun indented.

Hauskat vaput vaan ie-jäbille.