{"id":7361,"date":"2022-12-20T19:37:49","date_gmt":"2022-12-20T22:37:49","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/mdkcommonfile-man3\/"},"modified":"2022-12-20T19:37:49","modified_gmt":"2022-12-20T22:37:49","slug":"mdkcommonfile-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/mdkcommonfile-man3\/","title":{"rendered":"MDK::Common::File (man3)"},"content":{"rendered":"<h1 align=\"center\">MDK::Common::File<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#EXPORTS\">EXPORTS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">MDK::Common::File \u2212 miscellaneous file\/filename manipulation functions<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">use MDK::Common::File qw(:all);<\/p>\n<h2>EXPORTS <a name=\"EXPORTS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">dirname( <small>FILENAME<\/small> ) <br \/> basename( <small>FILENAME<\/small> )<\/p>\n<p style=\"margin-left:17%;\">returns the dirname\/basename of the file name<\/p>\n<p style=\"margin-left:11%;\">cat_( <small>FILES<\/small> )<\/p>\n<p style=\"margin-left:17%;\">returns the files contents: in scalar context it returns a single string, in array context it returns the lines.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">If no file is found, undef is returned<\/p>\n<p style=\"margin-left:11%;\">cat_or_die( <small>FILENAME<\/small> )<\/p>\n<p style=\"margin-left:17%;\">same as &#8220;cat_&#8221; but dies when something goes wrong<\/p>\n<p style=\"margin-left:11%;\">cat_utf8( <small>FILES<\/small> )<\/p>\n<p style=\"margin-left:17%;\">same as C(<cat_>) but reads utf8 encoded strings<\/p>\n<p style=\"margin-left:11%;\">cat_utf8_or_die( <small>FILES<\/small> )<\/p>\n<p style=\"margin-left:17%;\">same as C(<cat_or_die>) but reads utf8 encoded strings<\/p>\n<p style=\"margin-left:11%;\">cat__( <small>FILEHANDLE REF<\/small> )<\/p>\n<p style=\"margin-left:17%;\">returns the file content: in scalar context it returns a single string, in array context it returns the lines<\/p>\n<p style=\"margin-left:11%;\">output( <small>FILENAME, LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">creates a file and outputs the list (if the file exists, it is clobbered)<\/p>\n<p style=\"margin-left:11%;\">output_utf8( <small>FILENAME, LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">same as C(<output>) but writes utf8 encoded strings<\/p>\n<p style=\"margin-left:11%;\">secured_output( <small>FILENAME, LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">likes <b>output()<\/b> but prevents insecured usage (it dies if somebody try to exploit the race window between <b>unlink()<\/b> and <b>creat()<\/b>)<\/p>\n<p style=\"margin-left:11%;\">append_to_file( <small>FILENAME, LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">add the <small>LIST<\/small> at the end of the file<\/p>\n<p style=\"margin-left:11%;\">output_p( <small>FILENAME, LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">just like &#8220;output&#8221; but creates directories if needed<\/p>\n<p style=\"margin-left:11%;\">output_with_perm( <small>FILENAME, PERMISSION, LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">same as &#8220;output_p&#8221; but sets <small>FILENAME<\/small> permission to <small>PERMISSION<\/small> (using chmod)<\/p>\n<p style=\"margin-left:11%;\">mkdir_p( <small>DIRNAME<\/small> )<\/p>\n<p style=\"margin-left:17%;\">creates the directory (make parent directories as needed)<\/p>\n<p style=\"margin-left:11%;\">rm_rf( <small>FILES<\/small> )<\/p>\n<p style=\"margin-left:17%;\">remove the files (including sub-directories)<\/p>\n<p style=\"margin-left:11%;\">cp_f( <small>FILES, DEST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">just like &#8220;cp \u2212f&#8221;<\/p>\n<p style=\"margin-left:11%;\">cp_af( <small>FILES, DEST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">just like &#8220;cp \u2212af&#8221;<\/p>\n<p style=\"margin-left:11%;\">cp_afx( <small>FILES, DEST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">just like &#8220;cp \u2212afx&#8221;<\/p>\n<p style=\"margin-left:11%;\">linkf( <small>SOURCE, DESTINATION<\/small> ) <br \/> symlinkf( <small>SOURCE, DESTINATION<\/small> ) <br \/> renamef( <small>SOURCE, DESTINATION<\/small> )<\/p>\n<p style=\"margin-left:17%;\">same as link\/symlink\/rename but removes the destination file first<\/p>\n<p style=\"margin-left:11%;\">touch( <small>FILENAME<\/small> )<\/p>\n<p style=\"margin-left:17%;\">ensure the file exists, set the modification time to current time<\/p>\n<p style=\"margin-left:11%;\">all( <small>DIRNAME<\/small> )<\/p>\n<p style=\"margin-left:17%;\">returns all the file in directory (except &#8220;.&#8221; and &#8220;..&#8221;)<\/p>\n<p style=\"margin-left:11%;\">all_files_rec( <small>DIRNAME<\/small> )<\/p>\n<p style=\"margin-left:17%;\">returns all the files in directory and the sub-directories (except &#8220;.&#8221; and &#8220;..&#8221;)<\/p>\n<p style=\"margin-left:11%;\">glob_( <small>STRING<\/small> )<\/p>\n<p style=\"margin-left:17%;\">simple version of &#8220;glob&#8221;: doesn\u2019t handle wildcards in directory (eg: *\/foo.c), nor special constructs (eg: [0\u22129] or {a,b})<\/p>\n<p style=\"margin-left:11%;\">substInFile { <small>CODE<\/small> } <small>FILENAME<\/small><\/p>\n<p style=\"margin-left:17%;\">executes the code for each line of the file. You can know the end of the file is reached using &#8220;eof&#8221;<\/p>\n<p style=\"margin-left:11%;\">expand_symlinks( <small>FILENAME<\/small> )<\/p>\n<p style=\"margin-left:17%;\">expand the symlinks in the absolute filename: &#8220;expand_symlinks(&#8220;\/etc\/X11\/X&#8221;)&#8221; gives &#8220;\/usr\/bin\/Xorg&#8221;<\/p>\n<p style=\"margin-left:11%;\">openFileMaybeCompressed( <small>FILENAME<\/small> )<\/p>\n<p style=\"margin-left:17%;\">opens the file and returns the file handle. If the file is not found, tries to gunzip the file + .gz<\/p>\n<p style=\"margin-left:11%;\">catMaybeCompressed( <small>FILENAME<\/small> )<\/p>\n<p style=\"margin-left:17%;\">cat_ alike. If the file is not found, tries to gunzip the file + .gz<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">MDK::Common<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  MDK::Common::File \u2212 miscellaneous file\/filename manipulation functions <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3007,3675],"class_list":["post-7361","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-man3","tag-mdkcommonfile"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7361"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7361\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}