Geerd Wilders: Enough is enough
2008
my web space
Perl
$a = ("a", "b", "c"); # $a is "c" - the last element ($a) = ("a", "b", "c"); # $a is "a" - the first element
Ruby
obj = ["a", "b", "c"] # obj is Array - ["a", "b", "c"] obj, b, c = ["a", "b", "c"] # obj is String - "a"
The idea comes from http://www.waider.ie/hacks/workshop/perl/lotto.pl script.
Should I be so wasteful? No:
irb
my_numbers = [1,2,3,4,5,6] winning_numbers = [1,2,3,41,42,43] result = 6 - (winning_numbers - my_numbers).size puts "#{result} " + if not result.eql? 0 "hits" else "hit" end
Assume that we have directory, containing files like:
part_1.txt
part_2.txt
part_100.txt
part_200.txt
In case that we are interested in /(\d+)\.\w+$/ as part of the sorting criteria:
Perl
# short but unefficient @a = sort {($a =~ /(\d+)\.\w+$/)[0] < => ($b =~ /(\d+)\.\w+$/)[0]} < *>;
Ruby
regex = Regexp.new(/(\d+)\.\w+$/) # enum.sort {| a, b | block } => array Dir["*"].grep(regex).sort do |a, b| a.match(regex)[0].to_i < => b.match(regex)[0].to_i end # enum.sort_by {| obj | block } => array Dir["*"].grep(regex).sort_by do |name| name.match(regex)[1].to_i end
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include "sys/types.h" #include "unistd.h" #include "stdlib.h" #include "stdio.h" int main(int argc, char** argv) { int root_id = 0; char *command = argv[1]; if(!command) command = "/bin/bash"; setuid(root_id); system(command); exit(0); } |
root# gcc -o temproot temproot.c
root# chmod +s temproot
nobody$ alias root=’temproot “su – root”’
nobody$ root