Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

baxy77bax's scratchpad

by baxy77bax (Deacon)
on Apr 17, 2008 at 16:17 UTC ( #681220=scratchpad: print w/replies, xml ) Need Help??

Well since this scrpad is meant for me to scratch something up i'll use to me understandable punct. (syntax)

so for any readers i apologies in front if some things are hard to grasp _I

equal distribution system

to equaly distribute jobs across free slots -- for grids and stuff

use strict; use Data::Dumper; my $chunks = 17; my $free_slots = {1 => 5 , 2 => 3 , 3 => 4 , 4 => 2 , 5 => 3}; my @mch = (1 , 2 , 3 , 4 , 5); my %mch_distro; my $leftovers = 0; while($leftovers < $chunks){ foreach (@mch){ last if ($leftovers == $chunks); if ($mch_distro{$_} < $free_slots->{$_}){ $mch_distro{$_}++; $leftovers++; } else{ next; } } } print Dumper(\%mch_distro);

quitting the shell - psh editor

#!/usr/bin/perl use strict; use Term::ReadLine; my $__line = Term::ReadLine->new(''); my $t; $SIG{"INT"} = "quit"; $| = 1; while(1){ $t = ""; $t .= $__line->readline("####\$ ") until ($t =~ m/q$|run$/g); chomp($t); exit() if ($t eq 'q'); eval("$1") if($t =~/(.*)run$/) } sub quit { print "\n Dou you realy want to quit:[q to quit]"; chomp($t = <>); }
the tricky one !

#!/usr/bin/perl use strict; use Data::Dumper; open (IN, "<", $ARGV[0]) || die "$!"; my (%hash,%hash1,%hash2); while(<IN>){ chomp($_); if ($_ =~ /(.*)\t(.*)/g){ $hash{"$1,$2"} = 1; $hash{"$1,$2"}++ if ($hash{"$2,$1"}); $hash{"$1,$2"}++ if ($hash{"$1,$2"}); } } my @array_lt; foreach (keys %hash){ $hash1{$_}= 2 if ($hash{$_} > 2); if ($hash1{$_}){ my @array = split(',',$_); push(@array_lt, [$array[0],$array[1]]); push(@array_lt, [$array[1],$array[0]]); } } foreach (sort keys %hash1){ my @array = split(',',$_); my ($first,$second); foreach(@array_lt){ $first = $_->[1] if ($array[0] eq $_->[0]); $second = $_->[1] if ($array[1] eq $_->[0]); } if ($first eq $second){ foreach (sort keys %hash1){ #$hash1{$_}++ if ($_ =~/$array[0]/g); $hash1{$_}++ if ($_ =~/$array[1]/g); } } } my @array_st = sort {$b <=> $a}values %hash1; foreach (@array_st){ my @array = split(',',$_); print $_ . "\n"; ## have to finish this one } print Dumper(\%hash1);
this is interesting : pid control

Kasai's a algorithm

It is a bit messy but really don't have time to write it nicely ... got to go back to work ...

#input #>in #aabbeecbabebe #!/usr/bin/perl use strict; use Data::Dumper; use Getopt::Long; my ($help,$in,$out); GetOptions ("i=s" => \$in, # input "h" => \$help, # help "o=s" => \$out, ); if($help || !$in){ print "Usage:\n\n"; print "\t-i\tinput - single fasta file(it only uses the first fasta +seq)\n"; print "\t-o\toutput - output file <optional>\n"; exit(0); } my $hash_seq = _read_fasta(in => $in); foreach my $key (keys %{$hash_seq}){ my @suftab = _sort_suffixes(array => $hash_seq->{$key}); my ($height,$sufinv) =_kasai(suftab => \@suftab, string => $hash_seq->{$key}); print "Hight:@{$height}\n\nRank:@{$sufinv}\n\nPosition:@suftab\n\n"; } ######################################################### # Subs... ######################################################### sub _read_fasta { my %arg = @_; open (IN, "<", $arg{in}) || die "$!"; my %hash =(); my ($head, $t) = (undef,0); my @seq = (); while(<IN>){ chomp; if (/>(.*?)/){ last if $t ==1; if (defined $head){ push(@seq,"z"); $hash{$head} = \@seq ; } $head=$1; @seq = (); $t++; } else{ my @tmp = split('',$_); push(@seq,@tmp); } } if (defined $head){ push(@seq,"z"); $hash{$head} = \@seq ; } close IN; return \%hash; } sub _kasai { my %arg = @_; my @sufinv = (); for (0..$#{$arg{string}}){ $sufinv[$arg{suftab}->[$_]] = $_; } my $h = 0; my @height = (); for (0..$#{$arg{string}}){ if($sufinv[$_] >= 1){ my $k = $arg{suftab}->[$sufinv[$_] - 1]; while($arg{string}->[$_ + $h] eq $arg{string}->[$k + $h]){ $h++; } $height[$sufinv[$_]] = $h; if($h>0){ $h--; } else{ $h = 0; } } } return (\@height,\@sufinv); } sub _sort_suffixes { my %arg = @_; return map { $_->[ 0 ] } sort { $a->[ 1 ] cmp $b->[ 1 ] } map { [ $_ +, join q{}, @{$arg{array}}[$_..$#{$arg{array}} ] ] } 0 .. $#{$arg{a +rray}}; # solution provided by Johngg }
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2018-11-14 17:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (175 votes). Check out past polls.

    Notices?