OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [perl_gui/] [lib/] [perl/] [temp.pl] - Blame information for rev 18

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 alirezamon
#! /usr/bin/perl -w
2
use Glib qw/TRUE FALSE/;
3
 
4
use strict;
5
use warnings;
6
 
7
 
8
 
9
 
10
 
11
my @nums=(0,2,3,6,7);
12
 
13
 my $s=compress_nums(@nums);
14
 
15
print "$s\n";
16
 
17
 
18
sub compress_nums{
19
        my      @nums=@_;
20
        my @f=sort { $a <=> $b } @nums;
21
        my $s;
22
        my $ls;
23
        my $range=0;
24
        my $x;
25
 
26
 
27
        foreach my $p (@f){
28
                if(!defined $x) {
29
                        $s="$p";
30
                        $ls=$p;
31
 
32
                }
33
                else{
34
                        if($p-$x>1){ #gap exist
35
                                if( $range){
36
                                        $s=($x-$ls>1 )? "$s:$x,$p": "$s,$x,$p";
37
                                        $ls=$p;
38
                                        $range=0;
39
                                }else{
40
                                $s= "$s,$p";
41
                                $ls=$p;
42
 
43
                                }
44
 
45
                        }else {$range=1;}
46
 
47
 
48
 
49
                }
50
 
51
                $x=$p
52
        }
53
        if($range==1){ $s= ($x-$ls>1 )? "$s:$x":  "$s,$x";}
54
        #update $s($ls,$hs);
55
 
56
        return $s;
57
 
58
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.