It is not obsolete, require is used. One use case:
Usually there's a line reading
as the last evaluated statement in a module file, since require demands a true value from an included file.1;
As LanX pointed out, use is sort of a wrapper around require, but it doesn't return anything, it throws away the value returned by require. It is even a syntax error trying to assign from it:
$result = use Some::Module; # illegal
So you cannot assign from use, but you can from require. This is useful to load e.g. a config stash or getting back a data structure captured from Data::Dumper or Data::Dump into a file:
# file hash.pl # anonymous hash reference { name => 'foo', data => [1,2,3], } __END__
#!/usr/bin/perl # file program.pl use strict; use warnings; use Data::Dump; my $var = require './hash.pl'; dd $var; __END__
Output:
{ data => [1, 2, 3], name => "foo" }
Of course, you can do arbitrary computations in the required file.
If you just want the last computed value from a file without having to declare an our variable in both source and target, or using Exporter, this is the way to do it - if you expect a true value to be returned. Otherwise, you would do FILE.
In reply to Re: Is require still required?
by shmem
in thread Is require still required?
by Bod
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |