Quantcast

help me to read proper input from commandline erl

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

help me to read proper input from commandline erl

PONMUTHU.M
This post has NOT been accepted by the mailing list yet.
hi all,

      while get runtime command prompt variable via init:get_argument(name).


    i want to get a list . but in that " " are added while getting & assign to a varaible


% erl -mylist [1,2,3,4]

> {ok,[[List|_]|_]} = init:get_argument(mylist).
{ok,[["[1,2,3,4]"]]}
>List.
"[1,2,3,4]"



but expecting O/p as

>List.
[1,2,3,4]


please help , because of this double qutoes am not able to do Head & Tail .
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

help me to read proper input from commandline erl

Bengt Kleberg-4
Greetings,

What is the command line?
(Ex: erl -mylist 1 2 3 4, or erl -mylist "1,2,3,4" or ?).


bengt

On Fri, 2014-02-21 at 03:05 -0800, PONMUTHU.M wrote:

> hi all,
>
>       while get runtime command prompt variable via init:get_argument(name).
>
>
>     i want to get a list . but in that " " are added while getting & assign
> to a varaible
>
>
> % erl -mylist [1,2,3,4]
>
> > {ok,[[List|_]|_]} = init:get_argument(mylist).
> {ok,[["[1,2,3,4]"]]}
> >List.
> "[1,2,3,4]"
>
>
>
> but expecting O/p as
>
> >List.
> [1,2,3,4]
>
>
> please help , because of this double qutoes am not able to do Head & Tail .
>
>
>
>
> --
> View this message in context: http://erlang.2086793.n4.nabble.com/help-me-to-read-proper-input-from-commandline-erl-tp4655367.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

help me to read proper input from commandline erl

Matthew Evans
In reply to this post by PONMUTHU.M
Not sure if there's another way...
List = "[1,2,3,4]".                                    
{ok,T,_} = erl_scan:string(String++".").
{ok,A} = erl_parse:parse_exprs(T).      
{value,Value,_} = erl_eval:exprs(A, erl_eval:new_bindings()).
Value.[1,2,3,4]

> Date: Fri, 21 Feb 2014 03:05:53 -0800
> From: ponmuthu.m
> To: erlang-questions
> Subject: [erlang-questions] help me to read proper input from commandline erl
>
> hi all,
>
>       while get runtime command prompt variable via init:get_argument(name).
>
>
>     i want to get a list . but in that " " are added while getting & assign
> to a varaible
>
>
> % erl -mylist [1,2,3,4]
>
> > {ok,[[List|_]|_]} = init:get_argument(mylist).
> {ok,[["[1,2,3,4]"]]}
> >List.
> "[1,2,3,4]"
>
>
>
> but expecting O/p as
>
> >List.
> [1,2,3,4]
>
>
> please help , because of this double qutoes am not able to do Head & Tail .
>
>
>
>
> --
> View this message in context: http://erlang.2086793.n4.nabble.com/help-me-to-read-proper-input-from-commandline-erl-tp4655367.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions
     
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140221/73dbf2c6/attachment.html>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

help me to read proper input from commandline erl

Fred Youhanaie
A shorter alternative, though only by just one step, is to use erl_parse:parse_term(T) instead of parse_exprs and erl_eval:exprs.

So the steps after the "erl -mylist [1,2,3]." command is
(note the dot at the end of the argument)

{ok, [[Arg]]} = init:get_argument(mylist).
{ok, Tokens, _} = erl_scan:string(Arg).
{ok, List} = erl_parse:parse_term(Tokens).

See example in http://www.erlang.org/faq/how_do_i.html#id53476

Cheers
Fred


On 21/02/14 14:41, Matthew Evans wrote:

> Not sure if there's another way...
> List = "[1,2,3,4]".
> {ok,T,_} = erl_scan:string(String++".").
> {ok,A} = erl_parse:parse_exprs(T).
> {value,Value,_} = erl_eval:exprs(A, erl_eval:new_bindings()).
> Value.[1,2,3,4]
>
>> Date: Fri, 21 Feb 2014 03:05:53 -0800
>> From: ponmuthu.m
>> To: erlang-questions
>> Subject: [erlang-questions] help me to read proper input from commandline erl
>>
>> hi all,
>>
>>        while get runtime command prompt variable via init:get_argument(name).
>>
>>
>>      i want to get a list . but in that " " are added while getting & assign
>> to a varaible
>>
>>
>> % erl -mylist [1,2,3,4]
>>
>>> {ok,[[List|_]|_]} = init:get_argument(mylist).
>> {ok,[["[1,2,3,4]"]]}
>>> List.
>> "[1,2,3,4]"
>>
>>
>>
>> but expecting O/p as
>>
>>> List.
>> [1,2,3,4]
>>
>>
>> please help , because of this double qutoes am not able to do Head & Tail .
>>
>>
>>
>>
>> --
>> View this message in context: http://erlang.2086793.n4.nabble.com/help-me-to-read-proper-input-from-commandline-erl-tp4655367.html
>> Sent from the Erlang Questions mailing list archive at Nabble.com.
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions
>> http://erlang.org/mailman/listinfo/erlang-questions
>    
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

help me to read proper input from commandline erl

Dave Cottlehuber-2
Depending how complicated your requirements are, consider using

https://github.com/jcomellas/getopt

I'm sure there are other libraries out there, this is the only one I
had bookmarked.

On 21 February 2014 18:14, Fred Youhanaie <fly> wrote:

