• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Perl script include ?

mikeshn

Senior member
Hello

I have the code below that repeats in every Perl script(totally 22 script). I know that in C/C++ I can include the file. How can I do that in Perl? In other words, I want to make
function or include file and than call in each scipt

# 2 Send it to the socket

use IO::Socket;
$sock = IO::Socket::INET->new( PeerAddr => 'localhost',
PeerPort => '9399',
Proto => 'tcp'
);
die "Could not create socket: $! \n" unless $sock;
$sock->send($request);

# 3. Get feedback from socket and assign it to $feedback

$sock->recv($feedback,5000);
close ($sock);

# 4. Parse XML information

use XML::Simple;
my $xs1 = XML::Simple->new();
my $info = $xs1->XMLin($feedback);

Thanks
 
I believe you can use 'require /path/to/filename' and it'll be included, although I can't remember for sure right now.
 
Just throw that entire block of code into a file (let's call it mylib.pl for this example). At the end of mylib.pl, add:

1;

by itself on the very last line. Next, throw in:

require "mylib.pl";

at the top of the documents you want it included in. If it's in a different directory, be sure to include the path info before the filename. The 1; line in mylib.pl is very important since the included file needs to return a non-zero result when it's included. Hope this helps. 🙂
 
Back
Top