If
you have a question on how to do something in Perl, or
you need a Perl solution to an actual real-life problem, or
you're unsure why something you've tried just isn't working...
then this is the place to ask.
However, you might consider asking in the chatterbox first (if you're a
registered user). The response time tends to be quicker, and if it turns
out that the problem/solutions are too much for the cb to handle, the
kind monks will be sure to direct you here.
Does anyone know why I might get an error when I try to close STDIN, STDOUT, and STDERR in a child process? I get this error: child process STDIN is not a real system file handle
thanks...
I'm using Module::Build and have done for years. One thing seems odd to me: If you don't have a required module, it displays a nice message, but it still exits with success. This means you can't do this:
... and have it do what you'd think it would do, namely stop after the 'perl Build.pl' stage noticed that the prerequisite modules aren't there.
I'm guessing either a) I'm doing something wrong and it should work that way or b) I'm doing something wrong by trying to use it that way.
So, if I want to install Module::Build packaged modules via a shell script, what's the best way to tell the shell script if the prerequisite modules are or aren't installed?
I am trying to make DNS filter where I can send 'A' entry for some of the requested domains and redirect the request to a real DNS server if no domain matched.
I am stucked with the fact that tools like 'nslookup' send un-understandable characters to my perl script so I am unable to match anything and stopped working on the code until I get some help.
Here is my code:
use IO::Socket;
my $server = IO::Socket::INET->new(
Proto => 'udp',
LocalPort => 53,
);
die "Couldn't setup server: $@" unless $server;
while ( $server->recv(my $data , 1024, my $flag ) ) {
print "Got: $data\n";
}
Every once in a while, I'm getting a "GET" error on my program. I am fairly certain it is the website that is down. Rather than stopping the program and throwing off this error, is there a way to simply restart the program from the top? Thanks!
I love it when a program comes together - jdhannibal
I am having an issue where mime lite is not including the attachment when it sends out the file.
The main part of the script creates the attachment and is quite involved. Simply it creates a tab separated file since some of the data elements contain commas.
The script runs and mime lite sends the message but doesn't include the attachment.
Here is the section of my script for MIME::Lite
my $msg = MIME::Lite->new(
From => $from,
To => $lobmail,
Subject => 'DUA '. $lobn .' Ticket Activity Report',
Type => 'multipart/alternative',
);
$msg->attach (
Type => 'TEXT',
Data => "Attached is the ticket activity report for $lobn",
);
$msg->attach(
Type => 'text/plain',
Encoding => 'base64',
Path => '/home/eric/tmp/lobreport.tsv',
Filename => 'LobReport.tsv',
Disposition => 'attachment'
) or die "Unable to add attachment: $!\n";
$msg->send();
I seek the knowledge of the enlightened monks to help me reach the last leg of a forking server.
I have tried to read documentation available online, in cookbooks but I am not sure if it is the same as what I want.
The aim is to:
1. Create a telnet server running on port 7070.
2. Enable 5 clients at MAX to connect to it.
3. When 1 client is connected and running a command, all commands from other clients should be queued.(There are only 5 possible commands that a client can invoke, 2 of which are "printhelp" and "quit")
I have managed to reach level 1 and partially level 2. Multiple clients are able to connect to the server.
The problems that I face are these
A) When the first client dies, the server commits suicide. Advise is sought on this.
B) How can I prevent more than 5 clients from connecting.
C) How can I enable queuing of commands and ensuring the result of the commands are sent to the right client.
#!/usr/bin/perl -w
use IO::Socket;
use strict;
$SIG{CHLD} = sub{ wait; };
my $inputLine;
my $new_sock;
my $main_sock;
my $pid;
# Create Socket on port 7070
$main_sock = new IO::Socket::INET (
LocalHost => 'localhost',
LocalPort => '7070',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $main_sock;
print "Telnet Server listening on 7070....\n";
# Accept connection and fork child!
while( $new_sock = $main_sock->accept() ){
$pid = fork();
unless( defined($pid) ){
die "Cannot fork\n";
}
##################
# CHILD PROCESS
##################
if($pid == 0) {
# Print Welcome message!
welcomeClient($new_sock);
while( defined( $inputLine=<$new_sock>) ) {
$inputLine =~ s/[\r\n]//g;
if( $inputLine eq "printhelp" ){
callPrintHelp($new_sock);
}elsif( $inputLine eq "quit" ){
callQuit($new_sock);
exit(0);
}else{
print $new_sock "INFO> Not implemented yet
+\n";
}
}#while
exit(0);
}
##################
# CHILD PROCESS
##################
}# while main_sock
close($main_sock);
sub welcomeClient {
# Show starting point for client and help messages
my ($client_sock) = @_;
print $client_sock "######################################\n";
print $client_sock " Telnet Interface \n";
print $client_sock "######################################\n\n";
print $client_sock "INFO> Type 'printhelp' for help\n\n";
print $client_sock "READY:\n";
print $client_sock ">";
}
sub callPrintHelp{
my ($client_sock) = @_;
......
.....
}
sub callQuit{
my ($client_sock) = @_;
......
.....
}
Hello Monks!!!
The Win32::Scheduler module works fine in local machine to schedule a perl file. But when trying to connect to a remote go grid machine, it doesn't, and creates the job in local machine itself. There is a method - SetTargetComputer() where the host machine name is given. But i'm unaware where to give the Go grid machine's password. Here is my code