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

Seekers of Perl Wisdom

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

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.

User Questions
[PPM (Perl Package Manager)] Installing multiple modules from a single ppd file
No replies — Read more | Post response
by syphilis
on Mar 28, 2017 at 06:17
    Hi,
    Here follows a post I sent to ActiveState's ppm mailing list about 24 hours ago:

    <quote>

    Is it possible to have the one ppd file download, unpack and install more than one tarred and gzipped blib file.

    That is, instead of having just one "<CODEBASE HREF= ..." line, I'm looking for the option of having multiple such "<CODEBASE HREF=...." lines present in the one ppd file, such that a number of different tarred and gzipped blib files are dowwnloaded, unpacked and installed.

    Possible ? ... or do I have to put the additional files into their own separate ppm distro and pull them in with "DEPENDENCY NAME".

    Btw, is there a difference between DEPENDENCY NAME and REQUIRE NAME ?

    </quote>

    It's a very low volume mailing list, and no replies yet.
    So I thought I might repeat the post here.

    I've a vague notion that, at some time in the past, I've come across a ppd file that would install multiple perl modules, but I'm currently unable to locate such an example.

    Cheers,
    Rob
How to patch this module?
3 direct replies — Read more / Contribute
by ultranerds
on Mar 28, 2017 at 05:19
    Hi guys,

    I've setup my own server with Perl 5.22.1, and I'm having issues installing a Perl module (Kavorka, which is an annoying requirement of Net::Stripe). After some digging, it seems to be around this :

    PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::H +arness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/l +ib', 'blib/arch')" t/*.t t/01basic.t .................... ok t/02named-functions.t .......... Can't locate object method "_set_decl +ared_name" via package "Kavorka::Sub::Fun" at /root/.cpan/build/Kavor +ka-0.037-RoeMIW/blib/lib/Kavorka/Sub.pm line 182. t/02named-functions.t .......... Dubious, test returned 255 (wstat 652 +80, 0xff00) No subtests run t/03anon-functions.t ........... Can't locate object method "declared_ +name" via package "Kavorka::Sub::Fun" at /root/.cpan/build/Kavorka-0. +037-RoeMIW/blib/lib/Kavorka/Sub.pm line 48. t/03anon-functions.t ........... Dubious, test returned 255 (wstat 652 +80, 0xff00) No subtests run t/04named-methods.t ............ Can't locate object method "_set_decl +ared_name" via package "Kavorka::Sub::Method" at /root/.cpan/build/Ka +vorka-0.037-RoeMIW/blib/lib/Kavorka/Sub.pm line 182. t/04named-methods.t ............ Dubious, test returned 255 (wstat 652 +80, 0xff00) No subtests run t/05anon-methods.t ............. Can't locate object method "declared_ +name" via package "Kavorka::Sub::Method" at /root/.cpan/build/Kavorka +-0.037-RoeMIW/blib/lib/Kavorka/Sub.pm line 48. t/05anon-methods.t ............. Dubious, test returned 255 (wstat 652 +80, 0xff00) No subtests run t/10positional.t ............... Can't locate object method "_set_decl +ared_name" via package "Kavorka::Sub::Fun" at /root/.cpan/build/Kavor +ka-0.037-RoeMIW/blib/lib/Kavorka/Sub.pm line 182. t/10positional.t ............... Dubious, test returned 255 (wstat 652 +80, 0xff00) No subtests run t/11named.t .................... Can't locate object method "_set_decl +ared_name" via package "Kavorka::Sub::Fun" at /root/.cpan/build/Kavor +ka-0.037-RoeMIW/blib/lib/Kavorka/Sub.pm line 182. t/11named.t .................... Dubious, test returned 255 (wstat 652 +80, 0xff00) No subtests run t/12invocant.t ................. Can't locate object method "_set_decl +ared_name" via package "Kavorka::Sub::Method" at /root/.cpan/build/Ka +vorka-0.037-RoeMIW/blib/lib/Kavorka/Sub.pm line 182. t/12invocant.t ................. Dubious, test returned 255 (wstat 652 +80, 0xff00)
    ...etc

    I found a report of a bug in Devel::CallParser:

    https://rt.cpan.org/Public/Bug/Display.html?id=110623

    I made the change the suggest in the patch for CallParser.xs in the .gz file, but I can't work out what this file is meant to be:

    t/pad2.t

    (I don't see it in the .gz from CPAN)

    Can anyone point me? Its sooooo frustrating that ALL of my issues are resting on this one bug, that after over a year still doesn't seem to have been fixed in the official releas :/

    Thanks!

    Andy
perl6 custom operator problem
No replies — Read more | Post response
by freakcoco
on Mar 28, 2017 at 05:07

    hi monk I am studying chemistry in the university,
    and then I try to write all the things in the textbook with Perl6 or Perl,
    like balancing the chemical formula or other process!
    Then I encountered the problem is on perl6 custom operator.
    I feel I have been repeating my code and myself when i use the feature.
    It is hard to read and write, and what is the way to deal with such problems?

    #!/usr/bin/env perl6 use v6; #basic SI(International System of Units) type role MetricPrefix { method baseOn ( Str $base , Numeric $input ) { given $base { when 'pico' { return $input * 10**-12 } when 'namo' { return $input * 10**-9 } when 'micro' { return $input * 10**-6} when 'milli' { return $input * 10**-3 } when 'centi' { return $input * 10**-2 } when 'hecto' { return $input * 10**2 } when 'kilo' { return $input * 10**3 } when 'mega' { return $input * 10**6 } when 'giga' { return $input * 10**9 } when 'tera' { return $input * 10**12 } default { fail "you must input a metric prefix which allow + pico to tera" } } } } class Mass does MetricPrefix { #basic Mass is g is different form si statda has $.g; submethod BUILD ( :$!g ) { } } class Length does MetricPrefix { has $.Length ; submethod BUILD ( :$!Length ) { } } multi postfix:<(kg)>( $input ) { return Mass.new( g => Mass.baseOn("kilo",$input) ) or fail "you Mu +st input a number"; } multi postfix:<(g)>( $input ) { return Mass.new( g => $input ) or fail "you Must input a number"; } multi infix:<+>( Mass $inputOne , Mass $inputTwo ) is assoc<right> { return Mass.new( g => $inputOne.g + $inputTwo.g) or fail "error in + there "; } multi infix:<->( Mass $inputOne , Mass $inputTwo ) is assoc<right> { return Mass.new( g => $inputOne.g - $inputTwo.g) or fail "error in + there "; } multi infix:<*>( Mass $inputOne , Mass $inputTwo ) is assoc<right> is +tighter( &infix:<+> ) is tighter( &infix:<-> ) is tighter( &infix:</> +) { return Mass.new( g => $inputOne.g * $inputTwo.g) or fail "error in + there "; } multi infix:</>( Mass $inputOne , Mass $inputTwo ) is assoc<right> is +tighter( &infix:<+> ) is tighter( &infix:<-> ) { return Mass.new( g => $inputOne.g / $inputTwo.g) or fail "error in + there "; } #the meterLeng multi postfix:<(km)>( $input ) { return Length.new( Length => Length.baseOn("kilo",$input) ) or fai +l "you Must input a number"; } multi postfix:<(m)>( $input ) { return Length.new( Length => $input ) or fail "you Must input a nu +mber"; } multi infix:<+>( Length $inputOne , Length $inputTwo ) is assoc<right> + { return Length.new( Length => $inputOne.Length + $inputTwo.Length) +or fail "error in there "; } multi infix:<->( Length $inputOne , Length $inputTwo ) is assoc<right> + { return Length.new( Length => $inputOne.Length - $inputTwo.Length) +or fail "error in there "; } multi infix:<*>( Length $inputOne , Length $inputTwo ) is assoc<right> + is tighter( &infix:<+> ) is tighter( &infix:<-> ) is tighter( &infix +:</>) { return Length.new( Length => $inputOne.Length * $inputTwo.Length) +or fail "error in there "; } multi infix:</>( Length $inputOne , Length $inputTwo ) is assoc<right> + is tighter( &infix:<+> ) is tighter( &infix:<-> ) { return Length.new( Length => $inputOne.Length / $inputTwo.Length) +or fail "error in there "; } #just a test say 10(kg) + 1(g); say 10(m) + 1(m);
How best to write a cross-platform .xs module using x64 assembler?
1 direct reply — Read more / Contribute
by cnd
on Mar 28, 2017 at 04:18
    I wish to donate an intel chip-speed algorithm to perl users.

    It works exclusively on 64bit x64 compatible CPUs (mac, windows, linux at least).

    What would be the best way to make this available, and what build instructions (if any) do I need for those platforms so users can get and use my module ?

    Is anyone aware of any existing assembler .xs modules that work at least on linux, preferable also mac and maybe windows ?

    If anyone has suggestions for which assembler toolchains and debugging environments I should use for build pre-release testing - those would also be greatly received! Chris.

Q regex escape within variable
2 direct replies — Read more / Contribute
by palkia
on Mar 28, 2017 at 04:18
    Hello.

    I tried clustering some file names based on their prefix (those beginning with closers) while ignoring the specific numerical values within them.
    To achieve this, whenever a desired prefix pattern appeared, I subbed the numerical values with \d++ so it can be used later as a regex pattern,
    however since the prefix contains closers and possibly other special regex characters, I have sandwiched all non-\d++ parts with \Q and \E,
    but that raises the error Unrecognized escape \Q passed through in regex;
    I can't seem to figure what I am missing ?
    ... if($fName =~ /^([\[\(].+?[\]\)])/) { #pref detected. generalizing digits my $pref = '^\Q'.$1.'\E'; $pref =~ s/\d++/\\E\\d++\\Q/g; #finding indexes of matches to this prefix my @matchIndexes; for(my $mex=0;$mex<@fNames;$mex++) {if($fNames[$mex] =~ /$pref/i){push(@matchIndexes,$mex);}} ...
    Thank you very much for any assistance, and have an awesome day ☺

    Update: resolved by quotemeta(), thx to Eily.
MongoDB Stored procedure from Dancer2
2 direct replies — Read more / Contribute
by actarus2003
on Mar 28, 2017 at 02:42

    Good day Monks,

    i'm trying to execute a simple insert into mongodb from dancer2, but i failwhen the insert statement call a stored function to determine the "_id" of the new document. my goal is to have as document is a simple unique auto incremental counter as documents ID.

    First i save the function using mongo sheel,

    > db.system.js.save({_id:"getNextSequence", value:function(name){ var +ret = db.counters.findAndModify({query: { _id: name },update: { $inc: + { seq: 1 }},new: true});return ret.seq; }});

    then from Dancer2 post i try to insert the new documents:

    post "/commNew" => require_login sub { my $userh = logged_in_user; my $username=$userh->{username}; my $adm=lc(config->{app}{commAdmin}); if($username =~ m/$adm/){ info ("User is $username for comm 2b" ); my $res=$comms->insert_one({"_id"=> getNextSequence("comm-id") +,"year" => config->{app}{year}}); my $lastid = $res->inserted_id; my @kuy = body_parameters->keys; info ("Insert int Mongo: ".$lastid); foreach my $oto ( @kuy ) { info ("key name value: " .$oto ." value: ".body_parameters +->get($oto)); $comms->update_one( {"_id" => $lastid},{'$set' => {$oto => + body_parameters->get($oto)}}); } info ("User is $username for comm 2z" ); }else{ return 404; } };

    Instead of evaluate the stored function "getNextSequence", it try to add the document like { "_id" : "getNextSequence(\"comm-id\")",.....}

    Where i'm wrong ?

    thanks in advance

ORA-12154: TNS:could not resolve the connect identifier specified (DBD ERROR: OCIServerAttach)
2 direct replies — Read more / Contribute
by rajesh_perl
on Mar 28, 2017 at 02:08
    I have written simple DB connectivity program, i am getting the following error, plesae advice ?
    use strict; use warnings; use DBI; # . /opt/CA/WorkloadAutomationAE/autouser.DEV/autosys.sh.`hostname` # TNS_ADMIN = "/usr/oracle/product/11.2.0.4/network/admin"; my $driver = "Oracle"; my $database = "ASYSDEV2"; my $dsn = "DBI:$driver:database=$database"; my $userid = "autosysr"; my $password = "A13sm_sd"; my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;
    Error :
    DBI connect('database=ASYSDEV2','autosysr',...) failed: ORA-12154: TNS +:could not resolve the connect identifier specified (DBD ERROR: OCISe +rverAttach) at perl_DBI.pl line 15 ORA-12154: TNS:could not resolve the connect identifier specified (DBD + ERROR: OCIServerAttach) at perl_DBI.pl line 15.
Selenium::Firefox (on Linux): create session error, but why?
No replies — Read more | Post response
by 1nickt
on Mar 27, 2017 at 22:44

    Learned brethren,

    I have installed Selenium::Firefox on my linux machine. I have also installed the Firefox browser, geckodriver binary and Xvfb so Firefox can run pseudo-headlessly and a Selenium server is not required. I am trying to run the simplest test script:

    use strict; use warnings; use feature 'say'; use Carp::Always; use Selenium::Firefox; my $driver = Selenium::Firefox->new; say 'Binary mode: ' . $driver->binary_mode; $driver->get('http://www.google.com'); say $driver->get_title; $driver->shutdown_binary; __END__
    The module appears to behave as documented in so far as it finds and launches the relevant binaries, according to the process table:
    vagrant 1885 00:03 /usr/local/sbin/geckodriver --port 9090 --m +arionette-port 2828 --binary /usr/lib/firefox/firefox.sh vagrant 1890 00:02 /usr/lib/firefox/firefox --marionette --pro +file /tmp/rust_mozprofile.Bezoxqxkgze8 vagrant 1933 00:01 /usr/lib/firefox/plugin-container -greomni +/usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -a +ppdir /usr/lib/firefox/browser 1890 true tab
    But it just hangs then throws an exception when I run it with:
    DISPLAY=:42 perl test/selenium.pl
    I get the following error:
    Could not create new session: at .../lib/perl5/Selenium/Remote/Driver +.pm line 428.
    Working back using the stack trace as a map I found that the code for creating a session in Selenium::Remote::Driver is executed regardless of condition from within BUILD. I can't see any place where that is overridden by the class that extends it (Selenium::Firefox), even though use of that class should by definition rule out a session with the Selenium server.
    if ($self->has_desired_capabilities) { $self->new_desired_session( $self->desired_capabilities ); } else { # Connect to remote server & establish a new session $self->new_session( $self->extra_capabilities ); }

    I confess I am a bit lost a this point. Thanks for any tips!


    The way forward always starts with a minimal test.
Working around limit to number of connections with Net::OpenSSH
3 direct replies — Read more / Contribute
by nysus
on Mar 27, 2017 at 15:47

    I have the following method:

    sub get_file { my $self = shift; my $file_path = shift; my $file = RemoteFile->new({ path => $file_path, ssh => $self->ssh } ); my $content = $file->read_and_delete; # attempt to destroy the object $file = ''; return $content; }

    The RemoteFile object relies on Net::OpenSSH to make the needed connection to download a file through a wrapper role I've written, MyOpenSSH:

    package RemoteFile; use Carp; use Moose; use Modern::Perl; use File::Basename; use File::Slurper qw(read_text write_text); use Params::Validate; with 'MyOpenSSH', 'MyLogger2', 'DownloadDir'; use namespace::autoclean;

    The get_file function is called repeatedly. However, about the 250th time the function is called, the program crashes, I'm guessing because some limit is hit on the number of SSH connection needed by the RemoteFile objects. Increasing the MaxSessions on sshd didn't help. So I tried to resolve this problem by setting the $file scalar to an empty string to try to destroy the object and hopefully its associated Net::OpenSSH object but that didn't work either. I'm not sure what else I can try to resolve this.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Hash vs constant vs package vs other for data structure
6 direct replies — Read more / Contribute
by oldtechaa
on Mar 27, 2017 at 14:38

    I'm using an AoAoA currently for a data structure. An example of its use would be like this: $notes[$x][$y][0] = ... As you can see, the first two dimensions refer to the location of an object and the third refers to properties of that object such as flags and other data. My problem is that although the indices always refer to the same data member, it's not very readable or maintainable if you forget the index number for the data you want.

    A couple solutions I've thought of are below:

    • Use an AoAoH instead, and refer to each data member by name
    • Use constant declarations to name each index
    • Use upper-case variables to show their status as constant names for indices
    • Use a package with setter and getter functions or public data members and use an AoA with the package objects as the contents
    • Get other ideas from PM

    What do you think? I don't want to use any external CPAN distributions and I'd like the solution to not require too much boilerplate. Thanks for your time.


Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [LanX]: ... test

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (7)
    As of 2017-03-28 10:30 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Should Pluto Get Its Planethood Back?



      Results (329 votes). Check out past polls.