注册 登录
编程论坛 Perl论坛

perl 这么牛X的语言居然没人来?

mywaylgh 发布于 2010-03-10 15:45, 8517 次点击
print "hello world","\n";
15 回复
#2
好学2010-03-11 16:54
超级不喜欢perl和php的代码风格,虽然都很强悍
#3
mywaylgh2010-03-12 15:08
一下perl 代码版权归 mywaylgh 所有,请尽情享用....

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;

}


[ 本帖最后由 mywaylgh 于 2010-3-12 15:09 编辑 ]
#4
mywaylgh2010-03-12 15:10
sub subarray{
    # Get sub array and resort by input index
    my @output = map {$_[0]->[$_]} @{$_[1]};
    return @output;
}
#5
mywaylgh2010-03-12 15:10
sub unique{
    #Get unique elements of an array.
    my %seen = ();
    my @output = grep { ! $seen{$_} ++ } @_;
    return @output;
}
#6
mywaylgh2010-03-12 15:11
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;
}
#7
mywaylgh2010-03-12 15:11
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;
}
#8
pgy2010-03-22 16:31
我听见秋风扫落叶的声音~~~
#9
Alar302010-03-22 16:36
呵呵
真正牛X的应该是用语言的人
而不是语言本身
各种语言都有自身的适应性和局限性的
#10
chqcs2010-03-23 17:13
  强人!!! 
#11
mywaylgh2010-03-23 17:38
以下是引用pgy在2010-3-22 16:31:15的发言:

我听见秋风扫落叶的声音~~~
不过我这里现在只有春风啊.....
#12
lampeter1232010-05-24 14:24
早就听说perl的大名了,黑客高手经常用的语言
#13
qianyuinsour2010-07-29 12:29
我也是刚着手写perl程序,发现用它编写gui界面时,安装各种软件着实费力啊。
#14
jl72132010-11-20 15:01
额,这个版块太冷清了!
#15
bpmf06182011-04-03 00:50
哈哈哈!
#16
samuelchen2011-06-21 17:14
花花绿绿的符号,好玩吧
1