# typical hash-of-hashes: my %hash = ( a => { b => 2 }, c => { b => 4 } ); $hash{$key1}{$key2} = $value; #### while ( my ( $outer_key, $outer_value ) = each %hash ) { while ( my ( $inner_key, $inner_value ) = each %$outer_value ) { # do whatever... } } #### # with dups my @inner_keys = map { keys %$_ } values %hash; # without dups my @uniq_inner_keys = do { my %inner_keys; while ( my ( undef, $href ) = each %hash ) { @inner_keys{ keys %$href } = (); } keys %inner_keys; }; #### perl -lwe 'sub f { my $n = shift; return $n < 2 ? 1 : $n * f($n-1); } print f(7); eval { print f(8); }; if ( $@ ) { print "eval failed: $@" }' #### #!/bin/bash -x cp mutated-orig.plx mutated1.plx for i in 1 2 3 4 do this=mutated$i.plx echo ';' >> $this echo 'if ( $@ ) { print "eval: $@" }' >> $this perl -MO=Deparse $this | ./mut-dewhack.plx > m$i.pre-parse perl $this > m$i.out 2> m$i.err perl -MO=Deparse $this | ./mut-dewhack.plx > m$i.post-parse next=mutated$(( $i + 1 )).plx cp $this $next done; #### ./mutated1.plx: eval: line 1: unexpected EOF while looking for matching `"' ./mutated1.plx: eval: line 2: syntax error: unexpected end of file ./mutated1.plx: line 4: syntax error near unexpected token `.' ./mutated1.plx: line 4: `('`'|'-').('['^'"').('{'^'[').'\\$'.('`'|'-').('['^'#').('{'^'[').'='.('{'^'[').('^'^('`'|')')).('^'^('`'|'.')).('^'^('`'' #### cmd1 arg1 arg2 arg3 && \ cmd2 arg arg arg pirate arg arg arg #### foreach d in $( find . -type d -depth 1 -print ) do tar czf $d.tar.gz $d && \ rm -rf $d done #### $ perl -lwe '$_="[http://a|alpha] [http://b|beta]"; print; s{\[(http://.+?)\|(.+?)\]} {$2}gi; print' [http://a|alpha] [http://b|beta] alpha beta #### $ perl -lwe '$_="[http://a|alpha] [http://b|beta] [http://g]"; print; s{ \[ (http://.+?) (?: \| (.+?) )? \] } { qq!! . (defined $2 ? $2 : $1) . qq!\n! }giex; print' [http://a|alpha] [http://b|beta] [http://g] alpha beta http://g #### $ perl -lwe \ '$_="[http://a|alpha] [http://b|beta] [http://g]"; print; # match with title s{\[(http://[^\]\|]+)\|([^\]]+)\]} {$2\n}gi; # match without title s{\[(http://[^\]\|]+)\]} {$1\n}gi; print' [http://a|alpha] [http://b|beta] [http://g] alpha beta http://g #### my $x = join("", 0..9)x2; my $lx = length($x); my $next_mult = ($lx + 15) & ~0x0f; $x .= "*" x ($next_mult - $lx); print "|$x|\n"' #### =item $self->add_manufacturer( %args ); Adds a manufacturer to the database. Required keys in %args: company_id company_name address city state zip contact phone fax email account_number Returns the new manufacturer id. =cut sub add_manufacturer { my ( $self, %args ) = @_; # make sure we have all required keys my @cols = qw( company_id company_name address city state zip contact phone fax email account_number ); if ( my @missing = grep { ! exists $args{$_} } @cols ) { die "add_manufacturer: missing args @missing"; } # build up the SQL. to make more efficient, do # this only once and stash it somewhere. my $cols = join ',', ( 'id', cols ); my $places = join ',', ( '?' ) x ( 1 + @cols ); my $sql = "INSERT INTO sf_manufacturers ( $cols )" . " VALUES ( $places )"; # do the actual insertion here. $self->{dbh}->do( $sql, {}, undef, @args{@cols} ); # still need to get actual new id here... return $self->{dbh}->get_latest_insert_id(); } #### =item my $prefix = shortest_prefix @strings; Return the shortest prefix common to all @strings. Returns empty string if there is no prefix; returns C if there are no strings or if any of the values are themselves C =cut # algorithm by Ilya Z # implementation by Ken Fox # both ganked from c.l.p.misc: # http://groups.google.fm/groups?selm=199908100340.UAA13944%40long-lake.nihongo.org sub common_prefix ( @ ) { defined( my $prefix = shift ) or return undef; my $len = length $prefix or return ''; foreach my $w ( @_ ) { defined $w or return undef; while ( substr( $w, 0, $len ) ne $prefix ) { --$len; chop $prefix; } $len or return ''; } return $prefix; } #### SELECT * FROM my_table AS t, ( SELECT MAX( date ) AS max_date FROM my_table ) AS s WHERE t.date = s.max_date; #### #include int max_int = std::numeric_limits::max(); #### href="...&session=&mod=&..." #### bgcolor="" bgcolor="" >