Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: using "require"

  1. #1
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts

    using "require"

    Hello, im trying to create a base template which then loads data depending on what actions are taken. I included ( required ) some pages which was fine but then i included another file which I got a 500 internal error. pasting the code straight in and it works fine.

    heres what i've got;

    Code:
    #!/usr/bin/perl
    use strict;
    use warnings;
    use LWP::Simple;
    require LWP::UserAgent;
    use DBI;
    
    
    #deal with post requests
    require "perl/post-sort.pl";
    #loading stylesheets and javascripts
    require "header.pl";
    # bring in loggin js
    if( $arg{REQUEST_KEY} eq "") {
    	require "javascript/js-main-login.pl";
    }
    print "</head> \n";
    print " \n";
    ...
    ...
    ...
    perl/post-sort.pl

    Code:
    my %arg = ();
    for (split /\&/, <STDIN>) {
       my ($key, $val) = split /=/;
       $val =~ s/\+/ /g;
       $val =~ s/%([0-9a-fA-F]{2})/chr(hex($1))/ge;
       $arg{$key} = $val;
    }
    Any help much appreciated
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,871
    Thanks
    2
    Thanked 164 Times in 159 Posts
    If you want to write good quality Perl code, you will definitely not want to write your scripts in that manor.

    Use the CGI module!!!

    If you want to use a template, then use one Perl's template frameworks. The easiest to begin with is probably HTML::Template.
    http://search.cpan.org/~samtregar/HT....9/Template.pm

  • #3
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    AT the top of your perl file, you ought to have the location of files to be required, declared.

    eg
    Code:
    use lib '/var/www/bleh/name_of_dir';
    then in your perl, just

    Code:
    require 'name_of_file.pl';
    I prefer not simply to require the file but, to send a call to the required file. instead of using require'header.pl'; and it runs the header file, I usually do this

    Code:
    require'name_of_file';
    header($var1,$var2,$var3..etc);
    I can't recall all my reasons for doing it like this but, for one, it lets me determine how the header file runs, depending on what params have been sent to it.

    Final tip... why do you use a javascript login when it can't be secure and you are learning perl? I would suggest doing it better than I did and start to learn about security from the beginning otherwise, your scripts may well have holes in them which will necessitate a review/rewrite of them later.

    hth

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #4
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    AJAX can be secure. But thank you both.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #5
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,871
    Thanks
    2
    Thanked 164 Times in 159 Posts
    If you want secure logins, it would be best to use sessions and https

  • #6
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    Which it does do.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #7
    Regular Coder
    Join Date
    Oct 2004
    Posts
    168
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Did you post all the contents of your package? If so, it is missing code at the start and end :

    Code:
    package postsort;
    
    my %arg = ();
    for (split /\&/, <STDIN>) {
       my ($key, $val) = split /=/;
       $val =~ s/\+/ /g;
       $val =~ s/%([0-9a-fA-F]{2})/chr(hex($1))/ge;
       $arg{$key} = $val;
    }
    1;
    The package declaration should be the name of the file minus the .pl or .pm
    I removed the - in the name as this is not permitted.

    It's a good idea to add a preamble to each package, something like this :

    Code:
    use strict;
    use warnings;
    use version; our $VERSION = qw(0.01);
    Last edited by Puffin the Erb; 01-30-2010 at 02:48 PM. Reason: added code tags

  • Users who have thanked Puffin the Erb for this post:

    Phil Jackson (01-30-2010)

  • #8
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,871
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Rather than perpetuating incomplete and/or buggy form processing code, it would be better to use the CGI module.

    Replace the loading of the post-sort.pl script with this:
    Code:
    use CGI qw(:standard :cgi-lib);
    my %arg = Vars;
    or use the OO interface, which I prefer.
    Code:
    use CGI;
    my $cgi = CGI->new;
    my %arg = $cgi->Vars;
    either one of those is a far superior method.

    Code:
    package postsort;
    Lowercase package names are "reserved" for pragmas. It's better to use titlecase names.

    And, if you're going to turn it into a proper module, then it would be best to wrap that code in a subroutine that is exported and have that sub return a hash.

  • Users who have thanked FishMonger for this post:

    Phil Jackson (01-30-2010)

  • #9
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    Thanks going to give them a bash!
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •