[erlang-questions] Basic Erlang case question

Hynek Vychodil vychodil.hynek@REDACTED
Thu Jul 10 10:55:31 CEST 2008


It is only warning. You must be sure that all your branches bound variable
or in very rare case you know what you are doing.

On Thu, Jul 10, 2008 at 10:41 AM, Alexander Lamb
<alexander.lamb@REDACTED> wrote:

> Hello List,
>
> Here is a very simple code to search if a supplied password is correct
> or not:
>
>                                F1 = fun() -> mnesia:match_object(systems,
> #system_info{full_attribute = {System_Name,admin_password}, _ = '_'},
> read) end,
>                                case Password of
>                                        [] -> MD5_Password = [];
>                                        _Any -> MD5_Password =
> erlang:md5(Password)
>                                end,


% It will remove warning message.
MD5_Password = case Password of
      [] -> [];
      _ -> erlang:md5(Password)
   end,

>
>                                case mnesia:transaction(F1) of
>                                        {atomic, []}
>                                      -> {error, unknown_system};
>                                        {atomic, [#system_info{data =
> MD5_Password}]} -> {ok, password};
>                                        {atomic, _}
>                                               -> {error, bad_password};
>                                        {aborted, Reason}
>                                       -> {error, Reason}
>                                end
>
>
>
> Basically, if supplied Password is empty, the MD5_Password must be
> empty. If not, I encrypt the Password to compare it with stored version.
>
> My problem is that it compiles with a warning:
>
> ./cs_systems.erl:173: Warning: variable 'MD5_Password' exported from
> 'case' (line 167)
>
> Why? Obviously I am trying to match the password in the record I found
> with the password I supply.
>
> Thanks,
>
> Alex
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080710/83c4cd34/attachment.htm>


More information about the erlang-questions mailing list