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.
I'm having a problem. I'm porting some perl to C to speed it up, and I can't get the two languages to agree on what's going on. I'm using ActiveState's perl 5.24.1 for Windows. Consider the following code:
The code prints a string of 10s, indicating that the 13/10 combination in Windows has been translated to a bare 10. I can understand that, for compatibility reasons. But it seems to mean there is no way in Windows of telling a 13/10 combo from a bare 10. This makes a difference in my code, in that I can't get C and perl to hash the same string the same way. Am I missing something? Is there no way at all to tell a 13/10 from a 10 in Windows perl?
I believe the upshot of this, where my code is concerned, is that perl is doing it "wrong" compared to C and I'll never get the two to agree. I hope I'm wrong about that. I note with interest and mild annoyance that strlen("\n") == 1 even in C for windows. But C allows me to get at the underlying character buffer and perl does not.
Always unpack @_ first at line 22, column 1. See page 178 of PBP. (S
+everity: 4)
Subroutine "foo" does not end with "return" at line 22, column 1. See
+ page 197 of PBP. (Severity: 4)
I've found a partial workaround: running perlcritic on the output of B::Deparse instead of the source itself. It reports lots of sins committed by Function::Parameters themselves (e.g. Magic variable "$^H" should be assigned as "local" at line 14, column 44. See pages 81,82 of PBP.) but seems to work.
Unfortunately, it gets more complex when Types::Standard are added to the mix.
use Function::Parameters;
use Types::Standard qw( Num );
fun foo (Num $x) {
$x + 1
}
As expected, i sometimes get partial json objects in $data.
My first idea would be to so something like m/{.*?}/ against $data. Or rather some more elaborate version that deals with balanced parens and quoted strings.
My question is, is there an easier / simpler / more straightforward way to deal with something like this that I am missing?
-- Sec
EDIT: to clarify a bit.
The problem is that in the callback $data may just be
I am trying to create a hash and then print it out. When executing program, I am getting $key & $value need explicit package.
O wise monks, please show me the error of my ways :)
#! /usr/bin/perl
use v5.12;
use warnings;
## 2/15/19
my @people = qw{ fred barney fred wlima dino barney fred pebbles
+};
my %count; # new empty hash
$count{$_}++ foreach @people;
while ( ($key, $value) = each %count) {
print "$key => $value\n";
}
~
Friday afternoon question: what's the real purpose of namespace::autoclean in your OO code?
I've seen it in classes written with Moose, but the description Keep imports out of your namespace
doesn't really speak to me about the advantage of using it. Where am I going to get bitten if I don't use it. Just a simple answer will do.
thanks,
Ea
Sometimes I can think of 6 impossible LDAP attributes before breakfast.
I setup a new perl (strawberry portable) and I'm stuck with a failing connection to mysql server. That connection was working (and is still working) without problem on my old perl setup. I have no admin rights on the mysql server, I didn't create the users and password myself.
I have tried to move DBIx::Class in perl/site/lib and DBI in perl/vendor/lib from the old to the new install, but that does not change the problem.
The error is
DBI Connection failed: DBI connect('host= ... ;database= ... ;','user_
+name',...) failed: Authentication plugin 'mysql_old_password' cannot
+be loaded: The specified module could not be found.
at c:/spp/perl/vendor/lib/DBIx/Class/Storage/DBI.pm line 1517. at c:/
+spp/perl/vendor/lib/DBIx/Class/Schema.pm line 1118.
DBIx::Class::Schema::throw_exception(Dbc::Schema=HASH(0x5aa0c2
+4), "DBI Connection failed: DBI connect('host=mysql.unifr.ch;datab"..
+.) called at c:/spp/perl/vendor/lib/DBIx/Class/Storage.pm line 113
DBIx::Class::Storage::throw_exception(DBIx::Class::Storage::DB
+I=HASH(0x5aa516c), "DBI Connection failed: DBI connect('host=mysql.un
+ifr.ch;datab"...) called at c:/spp/perl/vendor/lib/DBIx/Class/Storage
+/DBI.pm line 1558
DBIx::Class::Storage::DBI::catch {...} ("DBI connect('host=mys
+ql.unifr.ch;database=dokpe_i02;','dokpe_"...) called at c:/spp/perl/v
+endor/lib/Try/Tiny.pm line 123
Having a problem keeping my floating point vars as floats and not being truncated to integers
when I try to split the string Lemme show working vs. non:
#working:
>perl -e 'printf "(%s)\n", $ARGV[0]', 2.3
(2.3)
#still good:
> perl -e 'printf "%s\n", do { $ARGV[0] }', 2.3
(2.3)
# now to split
> perl -we 'printf("(%s)\n", split(q(.), "$ARGV[0]" ) );' 2.3
Missing argument in printf at -e line 1.
()
Why missing (argument), and why empty output?
split should output an array in list context and the list length in scalar context, so either a list (array ref, I guess?) of "2, 3" or a scalar '2', as number of elements, no?
I'm writing a Perl module to try to autodetect whether a spreadsheet/csv file has a header row. It's a somewhat tricky problem especially when trying to factor in the kind of malformed data people might feed in. I'm sticking with simple cases for now. I'd like to try to do some statistical analysis of the data to help me. Unfortunately, my knowledge of statistics is very weak. I'm feeling my way in the dark. So take this sample column for example:
It's obviously a column of states. One thing that might jump out to a computer is that the length of the first row is 5 letters while the rest of the rows are two letters. Things can of course get fuzzier. The first row might have 5 letters while the rest of the columns have 2 OR 3 letters. Other tell-tale signs might be the header column is a string while the column is full of numbers. Or the header column might be named "STATUS" while the data might only contain the words "ACTIVE" or "RETIRED." The size of the column is also an important factor. If there is a lot of data, any statistical approach will likely be more accurate.
The Math::NumberCruncher module has some useful functions I think I could use like standard deviation to help me analyze things like how diverse the dataset is for a certain property (length, number of unique values, etc.). But I'm not really sure how I might apply it to be useful in a practical way. I found this interesting article was useful but there's no code and not being familiar with statistics, I'm still not clear on exactly how that analysis was done.
I intend to analyze each column and try to come up with some kind of "likely has header" factor based on the analysis. If it looks like most columns have a header, then it will determine that the spreadsheet has a header row.
Sorry this question is so open-ended. But any tips/advice you can think of would be appreciated.
$PM = "Perl Monk's";
$MCF = "Most Clueless FriarAbbotBishopPontiffDeaconCuratePriest Vicar";
$nysus = $PM . ' ' . $MCF; Click here if you love Perl Monks