a little help with file i/o

0 views
Skip to first unread message

Nathan Smith

unread,
Aug 19, 2016, 3:58:14 PM8/19/16
to MOO Talk
hi guys
So I finally managed to upgrade the server a bit, to a slightly more modern gamma moo.
I also now have file i/o, but am puzzling the best way to do the following:
someone submits an idea on the moo, it writes it to ideas.txt
when an admin views it, it then gets the content of the file, reads it and presents the admin with a list of titles. the admin chooses said title then reads it.
I was then think they delete it with a different command.
The writing to the file is easy. Something like the following:
file=file_open("ideas.txt","a-tf");
for x in(idea)
ile_writeline(file, x);
endfor

the reading not so sure on.
Perhaps something like this?
file=file_open("ideas.txt","r-tf");
what=file_readlines(file, 1, file_tell(file));
file_close(file);
titles=ideas={};
for x in(what)
if(index(x,"title")==1)
titles={@titles, x};
else
ideas={@ideas, x};
endif
endfor


then for delete... that is where I get stuck. How to read is easy, but then how to delete just the first?
I'd really appreciate if you guys could point in me the right direction here, the fileio docks don't provide sample moo codes, which is what I tend to learn from, so do tell me if I'm beating around the wrong bush here or something.
Much appreciated
Nate

Tim van Dijen

unread,
Aug 20, 2016, 11:56:54 AM8/20/16
to MOO-...@googlegroups.com
Why not make an ideas-directory and make a txt-file for every idea?

Op 19-8-2016 om 21:34 schreef Nathan Smith:
--
You received this message because you are subscribed to the Google Groups "MOO Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to MOO-talk+u...@googlegroups.com.
To post to this group, send email to MOO-...@googlegroups.com.
Visit this group at https://groups.google.com/group/MOO-talk.
For more options, visit https://groups.google.com/d/optout.

Nathan Smith

unread,
Aug 20, 2016, 8:38:51 PM8/20/16
to MOO Talk
hi tim!
I could do that, but just gave that as an example.
my question is, how would you read from a file, delete the first line, then write to the file.
I suppose you could do the hole, read into a list, remove element 1, re-write... but is it only possible with writeline?
thanks

Just Johnny

unread,
Aug 20, 2016, 8:38:51 PM8/20/16
to MOO Talk
Maybe start by writing a utility to read the contents of a filename passed in? One more for writing and another for deleting a file? These low level functions scream for abstractions. :)


To unsubscribe from this group and stop receiving emails from it, send an email to MOO-talk+unsubscribe@googlegroups.com.

To post to this group, send email to MOO-...@googlegroups.com.
Visit this group at https://groups.google.com/group/MOO-talk.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "MOO Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to MOO-talk+unsubscribe@googlegroups.com.

Littlefield, Tyler

unread,
Aug 20, 2016, 8:38:51 PM8/20/16
to Nathan Smith, MOO Talk
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 8/19/2016 3:34 PM, Nathan Smith wrote:
> hi guys So I finally managed to upgrade the server a bit, to a
> slightly more modern gamma moo. I also now have file i/o, but am
> puzzling the best way to do the following: someone submits an idea
> on the moo, it writes it to ideas.txt when an admin views it, it
> then gets the content of the file, reads it and presents the admin
> with a list of titles. the admin chooses said title then reads it.

