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 section is the place to ask. Post a new question!
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.
It currently produces a "readline() on closed filehandle FILE" if there is a space in the path. I've done a lot of research and the answer is quoting the path. I think I've done that. I'm running perl5.10.0 on MacOS 10.6.8.
Hi monks, I just registered. Thanks in advance!
I want to use WWW::Mechanize::get in an inherited class's "get" subroutine, but it does not export any error (like "GETting...") even while the Internet access is out. See my code:
package MyMech;
use base qw(WWW::Mechanize);
sub new {
my $class = shift or die $!;
my $self = $class->SUPER::new;
return bless $self, $class;
}
sub get {
my $self = shift;
$self->SUPER::get(@_);
}
I think the get routine should work just like the base class' one, but it never die when it fails GETting.
When I call the class and use the get subroutine while the Internet access is out, it just pass through the GETting error without saying anything and $mech->title produces "Uninitialized..." error.
It works perfectly when the access is not out.
Does anybody know why it happens? Thank you so much!
Return code = 65280
Error = No such file or directory
I have ensured that C:/zip.exe files exists and is executable. I tried executing other system binaries like cmd.exe but ran into the same issue.
My question is what could be causing this issue like
i. some environment setting is wrong and interfering with the system api and hence it is not able to load the binary.
ii. The $PATH variable in this environment is greater than 1024 characters. Is the length of this variable a concern or some paths set in this variable is causing this issue
Im curious if someone would be so kind as to share their experiences setting up a minimal perl container in lxc, openvz, bsd jails, linux-vserver or even chroots.
App::Staticperl (http://software.schmorp.de/pkg/App-Staticperl.html) looks like it might be a good starting point - if i wanted to avoid a stripped down installed of <favourite distro or bsd>
The ideal outcome would provide a container with mcpan and a given version of perl. Possibly some fusion of perlbrew and some dark magic to cook up the perl version then drop it in the container.
Use case is to wrap up apps and put resource limits on them. PAAS like really. I know uwsgi can use namespaces and what not, if someone has used that - please share!
when we use scalar keys %MyHash to get count of keys in a hash, does perl actually go through every key? I mean if it is a big hash having more than 100,000 keys, does it slow down?
I am able to read a mail from the inbox. My actual requirement is to fetch a mail from a subfolder in Outlook by comparing the subject of the mail in the Sub-Folder with a predefined text.
use Mail::Outlook;
use Win32::OLE::Const 'Microsoft Outlook';
my $outlook = new Mail::Outlook();
my $folder = $outlook->folder('Inbox');
my $message = $folder->last();
my $text = $message->Subject();
my $text1 = $message->From();
print "From : $text1\n";
print "Subject : $text\n";
Using the code above I can read the subject and from address of the mail in the inbox. But I'd like to read a mail from the sub-folder. Please provide some tips.
I have two PERL SCRIPT that stress CPU and MEMORY. I want to run them in parallel on hosts so I am trying to copy them on all the hosts and run them in parallel. I am utilizing a module Net::OpenSSH::Parallel to copy (which is working) and run the commands on all the nodes. I am not able to run these two SCRIPTS in parallel. I have tried to take the SCRIPT to background but only one of them runs. Could you guide where am I going wrong?
CPU SCRIPT
#!/usr/bin/perl
use strict;
use warnings;
my @cpu_cores = qw(4);
while (--$cpu_cores[0] and fork) {};
while () {};
MEMORY SCRIPT
#!/usr/bin/perl
use strict;
use warnings;
print "$$";
fork for 1 .. 4;
for (1 .. 10000) {
my $a = "xxxxx" x int rand 10_000_000;
my $b = ~$a;
my $c = reverse $b;
MAIN SCRIPT
use strict;
use warnings;
use Net::OpenSSH::Parallel;
use Term::ANSIColor;
use DBI;
#--------------------------------------------------------
#FINDING HOSTS FROM CLOUDERA MANAGER DATABASE
#--------------------------------------------------------
print color 'bold blue';
print " Finding hostname of the hosts configured\n\n";
my $ip_address = `ping r01mgt -w 1 | awk -F "(" '/PING/{print \$2}' |
+awk -F")" '{print \$1}'`;
chomp($ip_address);
# connect
my $dbh = DBI->connect("DBI:Pg:dbname=xxxx;host=$ip_address", "xxxx",
+"xxxx", {'RaiseError' => 1});
# execute SELECT query
my $sth = $dbh->prepare("SELECT name FROM hosts");
$sth->execute();
# iterate through resultset and create an array
my @hosts;
while(my $ref = $sth->fetchrow_hashref())
{
my($nodename, $hadoopname) = $ref->{'name'} =~ m/(\w+).(\w+)/;
push(@hosts, "$nodename");
}
@hosts = sort (@hosts);
print color 'reset';
#-----------------------------------------------------------
#COPYING THE PERL SCRIPTS AND EXECUTING THEM
#-----------------------------------------------------------
my $pssh = Net::OpenSSH::Parallel->new();
$pssh->add_host($_) for @hosts;
$pssh->push('*', scp_put => '/root/cpu.pl', '/root/');
$pssh->push('*', scp_put => '/root/memory.pl', '/root/');
$pssh->push('*', command => '/usr/bin/perl', '/root/cpu.pl', '/tmp/cpu
+');
$pssh->push('*', command => '/usr/bin/perl', '/root/memory.pl', '/tmp/
+memory');
$pssh->run;
USING THREADS TO RUN SCRIPTS IN PARALLEL
#!/usr/bin/perl
use strict;
use warnings;
use threads;
sub cpu {
my @cpu_cores = qw(4);
print "CPU";
while (--$cpu_cores[0] and fork) {};
while () {};
}
sub memory {
print "MEMORY";
fork for 1 .. 4;
for (1 .. 10000) {
my $a = "xxxxx" x int rand 10_000_000;
my $b = ~$a;
my $c = reverse $b;
}
}
my $firstThread = threads->create(\&cpu);
my $secondThread = threads->create(\&memory);
$_->join() foreach ( $firstThread, $secondThread );