erlang 关于表达式的不同用法。

看下边的例子,对于不同的表达式,可以用不同的方法去实现,代码可以体会到里边有的不同。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
filter2( Line )->
   Num = re:run(Line, "[0-9]{6}", [{capture,first,list}]),
   if
      Num /= nomatch ->
         {A,[B]} = Num,
         F = string:substr(B,1,1),
         if
            F =:= "0"; F =:= "3"; F =:= "6"->
               B;
         true->
            false
         end;
      true->
         false
   end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
getvalue(Key,B) when Key =:= "0"; Key =:= "6"; Key =:= "3"->
   B;
getvalue(_,_)->
   false.

filter3( Line )->
   case re:run(Line, "[0-9]{6}", [{capture,first,list}]) of
      nomatch->
         false;
      Value ->
         {A,[B]} = Value,
         getvalue( string:left( B, 1 ), B )
   end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
getvalue2(Key,B) when Key =:= "0"; Key =:= "6"; Key =:= "3"->
   B;
getvalue2(_,_)->
   false.

guard( A ) when A =:= nomatch->
   false;
guard( {A, [B] } )->
   getvalue2( string:left( B, 1 ), B ).

filter4( Line )->
   Ret = re:run(Line, "[0-9]{6}", [{capture,first,list}]),
   guard( Ret ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

state(X) when X =:= false->
      false;
state(_) ->
      true.

test8()->
   Array = ["fafds","ac002345ae","afsaf600123", "abcef300425"],
   Ssa = [ filter2(Item) || Item <- Array, filter2(Item) /= false ],
   Ssb = [ filter3(Item) || Item <- Array, filter3(Item) /= false ],
   Ssc = [ filter4(Item) || Item <- Array, filter4(Item) /= false ],

   Fun = fun(X)->
   if
      X =:= false->
         false;
      true->
         true
   end
         end,

   Ls2 = lists:filter( Fun, Ssa ),
   Ls = lists:filter( state, Ssa ),
   A = 1.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值