www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How can I pass an argument to rdmd --evel=

reply k-five <vhsu30 yahoo.com> writes:
After reading about rdmd and --eval, I tried this:

rdmd --eval='auto f=File("ddoc.html");foreach(line;f.byLine) 
if(line.length<10) writeln(line);f.close'

and worked!

Now I am wonder if there is a way to pass "ddoc.html" to this 
one-liner? that can work with --loop.

I mean:
// --loop by default has foreach(line ...
// like perl -n
rdmd --loop='if( line.length < 10 ) writeln( line );' ddoc.html

but it is an error in syntax and rdmd says:
Cannot have both --eval and a program file ('ddoc.html')
May 07
parent reply Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
On Sunday, 7 May 2017 at 10:49:25 UTC, k-five wrote:
 After reading about rdmd and --eval, I tried this:

 rdmd --eval='auto f=File("ddoc.html");foreach(line;f.byLine) 
 if(line.length<10) writeln(line);f.close'

 and worked!

 Now I am wonder if there is a way to pass "ddoc.html" to this 
 one-liner? that can work with --loop.

 I mean:
 // --loop by default has foreach(line ...
 // like perl -n
 rdmd --loop='if( line.length < 10 ) writeln( line );' ddoc.html

 but it is an error in syntax and rdmd says:
 Cannot have both --eval and a program file ('ddoc.html')
Currently it's not possible:
May 07
next sibling parent Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
On Sunday, 7 May 2017 at 11:11:05 UTC, Vladimir Panteleev wrote:
 Currently it's not possible:
https://issues.dlang.org/show_bug.cgi?id=13345
May 07
prev sibling parent reply k-five <vhsu30 yahoo.com> writes:
On Sunday, 7 May 2017 at 11:11:05 UTC, Vladimir Panteleev wrote:
 On Sunday, 7 May 2017 at 10:49:25 UTC, k-five wrote:
 After reading about rdmd and --eval, I tried this:

 rdmd --eval='auto f=File("ddoc.html");foreach(line;f.byLine) 
 if(line.length<10) writeln(line);f.close'

 and worked!

 Now I am wonder if there is a way to pass "ddoc.html" to this 
 one-liner? that can work with --loop.

 I mean:
 // --loop by default has foreach(line ...
 // like perl -n
 rdmd --loop='if( line.length < 10 ) writeln( line );' ddoc.html

 but it is an error in syntax and rdmd says:
 Cannot have both --eval and a program file ('ddoc.html')
Currently it's not possible:
It should be possible! rdmd --eval=, without accepting argument is useless.
May 07
parent reply Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
On Sunday, 7 May 2017 at 11:29:30 UTC, k-five wrote:
 It should be possible!
 rdmd --eval=, without accepting argument is useless.
FWIW, you can still pass input through stdin.
May 07
parent k-five <vhsu30 yahoo.com> writes:
On Sunday, 7 May 2017 at 13:45:37 UTC, Vladimir Panteleev wrote:
 On Sunday, 7 May 2017 at 11:29:30 UTC, k-five wrote:
 It should be possible!
 rdmd --eval=, without accepting argument is useless.
FWIW, you can still pass input through stdin.
Well how about --build-only? with this argument it would be better to create executable file in the current directory not in the /tmp/.rddmd-1000/ and with a name like: eval.E201596D1C1E063AACF70666A4DBE264 This is a very useful tool if had some feature of awk and some of perl Unfortunately I only for a two weeks long got involved with leaning D, if I had experience with D I make it so nicer. -e is better than --eval -n is better than --loop because a one-liner should be as short as possible. Anyways thanks for replay. Also your website: http://thecybershadow.net/d/dconf2016/ was so nice.
May 07