Beefy Boxes and Bandwidth Generously Provided by pair Networks Russ
good chemistry is complicated,
and a little bit messy -LW

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
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! :)
Delay running Perl execs in Windows
4 direct replies — Read more / Contribute
by Raineer
on Apr 15, 2014 at 10:19

    Hello all,

    I use Perl to write trace and log parsers for my engineering group. They are a Windows crowd and most are not savvy enough to use native Perl.

    I use `pp` to package the scripts into executables which they can run on Windows, and I've had great success doing so.

    My question is - Why do freshly-packed execs have such a long delay the first time they are run in Windows on a given machine? I even see this on my own machine - I pack with `pp`, then launching the file gives me a black screen hang for 30-60 seconds and the program proceeds as desired. Subsequent launches have no delay at all.

    My colleagues see this same behavior as well. It's a nuisance at worst, but I would really like to eliminate this. I can see the behavior on the simplest of programs, at most my typical programs only import Archive::Tar.

    Are there further settings I can use in `pp` to eliminate this delay? I have searched and searched but haven't found a report that matches this behavior, though I can't believe I'm the only one.

    I'm using Strawberry 5.16, but I have seen the same behavior on every distro and version I have used. Thank you.

What are (popular) modules that access/modify @ARGV?
4 direct replies — Read more / Contribute
by frozenwithjoy
on Apr 14, 2014 at 04:55

    I'm working on a project that needs to access @ARGV before anything else does. I figured I'd add a subroutine that checks for potential conflicts and issues a warning if any of the more popular modules that access/modify @ARGV are loaded at the time my module is imported.

    I know that it isn't feasible to list/check all potentially conflicting modules (see @conflicts below). Nevertheless, I'd like to come up with a decent list of popular/commonly used modules that touch @ARGV. What are your favorites?

    This code identifies modules loaded both directly and indirectly (i.e., as dependencies). It works fine and I'm not asking for help with it (but I certainly won't turn away any comments/suggestions):

    use Module::Loaded; sub _check_for_conflicts { my @conflicts = qw(AppConfig Getopt::Args Getopt::Long Getopt::Simple Getopt +::Std); my @loaded; for (@conflicts) { push @loaded, $_ if defined is_loaded($_); } if ( scalar @loaded > 0 ) { print STDERR <<EOF; WARNING: A module that accesses '\@ARGV' has been loaded before Log::Reproducib +le. To avoid potential conflicts, we recommended changing your script such that Log::Reproducible is imported before the following module(s): EOF print STDERR " $_\n" for sort @loaded; print STDERR "\n"; } }

    Thanks all!

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 wandering the Monastery: (19)
As of 2014-04-17 16:13 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (453 votes), past polls