免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4236 | 回复: 11
打印 上一主题 下一主题

关于定义二维数组的疑惑(解决,回去看书中) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-10-28 16:14 |只看该作者 |倒序浏览
my @arr = ();

for my $i ( 0 .. 4 ) {
       
      for my $j ( 0 .. 23 ) {
            
           arr[$i][$j]=0;
      }
}

以上是预定义二维数组等于0, 当我想换种写法的时候,遇到以下的问题..
my @arr1 = ( 0 .. 4 );
my @arr2 = ( 0 .. 23 );

for my $i ( @arr1 ) {
      
      push $arr[$i] = [ @arr2];

}


print $arr1[0][23];   

结果为23. 我只想
$arr[ 0 .. 4 ] [ 0 .. 23 ] = 0;


请问是否只能用第一种方法,还请各位大大以上哪种方法比较好,或者有别的方法更好的....

[ 本帖最后由 hyoryeo 于 2009-10-30 17:57 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-10-28 17:04 |只看该作者
push $arr[$i] = [ @arr2];
这句不对哦。

哎呀在perl里你不用初始化数组和分配内存滴。
数组增与删直接操作就行,不用预分配。
这就是script语言的好处。

论坛徽章:
0
3 [报告]
发表于 2009-10-28 17:36 |只看该作者
原帖由 兰花仙子 于 2009-10-28 17:04 发表
push $arr[$i] = [ @arr2];
这句不对哦。

哎呀在perl里你不用初始化数组和分配内存滴。
数组增与删直接操作就行,不用预分配。
这就是script语言的好处。



我是看这里的..
$AoA[$i] = [ @array ];      # 最安全,有时候最快 from PerlProgrammingChina3rd



因此我的目的是做统计报表, 而且有好几个subroutine, 所以需要用预定义数组....请看我的程序.....

论坛徽章:
0
4 [报告]
发表于 2009-10-28 17:40 |只看该作者
我的程序请看, 还请告诉我有什么需要改善的..

程序有点长....


  1. #!/usr/bin/perl

  2. use POSIX;
  3. use strict;
  4. use warnings;
  5. use Template;

  6. # define variable
  7. my $dir = $ARGV[0];        # input var of home
  8. my $home_dir = "/home/md";
  9. my $bin_dir = "$home_dir/bin";
  10. #my $tmp_dir = "$home_dir/tmp";
  11. my $tmp_dir = "/smc/tmp/sharon";
  12. #my $error_dir = "$home_dir/error";
  13. my $error_dir = "/smc/tmp/sharon";
  14. my $log_dir = "$home_dir/log";
  15. my $infile= "";
  16. my $Count = 0;
  17. my %recordhash = ();
  18. my %confighash = ();
  19. my @durtab = ();
  20. my %statab =();
  21. my @notab = ();

  22. my $ysdate = strftime("%Y%m%d",localtime(time-86400));
  23. if($dir=~/miepcdr/i or $dir =~/httpcdr/i) {        # Make sure confirm the Directory, it must be Case-insensitive miepcdr or httpcdr;
  24.         &ReadFolder($dir,$tmp_dir,$bin_dir,\@durtab,\%statab,\@notab,$error_dir); # It pass the specified global variable to subroutine.
  25.         &printhtmlreporttable(\@durtab,\%statab,\@notab,$dir); # It pass the specified global variable to subroutine.
  26.         @durtab = ();       
  27.         %statab = ();       
  28.         @notab = ();       
  29. } else {
  30.         print "Error: Is not the implementation of the directory!\n";
  31.         exit;
  32. }

  33. sub ReadFolder() {
  34.         my($dir,$tmp_dir,$bin_dir,$durtab,$statab,$notab,$error_dir)=@_; # Reference the Global Variable, Please look for line 30.
  35.        
  36.         if ( !-d $dir ) {
  37.                 print "Error: No exists directory, Please check!";
  38.                 exit;
  39.         } else {
  40.                
  41.                 if( !opendir (DH,$dir) ) {
  42.                         die ( "Can't open $dir:$!" );
  43.                 }
  44.                
  45.                 chdir( $dir );
  46.         }
  47.        
  48.         # ---------------Start config file -----------------------
  49.         if ( !open(CONF,"$bin_dir/config.txt") ) {
  50.                 die( "Can not open the file" );
  51.         }
  52.        
  53.         while(<CONF>) {
  54.         chomp;
  55.                
  56.                 if ( /(\d{1,3}\.)(\d{1,3}\.\d{1,3}\.\d{1,3}) / ) {
  57.                         $confighash{$1}{$2} = 1;
  58.                 } else {
  59.                        
  60.                         if ( /(\w+\.)(\w.*) / ) {
  61.                                  $confighash{$1}{$2} = 1;
  62.                         }

  63.                 }
  64.         }
  65.         close(CONF);
  66.         # ---------------End config file -----------------------

  67.         &defaultarray($durtab,$notab);        # Iinitialize the Global Array @durtab and @notab;

  68.         foreach $infile(readdir DH) {
  69.        
  70.                 if( $infile =~/(.+)\-$ysdate\.DAT\.Z$/ ) {
  71.        
  72.                         &checkfilecontent($infile, $dir, \%confighash,$durtab,$statab,$notab,$error_dir);# It pass the specified variable to the subroutine.       
  73.                 }
  74.         }
  75.         %confighash = ();
  76.         closedir DH;
  77. }

  78. sub defaultarray() {
  79.     my ($newdur,$newnon ) = @_; # Reference the Global Array, Please look for line 74.

  80.     for my $i ( 0 .. 3 ){

  81.                 for my $j ( 0, 1 ) {

  82.                 for my $k ( 0 .. 4 ) {

  83.                                 $newdur->[$i]->[$j]->[$k]=0;
  84.                                 $newnon->[$i]->[$j]=0;
  85.                         }
  86.                 }
  87.     }
  88. }

  89. sub checkfilecontent() { # read each line
  90.        
  91.         my ($in, $dir ,$conf,$durtab,$statab,$notab,$error_dir)= @_; # Reference the Global Variable, Please look for line 80.
  92.         my $status;
  93.         my $code;
  94.         my $start;
  95.         my $end;
  96.         my $url;
  97.         my $noneurl;
  98.         my $dur;
  99.         my $chksta;
  100.         my $staer4;
  101.         my $chkdur;
  102.         my $classsta;
  103.         my $type;
  104.         my $noname = "";
  105.         my $date = strftime("%Y%m%d%H%M%S",localtime(time));
  106.        
  107.         if( !open( IN,"zcat $in|" )) {
  108.                 die( "Could not open file $infile:$!" );
  109.         }

  110.         if ( !open( LOG,">>$log_dir/Report.out" )) {
  111.                 die( "Could not open file $log_dir/Report.out:$!" );
  112.         }

  113.         if ( $dir=~/miepcdr/i ) {
  114.                 print LOG "$date: MIEP::$in is reading.\n";
  115.         } elsif ( $dir =~/httpcdr/i ) {
  116.                 print LOG "$date: HTTP::$in is reading.\n";
  117.         }        # Record reading file # Please look for /home/md/log/Report.out;
  118.        
  119.         while( <IN> ) {
  120.                 chomp;
  121.                 next if /^Record.*\(.*\).*\"MiepPush.+\"/ .. /End/; # ignore the part.
  122.                 if ( /^Record.*\(\d+\).*\"MiepPull.+"/ ) {
  123.                         $start=$_;
  124.                
  125.                 } elsif ( /\s+\"(.*)\"\s\=\s\"(.*)\"/ ) {
  126.                         $status = $1;
  127.                         $code = $2;
  128.                         $recordhash{$status} = $code;       
  129.        
  130.                 } elsif ( /(^End.*Record.*\(\d+\))/ ) {
  131.                         $end = $_;
  132.                        
  133.                         if ( exists $recordhash{"url"} ) {
  134.                                
  135.                                 $url = $recordhash{"url"};
  136.                                 $dur = $recordhash{"urlDurationTime"};
  137.                                
  138.                                 $type = &checktypeofurl($url,$conf); # It return 0--SmartIN, 1--MMS, 2--CP, 3--IOM.
  139.                                 $chksta = &checkStatus($type,\%recordhash); # It return the full Status, e.g. 200 OK.
  140.                                
  141.                                 $staer4 = (split / +/,$chksta)[0];
  142.                                 $chkdur = &checkDuration($dur); # It return urlDuration 0 -- 0s - 2s, 1 -- 2s - 5s, 2 -- 5s - 10s, 3 -- 10s - 20s, 4 -- 20+s.
  143.                                 $classsta = &duratonclassbystatus($staer4,$durtab,\%recordhash,$dir,$start,$end,$type,$ysdate,$error_dir); # It return 0 -- less then 400,        1 -- greater than or equal to 400
  144.                                
  145.                                 $durtab->[$type]->[$classsta]->[$chkdur] = $durtab->[$type]->[$classsta]->[$chkdur] + 1; # Counting

  146.                                 if ( $staer4 >= 400 && $type != 1 ) {
  147.                                        
  148.                                         if ( $url =~/favicon.ico/i ){
  149.                                                 $noneurl = 0;
  150.                                         } elsif ($url =~/Microsoft\-Server\-ActiveSync/i ) {
  151.                                                 $noneurl = 1;
  152.                                         } else {
  153.                                                 $noneurl = 2;
  154.                                         }
  155.                                         if (exists $notab->[$type]->[$noneurl] ) {
  156.                                                 $notab->[$type]->[$noneurl] = $notab->[$type]->[$noneurl] + 1;
  157.                                         } # Counting
  158.                                         next if $url =~/favicon.ico/i or $url =~/Microsoft\-Server\-ActiveSync/i; # ignore a Report while if match the specified url.
  159.                                 }
  160.                         }
  161.                         undef %recordhash; # Empty for A report.

  162.                         if ( exists $statab->{$type}->{$chksta} ){
  163.                                 $statab->{$type}->{$chksta} = $statab->{$type}->{$chksta} + 1;
  164.                         } else {
  165.                                 $statab->{$type}->{$chksta} = 1;
  166.                         } # Counting
  167.                 }
  168.         }
  169.         close(IN);
  170. }

  171. sub checktypeofurl(){

  172.     my ( $url, $conf ) = @_; # Peference the variable, Please look for line 154.
  173.     my $ret = 3; # return 3 while the url can not be match

  174.         if ( $url =~/mms\.smartone.*|mms2\.smartone.*|mms4\.smartone.*|mms9\.smartone.*|disc1\.smartone\-vodafone\.com|202\.140\.96\.(?=92|208|46|97|227|47).+|10\.16\.96\.(?=76|79|93|94|187|188|180|137|167).+|202\.140\.106\.64/i ) {
  175.             $ret = 1;
  176.     } elsif ( $url =~/.*\.smartone\.com\.hk|.*\.smartone\-vodafone\.com\.hk|.*\.smartone\-vodafone\.com|202\.140\.(?=86\.+|96\.+|106\.+|93\.+|83\.+|76\.+|74\.+|100\.+|104\.+)/i ) {
  177.             $ret = 0;
  178.     } else {
  179.                
  180.                 foreach my $key (keys %{$conf}) { # return 2 while if find url in config file. Please look for line 55.
  181.                     my $hash = $conf->{$key};
  182.                    
  183.                         if ( $url =~/http\:\/\/$key/ ) {
  184.                                
  185.                                 for my $key2 ( keys %{$hash} ) {
  186.                                     
  187.                                         if ( $url =~/$key2/ ) {
  188.                                                 $ret = 2;
  189.                                        
  190.                                         }

  191.                                 }

  192.                     }
  193.                 }
  194.         }
  195.         return $ret;
  196. }

  197. sub checkDuration() {

  198.     my $duration = shift;  # Peference the variable, Please look for line 160.
  199.     my $durms;
  200.     my $ret;

  201.     if ( $duration=~/(\d+)/ ) { # $1 Units is millisecond;
  202.                 $durms = sprintf("%f", $1 / 1000); # change units to second, the question is it will rounding
  203.                 $durms =~s/(\d+)\.\d+/$1/; # Retaining only the integer

  204.                 if ( $durms < 2 ) {
  205.                         $ret = 0;
  206.                 } elsif ( $durms < 5 ) {
  207.                         $ret = 1;
  208.                 } elsif ( $durms < 10 ) {
  209.                         $ret = 2;
  210.                 } elsif ( $durms < 20 ) {
  211.                         $ret = 3;
  212.                 } elsif ( $durms >= 20 ) {
  213.                         $ret = 4;
  214.                 }
  215.     }
  216.     return $ret;
  217. }

  218. sub checkStatus() {

  219.     my ($ty,$hash) = @_; # Peference the variable, Please look for line 157.
  220.     my $code;
  221.     my $letter;
  222.     my $codeinfo;

  223.     my $sta = $hash->{"returnCode"} || $hash->{"STATUS"}; # $sta can equal $hash->{"returnCode"} or $hash->{"STATUS"}
  224.         my $stainfo = $hash->{"STATUSCODE"};
  225.     my $size = $hash->{"contentSizeFromTerminal"};

  226.         if ( $sta =~/^(\d{3})\s(.*)/) {

  227.             $code = $1;
  228.             $codeinfo =$2;

  229.             if ( $ty == 1 ) { # if type equal MMS, Please look for line 156.
  230.                         if ($code == 500) {
  231.                                 if ( hex($size) < 54 ) {
  232.                                         $codeinfo = "read reply to null recipient";
  233.                                 }
  234.                         }
  235.             }

  236.             if ($codeinfo=~/^\W.*/) {
  237.                         $codeinfo = $code." url link";

  238.             } else {

  239.                         $letter = lc($codeinfo);
  240.                         $letter =~s/\s+$//g;
  241.                         $letter=~s/(?<=\b|^)(\w)/\u$&/g; # the first letters change Capital.
  242.                         $codeinfo = $code." ".$letter;

  243.             }

  244.     } elsif ( $sta =~/^(\d{3})/ ) {
  245.             $code = $1;

  246.                 if ( $stainfo =~/(.*)/i ) {
  247.                         $letter = lc($1);
  248.                        
  249.                         if ($letter =~/^\W.*/) {
  250.                                 $letter = "url link";
  251.                         }
  252.             
  253.                         $letter =~s/\s+$//g;
  254.                         $letter=~s/(?<=\b|^)(\w)/\u$&/g; # the first letters change Capital.
  255.                         $codeinfo = $code." ".$letter;
  256.                 }

  257.     }
  258.     return $codeinfo;
  259. }

  260. sub duratonclassbystatus(){
  261.        
  262.     my ($sta, $tab, $hash,$dir,$start,$end,$type,$ysdate,$error_dir) = @_; # Peference the variable, Please look for line 161.
  263.         my $ret; # return var
  264.        
  265.         if ( $sta < 400 ) {
  266.                 $ret = 0;
  267.        
  268.         } else {
  269.                 $ret = 1;
  270.                 &exporterrorcase($hash,$dir,$type,$ysdate,$start,$end,$error_dir); # generate the error report.

  271.         }
  272.         return $ret;
  273. }

  274. sub exporterrorcase(){

  275.     my ($hash,$dir,$ty,$ysdate,$start,$end,$error_dir) = @_; # Peference the variable, Please look for line 321.
  276.     my $sta = $hash->{"returncode"} || $hash->{"STATUS"};
  277.     my $typecdr=(split(/\//, $dir))[-1];
  278.         my $errname = "";

  279.         if ( $ty == 0 ) {
  280.                 $errname = "error_".$typecdr."_smtin".$ysdate;
  281.         } elsif ( $ty == 1 ) {
  282.                 $errname = "error_".$typecdr."_mms".$ysdate;
  283.         } elsif ( $ty == 2 ) {
  284.                 $errname = "error_".$typecdr."_cp".$ysdate;
  285.         } elsif ( $ty == 3 ) {
  286.                 $errname = "error_".$typecdr."_iom".$ysdate;
  287.         }
  288.    
  289.         if ( !open (OUT,">>$error_dir/$errname" ) ) { die("Can not write the error file $errname:$!"); }
  290.         print OUT $start."\n";
  291.    
  292.         foreach (keys %{$hash}) {
  293.                 print OUT "\"".$_."\" = \"".$hash->{$_}."\"\n";
  294.     }
  295.    
  296.         print OUT $end."\n";
  297.        
  298.         close(OUT);
  299. }

  300. sub printhtmlreporttable(){
  301.        
  302.         my ($durtab,$statab,$notab,$dir) = @_; # Peference the variable, Please look for line 31.
  303.        
  304.         my $smnto = 0; # number of smtin total
  305.         my $mmsto = 0; # number of mms total
  306.         my $cpsto = 0; # number of cp total
  307.         my $iomto = 0; # number of iom total
  308.         my $percg = 0; # Calculating the percentage
  309.         my $typne = ""; # type of the name
  310.         my @perto = (0 .. 3); # array of total

  311.         my @type = sort keys %{$statab};
  312.        
  313.         for my $t (@type) {

  314.                 for my $c ( 0 , 1 ) {
  315.                
  316.                         for my $d ( 0 .. 4 ) {
  317.                        
  318.                                 if ( $t == 0 ) {
  319.                                         $smnto = $durtab->[$t]->[$c]->[$d] + $smnto;
  320.                                 } elsif ( $t == 1 ) {
  321.                                         $mmsto = $durtab->[$t]->[$c]->[$d] + $mmsto;
  322.                                 } elsif ( $t == 2 ) {
  323.                                         $cpsto = $durtab->[$t]->[$c]->[$d] + $cpsto;
  324.                                 } elsif ( $t == 3 ) {
  325.                                         $iomto = $durtab->[$t]->[$c]->[$d] + $iomto;
  326.                                 }
  327.                        
  328.                         }

  329.                 }

  330.         }
  331.         my @total = ($smnto,$mmsto,$cpsto,$iomto); # the diff total
  332.        
  333.         for my $n (@perto){
  334.                 $perto[$n] = 0;
  335.         } # initiatize the $perto[$n] = 0;
  336.        
  337.         # ------------------------------- html ------------------------------
  338.         print "<html>";
  339.        
  340.         # ------- head ---------
  341.         print "<head>";
  342.         print "<title>Percentage Report </title>";
  343.         print "<style type=text/css>";
  344.         print 'table {background-color: #000000;}';
  345.         print 'td {background-color: #FFFFFF;text-align:center; font size=10pt ;font fac=Arial}';
  346.         print 'th {background-color: #FFFFFF;text-align:center; font size=10pt ;font fac=Arial}';
  347.         print "</style>";
  348.         print "</head>";
  349.         # ------- head ---------

  350.         # ------- body ---------
  351.         print "<body>";
  352.         print "<center>";
  353.         print "<table border='0' cellspacing='1' width='65%'>";
  354.        
  355.         for my $t (@type) {
  356.                
  357.                 $typne = "SmarToneiN" if $t == 0;       
  358.                 $typne = "MMS" if $t == 1;
  359.                 $typne = "CP" if $t == 2;
  360.                 $typne = "IOM" if $t == 3;
  361.                
  362.                 my $distp = 1; # as a distinction between success or failure of the temporary
  363.                 my $sucto = 0; # number of sucessfull total
  364.                 my $faito = 0; # number of failure total
  365.                
  366.                 print "<tr><th colspan='3'><p align='center'><b>$typne</b></th></tr>";
  367.                 print "<tr><th colspan='3'><p align='left'><b>Successful Status</b></th></tr>";
  368.                 foreach my $status (sort keys %{$statab->{$t}} ) {
  369.                         $percg = sprintf("%.2f",$statab->{$t}->{$status} / $total[$t] * 100).'%';
  370.                         my $cutst = (split / +/,$status)[0]; # split of the first part as a judge to of success or failure;
  371.                                
  372.                         if ( $cutst < 400 ) {
  373.                                 $sucto = $statab->{$t}->{$status} + $sucto;
  374.                                 print "<tr><td width='50%'><p align='left'>$status</td><td width='30%'><p align='center'>$statab->{$t}->{$status}</td><td width='20%'><p align='center'>$percg</td>";
  375.                                
  376.                         } else {
  377.                                        
  378.                                 if ( $t != 1  ) {
  379.                                         print "<tr><th colspan='3'><p align='left'>&nbsp;</th></tr><tr><th colspan='3'><p align='left'><b>Failed Status (Not including the fail case of favicon.ico and Microsoft-Server-ActiveSync)</b></th></tr>" if $distp == 1;  
  380.                                 } else {
  381.                                         print "<tr><th colspan='3'><p align='left'>&nbsp;</th></tr><tr><th colspan='3'><p align='left'><b>Failed Status</b></th></tr>" if $distp == 1;
  382.                                 }

  383.                                 $faito =  $statab->{$t}->{$status} + $faito;
  384.                                 print "<tr><td width='50%'><p align='left'>$status</td><td width='30%'><p align='center'>$statab->{$t}->{$status}</td><td width='20%'><p align='center'>$percg</td></tr>";
  385.                                 $distp = 2;

  386.                         }
  387.                                
  388.                 }
  389.                
  390.                 for my $c ( 0 , 1 ) {
  391.                        
  392.                         print "<tr><th colspan='3'><p align='left'>&nbsp;</th></tr><tr><th colspan='3'><p align='left'><b>Duration (Success)</b></th></tr>" if $c ==0;
  393.                         print "<tr><th colspan='3'><p align='left'>&nbsp;</th></tr><tr><th colspan='3'><p align='left'><b>Duration (Fail)</b></th></tr>" if $c ==1;
  394.                
  395.                         for my $d ( 0 .. 4 ) {
  396.                                 print "<tr><td width='50%'><p align='left'>Duration 0s - 2s</td>" if $d == 0;
  397.                                 print "<tr><td width='50%'><p align='left'>Duration 2s - 5s</td>" if $d == 1;
  398.                                 print "<tr><td width='50%'><p align='left'>Duration 5s - 10s</td>" if $d == 2;
  399.                                 print "<tr><td width='50%'><p align='left'>Duration 10s - 20s</td>" if $d == 3;
  400.                                 print "<tr><td width='50%'><p align='left'>Duration 20 +s</td>" if $d == 4;
  401.                                 $percg = sprintf("%.2f",$durtab->[$t]->[$c]->[$d] / $total[$t] * 100).'%';
  402.                                 print "<td width='30%'><p align='center'>$durtab->[$t]->[$c]->[$d]</td><td width='20%'><p align='center'>$percg</td></tr>";
  403.                         }

  404.                 }

  405.                 $perto[0] = sprintf("%.2f",$sucto / $total[$t] * 100).'%';
  406.                 $perto[1] = sprintf("%.2f",$faito / $total[$t] * 100).'%';
  407.                 $perto[2] = sprintf("%.2f",$notab->[$t]->[0] / $total[$t] * 100).'%';
  408.                 $perto[3] = sprintf("%.2f",$notab->[$t]->[1] / $total[$t] * 100).'%';
  409.                
  410.                 print "<tr><th colspan='3'><p align='left'>&nbsp;</th></tr><tr><td width='50%'><p align='left'><b>$typne Total Successful</b></td><td width='30%'><p align='center'>$sucto</td><td width='20%'><p align='center'>$perto[0]</td></tr>";
  411.                 print "<tr><td width='50%'><p align='left'><b>$typne Total Failed</b></td><td width='30%'><p align='center'>$faito</td><td width='20%'><p align='center'>$perto[1]</td></tr>";
  412.                 if ( $t != 1 ) {
  413.                         print "<tr><td width='50%'><p align='left'><b>$typne Total favicon.ico</b></td><td width='30%'><p align='center'>$notab->[$t]->[0]</td><td width='20%'><p align='center'>$perto[2]</td></tr>";
  414.                         print "<tr><td width='50%'><p align='left'><b>$typne Total Microsoft-Server-ActiveSync</b></td><td width='30%'><p align='center'>$notab->[$t]->[1]</td><td width='20%'><p align='center'>$perto[3]</td></tr>";
  415.                 }
  416.                 print "<tr><td width='50%'><p align='left'><b>$typne Total</b></td><td width='30%'><p align='center'>$total[$t]</td><td width='20%'><p align='center'>&nbsp;</td></tr>";
  417.        
  418.         }
  419.         print "</center></body>";
  420.         # ------- body ---------
  421.        
  422.         print "</html>";
  423.         # ------------------------------- html ------------------------------
  424.        
  425.         @type = ();
  426.         @perto = ();       
  427. }

复制代码

[ 本帖最后由 hyoryeo 于 2009-10-28 17:59 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2009-10-28 17:45 |只看该作者
没看到程序哦。。
你的目的是什么呢?原始数据是什么呢?

论坛徽章:
0
6 [报告]
发表于 2009-10-28 17:50 |只看该作者
原帖由 兰花仙子 于 2009-10-28 17:45 发表
没看到程序哦。。
你的目的是什么呢?原始数据是什么呢?


有点慢...放上去了...目的是对LOG中的内容做Report...

Record (35011) "MiepPullWtdr"
"wtdrId" = "672315464"
"httpMethod" = "POST"
"uaIdentificationString" = "SonyEricssonW890i/R1EA"
"returnCode" = "500 Internal Server Error"
"destinationIPAddress" = "202.140.96.190"
"imsi" = "454061101100000"
"timeStamp" = "20091027135700"
"contentSizeFromTerminal" = "32"
"authentication" = "0"
"dialledDigit" = "PICM"
"nasIPAddress" = "10.30.7.9"
"radioAccessType" = "1"
"url" = "http://mms.smartone-vodafone.com/server"
"acctAuthentication" = "1"
"apn" = "smartone-vodafone"
"chargingCharacteristics" = "0800"
"networkAccessType" = "GPRS"
"nasIdentifier" = "ggsn02"
"urlDurationTime" = "0"
"eventStatus" = "0"
"contentSizeToTerminal" = "01B9"
"e164OfAccessServer" = "smartone-vodafone"
"chargingId" = "837703948"
"msisdn" = "85261101403"
"acctSessionId" = "CB4E2E2231EE590C"
"sgsnIPAdress" = "203.78.46.9"
"bearerType" = "0"
"sourceIPAddress" = "10.73.13.208"
"stackConfig" = "4"
"recordingEntity" = "MIEP"
End of Record (35011)




Record (288419) "MiepPullWtdr"
"uaIdentificationString" = "iPhoneOS/3.0.1 (7A400) "
"sysid" = "zproxy3-80"
"STATUS" = "500"
"downlink" = "85"
"imsi" = "454061101200000"
"timeStamp" = "20091027192642"
"contentSizeFromTerminal" = "26"
"dialledDigit" = "Inet_browsing(unknown)(HTTP1)"
"radioAccessType" = "1"
"url" = "http://mms.smartone-vodafone/server"
"apn" = "smartone-vodafone"
"networkAccessType" = ""
"uplink" = "38"
"urlDurationTime" = "9"
"contentSizeToTerminal" = "55"
"chargingId" = "258769907"
"msisdn" = "85293127155"
"sourceIPAddress" = "10.52.102.70"
"sgsnIPAdress" = "203.78.47.9"
"STATUSCODE" = "Can't connect to mms.smartone-vodafone:80 (Bad hostname 'mms.sma
rtone-vodafone')"
End of Record (288419)

两种类型

论坛徽章:
0
7 [报告]
发表于 2009-10-28 18:01 |只看该作者
oops....MM偶帮不了你了,太长了。

总之,我的意思是,比如你要创建任何数据结构,直接来就行,不用预分配空间。

比如:

# perl -MData::Dumper -e 'my @x; $x[0][1] = 1; print Dumper \@x'
$VAR1 = [
          [
            undef,
            1
          ]
        ];

看到没?你直接赋值就行,一个AoA就创建好了。
hash也一样,如:

# perl -MData::Dumper -e 'my %x; $x{'ip'}->{'point'} = 1; print Dumper \%x'
$VAR1 = {
          'ip' => {
                    'point' => 1
                  }
        };

虽然只赋值了一次,但是一个HoH就自动产生了。

论坛徽章:
0
8 [报告]
发表于 2009-10-28 18:12 |只看该作者
原帖由 兰花仙子 于 2009-10-28 18:01 发表
oops....MM偶帮不了你了,太长了。

总之,我的意思是,比如你要创建任何数据结构,直接来就行,不用预分配空间。

比如:

# perl -MData:umper -e 'my @x; $x[0][1] = 1; print Dumper \@x'
$VAR1 = ...



嗯..其实我不太会用Data:umper,之前看了一下不太敢用,我再去看看关于Data:umper

论坛徽章:
0
9 [报告]
发表于 2009-10-28 18:15 |只看该作者
原帖由 hyoryeo 于 2009-10-28 18:12 发表



嗯..其实我不太会用Data:umper,之前看了一下不太敢用,我再去看看关于Data:umper


它没什么,只是Dump出数据结构给你参考。

论坛徽章:
0
10 [报告]
发表于 2009-10-28 18:54 |只看该作者
给你一个link,perl的数据结构:http://www.pgsqldb.org/mwiki/index.php/DataStructures
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP