fork(2) download
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use feature 'say';
  5.  
  6. say "This is perl $^V";
  7.  
  8. package Input {
  9. sub awesome {
  10. say "yay, this works";
  11. }
  12. }
  13.  
  14. # this works
  15. 'Input'->awesome;
  16.  
  17. # the "open" is parsed, but not actually executed
  18. eval <<'END';
  19. sub red_herring {
  20. open Input, "<&", \*STDIN or die $!;
  21. }
  22. END
  23. say "eval failed: $@" if $@;
  24.  
  25. # this will die
  26. 'Input'->awesome;
  27. };
  28. say "Caught: $@" if $@;
Success #stdin #stdout 0.01s 4128KB
stdin
Standard input is empty
stdout
This is perl v5.16.2
yay, this works
Caught: Can't locate object method "awesome" via package "IO::File" at prog.pl line 27.