Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

required files

by Anonymous Monk
on Apr 18, 2006 at 21:23 UTC ( #544203=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to write a hack for YaBB forum 2.1 and am having a problem with, which should be, a very simple print.

I am simply require "test.pl"; and inside this file is just print "username is $username"; 1;.

It's not printing anything out. However, when I add the shebang in AND add a print header, it does print but it prints out ooblygoop (like the pragma and stuff) because it's already been printed by the original script.

It does print the message with header, but prints nothing without.

Any ideas how I can get this to work?

Replies are listed 'Best First'.
Re: required files
by sulfericacid (Deacon) on Apr 19, 2006 at 00:48 UTC
    Ahh, a YaBB user. The error lies in YaBB NOT being coded for warnings or strict. But what's going on is you're trying to print your message BEFORE the headers are actually printed. And when you add the headers, you really are doubling them making the real headers push through as text.

    Look at the boardindex function for more information on where the headers are coming from :)



    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid
Re: required files
by ikegami (Patriarch) on Apr 18, 2006 at 23:34 UTC

    99.9% of the time, if the file being included has no package statement, you want do instead of require. require only runs the included file once, not once per require.

    >type 544228.pl print '!'; >perl -e "require '544228.pl'; require '544228.pl'" ! >perl -e "do '544228.pl'; do '544228.pl'" !!
      Hi. I changed require to do and it's not doing anything either. No errors or anything. Just not printing if I don't print the print header;
Re: required files
by GrandFather (Saint) on Apr 18, 2006 at 21:33 UTC

    Sometimes 10 lines of code is worth a few hundred words of description. This is one of those times - show us some code. Remember to check that you get no errors or warnings when you include use strict; use warnings in your code.


    DWIM is Perl's answer to Gödel
      Well, to get the gest of I I'll post the entire yabb.pl file. You can see my small require "test.pl" in there.
      test.pl ----------------------------- sub thisisatest { print "username is $username"; } 1;
      main script (look for ################### for my code) ---------------------------- #!/usr/bin/perl -- if ($action eq 'detailedversion') { return 1; } # Make sure the module path is present # Some servers need all the subdirs in @INC too. push(@INC, "./Modules"); push(@INC, "./Modules/Upload"); push(@INC, "./Modules/Digest"); if ($ENV{'SERVER_SOFTWARE'} =~ /IIS/) { $yyIIS = 1; $0 =~ m~(.*)(\\|/)~; $yypath = $1; $yypath =~ s~\\~/~g; chdir($yypath); push(@INC, $yypath); } # Check for Time::HiRes #eval { require Time::HiRes; import Time::HiRes qw(time); }; #if ($@) { $START_TIME = 0; } #else { $START_TIME = time; } ### Requirements and Errors ### $script_root = $ENV{'SCRIPT_FILENAME'}; $script_root =~ s/\/YaBB\.(pl|cgi)//ig; if (-e "Paths.pl") { require "Paths.pl"; } elsif (-e "$script_root/Paths.pl") { require "$script_root/Paths.pl"; +} require "$vardir/Settings.pl"; require "$vardir/advsettings.txt"; require "$vardir/secsettings.txt"; require "$vardir/membergroups.txt"; require "$sourcedir/Subs.pl"; require "$sourcedir/DateTime.pl"; require "$sourcedir/Load.pl"; #require "test.pl"; # Those who write software only for pay should go hurt some other fiel +d. # - Erik Naggum &LoadCookie; # Load the user's cookie (or set to guest) &LoadUserSettings; # Load user settings &WhatTemplate; # Figure out which template to be using. &WhatLanguage; # Figure out which language file we should be us +ing! :D ################################################# #below ################################################# require "test.pl"; &thisisatest; ################################################# # end #################################################

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://544203]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2022-01-16 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (49 votes). Check out past polls.

    Notices?