Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Problems? Is your data what you think it is?

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
Sockets, eval , and DIE
1 direct reply — Read more / Contribute
by Wiggins
on Apr 17, 2014 at 12:12
    I am looking for edge condition precedences. Syswrite to a closed socket(closed at remote end) results in Perl termination, with or without eval. Are there edge conditions that allow this?

    This code (without the eval and test blocks) can be seen on the botton of page 209 of Advance Perl Programming, #1. The MSG module.

    while (@$rq) { my $msg = $rq->[0]; my $bytes_to_write = length($msg) - $offset; my $bytes_written = 0; while ($bytes_to_write) { #write the prefixed length print "_send: syswrite to sock prefix length\n"; eval { $bytes_written = syswrite ($sock, $msg, $bytes_to_write, $offset); }; if ($@){ print "_send: syswrite to sock error <$@>\n"; } print "_send: syswrite to sock returned <$bytes_written>\n"; if (!defined($bytes_written)) { if (_err_will_block($!)) { # Should happen only in deferred mode. Record how # much we have already sent. $conn->{send_offset} = $offset; # Event handler should already be set, so we will # be called back eventually, and will resume sending return 1; ...
    This is Perl 5.14.
    The consistant result, running in foreground, when the server is shutdown, and a client send is attempted is:
    checkRealTTY:: starting UID=<UID> rIP=<> Acct=<root> _send entered <Msg=HASH(0x29987c8)> flush=<1> _send: syswrite to sock prefix length root@kali:/usr/share/msg/bin#

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

Pre-pen testing code review
2 direct replies — Read more / Contribute
by tachyon-II
on Apr 17, 2014 at 12:01

    We have a reasonably well organised Catalyst MVC app that is about to undergo a code available pen test.

    I'm looking to get someone with an interest in the area to do a pre-pen test code review and would like any pointers the community has about good places to look, or specific people to ask.

    As well as the perl there is quite a bit of AJAX as well as iOS and Android apps that interfaces with the perl core.

install Devel::Cover 1.09
2 direct replies — Read more / Contribute
by perl_help26
on Apr 17, 2014 at 06:04
    I am trying to install an earlier version of Devel::Cover (i.e. Devel::Cover 1.09) how do I do that exactly? Thanks
Persistent HTTP connection
2 direct replies — Read more / Contribute
by mst226
on Apr 17, 2014 at 05:31
    Hi everyone.

    I am trying to write a web client that connects to an API using HTTP. The API server is the Gephi software ( with the "streaming plugin" which accepts commands to modify a graph in real-time. My goal is to visualize Internet traffic showing end-stations as nodes and connections as edges.

    The API was not written by me and there is no way to change its behaviour. (There might be, but this is out of scope)

    This API is somehow special since the HTTP connection stays open the whole time (even if it is idle).

    So, my plan is to:
    1. make a http connection to the server
    2. send commands (POST) in JSON format using the established connection
    3. wait for a reply which might take a while
    4. send more commands
    5. wait for replies
    and so on.

    Only steps 1. and 2. are fixed. There is no order in the following steps. Some commands expect a reply while others do not. Also it is possible to send hundreds of commands without waiting for reply.

    I tried to build the web/api client using LWP and IO::Socket::INET, but the connection is closed at some point in time.

    Basically it is possible to open/close the connection for every single command, but this limits the performance of the web/api client.

    The API is described here:
    Is it focused on Java but on the bottom there are examples of the command syntax.

    Can you give me some hints how to continue?

How to get the path coverage (or lines of code executed) after running a perl test file
2 direct replies — Read more / Contribute
by perl_help26
on Apr 16, 2014 at 11:11

    Hello Everyone, I wrote a test file using LWP::Simple. How can I know the path coverage of my test file or the lines of code being executed in my program? Is there an easy way? Preferably not with Devel::Cover since it just won't install using cpan!... (there's a test that's failing aeval_merge.t does anyone know why? Thank you...

Comparing results of math operations
8 direct replies — Read more / Contribute
by stangoesagain
on Apr 16, 2014 at 05:12
    Little real life problem
    #!/usr/bin/perl use strict; use warnings; use 5.010; my $x=0.95*806; my $y=1.3*589; say $x <=> $y; $x == $y ? say 'equal' : say $x.' '.$y; say $x cmp $y; $x eq $y ? say 'equal' : say $x.' '.$y; #now with simpler math $x=2*1.25; $y=5*0.5; say $x <=> $y; $x == $y ? say 'equal' : say $x.' '.$y; say $x cmp $y; $x eq $y ? say 'equal' : say $x.' '.$y;
    -1 765.7 765.7 0 equal 0 equal 0 equal
    Why? What's wrong?
better way to escape escapes
5 direct replies — Read more / Contribute
by RonW
on Apr 15, 2014 at 19:48
    I am processing an input format that can use either @ or \ to introduce inline directives. when a literal @ or \ is in the input, either character can be used to escape either character. IE: @@ or \@ or \\ or @\

    Currently, I replace the escape sequences with place holders, then extract directives, then replace the placeholders with the intended literal occurrences of @ and \ in the string.

    s/(?<![\\\@])[\\\@]\@/\x11/g; s/(?<![\\\@])[\\\@]\\/\x12/g; while (/[\\\@]([_A-Za-z]+)/) { print "Extracted code '$1'\n"; s/[\\\@]$1//; } s/\x11/\@/g; s/\x12/\\/g;

    I'm sure there's a better way, but my search-foo is lacking. And so is my regex-foo. (And there's likely an input file that will break this.)

    (and no, it's not LaTeX, despite the similarities)

Perl Directory file extension stats.
3 direct replies — Read more / Contribute
by sidsinha
on Apr 15, 2014 at 17:32

    I had a question regarding Perl directory statistics. Are there any perl packages that I can use to list the number of unique file extentions in a given directory?

    For ex, it should parse through an input directory (including subdir) and return the number of unique file types (for ex, 200 .bmp , 50 jpg ,20 txt) etc.

    Please guide me . thanks.
Lingua: Transform "wasn't" into "was not"
1 direct reply — Read more / Contribute
by Anonymous Monk
on Apr 15, 2014 at 14:09


    As the title suggests, I'm looking for a module which converts various English shortcuts like we're into we are, I'm into I am, etc...

    I couldn't find any module in CPAN which does this. Maybe I haven't looked for the right name.
    So my question is: did anyone worked with something similar before? What module would you recommend for doing this?


Optimizing a naive clustering algorithm
3 direct replies — Read more / Contribute
by BUU
on Apr 15, 2014 at 12:09

    I'm attempting to implement a basic hierarchical agglomerative clustering algorithm to be used to create an arbitrary number of clusters from an existing dataset. More reading about the general concept can be found at at or your friendly neighborhood google.

    A word about the dataset.

    My data consists of some 1500-5000 "items" each of which contains a set of "words". These words are 5-30 character strings. Each set of words contains no duplicates. There are between 5-100 "words" in a set.

    Some words about the existing code.

    The theoretical complexity of such an algorithm is something like O(cn2d2) but I suspect my implementation is considerably worse since I ran it for over 11 hours and it only managed to consolidate 500 of the 1600 items.

    The "merge" function is obviously very silly, I wrote it without thinking very hard and it doesn't do much. On the other hand I don't think it impacts the performance.

    The vast majority of the time spent is going to be in the max_diff function, which appears to get exponentially slower as the program continues to run.

    The datastructure being produced is necessary, that is it should be a binary tree made of array-refs where each leaf is either another tree or an actual item. (Its necessary because we don't know how many clusters we want to produce).

    Suggestions for optimizations or even different algorithms gratefully received.

Perl formatting beginner
5 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 15, 2014 at 11:23

    Hi all i am new to perl just trying to figure out how I would format my output to look a certain way if possible. I want it be in 3 columns 10 rows Avery 5160 format, but without the use of PostScript. but right now it only show all in one column all the way down.

    #!/usr/bin/perl # Program name: # Purpose: Open disk file. Read and display the records in # the file. Count the number of records in the file. format LABEL = @<<<<<<<<<<<<<<<< $CUSTID @<<<<<<<<<<<<<<<< $fname @<<<<<<<<<<<<<<<< $lname @<<<<<<<<<<<<<<<< $phone @<<<<<<<<<<<<<<<< $address @<<<<<<<<<<<<<<<< $city @<<<<<<<<<<<<<<<< $state @<<<<<<<<<<<<<<<< $zip @<<<<<<<<<<<<<<<< $email . #$topmargin = 0.60; #$poleft = 0.4; $pomiddle = 3.20; $poright = 5.95; $lheight = 1; $row = int($opt{r}) || 1; # chop off any fractional parts and $col = int($opt{c}) || 1; if ($col == 1) { $po = $poleft; } elsif ($col == 2) { $po = $pomiddle; } else { $po = $poright; } # $sp = ($topmargin + ($row - 1)*$lheight); # required terminator for format definition open (FILEIN, "cust.txt") || warn "Could not open passwd file\n"; open (LABEL, ">labels-to-print") || warn "Can't create labels file\n"; while (<FILEIN>) { #print "$_"; ($CUSTID,$fname,$lname,$phone,$address,$city,$state,$zip,$email) += split(/,/,$_); # Or use array: @fields = split(/,/,$_); write(LABEL); # send to output ++$line_count; } print ("File \"passwd\" has $line_count lines. \n"); close (FILEIN); close (LABEL);
Extracting a chapter from text file
5 direct replies — Read more / Contribute
by jwkuo87
on Apr 15, 2014 at 10:28
    Hi everyone. I'm fairly new to Perl and am trying to extract a specific chapter from a text file. In the example below, I would like to retrieve the text from Chapter 2.
    Table of Contents Chapter 1. Introduction Chapter 2. Main Chapter 3. Conclusion ============================== Chapter 1. Introduction This is the introduction preceding Chapter 2. Chapter 2. Main This is the text contained in Chapter 2 and will contain a lot of text + with at least 100 words and probably somewhere around 1000-5000. Chapter 3. Conclusion This is the conclusion.
    The Perl script should extract "This is the text contained in Chapter 2 and will contain a lot of text with at least 100 words and probably somewhere around 1000-5000." from the file and write the output to a new file. Unfortunately, the code below only gives me the first matches, i.e. the text from the table of contents.
    #!/usr/bin/perl -w #use strict; my $startstring='Chapter\s2\.\sMain'; my $endstring='Chapter\s3\.\sConclusion'; { local $/; open (SLURP, "C:\\Text\\1.txt") or die $!; $data = <SLURP>; close SLURP or die $!; { @finds=$data=~m/($startstring.*?$endstring)/ismo; } open my $OUTFILE, ">", "C:\\Text\\Chapter2\\1.txt" or die $!; print $OUTFILE "@finds"; close $OUTFILE; }
    Is there a way to refine my search function so it works as I would like it to? Like including a rule where the startstring must be skipped if the preceding 5 strings contains "Chapter 1. Introduction" and/or the output should contain at least 100 words? Thanks in advance! :)
New Cool Uses for Perl
Sidef - The experimental scripting language written in Perl
No replies — Read more | Post response
by trizen
on Apr 17, 2014 at 09:28

    I remember that, a few years ago, someone asked a question about Writing a Programming Language in Perl. I was a little bit skeptical at first, but very interested in this subject too. Few years passed by, until me and a friend of mine decided to create a toy-language from scratch without using anything else, but Perl. We wanted it as simple as possible and powerful as much at it can be.

    Object-oriented paradigm must be the answer, right? We thought so. And it is, partially. The language we designed is called Sidef. It strongly follows the OO style and every data is stored inside of an object, which can have its own methods and operators defined to work on that type of data. (actually, in Sidef, an operator and a method are the same thing)

    Simplicity? What do we mean by simple? How simple can a programming language be defined? This is the main question that I wanted to answer. A year after the birth of the project, I think we found a reasonable answer: objects and methods. This is, I think, the simplest way a programming language can be defined. But, what about conditional expressions? They can't be created by objects and methods only, right? Wrong! They can:

    if (false) { } elsif (true) { } else { }
    is equivalent with:
    var condObj = if(false); # 'if' object condObj do { } elsif(true) do { } else { }
    What? Yes, the above code is valid code. if(expr) returns an object which accepts methods like 'do', 'elsif' and 'else'.
    This proves how flexible an OO language can be. The basic definition of Sidef is this: obj.method(obj), with minor exceptions.

    Objects are:
    • strings
    • files
    • numbers
    • arrays
    • anything else
    while methods are functions defined for that kind of object which returns other objects.

    In Sidef, the numbers have a very special purpose. We see the language as a toy-language and recommend to be seen only this way, but still it can be used in simple home-made projects, especially in those involving number computation. Numbers, by default, are represented by Math::BigFloat objects, giving them a better precision at the cost of being somewhat slower than Perl's standard representation for numbers (-Nfast).

    Perl related features:
    • any Sidef script can be compiled to a stand-alone Perl program (-c)
    • can load and use Perl modules (both OO and functional)
    • can evaluate arbitrary Perl code (Sys.eval(""))
    • supports memoization via Memoize (-M) (not enabled by default)
    • no CPAN module is required

    The project is available at:
    The documentation page:
    The RosettaCode page:

    The very basic concept of the language can be found at:

New Monk Discussion
propose updating node about linking to cpan modules
4 direct replies — Read more / Contribute
by Lotus1
on Apr 16, 2014 at 11:34
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (15)
As of 2014-04-17 20:15 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (454 votes), past polls