+ -
当前位置:首页 → 问答吧 → map中如何实现正则替换

map中如何实现正则替换

时间:2011-02-10

来源:互联网

比如
  1. @list=qw(perl5,php5);

  2. print "@list";
  3. @list=map {s/5/6/ } @list;
  4. print "@list";
复制代码
我要把列表中5替换成6  如果写成
  1. @list=qw(perl5,php5);

  2. print "@list";
  3. @list=map {s/5/6/,$_ } @list;
  4. print "@list";
复制代码
又会多出来数字

作者: yakczh   发布时间: 2011-02-10

本帖最后由 jason680 于 2011-02-10 17:58 编辑


QUOTE:
比如我要把列表中5替换成6  如果写成又会多出来数字
yakczh 发表于 2011-02-10 17:35



你的code是不是弄错了...

  1. @list=(perl5,php5);

  2. print "@list\n";
  3. map {s/5/6/ } @list; #或 s/5/6/ for @list;
  4. print "@list\n";
复制代码


@list=qw(perl5,php5);
改成
@list=(perl5,php5);

@list=qw(perl5 php5);

作者: jason680   发布时间: 2011-02-10