> A shorter alternative, though only by just one step, is to use
> erl_parse:parse_term(T) instead of parse_exprs and erl_eval:exprs.
>
> So the steps after the "erl -mylist [1,2,3]." command is
> (note the dot at the end of the argument)
>
> {ok, [[Arg]]} = init:get_argument(mylist).
> {ok, Tokens, _} = erl_scan:string(Arg).
> {ok, List} = erl_parse:parse_term(Tokens).
>
> See example in http://www.erlang.org/faq/how_do_i.html#id53476
>
> Cheers
> Fred
>
>
>
> On 21/02/14 14:41, Matthew Evans wrote:
>>
>> Not sure if there's another way...
>> List = "[1,2,3,4]".
>> {ok,T,_} = erl_scan:string(String++".").
>> {ok,A} = erl_parse:parse_exprs(T).
>> {value,Value,_} = erl_eval:exprs(A, erl_eval:new_bindings()).
>> Value.[1,2,3,4]
>>
>>> Date: Fri, 21 Feb 2014 03:05:53 -0800
>>> From: ponmuthu.m
>>> To: erlang-questions
>>> Subject: [erlang-questions] help me to read proper input from commandline
>>> erl
>>>
>>> hi all,
>>>
>>>        while get runtime command prompt variable via
>>> init:get_argument(name).
>>>
>>>
>>>      i want to get a list . but in that " " are added while getting &
>>> assign
>>> to a varaible
>>>
>>>
>>> % erl -mylist [1,2,3,4]
>>>
>>>> {ok,[[List|_]|_]} = init:get_argument(mylist).
>>>
>>> {ok,[["[1,2,3,4]"]]}
>>>>
>>>> List.
>>>
>>> "[1,2,3,4]"
>>>
>>>
>>>
>>> but expecting O/p as
>>>
>>>> List.
>>>
>>> [1,2,3,4]
>>>
>>>
>>> please help , because of this double qutoes am not able to do Head & Tail
>>> .
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://erlang.2086793.n4.nabble.com/help-me-to-read-proper-input-from-commandline-erl-tp4655367.html
>>> Sent from the Erlang Questions mailing list archive at Nabble.com.
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

help me to read proper input from commandline erl

João Neves
Docopt-erl is also pretty nice since it lets you build your command line
arguments by documenting them properly. :)

https://github.com/plux/docopt-erl

--
Jo?o Neves


2014-02-21 18:39 GMT+01:00 Dave Cottlehuber <dch>:

> Depending how complicated your requirements are, consider using
>
> https://github.com/jcomellas/getopt
>
> I'm sure there are other libraries out there, this is the only one I
> had bookmarked.
>
> On 21 February 2014 18:14, Fred Youhanaie <fly> wrote:
> > A shorter alternative, though only by just one step, is to use
> > erl_parse:parse_term(T) instead of parse_exprs and erl_eval:exprs.
> >
> > So the steps after the "erl -mylist [1,2,3]." command is
> > (note the dot at the end of the argument)
> >
> > {ok, [[Arg]]} = init:get_argument(mylist).
> > {ok, Tokens, _} = erl_scan:string(Arg).
> > {ok, List} = erl_parse:parse_term(Tokens).
> >
> > See example in http://www.erlang.org/faq/how_do_i.html#id53476
> >
> > Cheers
> > Fred
> >
> >
> >
> > On 21/02/14 14:41, Matthew Evans wrote:
> >>
> >> Not sure if there's another way...
> >> List = "[1,2,3,4]".
> >> {ok,T,_} = erl_scan:string(String++".").
> >> {ok,A} = erl_parse:parse_exprs(T).
> >> {value,Value,_} = erl_eval:exprs(A, erl_eval:new_bindings()).
> >> Value.[1,2,3,4]
> >>
> >>> Date: Fri, 21 Feb 2014 03:05:53 -0800
> >>> From: ponmuthu.m
> >>> To: erlang-questions
> >>> Subject: [erlang-questions] help me to read proper input from
> commandline
> >>> erl
> >>>
> >>> hi all,
> >>>
> >>>        while get runtime command prompt variable via
> >>> init:get_argument(name).
> >>>
> >>>
> >>>      i want to get a list . but in that " " are added while getting &
> >>> assign
> >>> to a varaible
> >>>
> >>>
> >>> % erl -mylist [1,2,3,4]
> >>>
> >>>> {ok,[[List|_]|_]} = init:get_argument(mylist).
> >>>
> >>> {ok,[["[1,2,3,4]"]]}
> >>>>
> >>>> List.
> >>>
> >>> "[1,2,3,4]"
> >>>
> >>>
> >>>
> >>> but expecting O/p as
> >>>
> >>>> List.
> >>>
> >>> [1,2,3,4]
> >>>
> >>>
> >>> please help , because of this double qutoes am not able to do Head &
> Tail
> >>> .
> >>>
> >>>
> >>>
> >>>
> >>> --
> >>> View this message in context:
> >>>
> http://erlang.2086793.n4.nabble.com/help-me-to-read-proper-input-from-commandline-erl-tp4655367.html
> >>> Sent from the Erlang Questions mailing list archive at Nabble.com.
> >>> _______________________________________________
> >>> erlang-questions mailing list
> >>> erlang-questions
> >>> http://erlang.org/mailman/listinfo/erlang-questions
> >>
> >>
> >>
> >>
> >>
> >> _______________________________________________
> >> erlang-questions mailing list
> >> erlang-questions
> >> http://erlang.org/mailman/listinfo/erlang-questions
> >>
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions
> > http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140221/ea180339/attachment.html>

Loading...