Take notes on the command line: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
|||
Line 338: | Line 338: | ||
if (note) fclose(note); |
if (note) fclose(note); |
||
return 0; |
return 0; |
||
}</lang> |
|||
=={{header|C sharp|C#}}== |
|||
<lang csharp>using System; |
|||
using System.IO; |
|||
using System.Text; |
|||
namespace RosettaCode |
|||
{ |
|||
internal class Program |
|||
{ |
|||
private const string FileName = "NOTES.TXT"; |
|||
private static void Main(string[] args) |
|||
{ |
|||
if (args.Length==0) |
|||
{ |
|||
string txt = File.ReadAllText(FileName); |
|||
Console.WriteLine(txt); |
|||
} |
|||
else |
|||
{ |
|||
var sb = new StringBuilder(); |
|||
sb.Append(DateTime.Now).Append("\n\t"); |
|||
foreach (string s in args) |
|||
sb.Append(s).Append(" "); |
|||
sb.Append("\n"); |
|||
if (File.Exists(FileName)) |
|||
File.AppendAllText(FileName, sb.ToString()); |
|||
else |
|||
File.WriteAllText(FileName, sb.ToString()); |
|||
} |
|||
} |
|||
} |
|||
}</lang> |
}</lang> |
||
Line 377: | Line 412: | ||
} |
} |
||
} |
} |
||
}</lang> |
|||
=={{header|C sharp|C#}}== |
|||
<lang csharp>using System; |
|||
using System.IO; |
|||
using System.Text; |
|||
namespace RosettaCode |
|||
{ |
|||
internal class Program |
|||
{ |
|||
private const string FileName = "NOTES.TXT"; |
|||
private static void Main(string[] args) |
|||
{ |
|||
if (args.Length==0) |
|||
{ |
|||
string txt = File.ReadAllText(FileName); |
|||
Console.WriteLine(txt); |
|||
} |
|||
else |
|||
{ |
|||
var sb = new StringBuilder(); |
|||
sb.Append(DateTime.Now).Append("\n\t"); |
|||
foreach (string s in args) |
|||
sb.Append(s).Append(" "); |
|||
sb.Append("\n"); |
|||
if (File.Exists(FileName)) |
|||
File.AppendAllText(FileName, sb.ToString()); |
|||
else |
|||
File.WriteAllText(FileName, sb.ToString()); |
|||
} |
|||
} |
|||
} |
|||
}</lang> |
}</lang> |
||
Line 1,538: | Line 1,538: | ||
Test line 2. |
Test line 2. |
||
</pre> |
</pre> |
||
=={{header|Perl 6}}== |
|||
<lang perl6>my $file = 'notes.txt'; |
|||
multi MAIN() { |
|||
print slurp($file); |
|||
} |
|||
multi MAIN(*@note) { |
|||
my $fh = open($file, :a); |
|||
$fh.say: DateTime.now, "\n\t", @note; |
|||
$fh.close; |
|||
}</lang> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 1,575: | Line 1,561: | ||
close(fn) |
close(fn) |
||
end if</lang> |
end if</lang> |
||
=={{header|PHP}}== |
|||
<lang php> |
|||
#!/usr/bin/php |
|||
<?php |
|||
if ($argc > 1) |
|||
file_put_contents( |
|||
'notes.txt', |
|||
date('r')."\n\t".implode(' ', array_slice($argv, 1))."\n", |
|||
FILE_APPEND |
|||
); |
|||
else |
|||
@readfile('notes.txt'); |
|||
</lang> |
|||
Note that the error suppression operator (@) is considered bad coding practice. |
|||
'''Sample notes.txt file''' |
|||
<pre> |
|||
zls@zls:~$ ./notes hello rosetta code |
|||
zls@zls:~$ ./notes todo notes program |
|||
zls@zls:~$ ./notes |
|||
Tue, 12 Jun 2012 19:27:35 +0200 |
|||
hello rosetta code |
|||
Tue, 12 Jun 2012 19:27:45 +0200 |
|||
todo notes program |
|||
</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
Line 1,682: | Line 1,695: | ||
2010-04-01T17:08:20.718000 |
2010-04-01T17:08:20.718000 |
||
go for it</pre> |
go for it</pre> |
||
=={{header|PHP}}== |
|||
<lang php> |
|||
#!/usr/bin/php |
|||
<?php |
|||
if ($argc > 1) |
|||
file_put_contents( |
|||
'notes.txt', |
|||
date('r')."\n\t".implode(' ', array_slice($argv, 1))."\n", |
|||
FILE_APPEND |
|||
); |
|||
else |
|||
@readfile('notes.txt'); |
|||
</lang> |
|||
Note that the error suppression operator (@) is considered bad coding practice. |
|||
'''Sample notes.txt file''' |
|||
<pre> |
|||
zls@zls:~$ ./notes hello rosetta code |
|||
zls@zls:~$ ./notes todo notes program |
|||
zls@zls:~$ ./notes |
|||
Tue, 12 Jun 2012 19:27:35 +0200 |
|||
hello rosetta code |
|||
Tue, 12 Jun 2012 19:27:45 +0200 |
|||
todo notes program |
|||
</pre> |
|||
=={{header|R}}== |
=={{header|R}}== |
||
Line 1,742: | Line 1,728: | ||
(string-join notes)))))) |
(string-join notes)))))) |
||
</lang> |
</lang> |
||
=={{header|Raku}}== |
|||
(formerly Perl 6) |
|||
<lang perl6>my $file = 'notes.txt'; |
|||
multi MAIN() { |
|||
print slurp($file); |
|||
} |
|||
multi MAIN(*@note) { |
|||
my $fh = open($file, :a); |
|||
$fh.say: DateTime.now, "\n\t", @note; |
|||
$fh.close; |
|||
}</lang> |
|||
=={{header|REBOL}}== |
=={{header|REBOL}}== |