Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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
Again Fuzzy regex !!!!
4 direct replies — Read more / Contribute
by samman
on May 22, 2015 at 17:20

    Help Me perl Monks !!!!!! I know that you have asked this question a million times before but I didn't find an answer full my needs > I want to fuzzy search a short string ( up to 25 letter ) against a long string (very very long ) with miss match >> Yes I tried Xor :

    my $str = $Genome; my $match = "ATCGACTACGACTCGACT"; my $len = length($match); for my $i ( 0 .. length($str) - $len ) { my $s = substr $str, $i, $len; my $x = $s ^ $match; $x =~ tr/\0//d; # equal characters xor to \0 print "'$s' at offset $i matched\t".length($x)."\n" unles +s length($x) > 5; }

    but it was slow but I found this code which has been writen was in c but I couldn't handle it , to extract what he did and rewrite it in perl, I want to do the same like what he did but in perl >>> as it was faster , could you please tell me how to do like it in perl !!!!!!!

Memory leaks in DBD::Firebird
2 direct replies — Read more / Contribute
by Steve_BZ
on May 22, 2015 at 12:32

    Hi Monks,

    There seems to be a memory leak in DBD::Firebird (or one of its dependencies). Every call after the first one seems to leak 1 Scalar Value (SV).

    Here is a code sample which will create a table, query it 6 times and drop it.

    Each query loses 1 SV.

    I have upgraded to the latest version of DBD::Firebird and I'm on Kubuntu 14.04 lts with Firebird 2.5.

    Update: Thanks to sierpinski for pointing out that there was no question here. Has anyone seen this before? I imagine it might be the driver, but I guess it could be Firebird too. I'd like to see where the problem is. If it's fixable, we should fix it, otherwise I'll need to workaround it. Suggestions welcome.

    Here is the code, you just need to create an empty database file (I use Flamerobin for this) and modify the dsn in the code appropriately.

    Thanks for your help

    Code follows

    Regards

    Steve

issue with perl debugger when using weak reference
No replies — Read more | Post response
by ssaraogi
on May 22, 2015 at 11:51
    I am using Test::MockModule in one of my unit tests which fails in the debug mode (perl -d <test>) but passes in the normal mode (perl <test>)

    After some debugging, i found it to be a weak reference not getting destroyed in the debug mode.

    I tried searching for similar issues but could not find anything related so far. I am not able to further figure out what the issue is here and needed help.
    What could be the issue here? Is this a known issue?

    Following code reproduces this issue:

    >> ./repro.pl
    Use of uninitialized value $weak_objref in concatenation (.) or string at repro.pl line 48.

    >> perl -d ./repro.pl
    Package=HASH(0x68e068)

    repro.pl
    --------
    #!/home/utils/perl-5.10/5.10.1-nothreads-64/bin/perl use strict; use warnings FATAL => 'all'; use Scalar::Util qw(weaken); my $package_name = 'Package'; my $method_name = 'method'; my $weak_objref; { # This function creates a weak object reference and returns a code + reference sub create_weak_objref { # create any object my $self = bless {}, $package_name; # make a weak reference to the above created object $weak_objref = $self; weaken( $weak_objref ); # return a code reference which mucks around with the above cr +eated object return sub { # Need following to be able to use the string $resolved_me +thod_name later as symbol reference no strict 'refs'; # Both the following steps needs to be done to be able to +reproduce bug in the debug mode # Skipping any of them or moving any out to the parent met +hod does not reproduce the bug # set any arbitrary data inside the object $self->{_arbit_data} = 1; # update packages symbol table to create method 'method_na +me' my $resolved_method_name = "${package_name}::{${method_nam +e}}"; *{$resolved_method_name} = sub {}; }; }; my $coderef = create_weak_objref(); # call the returned code reference $coderef->(); } # Weak reference should be undefined here - but it does get printed in + the debug mode :( print "$weak_objref\n"; 1;
Strawberry Perl and alarm() on Windows
2 direct replies — Read more / Contribute
by bloonix
on May 22, 2015 at 11:35
    Hello together,

    today I tested Strawberry Perl 5.20.2.1 under Windows 8 and it seems that alarm() works. I am confused.
    #!perl.exe use strict; use warnings; print scalar localtime, "\n"; eval { $SIG{__DIE__} = sub { alarm(0) }; $SIG{ALRM} = sub { die "timeout" }; alarm(3); sleep 5; alarm(0); }; print $@ if $@; print scalar localtime, "\n";
    The output:
    Fri May 22 17:21:27 2015
    timeout at c:\test\test.pl line 9.
    Fri May 22 17:21:30 2015
    
    Is that a new feature in newer Windows versions or does Strawberry Perl implements a workaround for alarm?

    Regards, Jonny
OT: Windows Non-Full-Screen Remote Desktop
1 direct reply — Read more / Contribute
by marinersk
on May 22, 2015 at 09:15

    Apologies for the off-topic post, but I asked this question at StackOverflow and, other than a mysterious drive-by downvote, I have had no response.

    I'm hoping someone here, with an eye toward automation in any environment where Perl runs, might have bumped into this and knows how to work around it.

    I'm trying to launch Remote Desktop in a way that permits my local keyboard-driven macros to manipulate the window without having to first reach for the mouse and click on the "Restore Down" button.

    I've tried a few variants of the command line invocation (both from Perl and from the actual command line) and I just can't seem to get it to launch in the mode I want without creating an RDP file. If that's the answer I have to have, then so be it, but I was hoping for one less layer of kludgeness here.

    My basic invocation technique is:

    mstsc /v:%SFS_FNDKEY% /w:1024 /h:768

    Adding the /f parameter forces it to occupy the full screen, as expected, but leaving the /f off leaves it in this odd hybrid state; it does not take up the full screen, but considers itself to be in full-screen mode, complete with the "Restore Down" button which needs to be clicked before my local keyboard-driven macros can assume control of the window.

    Any cluebats out there? I know it's likely a fairly odd request, since most people want full-screen mode, but being different is nothing new over here. : -)

transform XML to XML
2 direct replies — Read more / Contribute
by Anonymous Monk
on May 22, 2015 at 05:27

    Which module should I use for transforming an XML document to another XML document? i.e a field in the first document is differently named in the second document, or it can have extra attributes etc

    Is that a job for XSLT? The examples I've seen transform from XML to HTML etc but not from XML to XML

string compare matches incorrectly
5 direct replies — Read more / Contribute
by Yaerox
on May 22, 2015 at 05:12
    I'm doing a check between a database and a csv-file. I got a list of values from database and I need to check if there are is a matching line in my csv file, i have to delete this line. At the end I got a csv-file with lines not stored in db now. Long story short, I got an if clause:
    my $dbval1 = ""; my $dbval2 = ""; my $val1 = ""; my $val2 = ""; if ($dbval1 eq $val1 && $dbval2 eq $val2) { print "$dbval1 = $val1 && $dbval2 = $val2\n"; }
    which is printing values which doesn't match. The values can be alphanumeric and the database is using varchar2.

    Update: including some values:
    35000970 = 35000913 && AB00035515 = 11506 35000970 = 35000914 && AB00035515 = 121475 35000970 = 35000921 && AB00035515 = 58065


    Update 2: I have no idea what was wrong, I stopped working on this and fixed another bug, now this works. Sry for no solution.
Kill a serial of jobs with a button click in Perl/TK
2 direct replies — Read more / Contribute
by Janish
on May 22, 2015 at 02:56

    Hello monks

    Pls help me on this. I have a few of jobs whereby each of them will be triggered in sequential manner when a "RunAll" button is clicked. How do I set another "KillAll" button to kill all the invoked jobs in case I want to abort all the rest of jobs halfway?

    Below is how I invoked my jobs (note: I'm using Tk::ExecuteCommand in my script). Each job is triggered successfully one after another but it only kill job1 in below code for sub KillAll

    Code for "RunAll" button:-

    sub RunAll{ $run_job1_bttn->invoke(); $run_job2_bttn->invoke(); $run_job3_bttn->invoke(); }

    Code for "KillAll" button:-

    sub KillAll { my $msg = $mw->Dialog( -title => "Warning", -buttons => [ "Yes", "Cancel" ], ); $msg->add("Label", -text => "Sure to kill all jobs?", -wraplength => '300', )->pack(); my $killbutton = $msg->Show; if ($killbutton eq "Yes") { $ec_job1->kill_command; $ec_job2->kill_command; $ec_job3->kill_command;#each $ec_job is execute_command callin +g an external script. } }

    Pls suggest a method so that I can kill all running jobs successfully without abort the window. Thank you!

How to write regex for special characters without using back slashes??
4 direct replies — Read more / Contribute
by sumathigokul
on May 22, 2015 at 01:39

    Hi perl monks...

    Please suggest me how to search and substitute for word with special characters without using back slashes..

    my @nets = "in1_[0], in1_[1]";

    since variable nets contains auto generated words, sometimes it may contain simple words without any special variables as follows

    my @nets = "a_c, b_c, N_05";

    lets say my file has in1_[0] word at many lines of codes and i wrote a perl script to search for in1_[0] i.e. $nets[0] word and replace it with in1_1 word i.e. $nets1...

    while (<DATA>){ print "substitution is done" if (s/$nets[0]/$nets[1]/); }

    But, while executing the script i understood that special characters [] are present in variable nets, hence this substitution regex statement is not working... i read that i have to use back slashes for those characters... since nets file will be auto generated and sometimes only it may contain array values, how can i generalize this regex script accordingly...

    -DATA- in1_c[0] in1_c[1] in1_c[0] in1_c[1] a_c in1_c[0] b_c in1_c[1] in1_c[0] in1_c[1]
an algorithm to randomly pick items that are present at different frequencies
2 direct replies — Read more / Contribute
by efoss
on May 21, 2015 at 20:39
    I want to randomly choose an item from a list of items, each of which has a different probability of being chosen. So essentially I have

    A 10e-6

    B 2x10e-7

    C 10e-5

    etc.

    I want to reach in and choose an item randomly and to have the frequency with which I choose item A, B, C, etc. reflect the frequency that it is present. I can think of messy ways to do this, e.g. populate an array with items according to their frequencies and then randomly choose one item from the array. Can someone suggest a better approach? Thank you.

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (8)
    As of 2015-05-23 00:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      In my home, the TV remote control is ...









      Results (465 votes), past polls