Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

The Monastery Gates

( #131=superdoc: print w/ replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Apache Kafka prior use
No replies — Read more | Post response
by Wiggins
on Jul 23, 2016 at 14:52
    I am looking for advice from someone who has sailed a possibly mythical sea named 'Apache Kafka' in a Perl boat.

    Due to a thinness of published guidance for the Perl interface, I would like to know if a different Producer is needed for each 'different topic'? I have the producer and consumer each on separate threads. But now have to publish to 3 different topics. I know consumers a 1:1 with topics. Are publishers the same?

    It is always better to have seen your target for yourself, rather than depend upon someone else's description.

Regex on a variable with special characters
3 direct replies — Read more / Contribute
by jaydee
on Jul 22, 2016 at 04:40
    I have 2 variables one is simple like below.
    $x = "SERVER-NAME";
    and I am trying to see if $y starts with $x, but $y sometimes contains regex special characters like ()[], also ** which can give me errors.

    How can I safely check if $x at the start of $y?

    $y =~ /^$x/;
    is the current regex I am using.
XS generation error, function returning list
1 direct reply — Read more / Contribute
by Cacadril
on Jul 21, 2016 at 15:46

    Following the perlxstut, in example 5 I get the following error:

    Mytest.c:251:2: error: too few arguments to function 'statfs'

    The example creates a module function statfs that is tested like this in t/Mytest.t:

    my @a; @a = &Mytest::my_statfs("/blech"); # Test non-existent file/directory ok( scalar(@a) == 1 && $a[0] == 2 ); @a = &Mytest::my_statfs("/"); # Test existing file/directory is ( scalar(@a), 7 );

    In other words, the function returns a list.

    In Mytest.xs:

    #include <sys/vfs.h> ... void statfs(path) char * path INIT: int i; struct statfs buf; PCODE: i = statfs(path, &buf); if (i == 0) { XPUSHs(sv_2mortal(newSVnv(buf.f_bavail))); XPUSHs(sv_2mortal(newSVnv(buf.f_bfree))); XPUSHs(sv_2mortal(newSVnv(buf.f_blocks))); XPUSHs(sv_2mortal(newSVnv(buf.f_bsize))); XPUSHs(sv_2mortal(newSVnv(buf.f_ffree))); XPUSHs(sv_2mortal(newSVnv(buf.f_files))); XPUSHs(sv_2mortal(newSVnv(buf.f_type))); } else { XPUSHs(sv_2mortal(newSVnv(errno))); }

    The Makefile.PL generates the following C code:

    XS_EUPXS(XS_Mytest_statfs) { dVAR; dXSARGS; if (items != 1) croak_xs_usage(cv, "path"); { char * path = (char *)SvPV_nolen(ST(0)) ; #line 43 "Mytest.xs" int i; struct statfs buf; PCODE: i = statfs(path, &buf); if (i == 0) { XPUSHs(sv_2mortal(newSVnv(buf.f_bavail))); XPUSHs(sv_2mortal(newSVnv(buf.f_bfree))); XPUSHs(sv_2mortal(newSVnv(buf.f_blocks))); XPUSHs(sv_2mortal(newSVnv(buf.f_bsize))); XPUSHs(sv_2mortal(newSVnv(buf.f_ffree))); XPUSHs(sv_2mortal(newSVnv(buf.f_files))); XPUSHs(sv_2mortal(newSVnv(buf.f_type))); } else { XPUSHs(sv_2mortal(newSVnv(errno))); } #line 250 "Mytest.c" statfs(path); } XSRETURN_EMPTY; }

    Look near the end of this function. Why is this call to statfs being generated? I have tried to call the module function "my_statfs" instead of "statfs", Then the call near the end of the function becomes my_statfs(buf), while the call to the actual library function statfs remains statfs(path, buf), and the compiler message becomes "undefined reference to `my_statfs'".

    Why is this call being generated? What am I doing wrong?

    And, is XSRETURN_EMPTY the appropriate macro for a function that returns a non-empty list?

Match Line And Combine Into One Line
4 direct replies — Read more / Contribute
by jlope043
on Jul 21, 2016 at 13:37
    Hello Everyone, I am very new to Perl and have been learning it for the last few months now, but I have a scenario here that is a little out of my skill level and seeking help from the Pros on here. I have a report that I was given and need to reformat the report into a cleaner file to import into my system. I haven't a clue how to start to write this code which is why I didn't include one. I know I will need something like a MATCH or FIND, maybe a CHOMP and so one. What I want to do is combine the lines into the matching account. I have included a copy of my INPUT file and the format of my expected OUPUT file. Any help and explanation of the code would be great! Thank you in advance.

    input

    H123456,20151209,THIS IS A TEST H123456,20151209,TO COMBINE ALL H123456,20151209,MY MATCHING LINES H123456,20151209,INTO THE FIRST LINE H123456,20151209,THAT MATCHES. H654321,20151209,MATCH LINES FOR THIS H654321,20151209,ACCT INTO THE H654321,20151209,TOP LINE OF THE ACCT H432165,20151209,SINGLE LINE FOR THIS ONE

    expected output

    H123456,20151209,THIS IS A TEST TO COMBINE ALL MY MATCHING LINES INTO +THE FIRST LINE THAT MATCHES. H654321,20151209,MATCH LINES FOR THIS ACCT INTO THE TOP LINE OF THE AC +CT. H432165,20151209,SINGLE LINE FOR THIS ONE
Average start time handling midnight
8 direct replies — Read more / Contribute
by chrisjej
on Jul 21, 2016 at 08:16

    I'm wondering if anyone has a good algorithm to work out average start time that handles times over midnight. Assume the job runs once every 24 hours and will usually start within a 6 hour window.

    Obviously you could just sum seconds since midnight / number entries, which would work well if your times were:

    11:00 and 13:00 where it would give the plausible 12:00

    However...

    23:00 and 01:00 would also give the answer 12:00 whereas 00:00 is desirable.

    If, instead, you calculated this second example on seconds since 12:00 - you would get the desired answer of 00:00. But then the first example would also give you 00:00.

    I'm thinking you could do it by doing a first pass to generate a histogram and then derive a good base time from that.

    But I was hoping someone might already have implemented or know of a solution.

Perl API version v5.18.0 of ... does not match v5.16.0 ...
3 direct replies — Read more / Contribute
by Nightgem
on Jul 21, 2016 at 05:18

    Hi!

    I'm having trouble getting a Perl module (File::Sync) to work:
    perl -e "use File::Sync" Perl API version v5.18.0 of File::Sync does not match v5.16.0 at /usr/ +lib64/perl5/DynaLoader.pm line 213. Compilation failed in require at -e line 1. BEGIN failed--compilation aborted at -e line 1.

    The Perl version installed on the system is v5.16.3, built for x86_64-linux-thread-multi. I was wondering if anyone here could point me in the right direction to get this fixed and working properly. The File::Sync module was installed using cpanm.

    Thanks!
Variables are automatically rounded off in perl
5 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 21, 2016 at 02:37
    $hash->{TGT}=3335.9999999999995; print $hash->{TGT}; Actual Result:- 3336 Excepted Result:- 3335.9999999999995
Install and then load missing modules with in a script
1 direct reply — Read more / Contribute
by edimusrex
on Jul 20, 2016 at 14:16

    I am not sure if what I am attempting is possible but I'll ask any ways. I have a script which performs various checks. This script will be deployed on at least 6 servers. Currently I only require it to use 2 modules, DateTime and DBI; The idea is that it will first check to see if those modules are indeed installed and if they are not, install and load them. I am looking into Module::Load but not sure if it can handle what I am trying to accomplish. I'd prefer not to use a module to do this. What I currently have is the following

    #!/usr/bin/perl use warnings; use strict; my $version = `cat /etc/*-release | head -n 1`; chomp $version; my ($os) = $version =~ /(Ubuntu|CentOS)/; my %rhel = ( "DBI" => "perl-Class-DBI-mysql.noarch", "DateTime" => "perl-DateTime.x86_64", ); if ($os eq 'CentOS'){ foreach my $mod (keys %rhel){ eval { require $mod; $mod->import(); 1; } or do { system("yum install $rhel{$mod} -y"); } } }

    2 issues with this, 1 it does not actually seem to load the module and 2 I don't want the text in STDOUT from the eval.

    If any of this makes any sense and you can help I'd love the advice. Thanks in advance


    ------ UPDATE ------

    Seems like I have solved my issue. Here is what I ended up doing

    #!/usr/bin/perl use warnings; use strict; my $version = `cat /etc/*-release | head -n 1`; chomp $version; my ($os) = $version =~ /(Ubuntu|CentOS)/; my %rhel = ( "DBI" => "perl-Class-DBI-mysql.noarch", "DateTime" => "perl-DateTime.x86_64", ); if ($os eq 'CentOS'){ foreach my $mod (keys %rhel){ eval "use $mod"; if($@){ system("yum install $rhel{$mod} -y"); eval "use $mod"; } } }

    Thanks for the help

How to handle modules across different versions
2 direct replies — Read more / Contribute
by ksublondie
on Jul 20, 2016 at 10:50
    I have a couple windows servers running scheduled tasks in perl. Once upon a time, they were all in perl v 5.6. Over the years, we've been slowly trying to upgrade the old scripts to and creating the new scripts in the latest and greatest version at the time. So now we're running multiple versions.

    Of course, all the common functionality (email sending, network variables, etc) are kept in common modules. Currently, we have a different common.pm for each perl version. Is there a good way to simply have one common.pm for all versions? Or is it inevitable with running different versions?

Passing integer pointer in XS?
3 direct replies — Read more / Contribute
by martin67
on Jul 18, 2016 at 10:49
    Hi, I've started to use XS for interfacing an existing C library. It works so far until I come to passing integer pointers. I could really use some help here... The C function is defined as
    int WINAPI tdSensor( char * protocol, int protocolLen, char * model, int modelLen, int * id, int * dataTypes ) Use this function to iterate over all sensors. Iterate until TELLSTICK +_SUCCESS is not returned. Parameters: [out] protocol A by ref string where the protocol of the sensor +will be placed. [in] protocolLen The length of the protocol parameter. [out] model A by ref string where the model of the sensor will b +e placed. [in] modelLen The length of the model parameter. [out] id A by ref int where the id of the sensor will be placed. [out] dataTypes A by ref int with flags for the supported sensor + values. Returns: TELLSTICK_SUCCESS if there is more sensors to be fetched.
    My definition in the XS file look like this:
    int tdSensor(protocol, protocolLen, model, modelLen, id, dataTypes) char * protocol int protocolLen char * model int modelLen int * id int * dataTypes
    I had to add a definition in my typedef file:
    TYPEMAP int * T_PTR
    But this doesn't work as I think it should. I've tried with T_PV and T_PTRREF but no luck. When I call the code from my test program it looks like this:
    my $protocol = "aaaaaaaaaaaaaaaaaaaaaaaaa"; my $model = "bbbbbbbbbbbbbbbbbbbbbbbbb"; my $sensorId = 1; my $dataTypes = 2; while (TellStick::tdSensor($protocol, 25, $model, 25, $sensorId, $data +Types) == TELLSTICK_SUCCESS) { print "res: $res, protocol: $protocol, model: $model, sensorId: $sen +sorId, dataTypes: $dataTypes\n"; }
    I'm not really sure how I should call the function from Perl. Trial and error gave me that I needed to set a value on the strings (protocl & model) before calling tdSensor. But this does not seem to work for the integer pointers. Or should I call them like '\$sensorID' instead?

    It seems like it should be pretty trivial to pass a integer pointer so I hope to get some wisdom on how to do this from the Monks...

New Meditations
Larry Wall on Slashdot
2 direct replies — Read more / Contribute
by perldigious
on Jul 18, 2016 at 15:59
New Monk Discussion
Perlmonks proportion of Perl's "web presence" ?
1 direct reply — Read more / Contribute
by LanX
on Jul 17, 2016 at 19:06
    Hi

    How big is the importance of this site for the internet presence of the Perl community?

    Let's assume search results are representative...

    ... so when searching for Perl code, how probable is it that a search result leads me to the monastery?

    I have the impression most elaborated search queries ( like any word + " perl code " ) will show at least one link to this monastery among probably perldoc stuff ( http://perldoc.perl.org ), CPAN-Modules (http://cpan.org,http://metacpan.org), competitors (http://stackoverflow.com) and some hijacked "O'Relly" books.

    Is there a way to tell from google or DDG statistics?

    I think that the importance is even higher then 10%, because many monastery links are often subsumed under one "master" perlmonks link.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

    EDIT
    changed title
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2016-07-24 15:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (221 votes). Check out past polls.