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
Use of uninitialized value $i in bitwise and (&) at <Netmask.pm>
1 direct reply — Read more / Contribute
by dotowwxo
on Dec 18, 2017 at 03:45
    Hello everyone, I am very new to Perl. Any help would be greatly appreciated because I am stucked here for quite a long time :(

    Basically what I am trying to do is:

    1. I have a list of IP address in testingIP.txt

    2. I want to loop through the text file and find out which IP address is in the net mask that I have specified using a PERL module that I have installed -- Net::Netmask http://search.cpan.org/~muir/Net-Netmask-1.9015/Netmask.pod

    Unfortunately, it only works when there is only 1 IP address in testingIP.txt, this is my output for my current code:

    Use of uninitialized value $i in bitwise and (&) at /usr/local/share/p +erl5/site_perl/5.26/Net/Netmask.pm line 411, <$fh> line 1. IP address: 192.168.1.1 is not inside 192.168.1.0/27 Use of uninitialized value $i in bitwise and (&) at /usr/local/share/p +erl5/site_perl/5.26/Net/Netmask.pm line 411, <$fh> line 2. IP address: 192.168.1.2 is not inside 192.168.1.0/27 Use of uninitialized value $i in bitwise and (&) at /usr/local/share/p +erl5/site_perl/5.26/Net/Netmask.pm line 411, <$fh> line 3. IP address: 192.168.1.3 is not inside 192.168.1.0/27 IP address: 192.168.1.4 is inside 192.168.1.0/27

    This is my code

    #!/usr/bin/perl use strict; use warnings; use Net::Netmask; my $filename = 'testingIP.txt'; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; my $block = Net::Netmask->new("192.168.1.0/27"); while (my $row = <$fh>){ my @row = $row; for (my $i=0; $i < scalar(@row); $i++){ if ($block->match($row[$i])){ print "IP address: $row[$i] is inside $block\n"; } else{ print "IP address: $row is not inside $block\n"; } } }
Defining your own regex character class
2 direct replies — Read more / Contribute
by igoryonya
on Dec 18, 2017 at 00:18
    Hello, is there a way to define your own regex character class, such as [[:digit:]].
    So, I would, for example, define a regex:

    /\b(?:[[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}\b/

    and assign it to a:

    [[:ipv4:]]

    Is it possible to do something like that?

how to name an anonymous reference
4 direct replies — Read more / Contribute
by omkellogg
on Dec 17, 2017 at 16:59

    Let there be a small language for creating annotations. (The actual case in point is section 7.4.15 in OMG IDL4, http://www.omg.org/spec/IDL/4.1/PDF).

    Some annotations are predefined. In order to support both predefined annotations and user defined annotations, I would use an array, e.g.:

    sub ULONG () { 9 } sub ENUM () { 23 } my @annotations = ( [ "id", [ ULONG, "value", undef ] ], [ "autoid", [ ENUM, "AutoidKind", [ "SEQUENTIAL", "HASH" ] ], [ $annotations[1]->[1], "value", "HASH" ] ] );

    The idea is that the array is initialized with the predefined annotations, and user defined annotations are parsed and appended onto the same array later on.

    In the example above, the predefined annotation autoid first defines an enum type AutoidKind with values SEQUENTIAL and HASH, and then shall define a parameter named value of the enum type just defined.

    The notation $annotations[1]->[1] for referencing the enum type does not work - probably because the declaration @annotations is still in progress at the point of reference.

    Perhaps there is a different way to achieve what I am trying to do?

    Thanks.
[SOLVED] Dist::Zilla Getting rid of {{$NEXT}} at top of Changes file on GitHub
1 direct reply — Read more / Contribute
by nysus
on Dec 17, 2017 at 16:31

    I've been tinkering with the dist.ini file:

    [Git::NextVersion] [PodVersion] [PkgVersion] [NextRelease] [ReadmeAnyFromPod] type = markdown location = root phase = release [Git::Check] [Git::Commit] allow_dirty = README.mkdn allow_dirty = Changes [Git::Tag] [Git::Push] [GatherDir] [PruneCruft] [ManifestSkip] [MetaYAML] [License] [Readme] [ExtraTests] [ExecDir] [ShareDir] [MakeMaker] [Manifest] [TestRelease] [FakeRelease]

    I have it so that only the modules, a README.mkdn file, and a Changes files get uploaded to github. In the generated distro, the Changes file looks fine. But in the version that gets uploaded to GitHub from my repository's root, there is an unsightly {{$NEXT}} line in there. I'm wondering if there is an easy way to get rid of it using the tools available in Dist::Zilla.

    Solution

    The nifty Dist::Zilla::Plugin::Run came to the rescue. Here is how you do it:

    [NextRelease] [Run::AfterRelease] run = cp Changes tmp && cp %n-%v/Changes . <snip> [Git::Commit] allow_dirty = README.mkdn allow_dirty = Changes [Git::Tag] [Git::Push] [Run::AfterRelease / MyAppAfter] run = cp tmp/Changes Changes

    The [Run::AfterRelease] bit runs the command in the next line. The first run command has two commands. First it copies the Changes file with the {{$next}} code in it over to the tmp directory. Next, it gets overwritten by the "clean" version of the Changes file. The second run command simply moves the Changes file in the tmp directory back to the repository's root directory.

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

[maybe OT] What kind of bug was that? Non-deterministic result with C integer overflow?
2 direct replies — Read more / Contribute
by vr
on Dec 17, 2017 at 08:25
    use strict; use warnings; use feature 'say'; use PDL; use PDL::Image2D; use PDL::IO::Image; # sample: http://image.ibb.co/i6Qj76/test171217.png my $fn = 'test171217.png'; my $pdl = PDL::IO::Image-> new_from_file( $fn )-> pixels_to_pdl-> shor +t; say $pdl-> info; my $segmented = cc8compt( $pdl ); say $segmented-> info; say $segmented-> max;

    Function cc8compt in PDL 2.015, that shipped with Strawberry 5.24.0, returns piddle of same data format as its argument, i.e. e.g. short for short. Later versions appear to always return long, and therefore the described bug can not be observed.

    Running the script several times, I'm getting something like this:

    D:\>perl 171217.pl PDL: Short D [1200,3950] PDL: Short D [1200,3950] 32756 D:\>perl 171217.pl PDL: Short D [1200,3950] PDL: Short D [1200,3950] 32764 D:\>perl 171217.pl PDL: Short D [1200,3950] PDL: Short D [1200,3950] 32736 D:\>perl 171217.pl PDL: Short D [1200,3950] PDL: Short D [1200,3950] 32756 D:\>perl 171217.pl PDL: Short D [1200,3950] PDL: Short D [1200,3950] 32760

    The result is unpredictable, and I'm puzzled why -- even if Google says that signed integer overflow is "undefined behaviour", but shouldn't result be deterministic, at least? If I'm wrong, what exactly is happenning, during program execution? And BTW, changing short to long, in code, leads to correct (?) maximum count of 28299, value below maximum positive short, so it's unclear why any problems happen at all (I'm not brave enough to look into PDL source).

    I also was trying to use simple sample pdl, e.g. a kind of checker-board, but with that, no problem like described above.

Can't install Bot::BasicBot module
1 direct reply — Read more / Contribute
by Anonymous Monk
on Dec 17, 2017 at 07:41

    It just stops at that last line, nothing happens...

    Is this a network problem?

    c:\perl_test>cpan Bot::BasicBot Loading internal null logger. Install Log::Log4perl for logging messag +es CPAN: CPAN::SQLite loaded ok (v0.211) Database was generated on Sat, 16 Dec 2017 18:26:32 GMT Running install for module 'Bot::BasicBot' CPAN: Digest::SHA loaded ok (v5.96) CPAN: Compress::Zlib loaded ok (v2.074) Checksum for C:\STRAWB~1\cpan\sources\authors\id\B\BI\BIGPRESH\Bot-Bas +icBot-0.91.tar.gz ok CPAN: Archive::Tar loaded ok (v2.26) CPAN: YAML::XS loaded ok (v0.66) CPAN: CPAN::Meta::Requirements loaded ok (v2.140) CPAN: Parse::CPAN::Meta loaded ok (v2.150010) CPAN: CPAN::Meta loaded ok (v2.150010) CPAN: Module::CoreList loaded ok (v5.20170821) Configuring B/BI/BIGPRESH/Bot-BasicBot-0.91.tar.gz with Makefile.PL Checking if your kit is complete... Looks good Warning: prerequisite POE 0 not found. Warning: prerequisite POE::Component::IRC 6.62 not found. Generating a gmake-style Makefile Writing Makefile for Bot::BasicBot "\x{00f0}" does not map to cp437 at C:/Strawberry/perl/lib/ExtUtils/Ma +keMaker.pm line 1266. "\x{00f0}" does not map to cp437 at C:/Strawberry/perl/lib/ExtUtils/Ma +keMaker.pm line 1266. "\x{00f0}" does not map to cp437 at C:/Strawberry/perl/lib/ExtUtils/Ma +keMaker.pm line 1266. "\x{00f0}" does not map to cp437 at C:/Strawberry/perl/lib/ExtUtils/Ma +keMaker.pm line 1266. Writing MYMETA.yml and MYMETA.json BIGPRESH/Bot-BasicBot-0.91.tar.gz C:\Strawberry\perl\bin\perl.exe Makefile.PL -- OK Running make for B/BI/BIGPRESH/Bot-BasicBot-0.91.tar.gz ---- Unsatisfied dependencies detected during ---- ---- BIGPRESH/Bot-BasicBot-0.91.tar.gz ---- POE [requires] POE::Component::IRC [requires] Running install for module 'POE' Checksum for C:\STRAWB~1\cpan\sources\authors\id\R\RC\RCAPUTO\POE-1.36 +7.tar.gz ok Configuring R/RC/RCAPUTO/POE-1.367.tar.gz with Makefile.PL ============================================= Prompts may be bypassed by running: C:\Strawberry\perl\bin\perl.exe Makefile.PL --default ============================================= Some of POE's tests require a functional network. You can skip these tests if you'd like. Would you like to skip the network tests? [n] n *** Some optional features may not be available: *** Curses 1.08 could not be loaded. *** IO::Pty 1.02 could not be loaded. Checking if your kit is complete... Looks good Generating a gmake-style Makefile Writing Makefile for POE Writing MYMETA.yml and MYMETA.json RCAPUTO/POE-1.367.tar.gz C:\Strawberry\perl\bin\perl.exe Makefile.PL -- OK Running make for R/RC/RCAPUTO/POE-1.367.tar.gz "C:\Strawberry\perl\bin\perl.exe" mylib\gen-tests.perl lib/POE.pm cp lib/POE/Filter/Grep.pm blib\lib\POE\Filter\Grep.pm cp lib/POE/Loop/Select.pm blib\lib\POE\Loop\Select.pm cp lib/POE/Filter/RecordBlock.pm blib\lib\POE\Filter\RecordBlock.pm cp lib/POE/NFA.pm blib\lib\POE\NFA.pm cp lib/POE/Component/Client/TCP.pm blib\lib\POE\Component\Client\TCP.p +m cp lib/POE/Filter/Stream.pm blib\lib\POE\Filter\Stream.pm cp lib/POE.pm blib\lib\POE.pm cp lib/POE/Driver.pm blib\lib\POE\Driver.pm cp lib/POE/Component.pm blib\lib\POE\Component.pm cp lib/POE/Filter/Line.pm blib\lib\POE\Filter\Line.pm cp lib/POE/Filter/Block.pm blib\lib\POE\Filter\Block.pm cp lib/POE/Kernel.pm blib\lib\POE\Kernel.pm cp lib/POE/Filter/Map.pm blib\lib\POE\Filter\Map.pm cp lib/POE/Filter/Reference.pm blib\lib\POE\Filter\Reference.pm cp lib/POE/Loop.pm blib\lib\POE\Loop.pm cp lib/POE/Pipe.pm blib\lib\POE\Pipe.pm cp lib/POE/Filter.pm blib\lib\POE\Filter.pm cp lib/POE/Filter/Stackable.pm blib\lib\POE\Filter\Stackable.pm cp lib/POE/Component/Server/TCP.pm blib\lib\POE\Component\Server\TCP.p +m cp lib/POE/Loop/PerlSignals.pm blib\lib\POE\Loop\PerlSignals.pm cp lib/POE/Driver/SysRW.pm blib\lib\POE\Driver\SysRW.pm cp lib/POE/Loop/IO_Poll.pm blib\lib\POE\Loop\IO_Poll.pm cp lib/POE/Pipe/OneWay.pm blib\lib\POE\Pipe\OneWay.pm cp lib/POE/Filter/HTTPD.pm blib\lib\POE\Filter\HTTPD.pm cp lib/POE/Wheel/ReadLine.pm blib\lib\POE\Wheel\ReadLine.pm cp lib/POE/Test/Sequence.pm blib\lib\POE\Test\Sequence.pm cp lib/POE/Wheel/ReadWrite.pm blib\lib\POE\Wheel\ReadWrite.pm cp lib/POE/Resource/Aliases.pm blib\lib\POE\Resource\Aliases.pm cp lib/POE/Wheel.pm blib\lib\POE\Wheel.pm cp lib/POE/Queue.pm blib\lib\POE\Queue.pm cp lib/POE/Resources.pm blib\lib\POE\Resources.pm cp lib/POE/Pipe/TwoWay.pm blib\lib\POE\Pipe\TwoWay.pm cp lib/POE/Resource/FileHandles.pm blib\lib\POE\Resource\FileHandles.p +m cp lib/POE/Wheel/FollowTail.pm blib\lib\POE\Wheel\FollowTail.pm cp lib/POE/Resource/Sessions.pm blib\lib\POE\Resource\Sessions.pm cp lib/POE/Resource/Signals.pm blib\lib\POE\Resource\Signals.pm cp lib/POE/Session.pm blib\lib\POE\Session.pm cp lib/POE/Wheel/Curses.pm blib\lib\POE\Wheel\Curses.pm cp lib/POE/Wheel/ListenAccept.pm blib\lib\POE\Wheel\ListenAccept.pm cp lib/POE/Queue/Array.pm blib\lib\POE\Queue\Array.pm cp lib/POE/Wheel/Run.pm blib\lib\POE\Wheel\Run.pm cp lib/POE/Resource/Extrefs.pm blib\lib\POE\Resource\Extrefs.pm cp lib/POE/Resource.pm blib\lib\POE\Resource.pm cp lib/POE/Resource/SIDs.pm blib\lib\POE\Resource\SIDs.pm cp lib/POE/Resource/Clock.pm blib\lib\POE\Resource\Clock.pm cp lib/POE/Resource/Events.pm blib\lib\POE\Resource\Events.pm cp lib/POE/Wheel/SocketFactory.pm blib\lib\POE\Wheel\SocketFactory.pm RCAPUTO/POE-1.367.tar.gz C:\STRAWB~1\c\bin\gmake.exe -- OK Running make test "C:\Strawberry\perl\bin\perl.exe" mylib\gen-tests.perl lib/POE.pm "C:\Strawberry\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::H +arness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\l +ib', 'blib\arch')" t/*.t t/*/*.t t/*/*/*.t t/00_info.t ........................................ 1/1 # Testing POE + 1.367, POE::Test::Loops 1.360, Perl 5.026000, C:\Strawberry\perl\bin +\perl.exe on MSWin32 # pogomips: 49994203 t/00_info.t ........................................ ok t/10_units/01_pod/01_pod.t ......................... skipped: enable b +y setting RELEASE_TESTING t/10_units/01_pod/02_pod_coverage.t ................ skipped: enable b +y setting RELEASE_TESTING t/10_units/01_pod/03_pod_no404s.t .................. skipped: enable b +y setting RELEASE_TESTING t/10_units/01_pod/04_pod_linkcheck.t ............... skipped: enable b +y setting RELEASE_TESTING t/10_units/02_pipes/01_base.t ...................... skipped: not impl +emented yet t/10_units/02_pipes/02_oneway.t .................... ok t/10_units/02_pipes/03_twoway.t .................... ok t/10_units/03_base/01_poe.t ........................ ok t/10_units/03_base/03_component.t .................. ok t/10_units/03_base/04_driver.t ..................... ok t/10_units/03_base/05_filter.t ..................... ok t/10_units/03_base/06_loop.t ....................... ok t/10_units/03_base/07_queue.t ...................... ok t/10_units/03_base/08_resource.t ................... ok t/10_units/03_base/09_resources.t .................. ok t/10_units/03_base/10_wheel.t ...................... ok t/10_units/03_base/11_assert_usage.t ............... ok t/10_units/03_base/12_assert_retval.t .............. ok t/10_units/03_base/13_assert_data.t ................ ok t/10_units/03_base/14_kernel.t ..................... ok t/10_units/03_base/15_kernel_internal.t ............ ok t/10_units/03_base/16_nfa_usage.t .................. ok t/10_units/03_base/17_detach_start.t ............... ok t/10_units/04_drivers/01_sysrw.t ................... 1/17
safe navigation in perl?
4 direct replies — Read more / Contribute
by morgon
on Dec 16, 2017 at 23:17
    Hi,

    recently I've done things like this (sorry, I am a bit drunk and too lazy to look up the actual code - but you get the gist...):

    my $subtree = $dom->find($whatever); $subtree->delete if $substree;
    And I was wondering if there was a better way to do this, some kind of Groovy "safe navigation" operator that would allow one to write:
    #pseudo-code - does not run!!! $dom->find($whatever)?->delete;
    i.e. a method-invocation that would check if the receicer was defined at all and simply does nothing if the receiver is undefined.

    I ask because something in the back of my mind tells me that I may have heard something to this effect at a conference, but as I said - I am a bit drunk...

    Many thanks!

Good CPAN project to give my kid some insight into development process?
2 direct replies — Read more / Contribute
by nysus
on Dec 16, 2017 at 13:51

    Over the upcoming Christmas break, I want to give my kid some direct insight into open source development and the process of software development. He may never end up being a software developer, but I'm thinking he should at least know the fundamentals and the tools involved in the process that is a big factor in our world.

    And now that I have finally learned myself how to contribute a CPAN module, I thought having him, under his name, contribute a module that anyone could download and modify would help get him excited.

    I don't want to pollute CPAN with something completely useless. So I'm wondering if anyone had a good idea for a simple module that did something fairly trivial but useful. He's into PC games and games on Steam and is big into League of Legends (which I know very little about). Maybe it could be related to that where it scrapes some info of the web and emails updates or something like that.

    Any thoughts or ideas are greatly appreciated!

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

Making the CPAN/GitHub updating process painless
4 direct replies — Read more / Contribute
by nysus
on Dec 16, 2017 at 11:09

    OK, finally created a CPAN module. I am now the most clueless Perl Developer.

    Getting something up and working on CPAN was fairly painless. I might not have known exactly what I was doing with commands like h2xs and make distcheck but blindly following the advice of some helpful documentation worked. I'm still left scratching my head over where the process pulled in my email address from (it's the wrong one) and the best way to get my GitHub repo linked on the left hand side of the metacpan page. I'll figure this out in due time.

    My question is, are there tools out there to this whole process as seamless and painless as possible? After making a couple of revisions to my module, I notice there are many repetitive tasks. There are a couple of dozen commands involved with making even a simple change to a POD file in the module. I'm imagining there must be script or suite of tools that:

    1) Had a simple config file where you put in all your PAUSE account and GitHub credentials and knew which repo on github your project was associated with

    2) Config file would also contain any info that goes into Makefile.PL and offer suggestions if you are missing data in your config or it can't figure it out from POD or module code

    3) Would automatically generate required CPAN files and upload them to CPAN for you

    4) Would push the changes automatically out to your github repo

    5) Take care of versioning information for you

    6) Generate necessary README files.

    So, for example, let's say I want to do something as fix an embarrassing typo to the POD that I wanted to push out immediately. First, I'd make the change. Then I'd be sure to change the version number in the code. Then I'd be sure to change the version number in the READMD.md file for GitHub and the plain README file for CPAN. Then I'd change the name of directory the code is in for cpan. Then I'd issue (after looking them up first) my commands to generate the updated CPAN version. Then I upload my tarball to PAUSE (after transferring it to another machine that has a browser on it). Then I issue my git commands to commit the new code to GitHub. Then I check cpan and github to make sure I didn't screw something up.

    Instead of all that, ideally, I'd like just do something like this from the command line: update_module -v .22

    and be done.

    There seems like there are a patchwork of tools out there to do parts of these tasks but I'm not sure if there is anything that does it all. Can anyone point me in the right direction? Thanks.

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

read email-message
1 direct reply — Read more / Contribute
by Anonymous Monk
on Dec 16, 2017 at 05:02

    Hi everyone. I'm trying to write a script that reads the last message in the google mailbox, but i am failing. I am using the module Mail::IMAPClient. The code i use to try to get the actual message looks like this:

    $string = $client->message_string($msg);

    But when i print the string ($string), I get all sorts of information on the screen but not the actual message. I also tried:

    $string = $client->body_string($msg);

    But it gives the same result. I have been looking on the internet for answers but can't find something useful. I hope you can tell me.


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?
    and God said, "Let Newton be!"...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (8)
    As of 2017-12-18 09:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What programming language do you hate the most?




















      Results (475 votes). Check out past polls.

      Notices?