Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: Why am I getting "premature end of script header"? - eval { use }

by lokiloki (Beadle)
on Nov 27, 2006 at 22:29 UTC ( #586345=note: print w/replies, xml ) Need Help??

in reply to Re: Why am I getting "premature end of script header"? - eval { use }
in thread Why am I getting "premature end of script header"?

thanks... what about this...
print "Content-type: text/html\n\n"; print "here we go again..."; &a; sub a { BEGIN { eval ("use fakemodule;"); if ($@) { print "error happened $@"; } else { print "error didnt happen, do some stuff"; } } }

Considered by ikegami: Dup of Re^2: Why am I getting "premature end of script header"?
Unconsidered by Arunbear: reaping blocked by keep (and edit) votes; (Keep: 5, Edit: 3, Reap: 18)

  • Comment on Re^2: Why am I getting "premature end of script header"? - eval { use }
  • Download Code

Replies are listed 'Best First'.
Re^3: Why am I getting "premature end of script header"? - &subroutine calling style
by imp (Priest) on Nov 27, 2006 at 22:46 UTC
    This would be sufficient:
    BEGIN { if( eval "use fakemodule; 1;") { print STDERR "Loaded fakemodule"; } else { print STDERR "Couldn't load fakemodule."; } }
    Don't put BEGIN blocks inside a subroutine, they won't do what you want.

    Don't print in the BEGIN block, it will come before the Content-type header

    Calling a subroutine with the '&a' syntax has the following effects, from perlsub:

    • &NAME(LIST); # Circumvent prototypes.
    • &NAME; # Makes current @_ visible to called subroutine.
    In your code you used the &a; form, which would make the current @_ visible to the called subroutine. For example:
    first(1,2,3); sub first { &second; } sub second { print for @_; } # Output is 123
    Although it isn't relevant for this particular case it is still good to be aware of the prototype circumvention behaviour. Here is an example:
    use strict; use warnings; use Data::Dumper; sub pro(\@) { print Dumper \@_; } my @list = (1,2,3); pro(@list); &pro(@list);
    $VAR1 = [ [ 1, 2, 3 ] ]; $VAR1 = [ 1, 2, 3 ];
      thank you... so the takeaway message is that I should call subroutines via subroutine; and not &subroutine;? this must be a new thing? because the Perl book I have (admittedly the first edition o'reilly one) says that i should call subroutines with the ampersand...?
        Aye, the &subroutine; style is optional in any modern perl. I can't recall what version that changed in, but it was a fairly long time ago.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://586345]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2022-08-14 16:43 GMT
Find Nodes?
    Voting Booth?

    No recent polls found