Any reason why you wouldn't just use a multidimensional list?
> I was then think they delete it with a different command. The
> writing to the file is easy. Something like the following:
> file=file_open("ideas.txt","a-tf"); for x in(idea)
> ile_writeline(file, x); endfor
>
> the reading not so sure on. Perhaps something like this?
> file=file_open("ideas.txt","r-tf"); what=file_readlines(file, 1,
> file_tell(file)); file_close(file); titles=ideas={}; for x
> in(what) if(index(x,"title")==1) titles={@titles, x}; else
> ideas={@ideas, x}; endif endfor
>
>
> then for delete... that is where I get stuck. How to read is easy,
> but then how to delete just the first? I'd really appreciate if you
> guys could point in me the right direction here, the fileio docks
> don't provide sample moo codes, which is what I tend to learn from,
> so do tell me if I'm beating around the wrong bush here or
> something. Much appreciated Nate
>
> -- You received this message because you are subscribed to the
> Google Groups "MOO Talk" group. To unsubscribe from this group and
> stop receiving emails from it, send an email to
> MOO-talk+u...@googlegroups.com
> <mailto:MOO-talk+u...@googlegroups.com>. To post to this
> group, send email to MOO-...@googlegroups.com
> <mailto:MOO-...@googlegroups.com>. Visit this group at
- --
Take care,
Ty
Twitter: @sorressean
Web: https://tysdomain.com
Pubkey: https://tysdomain.com/files/pubkey.asc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBAgAGBQJXt3BHAAoJEAdP60+BYxejeLgH/jJ1nb2foith7sd9FvaO/9uh
W8MIjNaMX6WGhWZ5hVw4qXcp2tu9yGeyqdmCLR98kiALZop9X4MjJXwHZqbmU2ur
WXkjPJF5mg4UgenuEcBWbXjybu2vKwYRNJODQ/bAFTYH616Ko6n4jVgjFzJoykFO
ULlqOpmzuUjpWPw/mDSqhnx6mCpWa2NEWxgX/GISyXUnocBi7jX3oFThWkkQ/jqh
eCqCz1zuwfb7o7dxJSZLQ5TOux1Gszjk+GeZ3py9MhR8NxXHT75sU37y7meMDrzr
4Xu4z5JhAHTF/pl337LBTsJS2x7r2S4JcB0dwO7eTp9DW2BK1XFzeAvXRXQnKyE=
=m+VB
-----END PGP SIGNATURE-----

Littlefield, Tyler

unread,
Aug 20, 2016, 10:26:25 PM8/20/16
to Nathan Smith, MOO Talk
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 8/20/2016 6:24 PM, Nathan Smith wrote:
> hi tim! I could do that, but just gave that as an example. my
> question is, how would you read from a file, delete the first
> line, then write to the file. I suppose you could do the hole, read
> into a list, remove element 1, re-write... but is it only possible
> with writeline? thanks
>

files inherently are sequential access, whether that's reading or
writing. You can not delete a single line from the top without
rewriting the entire file. so in this case, get a list of all lines,
delete what you want and rewrite is the best solution.
HTH,
>> MOO-talk+u...@googlegroups.com <javascript:>. To post to this
>> group, send email to MOO-...@googlegroups.com <javascript:>.
>> <https://groups.google.com/group/MOO-talk>. For more options,
>> visit https://groups.google.com/d/optout
>> <https://groups.google.com/d/optout>.
>
> -- You received this message because you are subscribed to the
> Google Groups "MOO Talk" group. To unsubscribe from this group and
> stop receiving emails from it, send an email to
> MOO-talk+u...@googlegroups.com
> <mailto:MOO-talk+u...@googlegroups.com>. To post to this
> group, send email to MOO-...@googlegroups.com
> <mailto:MOO-...@googlegroups.com>. Visit this group at
- --
Take care,
Ty
Twitter: @sorressean
Web: https://tysdomain.com
Pubkey: https://tysdomain.com/files/pubkey.asc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBAgAGBQJXuQY9AAoJEAdP60+BYxejlTUH/2YNeoyFEyq1KbD4yXqMPPgL
IRMkpcKWSJNK9guPEdqcwKkzoJFNlyCH4bfG9j8U02JrMDDaMNJjHhwy2gRA9+Lj
kjKbxyA1hbYibxlJTz5NB9YXoQAxRCF1Tasz/v0HQN3Km1W11qJ587rkdWyyAy8o
xp0vPIY281uDt98VnuYt9BNQ1ZXtaLWmq1j1cAJ9GPcD7N3egNZyKEKS3MCvF9WM
BNwxxmYXPkp74i3Q8m9SDxB+Xx6F3Z7y3rCKFjHobs8A2jLeTw1eqIla5QIUeOkl
XdfjOu4mQMYAWalGMw1xhYOiOuAcZxHTWkUmUQzs1BCMurjYxYU/U8w8Eg7lcCo=
=V8XZ
-----END PGP SIGNATURE-----

Nathan Smith

unread,
Aug 21, 2016, 12:05:33 AM8/21/16
to MOO Talk, moo-...@googlegroups.com
hi again
I've hit a problem, that's a great idea and I will do that, thanks for that but..
file_readline(file);
result is:
interrupted system caller.
What on eeeeaaarth?
thanks
To unsubscribe from this group and stop receiving emails from it, send an email to MOO-talk+u...@googlegroups.com.

To post to this group, send email to MOO-...@googlegroups.com.
Visit this group at https://groups.google.com/group/MOO-talk.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "MOO Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to MOO-talk+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages