码迷,mamicode.com
首页 > 其他好文 > 详细

小时代5-perl对文件按列排序

时间:2014-09-15 17:10:29      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   ar   for   文件   数据   div   

perl中经常有会遇到处理CSV格式的文件,这样的文件类似二维数组,因此实际上的操作时对二维数组的操作了。
对这样的行列表格,我们常常需要按照某列,或者先按照某列,再按另一列进行排序,具体的操作可以看一下下面的实现:

  1.  
  2. #!/usr/bin/perl
  3. my @line;
  4. while(<>)
  5. {
  6.   chomp;
  7.   push @line, [ split ];
  8. }
  9. foreach ( sort { $a->[0] <=> $b->[0] or $a->[1] <=> $b->[1] or $a->[2] <=> $b->[2] } @line)
  10. {
  11.   print @$_, "n";
  12. }

注意:
对于大的文件,最好不要这么用。
该脚本会把数据全部搬到内存。

www.bbilo.com/gbdfzmzc
www.bbilo.com/gbdfbjl
www.bbilo.com/gbdfylyq
www.bbilo.com/mdgbdfrqrh
www.bbilo.com/gbdfmdyjm
www.bbilo.com/mdgbdfaqm
www.bbilo.com/gbdfkmdl
www.bbilo.com/gbdfxwz
www.bbilo.com/gbdfwtzx
www.bbilo.com/gbdfdms
www.bbilo.com/gbdfzc
www.bbilo.com/gbdfsy
www.bbilo.com/gbdfwzx
www.bbilo.com/gbdfnyqb
www.bbilo.com/gbdfzj
www.bbilo.com/gbdfdz
www.jdcvv.com/gbdfylw
www.jdcvv.com/gbdf
www.jdcvv.com/gbdfkh
www.jdcvv.com/gbdfyl
www.jdcvv.com/gbdfhykh
www.jdcvv.com/1659988_comgbdf
www.jdcvv.com/gbdfshy
www.jdcvv.com/gbdfgw
www.jdcvv.com/gbdfwt
www.jdcvv.com/gbdfylc
www.jdcvv.com/gbdfdl
www.jdcvv.com/gbdfxc
www.jdcvv.com/gbdfyldl
www.jdcvv.com/gbdfylkh
www.jdcvv.com/gggbdfylc
www.jdcvv.com/gbdfsjzmdl
www.jdcvv.com/gbdfzmnyq
www.jdcvv.com/gbdfyj
www.jdcvv.com/gbdfxmf
www.jdcvv.com/szdmdgbdf
www.jdcvv.com/mdgbdf
www.jdcvv.com/gbdfdlkh
www.jdcvv.com/gbdfkh1581260
www.jdcvv.com/gbdfylhbwz
www.jdcvv.com/gbdfyq
www.jdcvv.com/sygbdfyl
www.jdcvv.com/gbdfylzmyq
www.jdcvv.com/gbdfylyflm
www.jdcvv.com/gbdfylcznl
www.jdcvv.com/gbdfwz
www.jdcvv.com/gbdftz
www.jdcvv.com/gbdfdh
www.jdcvv.com/gbdfsj
www.jdcvv.com/gggbdf
www.jdcvv.com/gbdfgfw
www.jdcvv.com/gbdfkhw
www.jdcvv.com/gbdfsh
www.jdcvv.com/gbdfsjxz
www.jdcvv.com/gbdfylsjxz
www.jdcvv.com/gbdfwfm
www.jdcvv.com/gbdfdtkh
www.jdcvv.com/gbdfhy
www.jdcvv.com/gbdfrhkh
www.jdcvv.com/gbdfzdl
www.jdcvv.com/gbdfw
www.jdcvv.com/gbdfdtkmdl
www.jdcvv.com/gbdfglw
www.jdcvv.com/gbdfxjw
www.jdcvv.com/gbdfwtkhzx
www.jdcvv.com/gbdfwtdhkh
www.jdcvv.com/gbdfwkh
www.jdcvv.com/gbdfwthykh
www.jdcvv.com/gbdftgy
www.jdcvv.com/gbdfylwz
www.jdcvv.com/gbdfzmzc
www.jdcvv.com/gbdfbjl
www.jdcvv.com/gbdfylyq
www.jdcvv.com/mdgbdfrqrh
www.jdcvv.com/gbdfmdyjm
www.jdcvv.com/mdgbdfaqm
www.jdcvv.com/gbdfkmdl
www.jdcvv.com/gbdfxwz
www.jdcvv.com/gbdfwtzx
www.jdcvv.com/gbdfdms
www.jdcvv.com/gbdfzc
www.jdcvv.com/gbdfsy
www.jdcvv.com/gbdfwzx
www.jdcvv.com/gbdfzj
www.jdcvv.com/gbdfdz
www.vqjqu.com/gbdf
www.vqjqu.com/gbdfkh
www.vqjqu.com/gbdfylw
www.vqjqu.com/gbdfyl
www.vqjqu.com/gbdfhykh
www.vqjqu.com/1659988_comgbdf
www.vqjqu.com/gbdfdhtz
www.vqjqu.com/gbdfylpt
www.vqjqu.com/gbdfshy
www.vqjqu.com/gbdfzxkh
www.vqjqu.com/gbdfgw
www.vqjqu.com/gbdfwt
www.vqjqu.com/gbdfylc
www.vqjqu.com/gbdfdl
www.vqjqu.com/gbdfxc
www.vqjqu.com/gbdfyldl
www.vqjqu.com/gbdfkhbl
www.vqjqu.com/gbdfylkh
www.vqjqu.com/gbylgbdf
www.vqjqu.com/gggbdfylc
www.vqjqu.com/gbdfsjzmdl
www.vqjqu.com/gbdfylfl
www.vqjqu.com/gbdfzmnyq
www.vqjqu.com/gbdfyj
www.vqjqu.com/gbdfxmf
www.vqjqu.com/szdmdgbdf
www.vqjqu.com/mdgbdf
www.vqjqu.com/gbdfdhkh
www.vqjqu.com/gbdfdlkh
www.vqjqu.com/gbdfwtkh
www.vqjqu.com/gbdfkh1581260
www.vqjqu.com/gbdfylhbwz
www.vqjqu.com/gbdfyq
www.vqjqu.com/sygbdfyl
www.vqjqu.com/gbdfylzmyq
www.vqjqu.com/gbdfylyflm
www.vqjqu.com/gbdfylcznl
www.vqjqu.com/gbdfwz
www.vqjqu.com/gbdftz
www.vqjqu.com/gbdfdh
www.vqjqu.com/gbdfsj
www.vqjqu.com/gggbdf
www.vqjqu.com/gbdfgfw
www.vqjqu.com/gbdfkhw
www.vqjqu.com/gbdfsh
www.vqjqu.com/gbdfylsjxz
www.vqjqu.com/gbdfwfm
www.vqjqu.com/gbdfhy
www.vqjqu.com/gbdfzdl
www.vqjqu.com/gbdfw
www.vqjqu.com/gbdfdtkmdl
www.vqjqu.com/gbdfglw
www.vqjqu.com/gbdfxjw
www.vqjqu.com/gbdfwtkhzx
www.vqjqu.com/gbdfwtdhkh
www.vqjqu.com/gbdfwkh
www.vqjqu.com/gbdfwthykh
www.vqjqu.com/gbdftgy
www.vqjqu.com/gbdfylwz
www.vqjqu.com/gbdfzmzc
www.vqjqu.com/gbdfbjl
www.vqjqu.com/gbdfylyq
www.vqjqu.com/mdgbdfrqrh
www.vqjqu.com/gbdfmdyjm
www.vqjqu.com/mdgbdfaqm
www.vqjqu.com/gbdfkmdl
www.vqjqu.com/gbdfxwz
www.vqjqu.com/gbdfwtzx
www.vqjqu.com/gbdfdms
www.vqjqu.com/gbdfzc
www.vqjqu.com/gbdfsy
www.vqjqu.com/gbdfwzx
www.vqjqu.com/gbdfnyqb
www.vqjqu.com/gbdfzj
www.vqjqu.com/gbdfdz
www.ecbga.com/gbdf
www.ecbga.com/gbdfkh
www.ecbga.com/gbdfylw
www.ecbga.com/gbdfyl
www.ecbga.com/gbdfhykh
www.ecbga.com/1659988_comgbdf
www.ecbga.com/gbdfdhtz
www.ecbga.com/gbdfylpt
www.ecbga.com/gbdfshy
www.ecbga.com/gbdfzxkh
www.ecbga.com/gbdfgw
www.ecbga.com/gbdfwt
www.ecbga.com/gbdfylc
www.ecbga.com/gbdfdl
www.ecbga.com/gbdfxc
www.ecbga.com/gbdfyldl
www.ecbga.com/gbdfkhbl
www.ecbga.com/gbdfylkh
www.ecbga.com/gbylgbdf
www.ecbga.com/gggbdfylc
www.ecbga.com/gbdfsjzmdl
www.ecbga.com/gbdfylfl
www.ecbga.com/gbdfzmnyq
www.ecbga.com/gbdfyj
www.ecbga.com/gbdfxmf
www.ecbga.com/szdmdgbdf
www.ecbga.com/mdgbdf
www.ecbga.com/gbdfdhkh
www.ecbga.com/gbdfdlkh
www.ecbga.com/gbdfwtkh
www.ecbga.com/gbdfkh1581260
www.ecbga.com/gbdfylhbwz
www.ecbga.com/gbdfyq
www.ecbga.com/sygbdfyl
www.ecbga.com/gbdfylzmyq
www.ecbga.com/gbdfylyflm
www.ecbga.com/gbdfylcznl
www.ecbga.com/gbdfwz
www.ecbga.com/gbdftz
www.ecbga.com/gbdfdh
www.ecbga.com/gbdfsj
www.ecbga.com/gggbdf
www.ecbga.com/gbdfgfw
www.ecbga.com/gbdfkhw
www.ecbga.com/gbdfsh
www.ecbga.com/gbdfylsjxz
www.ecbga.com/gbdfwfm
www.ecbga.com/gbdfdtkh
www.ecbga.com/gbdfhy
www.ecbga.com/gbdfrhkh
www.ecbga.com/gbdfzdl
www.ecbga.com/gbdfw
www.ecbga.com/gbdfdtkmdl
www.ecbga.com/gbdfglw
www.ecbga.com/gbdfxjw
www.ecbga.com/gbdfwtkhzx
www.ecbga.com/gbdfwtdhkh
www.ecbga.com/gbdfwkh
www.ecbga.com/gbdfwthykh
www.ecbga.com/gbdftgy
www.ecbga.com/gbdfylwz
www.ecbga.com/gbdfzmzc
www.ecbga.com/gbdfbjl
www.ecbga.com/gbdfylyq
www.ecbga.com/mdgbdfrqrh
www.ecbga.com/gbdfmdyjm
www.ecbga.com/mdgbdfaqm
www.ecbga.com/gbdfkmdl
www.ecbga.com/gbdfxwz
www.ecbga.com/gbdfwtzx
www.ecbga.com/gbdfdms
www.ecbga.com/gbdfzc
www.ecbga.com/gbdfsy
www.ecbga.com/gbdfwzx
www.ecbga.com/gbdfnyqb
www.ecbga.com/gbdfzj
www.ecbga.com/gbdfdz
www.urukw.com/gbdf
www.urukw.com/gbdfkh
www.urukw.com/gbdfylw
www.urukw.com/gbdfyl
www.urukw.com/gbdfhykh
www.urukw.com/1659988_comgbdf
www.urukw.com/gbdfdhtz
www.urukw.com/gbdfylpt
www.urukw.com/gbdfshy
www.urukw.com/gbdfzxkh
www.urukw.com/gbdfgw
www.urukw.com/gbdfwt
www.urukw.com/gbdfylc
www.urukw.com/gbdfdl
www.urukw.com/gbdfxc

 

小时代5-perl对文件按列排序

标签:style   blog   http   color   ar   for   文件   数据   div   

原文地址:http://www.cnblogs.com/perl2014/p/3972957.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!