{"id":2444,"date":"2017-12-08T10:42:46","date_gmt":"2017-12-08T10:42:46","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=2444"},"modified":"2025-02-01T23:08:06","modified_gmt":"2025-02-01T23:08:06","slug":"difference-between-use-and-require-in-perl-2","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/difference-between-use-and-require-in-perl-2\/","title":{"rendered":"Difference between use and require in perl"},"content":{"rendered":"<p><strong>rajeshkumar created the topic: Difference between use and require in perl<\/strong><br \/>\n|| use Vs require in perl || What is the difference between use and require?<\/p>\n<p>Except of course that use is evaluated at compile time where as require is evaluated at run time in other word, A use anywhere in the code will be evaluated when the code is run compiled, but require &#8211; import&#8217;s can only get evaluated when encoutered.<\/p>\n<p>The differences are many and often subtle:<\/p>\n<p>use only expects a bareword, require can take a bareword or an expression<\/p>\n<p>use is evaluated at compile-time, require at run-time<\/p>\n<p>use implicitly calls the import method of the module being loaded, require does not<\/p>\n<p>use excepts arguments in addition to the bareword (to be passed to import), require does not<\/p>\n<p>use does not behave like a function (i.e can&#8217;t be called with parens, can&#8217;t be used in an expression, etc), whereas require does<\/p>\n<p>do $file is like eval `cat $file`, except the former:<br \/>\n1.1: searches @INC and updates %INC.<br \/>\n1.2: bequeaths an *unrelated* lexical scope on the eval&#8217;ed code.<\/p>\n<p>require $file is like do $file, except the former:<br \/>\n2.1: checks for redundant loading, skipping already loaded files.<br \/>\n2.2: raises an exception on failure to find, compile, or execute $file.<\/p>\n<p>require Module is like require &#8220;Module.pm&#8221;, except the former:<br \/>\n3.1: translates each &#8220;::&#8221; into your system&#8217;s directory separator.<br \/>\n3.2: primes the parser to disambiguate class Module as an indirect object.<\/p>\n<p>use Module is like require Module, except the former:<br \/>\n4.1: loads the module at compile time, not run-time.<br \/>\n4.2: imports symbols and semantics from that package to the current one.<\/p>\n<p>Command to learn more about use and require<br \/>\n> perldoc -f require<br \/>\n> perldoc -f use<\/p>\n<p>Regards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @ <a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\">twitter.com\/RajeshKumarIn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>rajeshkumar created the topic: Difference between use and require in perl || use Vs require in perl || What is the difference between use and require? Except of course that use is evaluated at compile time where as require is evaluated at run time in other word, A use anywhere in the code will be&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[14],"tags":[175],"class_list":["post-2444","post","type-post","status-publish","format-standard","hentry","category-perl","tag-perl"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2444"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2444\/revisions"}],"predecessor-version":[{"id":2445,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2444\/revisions\/2445"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}