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.
I would like to create my own subroutines which would work the same way as print FILEHANDLE LIST works.
Is there any non-magic way to create a subroutine with an optional first argument? Or would that just create confusion in code?
The sub in question would be used to send a job into a queue. In most circumstances, there is only one queue. But there could be others. And the sub takes only one argument.
6109 changed on 2023-01-01 12:00, before status is ?
+after is C.
6109 changed on 2023-01-01 12:03, before value is 0 a
+fter is 2, before status is ? after is CS.
......
I've searched on CPAN, but all module about diff are generate or apply diff but not treat it. is there a module or convenient way to solve this?
Thanks in advance.
I have a dataset with columns and I want to evaluate a statement on each of the rows in the data. I can do this pretty easily. Loop
through each column, check if the column exists in the evaluation statement. If it does, replace the column name with the value
and do the evaluation. I can easily do this using regular expressions. Just curious how a true perl monk would approach this.
#!/usr/bin/perl
use strict;
use warnings;
my $row = {
a => 1,
b => 2,
c => 3,
d => 4
};
my $evalStatement="a>0";
sub evaluateRow {
my ($row) = @_;
## loop through each column a,b,c,d and if column exists in the evalua
+tion statement
## replace column with value
if (eval(1>0)) {
return 1 ## "ACCEPT row"
}
return 0 ## "REMOVE row"
}
I am trying to compute the number of intersecting array elements for multiple arrays (essentially elements belonging to separate parts of venn diagrams).
Initially and naively I thought this should be an easy thing to do and for 2 arrays it is:
1. Make a hash table for one array with keys being its elements
2. Loop through another array and count if an element exists in the previously created hash table
3. Subtract the number of shared elements from the total number of elements of each array.
But when the number of arrays increases the number of possible intersections between respective arrays increases (for A,B,C arrays we have A/B, A/C, B/C, A/B/C). So the problem I am having is how to scale the above algorithm.
Does anyone know a solution to this problem even if a limited number of sets can only be included (I think this is an NP problem thus any algorithm that can produce a solution for more than 7 arrays would be acceptable)
Hi Monks, I'm looking for suggestions on a personal project. I'm writing a program to fetch a page listing items for sale on an auction site, then parse it into an array (AoA) with title, link and price for each item (this part is done). The idea is to have it search the AoA next for items I'm looking for based on search parameters I set in a config file, then build an html file listing just those items so I can view it in a browser later. I'll use a cron job to run the program nightly.
I want to be able to do better than the basic search engine that you find on those type of sites. Maybe using something similar to SQL where you can have logical operators such as AND, OR, NOT and also be able to deal with variations in spelling of words. The search function is is where I'm looking for suggestions. Speed is not an issue and I'd like to avoid using a database. Are there any modules or examples that you can point me to? Thanks
Dear Monks,
I have recently embarked on my journey in Perl and I am already stuck with my first (most likely super trivial problem: I found a code snippet that I want to practice changing, where the example has the following array:
but the code does not run (it runs properly using the above snippet, but somehow the array must be written in the form I have specified above, else the grep command does not work.
Can you help me please?
I started learning Perl not too long ago (in 2016), and I am trying to get to a higher level. At least, I want to get familiar with every builtin function. Is there a website that explains what each builtin function does and how to use it with a little demo program that one can test?
I copied all the functions from perldoc and put them in an Excel file, and then I organized them into two groups -- the ones that I understand already and the ones that I don't understand. Then I broke them down into futher sub groups. These are the ones that I have used before and somewhat understand how they work and what they do:
FLOW-CONTROL:
goto sub if elsif else for foreach while continue next last return do die exit sleep kill system exec and or && || ? :
STDIO AND FILE SYSTEM I/O:
open print printf sysopen sysseek binmode eof rename chmod close unlink getc read stat utime seek tell sysread syswrite truncate opendir chdir closedir mkdir rmdir readdir rewinddir -e -f -s -d
MATH:
abs int ord srand rand exp cos sin sqrt ++ -- + - / * << >> == *= /= |= &= != >= <= < > | ^ & ! % ~
STRINGS:
substr length vec chomp chop pack unpack hex oct chr undef sprintf uc lc index rindex eq ne qw tr y s m x =~
OTHER:
use package import eval require warn __END__ __DATA__
Now, these are the ones that I don't understand:
Never used these and not sure: atan2 q qx qq qr chown reset gmtime fork link symlink local dump
bless our pos readline readlink syscall write format seekdir telldir
lock prototype formline getppid keys log
CPAN said I had an update this morning, so I performed it, to v2.36 . I THINK the previous version was around 1.96. I'm not sure because on the older systems, the command
I talked to CHATBOT AI, who suggested I edit ~/.cpan/CPAN/MyConfig.pm and change 'urllist' => [qhttps://cpan.org/]
</code>to'urllist' => [q[http://cpan.org/]]
(remove the "s") which I did; no effect.
I also tried to change it to both of these:
'urllist' => [q[http://metacpan.org/]]
and
'urllist' => [q[http://cpantesters.org/]]
But the error remained. It STILL looked in https://cpan.org, no matter WHAT I set that line to.
I also deleted /.cpan/BUILD , which chatbotAI said would kill the cache. No change, still the same error. It's ignoring the config changes. Yet when I rm -f .cpan, it rebuilds it THERE. So it does expect the config to be there. I'm doing all of this as root. I also did an updatebb and then locate on .cpan and the only one on the box is under ~/. Surprisingly, even
Friday, I have a ton of code to write, and down this rabbit-hole was the LAST thing I needed! Help is most appreciated- even help on going BACK to v1.9x ?
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).