Perl convert string to file handle
Improve this answer. It's no problem to write a string in the same manner. Can be useful with formats! Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. First I open a filehandle:. To get the length of the file, we use the -s function on the filehandle, which returns the file size in bytes.
For large files, this approach is faster than the do block method. When slurping a file, you may want to add a PerlIO layer instruction to the open argument:. With this code the first line looks the same except :unix has been appended to the file open direction. You can read more about the PerlIO layers here. Cool, huh? Updated: changed to give more examples, File::Slurp warning and include File::Slurper. Perl code to demonstrate the use.
Next Perl split Function. Recommended Articles. Perl Decision Making if, if-else, Nested—if, if-elsif ladder, unless, unless-else, unless-elsif. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Most popular in Perl. Use of print and say in Perl Introduction to Perl.
0コメント