in reply to The 'eval "require $module; 1"' idiom
I generally consider it to be cargo cult. There's no situation where require lives but returns false.
That said, your case 3 is incorrect. Require doesn't (always) return "1". It returns whatever the module returned.
$ cat Foo.pm package Foo; 2; $ perl -E'say eval "require Foo"' 2
Case 3b is correct though - if a module has already been loaded, require just returns 1.
$ perl -E'say eval "require Foo" for 1..3' 2 1 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: The 'eval "require $module; 1"' idiom (intended)
by tye (Sage) on Apr 19, 2014 at 18:54 UTC | |
by davido (Cardinal) on Apr 19, 2014 at 20:03 UTC | |
|
Re^2: The 'eval "require $module; 1"' idiom
by sedusedan (Pilgrim) on Apr 19, 2014 at 11:56 UTC | |
|
Re^2: The 'eval "require $module; 1"' idiom (one character cargo cult)
by Anonymous Monk on Apr 19, 2014 at 09:25 UTC | |
by tobyink (Canon) on Apr 19, 2014 at 09:38 UTC | |
by Anonymous Monk on Apr 19, 2014 at 09:48 UTC | |
by LanX (Saint) on Apr 19, 2014 at 19:54 UTC | |
by Anonymous Monk on Apr 19, 2014 at 20:41 UTC |