{"id":135,"date":"2009-11-15T18:14:16","date_gmt":"2009-11-15T18:14:16","guid":{"rendered":"http:\/\/www.adriangrigoras.com\/blog\/?p=135"},"modified":"2009-11-15T18:14:16","modified_gmt":"2009-11-15T18:14:16","slug":"handle-files-in-perl","status":"publish","type":"post","link":"https:\/\/adriangrigoras.com\/blog\/handle-files-in-perl\/","title":{"rendered":"Handle files in Perl"},"content":{"rendered":"<p>Read a file and put its content into one variable<\/p>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$line=&#8221;&#8221;;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">open (FILE, &#8220;&lt;&#8220;, &#8220;$public_html_dir\/upload\/promotii.html&#8221;);<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">@lines=&lt;FILE&gt;;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">foreach $l (@lines){<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$line.=$l;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">}<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">close(FILE);<\/div>\n<address>$line=&#8221;&#8221;;<\/p>\n<p>open (FILE, &#8220;&lt;&#8220;, &#8220;file.html&#8221;);<\/p>\n<p>@lines=&lt;FILE&gt;;<\/p>\n<p>foreach $l (@lines){<\/p>\n<p>$line.=$l;<\/p>\n<p>}<\/p>\n<p>close(FILE);<\/p>\n<p>Write to a file<\/p>\n<p>if($xEditor ne &#8220;&#8221;){<\/p>\n<p>open (FILE, &#8220;&gt;&#8221;, &#8220;file.html&#8221;);<\/p>\n<p>print FILE &#8220;$xEditor&#8221;;<\/p>\n<p>close (FILE);<\/p>\n<p>}<\/p>\n<address><\/address>\n<\/p><\/address>\n","protected":false},"excerpt":{"rendered":"<p>Read a file and put its content into one variable $line=&#8221;&#8221;; open (FILE, &#8220;&lt;&#8220;, &#8220;$public_html_dir\/upload\/promotii.html&#8221;); @lines=&lt;FILE&gt;; foreach $l (@lines){ $line.=$l; } close(FILE); $line=&#8221;&#8221;; open (FILE, &#8220;&lt;&#8220;, &#8220;file.html&#8221;); @lines=&lt;FILE&gt;; foreach $l (@lines){ $line.=$l; } close(FILE); Write to a file if($xEditor ne &#8220;&#8221;){ open (FILE, &#8220;&gt;&#8221;, &#8220;file.html&#8221;); print FILE &#8220;$xEditor&#8221;; close (FILE); }<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-135","post","type-post","status-publish","format-standard","hentry","category-perl"],"_links":{"self":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts\/135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/comments?post=135"}],"version-history":[{"count":0,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts\/135\/revisions"}],"wp:attachment":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/media?parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/categories?post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/tags?post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}