---------- Forwarded message ---------- From: Jérôme Étévé <jerome.et...@gmail.com> Date: 28 February 2012 14:45 Subject: Re: [Mason] I need help, please To: hha...@gmail.com
From the FAQ: <%init> $m->clear_buffer; my $fh = IO::File->new('< binary_file') or die $!; my $buffer; while (read $fh, $buffer, 8192) { $m->print($buffer); } $m->abort; </%init> Notice that $m->print is the way to output something. You might want to output the appropriate headers as well as the file content. I suppose you could also use File::Slurp to slurp your file in one go, although this method is probably better for large files. Cheers. On 28 February 2012 14:42, <hha...@gmail.com> wrote: > On Tue, 28 Feb 2012 09:05:36 -0500 (CST) > Eugenio Duran Aroche <edu...@estudiantes.uci.cu> wrote: > >> I need know how open, write and read files in Mason, I put this code and not >> show nothing in the browser, neither can't write in the file > > Well, you are not checking whether your open() succeeded. Nor are you > HTML-escaping your output. Not to mention the useless subject of your > e-mail. I'm not even mentioning the HTML mail your client sends out. > > You probably aren't in the correct directory or your web server doesn't > have the correct read permissions to the file. You might want to refer > to a netiquette guide for the other problems. > > > Anyway, as loth as I am to give ready solutions, I wrote a trivial > program to function as a scratch pad some time ago: > > <%args> > $text => undef > </%args> > <html> > <head><title>Scratchpad</title></head> > <body> > <form action="" method="post"> > <div> > <textarea name="text" cols="80" rows="25"><% $text |h %></textarea> > </div> > <div><input type="submit" value="Save" accesskey="s"></div> > </form> > </body> > </html> > <%init> > $r->content_type('text/html; charset=utf-8'); > > if ($text) { > if (-e $fn) { > rename($fn, "$fn.bak") or die "cannot rename"; > } > open my $fh, ">", $fn or die "cannot open for writing: $!"; > print $fh $text or die "cannot write: $!"; > close $fh; > } else { > my $fh; > if (-e $fn) { > open($fh, "<", $fn) or die "cannot read: $!"; > local $/ = undef; > $text = <$fh>; > close $fh; > } > } > </%init> > <%once> > my $fn = '/full/path/to/scratchpad.txt'; > </%once> > > ------------------------------------------------------------------------------ > Keep Your Developer Skills Current with LearnDevNow! > The most comprehensive online learning library for Microsoft developers > is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, > Metro Style Apps, more. Free future releases when you subscribe now! > http://p.sf.net/sfu/learndevnow-d2d > _______________________________________________ > Mason-users mailing list > Mason-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mason-users -- Jerome Eteve. http://sigstp.blogspot.com/ http://twitter.com/jeteve -- Jerome Eteve. http://sigstp.blogspot.com/ http://twitter.com/jeteve ------------------------------------------------------------------------------ Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d _______________________________________________ Mason-users mailing list Mason-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mason-users