From: Jim Avera Date: Thu, 22 May 1997 06:10:01 +0000 (+1200) Subject: Patch to show @INC when require dies X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2683423cd7aae39c7c67a005320f39d6e84a2f1f;p=p5sagit%2Fp5-mst-13.2.git Patch to show @INC when require dies When 'require' dies because it can't find the file in @INC, it would be helpful if perl printed out the contents of @INC, to help debu the problem (especially when perl is invoked in devious ways, such as via a C application in which perl is embedded with funny secret -I args passed to perl_parse!). I would like to contribute a patch to 5.004 to do just that. p5p-msgid: 9705230121.AA27872@membrane.hal.com --- diff --git a/pp_ctl.c b/pp_ctl.c index bc3ebb1..6052cb2 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -2306,10 +2306,20 @@ PP(pp_require) if (!tryrsfp) { if (op->op_type == OP_REQUIRE) { SV *msg = sv_2mortal(newSVpvf("Can't locate %s in @INC", name)); + SV *dirmsgsv = NEWSV(0, 0); + AV *ar = GvAVn(incgv); + I32 i; if (instr(SvPVX(msg), ".h ")) sv_catpv(msg, " (change .h to .ph maybe?)"); if (instr(SvPVX(msg), ".ph ")) sv_catpv(msg, " (did you run h2ph?)"); + sv_catpv(msg, "\n@INC contains:\n "); + for (i = 0; i <= AvFILL(ar); i++) { + char *dir = SvPVx(*av_fetch(ar, i, TRUE), na); + sv_setpvf(dirmsgsv, " %s\n ", dir); + sv_catsv(msg, dirmsgsv); + } + SvREFCNT_dec(dirmsgsv); DIE("%_", msg); }