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.
I have an array after splitting a text document into three different columns. I'm trying to retrieve the first value in the first column to compare against other values in that column and then print out that initial value but, when I use the following code, it prints all of the first column. I've tried several different methods of doing this but I think I'm just not understanding something. The code is below and any help is greatly appreciated. Thanks in advance!
my $file = $ARGV;
open (RAW, "./$file") or die "Can't open $file for read: $!";
open (OUT, ">./OUTPUT_$file") or die "Can't open Output_$file: $!";
my $line = $_;
next if ($line =~ /!/);
my @splits = split (',', $line);
my $first_value = @splits;
Hi all, I have this simple perl script working on an xml file, I want to print two attributes and one element, I just got two attributes, the element "observed", is not printed
Could you help me to fix it please
this is my code
Thanks in advance
my $file = 'sample.xml';
my $twig = XML::Twig->new();
my $root = $twig->root;
foreach my $species ($root->descendants('Ss'))
In a perl script i am calling a ksh file to copy files. (ie.) inside ksh file i am running the below tar command to copy the files from source to destination.
My task is, Need to create a 'success.ok' file, if tar command got succeed, else create 'failure.ok'. The issue is, while running ksh file through perl script, by default i am getting the exist value as '0' for both failure and success scenario..
KIndly please suggest how to solve this.
(tar cvf - * | cd /var/tmp/dump; tar xcf - ); output=\$\?; if \$output -eq 0; then touch /var/tmp/dump/success.ok; );
I'm observing an odd interaction of my module with Digest::MD5 that I haven't been able to figure out.
I'm implementing a read/write interface to a gzip variant using tied filehandles, with full seek/read/readline/tell support. I'm in the testing phase and nearly all of the tests I'm throwing at it seem to be working (basically performing exactly the same combinations of seek, read, <>, etc, on both my tied filehandle object (with the compressed file loaded) and a regular Perl filehandle opened on the uncompressed version, and comparing the output).
The one exception at this point is when I try to provide my tied filehandle to Digest::MD5's addfile() method. This doesn't work:
my $fh = B2B::BGZF::Reader->new_filehandle( $fn_bgzf );
my $hex = Digest::MD5->new()->addfile($fh)->hexdigest;
print $hex, "\n"; # prints d41d8cd98f00b204e9800998ecf8427e
The test returns almost immediately and it appears the hash returned is that of an empty string, so clearly the file is not actually being read. However, this works as expected:
my $fh = B2B::BGZF::Reader->new_filehandle( $fn_bgzf );
my $d = Digest::MD5->new();
my $buf = '';
$d->add($buf) while ( read $fh, $buf, 4096 );
my $hex = $d->hexdigest;
print $hex, "\n"; # prints the expected sum
Basically, I have only been able to observe the issue when using my module with the XS implementation of Digest::MD5. Debugging is difficult because I'm not sure what code is actually being called (apparently not the addfile() method of Digest::base or any other actual perl code I can find on my system). I have no problem just using the explicit read()/add() form with Digest::MD5, but if this is an indication of a subtle bug in my code I'd like to work it out - I'm just not sure how to do so.
Any help with understanding what Digest::MD5::addfile() is actually calling under the hood or what might be going on here would be greatly appreciated.
How can I get a match counter and use it as a prefix in the peplace term. For example, I have several times "position" in my text and want to peplace it with "position 1", "position 2" and so on. Many thanks in advance!
I'm running on SLES12, with apache 2.4.10 and mod_perl 2.0.8
In a vhost config file, I have a "PerlFixupHandler MyHandler" directive. Myhandler.pm is in /etc/apache2/script
If I do a perl -e'use MyHandler' from the commandline, everything works fine. But when it gets used from the server, it fails and is logging this in the error_log:
[Fri Aug 28 18:15:43.053198 2015] [perl:error] [pid 22133] [client x.x
+.x.x:x] failed to resolve handler `MyHandler': Can't locate Digest/SH
+A.pm: Permission denied at /etc/apache2/script/MyHandler.pm line 7.
+\nBEGIN failed--compilation aborted at /etc/apache2/script/MyHandler.
+pm line 7.\nCompilation failed in require at (eval 5) line 2.\n, refe
If I comment out the reference to Digest::SHA, it just fails on the next module.
For debugging, I added a BEGIN block to dump INC and to try and read the SHA.pm file, and that does not appear to cause any errors.
This configuration used to work fine on apache 2.2 ; I did some minimal updates to the configuration files for the new authentication stuff in 2.4, but nothing related to perl.
Any idea on what's wrong and how to fix it?
Edit: Here's the start of the .pm in question:
use Apache2::Const qw(:common);
use Digest::SHA qw(sha256_hex sha1_hex);
use Apache2::URI ();
use APR::Pool ();
Can I pass a given month to Time::Piece and get its last day?
use Time::Seconds qw(ONE_DAY ONE_WEEK ONE_MONTH ONE_YEAR);
# Create Time::Piece New Object for the dates
my $t = Time::Piece->new();
my $year = $t->year;
# Pass November, but it can be any month
my $month = "11";
my $last_day_month = $t->month_last_day($month); #??
print $last_day_month." days\n";