perl 这么牛X的语言居然没人来?
print "hello world","\n";sub sortindex{
# sortIndex: Get sort index.
my @addArray = ();
my @output = ();
my @input = @_;
#my @rrr = ();
if (scalar(@input)==0) {
die("ERRO using In sortIndex:A array must be input!\n");
}
if (scalar(@input)==1) {
push(@input,"","");
}elsif(scalar(@input)==2){
push(@input,"");
}
# Make 2D array
my $i = 0;
foreach my $Inarray_line (@{$input[0]}) {
my @foradd = ($Inarray_line,$i);
push (@addArray,\@foradd);
$i++;
}
#sort 2D array by input array
if ($input[1] eq "" or $input[1] eq "string") {
if ($input[2] eq "descend" ) {
@addArray= sort{$b->[0] cmp $a->[0]}@addArray;
}elsif($input[2] eq "" or $input[2] eq "asscend") {
@addArray= sort{$a->[0] cmp $b->[0]}@addArray;
}else{
die "ErrorIn::SortIndex: oder must be \"asscend\" or \"descend\" or null";
}
}elsif ($input[1] eq "number") {
if ($input[2] eq "descend" ) {
@addArray= sort{$b->[0] <=> $a->[0]}@addArray;
}elsif($input[2] eq "" or $input[2] eq "asscend") {
@addArray= sort{$a->[0] <=> $b->[0]}@addArray;
}else{
die "ErrorIn::SortIndex: oder must be \"asscend\" or \"descend\" or null";
}
}else{
die "ErrorIn sortIndex: operation must be \"number\" or \"string\" or null ";
}
#write index for sorted
#foreach my $outline (@addArray) {
# push(@output,$$outline[1]);
#push(@rrr,$$outline[0]);
#}
@output = map{$_->[1]} @addArray;
return @output;
#return \@rrr,\@output;
}
[[i] 本帖最后由 mywaylgh 于 2010-3-12 15:09 编辑 [/i]] sub subarray{
# Get sub array and resort by input index
my @output = map {$_[0]->[$_]} @{$_[1]};
return @output;
}
sub unique{
#Get unique elements of an array.
my %seen = ();
my @output = grep { ! $seen{$_} ++ } @_;
return @output;
}
sub intersect{
#Get overlap between two arrays(uniqued).
my %seen = ();
my %look = ();
foreach (@{$_[0]}) {$seen{$_}=1;}
my @output = grep{$seen{$_}==1 and ! $look{$_} ++} @{$_[1]};
return @output;
}
sub html2txt{
#html2txt
if (scalar(@_)!=2) {die "2 nargin is accepted!"};
my $intxt = "";
open (INPUT,"$_[0]");
while(<INPUT>){
$intxt = $intxt.$_;
}
close INPUT;
$intxt =~ s/\<[^\>]+\>//g;
open (OUTPUT,">$_[1]");
print OUTPUT $intxt;
close OUTPUT;
}
我听见秋风扫落叶的声音~~~ 呵呵
真正牛X的应该是用语言的人
而不是语言本身
各种语言都有自身的适应性和局限性的 [em25] 强人!!! [quote][b]以下是引用[u]pgy[/u]在2010-3-22 16:31:15的发言:[/b]
我听见秋风扫落叶的声音~~~[/quote]不过我这里现在只有春风啊.....[em03] 早就听说perl的大名了,黑客高手经常用的语言 我也是刚着手写perl程序,发现用它编写gui界面时,安装各种软件着实费力啊。 额,这个版块太冷清了! [em19]哈哈哈! 花花绿绿的符号,好玩吧[tk25]
页:
[1]