Take notes on the command line: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 338:
if (note) fclose(note);
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>
 
Line 377 ⟶ 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>
 
Line 1,538:
Test line 2.
</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}}==
Line 1,575 ⟶ 1,561:
close(fn)
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}}==
Line 1,682 ⟶ 1,695:
2010-04-01T17:08:20.718000
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}}==
Line 1,742 ⟶ 1,728:
(string-join notes))))))
</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}}==
10,327

edits