Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Difference between use and require in perl

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 evaluated when the code is run compiled, but require – import’s can only get evaluated when encoutered.

The differences are many and often subtle:

use only expects a bareword, require can take a bareword or an expression

use is evaluated at compile-time, require at run-time

use implicitly calls the import method of the module being loaded, require does not

use excepts arguments in addition to the bareword (to be passed to import), require does not

use does not behave like a function (i.e can’t be called with parens, can’t be used in an expression, etc), whereas require does

do $file is like eval `cat $file`, except the former:
1.1: searches @INC and updates %INC.
1.2: bequeaths an *unrelated* lexical scope on the eval’ed code.

require $file is like do $file, except the former:
2.1: checks for redundant loading, skipping already loaded files.
2.2: raises an exception on failure to find, compile, or execute $file.

require Module is like require “Module.pm”, except the former:
3.1: translates each “::” into your system’s directory separator.
3.2: primes the parser to disambiguate class Module as an indirect object.

use Module is like require Module, except the former:
4.1: loads the module at compile time, not run-time.
4.2: imports symbols and semantics from that package to the current one.

Command to learn more about use and require
> perldoc -f require
> perldoc -f use

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals

Similar Posts

  • Using perl send an html email

    rajeshkumar created the topic: using perl send an html email Using perl send an html email #!/usr/bin/perl -w use strict; use MIME::Lite; # SendTo email id my $email = ‘rajesh@scmgalaxy.com’; # create a new MIME Lite based email my $msg = MIME::Lite->new ( Subject => “HTML email test”, From => ‘rajesh@scmgalaxy.com’, To => rajesh@scmgalaxy.com, Type…

  • Difference between my and use

    scmuser created the topic: Difference between my and use Hi, What is the difference Between my and use in Perl? Could you please elaborate with few good examples? thanks Rajesh KumarI’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at…

  • Perl function to remove any element using value validation

    rajeshkumar created the topic: perl function to remove any element using value validation perl function to remove any element using value validation Not Working – my @items = (rajesh1, rajesh2,rajesh3,rajes4,rajesh5,rajesh7) my $index = 0; for my $value (@items) { print “testing $value\n”; if ( $value == “rajesh1” or $value == “rajesh2” or $value == “rajesh3”)…

  • Why do you program in Perl?

    scmuser created the topic: Why do you program in Perl? Why do you program in Perl? What are the advantages of Perl ovber python and other languages? Rajesh KumarI’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at Holiday Landmark,…

  • Connect to my MySQL database using Perl?

    rajeshkumar created the topic: connect to my MySQL database using Perl? #!/usr/bin/perl use DBI; $database = “DBNAME”; $hostname = “DBSERVER”; $port = “3306”; $username = “DBUSERNAME”; $password = ‘DBPASSWORD’; $dsn = “DBI:mysql:database=$database;host=$hostname;port=$port”; $dbh = DBI->connect($dsn, $username, $password) or die(“Could not connect!”); $sql = “SELECT * FROM mytable”; $sth = $dbh->prepare($sql); $sth->execute; while(($column1, $column2) = $sth->fetchrow_array)…

  • Installing Perl modules

    rajeshkumar created the topic: Installing Perl modules Perl modules may be installed using the CPAN module or from source. CPAN method perl -MCPAN -e shell (to get an interactive CPAN shell) perl -MCPAN -e ‘install Time::JulianDay’ (if you know the name of the module, you can install it directly without interacting with the CPAN shell)…

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments