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.
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.
Simple. Don't use it right? We'll I have data encrypted with this method that I need to decrypt first in order to upgrade it to something more secure and modern. I'd prefer not to have to decrypt, store it in the db, and then come back and re-encrypt using a new method.
my $ciphertext = $cipher->encrypt_hex($plaintext);
my $text = $cipher->decrypt_hex($ciphertext);
$text and $plantext aren't equal on 3.04 but they are on 2.33. I dug through the documentation and changelog but can't spot anything that says this shouldn't work. There are lots of new options in 3.04. I reached out to Lincoln Stein (the author) but I haven't heard back. Any other experts? :)
EDIT: It looks like I'm not the only one. https://rt.cpan.org/Public/Bug/Display.html?id=134355 Unfortunately I'm using different calling params and not sure how to adapt to my situation. :(
Is there a way to stop the CPAN Testing process?
And if there is, should I?
Last evening I uploaded a new version of Image::Square with new tests using PNG images for input and output instead of JPEG images. This followed the advice I got on Testing image output
The first two test results came in just before I settled down to sleep and they were both PASS so I went to sleep content...only to check this morning and find lots of FAILs 😕
This morning I uploaded a new version using the native GD image format and using cmp_ok instead of ok from hippo's Basic Testing Tutorial
So now that this latest version is uploaded, is there a way to stop CPAN Testers from wasting their precious resources on a module version that will fail at least some of the time? Does it stop automatically when a new version is uploaded?
Edit:
Changed link to point to GitHub repo and not the CPAN Tester results.
I've been asked to review and refactor/optimize a large collection of perl5 scripts, and a great many that include regular expressions would appear to benefit from s///e, the eval modifier, as in s/PATTERN/CODE/e, iff I can substitute ANY regex for CODE. Programming Perl 4th, pg 254 says, to wit: "Applications of this technique are limitless", and I agree if I can generalize the use of any regular expression in CODE. However, things are not going according to plan in my perl (v5.36.1) built for darwin-2level. A very simple case in point (I have much more complex instances once I can get this basic example to work.
my $str = 'This ia a real number, 123456.56';
say $str;
(my $res = $str) =~ s{ (\d+) }{ sprintf("%s", 4*$1) }xe; # $1*4, just
+to show /e works
say $res;
say "\$1 = $1";
(my $adj = $1) =~ s/(\d)/3/g; # replace each \d with '3', same reason
say $adj;
($res = $str) =~ s{ (\d+) }{ ($adj = $1) =~ s/(\d)/3/g }xe; # replace
+'123456' with '333333', proof of concept
say $res;
This ia a real number, 123456.56
This ia a real number, 493824.56
$1 = 123456
333333
This ia a real number, 6.56
The resulting string after substitution should be 333333.56. There are, indeed 6 substitutions, so it looks like the boolean value of each iteration is being substituted. The fragment '($adj = $1) =~' I believe is required because $1 is immutable, and the result is the same with /ee. Any suggestions re patterns of regex expressions in the CODE part of S/PATTERN/CODE/ would be very appreciated.
which seemed a strange proposition, because how could the scalar $_ contain both $i and $j? I tried it, thinking: "I gotta SEE this!". I thought perhaps Perl was clever enough to make $_ a reference to a list, but say or print of that would only be the reference, which was even more perplexing why it was suggested.But it only throws a syntax error on the second "for".
I have a working script and thus- the following is completely unnecessary. For the most part, I'm just wanting to "improve" the script by separating the data from the core script, and I'm asking for suggested good/best practices.
The data entries are each elements in an array of hashes. Here is an example of some the hash keys.
Is it best practices to leave it in the script or to save it to one data file or a list of data files? For my specific situation, there is no reason to set up an SQL server and database. I just want to use a simple file or files in a directory which contain the information I need to run the script with a little bit of abstraction.
Another question: is there a good CPAN module to use to input it into an array of hashing as already implemented in the script, I have no idea what to look for.
I'm branching out from working with HTML::TreeBuilder::XPath and HTML::Element which I am comfortable with. I am now trying to streamline some existing scripts by using XML::LibXML and XMLL::Element instead since that seems to allow transformation between various instances of XML more easily.
Or maybe not. There are some differences but by and large everything I have tried has gone well, and the parts I have refactored seem to run more quickly, except now I have become stumped by the error produced on line 19 in the script below, "XML::LibXML::Node::addSibling() -- nNode is not a blessed SV reference". How can I get past that and add a node?
#!/usr/bin/perl
use XML::LibXML;
use XML::Element;
use strict;
use warnings;
# produces the following error:
# XML::LibXML::Node::addSibling() -- nNode is not a blessed SV referen
+ce ...
my $html = XML::LibXML->load_xml( IO => *DATA{IO} );
foreach my $dd ($html->findnodes('//dd[*/*/a[@class="f"]]')) {
if (my $f = $dd->find('./*/*/a[@class="f"]/@href')) {
print qq(F=$f\n);
my $cc = XML::Element->new('dd');
$cc->push_content('foo');
$dd->addSibling($cc); # this line fails
}
}
print $html->toString,"\n";
exit(0);
__DATA__
<html><body>
<dl>
<dd><details><summary>Example</summary>
<dl>
<dd><details><summary>one
<a href="http://localhost/s1" class="s">0</a>
<a href="http://localhost/f1" class="f">0</a>
</summary></details></dd>
<dd><details><summary>two
<a href="http://localhost/s2" class="s">1</a>
<a href="http://localhost/f2" class="f">1</a>
</summary></details></dd>
<dd><details><summary>three
<a href="http://localhost/s3" class="s">2</a>
<a href="http://localhost/f3" class="f">2</a>
</summary></details></dd>
</dl></details>
</dd>
</dl>
</body></html>
The script successfully selects a specific set of dd elements below but cannot add a sibling to any of them, at least not the ways I've tried so far. I've tried quite a few permutations and variations on the theme, too.
Snippets of code should be wrapped in
<code> tags not<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).