Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
laziness, impatience, and hubris
 
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.

Want Mega XP? Prepare to have your hopes dashed, join in on the: poll ideas quest 2013  (Don't worry; you've got plenty of time.)

New Questions
Unconventional exit from while loop
4 direct replies — Read more / Contribute
by hdb
on May 24, 2013 at 14:28

    Background: In the recent thread help with simplifying program, BillKSmith recommended the use of <Algorithm::Combinatorics>. This uses iterators to go through combinations of data. I love to write terse code so I ended up with (which I did not post in the original thread):

    use strict; use warnings; use Algorithm::Combinatorics qw(combinations); my $rep = 5; # should be 100 my @data = 0..$rep; my $iter = combinations( \@data, 4 ); while( my ( $z, $y, $x, $w ) = @{ $iter->next // last } ) { next unless $w-2*$x+$y or $x-2*$y+$z; print "$w, $x, $y, $z\n"; }

    My question is about the // last part. I reads nicely like "next or last" but I am aware that this exit from the while loop makes while redundant. I might as well use goto or write

    while(1){ my ( $z, $y, $x, $w ) = @{ $iter->next // last }; ... }

    What do you think about this use of last here? Is it a nice short way of exiting the loop when the iterator becomes undef when exhausted or is this breaking too much of the loop's structure? Or are there even hidden dangers that I have not spotted?

Attempt to copy freed scalar and return value semantics
3 direct replies — Read more / Contribute
by turkanis
on May 24, 2013 at 12:48

    Hi Monks,

    Is there ever a difference in semantics between

    sub foo {
        ....
        my $value = <expression>;
        return $value;
    }

    and

    sub foo {
        ....
        return <expression>;
    }
    

    ?

    I ask this because I am experiencing a negative interaction between the Komodo remote debugger and the CPAN module DBIx::transaction. When debugging code that commits a transaction, I get an error like this:

    panic: attempt to copy freed scalar 350d010 to 15c7b68 at
    /usr/share/komodo/perllib/perl5db.pl line 4341, <STDIN> line 1.

    Strangely, I have found that I can fix the error by changing the definition of close_transaction in DBIx/Transaction/db.pm from

    sub close_transaction {
        my $self = shift;
        my $method = shift;
        my $code = DBI::db->can($method);
        $self->{private_DBIx_Transaction_Level} = 0;
        $self->clear_transaction_error;
        $self->transaction_trace($method);
        my $rv = $code->($self, @_);
        return $rv;
    }

    to

    sub close_transaction {
        my $self = shift;
        my $method = shift;
        my $code = DBI::db->can($method);
        $self->{private_DBIx_Transaction_Level} = 0;
        $self->clear_transaction_error;
        $self->transaction_trace($method);
        return $code->($self, @_);
    }

    to me, it looks like my change should have no effect, and yet it eliminates the panic. What's going on here? Could it be a bug in the Komodo remote debugging libraries, or in the Perl implementation, or in DBIx::Transaction?

    • Operating System: CentOS 6.0
    • Perl: v5.10.1 (*) built for x86_64-linux-thread-multi
    • Komodo: 7.0.0-beta2
    • DBIx::Transaction: 1.00
    Thanks
Memory usage on Mac
1 direct reply — Read more / Contribute
by aixtal
on May 24, 2013 at 08:08

    Dear Monks,

    I am aware of Memory::Usage, but it works only under Linux (using /proc). Is there any equivalent for Mac OS ? Or better yet a single module or wrapper that would handle both platforms ?

    I have the feeling that this should have been asked in the past, but could not find it in Super search.

    Many thanks

    --jean

About $/
4 direct replies — Read more / Contribute
by lddzjwwy
on May 24, 2013 at 04:50
    Hi guys, may I set two line end characters at the same time in Perl, sth. like $/ = "\r" or "\003"; ? Thanks in advance. BR Wei
Equivalent for delayed_job?
3 direct replies — Read more / Contribute
by parkan
on May 23, 2013 at 18:26

    I need to run background tasks at arbitrary points in the future, with queue behavior if multiple execute at or near the same time, ability to manipulate the task list, retry (ideally with exponentially longer retry window), etc.

    In Ruby, there is delayed_job (and php port djjob), which does this pretty much perfectly.

    The closest Perl solution I could find was Beanstalk::Job, but this doesn't appear to support execution in the "far future" (next week). There is also Schedule::At, which does (and also allows manipulation of the tasks) but it runs external commands and the jobs appear to be executed straight with no queueing mechanism

    Is there something that's more like delayed_job? Do I need to roll my own? Also: beanstalkd appears to be memory resident, mostly, and I'd prefer to have a db/disk backed queue
Cross-platform GUI for UNIX based scripts
5 direct replies — Read more / Contribute
by Anonymous Monk
on May 23, 2013 at 08:27

    Dear Monks,

    I am developing a Perl/C pipeline which is placed on an UNIX server. At the moment I am accessing it in Windows through Putty, providing simple command line arguments.

    I need to however make it easy to use for non-computer savvy people who use Linux/mac/windows. I am quite good in in making the software work but have no experience in cross-platforms compatibility, networks or GUIs.

    Does anyone have any idea what would be the best approach? The user need to submit a string and select multiple options. The program will then run for 2-3 days so it would be nice if there was a way to see the progress, cancel the script and see if it is finished. After it's done I need to visualize the data which atm I provide in excel spreadsheet.

    I was thinking about an JavaScript webpage with all the options but don't know is people will be able to access it easily in Windows. Maybe a Java or a Perl GUI?

    A multi-platform desktop app that connects to a server would be absolutely ideal but I have no idea how difficult it is to do for someone with limited knowledge of distributed systems.

    Any ideas are welcome. I spend a lot of time developing the pipeline but it won't be used a lot unless I make it incredibly easy to access. Thanks in advance for your advice. I am open to learning new stuff and spending 1 or 2 months on it.

HTML::TreeBuilder, HTML::Element, as_XML()
2 direct replies — Read more / Contribute
by perlig
on May 23, 2013 at 06:35
    Dear omniscient monks,

    i got some html/tei like data and want to parse it to xml format. it is working pretty well for some files.. but not for all.. here is my code:
    # pragma use strict; use warnings; # modules use XML::Simple; use XML::Tidy; use Data::Dumper; use Data::Diver qw( Dive DiveRef DiveError ); use HTML::TreeBuilder; use XML::Tidy::Tiny; # little helper use constant false => 0; use constant true => 1; ... # get instance of treebuilder my $root = HTML::TreeBuilder->new(); # configure treebuilder $root->ignore_unknown( false ); # dump data to the treebuilder $root->parse( $fileData ); # get name for target file my $target = $file; $target =~ s/$fileExtension$/xml/; # open output filehandle open( $FH, '>', $target ); # configure output binmode $FH, ":utf8"; # ERROR HERE 208: my $data = $root->guts()->as_XML(); print $FH xml_tidy( $data ); close $FH; ...
    caption has an invalid attribute name 'n' at script.pl line 208
    i substite all 'n' in the file.. but got still the same error. for that the 'n' is not the anchor of this error.. i dont know what going on here?!
    $root->guts()
    is okey.. it is all about the ->as_XML() :-((

    kindly, perlig

    $perlig =~ s/pec/cep/g if 'errors expected';
http request with LWP::Useragent
1 direct reply — Read more / Contribute
by Anonymous Monk
on May 23, 2013 at 05:34
    Hi, I am using LWP::UserAgent module to get HTTP response from YY.JSP and embed the same in div in my web page.

    I am getting the response. But the problem I get is below.

    In that JSP there is a frameset with mulitple frames. Each frame loads another X.JSP.

    When I get the response and check in browser, I do get the frame with JSP.

    But it does not load contents or should I say the response is not returning the contents of that X.JSP. I get following in response.
    <HTML>...<Body>.... <frameset cols=33%,* onunload="" ><frame border=1 frameborder=yes name +=client src=X.jsp></frameset>
    But, it does not show the contents from X.jsp. The page stays blank.

    Is it that LWP useragent module only process the first YY.JSP but not any X.JSP inside YY.JSP?

    Thanks in advance.

    - Amit
Net::Pcap, parsing packets offline
1 direct reply — Read more / Contribute
by raj_paps
on May 23, 2013 at 05:14
    I am parsing packets offline. I am able to do so with

    my $pcap = Net::Pcap::open_offline($fp, \$err);

    Net::Pcap::dispatch($pcap, 0, \&process_pkt_sip, $out);

    my problem is, I need to get the timestamp/timings of the packet for certain measurement. I saw perl code in some forums to retrieve timings for real time captures. any suggestions for offline..?
how to unpack a C struct with length array preceding data array
5 direct replies — Read more / Contribute
by johnlumby
on May 22, 2013 at 15:28

    my perl app receives a buffer containing this format

    { short lengths[2]; char data[???]; } where there are two items in data, of length lengths[0] and lengths[1] respectively.

    I have tried and tried to unpack this into 4 perl variables in a single unpack() call and failed. I had to resort to two unpack()'s, the first to extract the lengths followed by something like

    eval('($junk1 , $junk2, $data0, $data1) = unpack "ssA' . $data0_length + . "A" . $data1_length . '",$rcvd_buf;');

    which works fine, but can some kind Monk tell me how to do this in one unpack.

perl in a container (lxc or other)
1 direct reply — Read more / Contribute
by djzort
on May 22, 2013 at 07:03
    Im curious if someone would be so kind as to share their experiences setting up a minimal perl container in lxc, openvz, bsd jails, linux-vserver or even chroots.

    App::Staticperl (http://software.schmorp.de/pkg/App-Staticperl.html) looks like it might be a good starting point - if i wanted to avoid a stripped down installed of <favourite distro or bsd>

    The ideal outcome would provide a container with mcpan and a given version of perl. Possibly some fusion of perlbrew and some dark magic to cook up the perl version then drop it in the container.

    Use case is to wrap up apps and put resource limits on them. PAAS like really. I know uwsgi can use namespaces and what not, if someone has used that - please share!
eval point in hash ref
3 direct replies — Read more / Contribute
by ag4ve
on May 22, 2013 at 02:50
    I'd like to be able to do:
    ./dat_query '{seek}'
    or
    ./dat_query '{seek}{messages}'

    and have code do:
    print Dumper($nethist->{seek});
    or
    print Dumper($nethist->{seek}{messages});

    I've been trying:
    my $in = $ARGV[0]; my $val = eval '$nethist->$in'; print Dumper($val);
    and the like with no luck
New Meditations
map grep and sort
3 direct replies — Read more / Contribute
by coyocanid
on May 24, 2013 at 13:49

    I want to meditate on some of the most useful perl-isms that, while easy, are oft misunderstood for beginners. I say that, and am possibly projecting, since when I was a beginner, I had not grokked them and had misused them.

    Map, Grep and Sort are not the same thing, but are often used together. Flowing from right to left, they act like shell pipelining in reverse. They build something new, like a tiny little factory. While the original data structure is untouched, it should feel like a list is being transformed every step of the way.

Memorizing The s/// Option List For Fun and Profit
1 direct reply — Read more / Contribute
by QM
on May 23, 2013 at 08:34
    Did you ever want to memorize the s/// option list? The full list (from perlop) is msixpodualgcer.

    Here are some anagrams I found:
    * discourage p/m/xl (petite, medium, extra-large)
    * glamorised x cpu
    * Proclaimed, "g sux!" (oft heard?)
    * xl CPU ideograms (extra-large CPU)
    * goru x misplaced ("guru is misplaced")
    * ex-cpu marigolds
    * dog pux miracles (poo or pukes)

    Can anyone come up with something better?

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

What is the impact of 5.18.0?
2 direct replies — Read more / Contribute
by Tux
on May 19, 2013 at 06:53

    I use my laptop as test environment. When all (upgrades) pass on production/utility software, I upgrade my workstation. If that shows no problems after a few weeks, I start upgrading other production servers.

    So I installed 5.18.0 on my laptop as default perl, and then tried to install all CPAN modules I ever used in 5.16.x

    There are just a few things that stand out as a reason for FAILure:

    • Test files that use for $foo qw( … ) { which is now deprecated. The module autor should rewrite that to for $foo (qw( … )) {. I filed RT tickets for all I encountered. Lets hope the authors will fix their code.
    • POD failures. As the POD checker is now way stricter than the old version was, it shows more real trouble. And it should! The problem is that many authors ship the pod tests too, so the test suite will fail if Test::Pod and friends are installed, and thus cpan won't install those modules. That means manual work ignoring the pod errors (and when obvious file RT tickets). Authors: unless you keep in sync with reality and release often, please do not include pod tests in you distribution.
    • Loads of warnings when a module uses given/when as those are now marked experimental. I can ignore the warnings when testing, but will they fill up my logs when run in production code? When the module also uses Test::NoWarnings, one cannot install. A module like MooseX::App now won't install, and it causes many other modules that have this as a prerequisite to fail too.
    • XS authors that never updated ppport.h from Devel::PPPort. Easy to fix.
    • Modules that use Module::Install but ship ancient or incomplete versions of it in inc. The easiest solution for me was to just recursively remove inc/ and all problems vanish. I have no tuits to RT all of them.
    • Several modules fail because they declare optional deps that are actually hard deps, like using JSON::XS, Lexical::Sub or Data::Alias - which won't build under 5.18.0
    • Test failures, or maybe even code failures, due to hash randomization. Unless I am absolutely sure that the test is wrong, I cannot install these modules.
    • Some failures have been reported to the authors but the available fix has not (yet) been applied (like in Template::Toolkit RT#84778) or not yet released (Tk and SQL::Statement). When their repository is open, they build fine from the repo and I am confident the next release will build fine.

    The message is: perl-5.18.0 is awesome, but please please test the module you require before starting the installation on machines other than a test environment.


    Enjoy, Have FUN! H.Merijn
New Cool Uses for Perl
Connecting Javascript to Perl
No replies — Read more | Post response
by coyocanid
on May 24, 2013 at 14:42

    I've put together a new perl module on CPAN called Yote. It directly and automatically binds javascript client objects to perl server objects. The objects are container objects that live in an object database. The objects are lazily loaded as needed and are automatically stored with their contents automatically. The following example works out of the box as long as the Hello package is in the Yote server's perl classpath. The hello count will be preserved in Yote's data store.

    Server Side Perl
    package Hello; use base 'Yote::AppRoot'; sub hello { my( $self, $input ) = @_; $self->set_hello_count( $self->get_hello_count( 0 ) + 1 ); return "Hello $input, I have said hello ". $self->get_hello_count() . " times"; } 1;
    Client Side Javascript
    $.yote.init(); var hello_app = $.yote.fetch_app( 'Hello' ); alert( hello_app.hello( prompt( "What is your name?" ) ) );
Check network MTU size
2 direct replies — Read more / Contribute
by 5mi11er
on May 22, 2013 at 10:47
    I recently ran into a bunch of problems where our MPLS provider inadvertently modified the MTU sizes of several of our locations. Unfortunately at about the same time we had swapped out our firewall, so after spending significant time thinking we had weird issues with the new firewall, we finally discovered the actual problem was an incorrect MTU size for those sites.

    This wasn't the first time the MTU sizes had been monkeyed with, so I decided to throw something together that might help us identify MTU problems more quickly.

    I'd found Network Duplex speed test so, I used much of that for the actual ping packet creation, which referenced Net::Ping code, so I also compared the current version of that against what was given in the duplex test node. Then I had to figure out how to turn on the don't fragment flags of the packet. Anyway, the results are below.

    Hopefully someone else will find this useful.

    -Scott

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2013-05-25 10:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (519 votes), past polls