Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
There's more than one way to do things
 
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
Using __DATA__ from a package
3 direct replies — Read more / Contribute
by yoda54
on Jun 17, 2013 at 22:19
    Monks,

    How would do I access local __DATA__ inside a package?

    Thanks

    package Test; sub run { while(<Test::DATA>) { print "$_\n"; } } __DATA__ 1 #!/usr/bin/perl use strict; use warnings; use Test; Test::run();
Installing modules
4 direct replies — Read more / Contribute
by slugger415
on Jun 17, 2013 at 18:32

    Hello Perl wise ones, forgive me if I'm having my usual frustration with installing Perl modules on Windows XP with ActiveState. I specifically want to install DBD::JDBC.

    • I don't see it in the list when running ppm, and "ppm install DBD-JDBC" doesn't find it.
      ppm install DBD-JDBC ppm install failed: Can't find any package that provides DBD-JDBC
    • I also tried installing DBD::ODBC and got an "authorization required" error, but I don't know where to "authorize."
      ERROR: 401 Authorization Required
    • I tried adding cpan to the repository list in ppm (http://www.cpan.org) but zero modules are added.
    • I tried installing with cpan. I get dozens of errors, including a C Compiler not being installed. Just running "cpan" gives me this:
      It looks like you don't have a C compiler and make utility installed. + Trying to install dmake and the MinGW gcc compiler using the Perl Package Man +ager. This may take a a few minutes... Downloading MinGW-5.1.4.1...redirect Downloading MinGW-5.1.4.1...failed 401 Authorization Required ppm.bat install failed: 401 Authorization Required It looks like the installation of dmake and MinGW has failed. You wil +l not be able to run Makefile commands or compile C extension code. Please che +ck your internet connection and your proxy settings! cpan shell -- CPAN exploration and modules installation (v1.9402) Enter 'h' for help.
    • I looked at the instructions for installing modules on cpan.org which says you need a C compiler: "(it's easy to get this setup - don't panic), see your OS of choice below to find out how to get the right compiler." ... but couldn't find any instructions on how to install this.

    Perhaps this is all related to the authorization error? Any idea how I can get running here?

    Thank you as always...

Unit testing question with Test::Deep
No replies — Read more | Post response
by willjones
on Jun 17, 2013 at 16:20
    I have a structure I want to test for that comes back as a hash where one of the values is 'objects' which is an array of hash objects that have 2 fields that should always be present, but a 3rd field that may sometimes be present and sometimes not be present. When it is present I'd like to verify it with a re(...) comparison, but when it isn't present I'd like to prevent an error message telling me so... because it is optional! However if any other fields show up in there that aren't known optionals, I want to know about it. Does this make sense? How can I code this with Test::Deep? I read through the doc on cpan and noticed the superhash stuff, but I wasn't sure how to apply it with this array situation and also in such a way that met my specific needs. Any counsel would be appreciated... thanks.
    my $myObjs = { alpha => re('^alpha(.*)'), beta => re('\d+'), #myOptionalField => re('^opt(.*)'), #sometimes there is a "myOpti +onalField", but sometimes there is not. What to do? }; cmp_deeply( $response, { field1 => re('\d+'), field2 => 2, field3 => 1, objects => array_each($myObjs) }, 'testing for valid response structure' );
Smart matching is experimental/depreciated in 5.18 - recommendations?
5 direct replies — Read more / Contribute
by coolmichael
on Jun 17, 2013 at 15:39

    I've been reading the Perl 5.18 delta, and now that smartmatch is both experimental and depreciated I'm in a bit of a muck. I have a big project that uses given/when quite heavily (28 givens, 85 whens).

    What is the recommended way to fix this? I know I can turn off the warning, but I'd rather fix the code. The documentation says that given/when is subject to big changes and might even go away, so disabling the warning is only a temporary fix. An automatic fix would be nice, but I don't mind doing all the work by hand. I have a good test suite, so I'm not concerned about breaking things.

    Mostly the given/whens look like this:

    given($foo) { when('abc') {...} when(['foo', 'bar']) {...} default {...} };
PAR::Packer for 64-bit machine
2 direct replies — Read more / Contribute
by fionbarr
on Jun 17, 2013 at 15:19
    I am using 'pp' but it builds an executable for a 16-bit machine....is there a flag to select 64-bits?
Help Extract these lines
5 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 17, 2013 at 13:59
    I have this code. What I want is to have this hash data structure:
    %rec = { "telephone": "xx-ada-qwebasd", "car": "fasda-asd-123123-fkja123a", "ball" "97f921-a312-fas2", };
    This is what I tried so far... and it does not work... Help?
    #!/usr/bin/perl use strict; my %rec; while(<DATA>) { s/\"//g; if ( /id:/ ... /id:/) { my ($a) = /id: (\S+),/; my ($b) = /name: (\S+),/; print "$a - $b\n"; $rec{$b} = $a; } } __DATA__ "id": "xx-ada-qwebasd", "name": "telphone", "id": "fasda-asd-123123-fkja123a", "name": "car", "id": "97f921-a312-fas2", "name": "ball",
communicate with a program running in the background
1 direct reply — Read more / Contribute
by fionbarr
on Jun 17, 2013 at 13:38
    I'd like to ask for suggestions to control a program running as a Windows service....stop, start, monitor, etc. Shared memory doesn't look too practical (according to what I've found on CPAN)...I have considered a semaphore file which would be parsed at intervals.
arrange output in columns
5 direct replies — Read more / Contribute
by james4545
on Jun 17, 2013 at 13:16
    Hi Monks,

    I am newbie to perl and i am stuck in arranging the output. Here is my problem.

    I have N number of files that i process and get data such as :

    file 1 output :

    a
    b
    c
    file 2 output:

    2
    f
    4
    s
    w
    i want the final output to be like this (arranged in column and comma separated):
    a,2
    b,f
    c,4
    ,s
    ,w
    Please note that the number of files can be in 100's , so i cant simply use join function. Thanks.

how do i obtain blast result from the given file
3 direct replies — Read more / Contribute
by bingalee
on Jun 17, 2013 at 13:08

    I have a file of blast results of different sequences. Some of them have "no hits found", and the others have hits. How do I obtain the lines which have the results , ignoring the initial lines.

    Here"s what a file looks like

    BLASTX 2.2.26 [Sep-21-2011] Reference: Altschul, Stephen F., Thomas L. Madden, Alejandro A. Schaff +er, Jinghui Zhang, Zheng Zhang, Webb Miller, and David J. Lipman (1997), "Gapped BLAST and PSI-BLAST: a new generation of protein database sear +ch programs", Nucleic Acids Res. 25:3389-3402. Query= XLOC_000039-chr1:983051-985037 (1987 letters) Database: nr 26,236,801 sequences; 9,088,244,489 total letters Searching..................................................done Score + E Sequences producing significant alignments: (bits +) Value ref|XP_002322127.1| autoinhibited H+ ATPase [Populus trichocarpa... +195 2e-93 emb|CAD29314.1| plasma membrane H+-ATPase [Oryza sativa Japonica... +213 1e-55 ref|NP_001048647.1| Os03g0100800 [Oryza sativa Japonica Group] >... +213 1e-55 gb|EEC74325.1| hypothetical protein OsI_09609 [Oryza sativa Indi... +213 1e-55 gb|EMT10609.1| ATPase 11, plasma membrane-type [Aegilops tauschii] +208 3e-54 ref|XP_002511598.1| H(\+)-transporting atpase plant/fungi plasma... +207 3e-54 ref|XP_002274074.1| PREDICTED: ATPase 7, plasma membrane-type is... +207 5e-54 ref|XP_003633895.1| PREDICTED: ATPase 7, plasma membrane-type is... +207 6e-54 gb|AAA34099.1| plasma membrane H+ ATPase, partial [Nicotiana plu... +197 8e-54 ref|XP_003562242.1| PREDICTED: plasma membrane ATPase 1-like [Br... +207 8e-54 ref|XP_002326870.1| autoinhibited H+ ATPase [Populus trichocarpa... +206 1e-53 ref|XP_003529038.1| PREDICTED: plasma membrane ATPase 1-like iso... +205 4e-53

    There are many hits, but if I want the top ten only, what do i do?

    here"s the code i got so far for my entire task, I managed to do the first part, but am stuck at this one

    #!usr/bin/perl -w open(IN,"/home/maize/sequence-ID.txt"); open(OUT,">abc.txt"); open(OUT1,">blastresults.txt"); while($id=<IN>) { $id=~s/\n|\r//g; open(BLAST,"output/$id"); while($file=<BLAST>) { if ($file=~ m/No hits found/) { print OUT "$id \n"; } } close(BLAST); } close(IN); close(OUT); close(OUT1);

    so now i've created a text file which has the names of all those files without any hits. Now i have to create another file with the names of those which have significatn hits, along with the first ten hits. Please help :(

Replacement for/working version of CGI::App::Plugin::BREAD ???
No replies — Read more | Post response
by lee_crites
on Jun 17, 2013 at 12:47

    CGI::Application::Plugin::BREAD

    Howdy, y'all;

    I am working through my first CGI::Application module. I kind of like what I am seeing, and would like to continue on with it. I guess I am not married to it, so other options are available, but at this moment, it is what I am working with.

    I was going to write a plugin of my own that took a MySQL table name and view name, and present the user with a CRUD based page. I was going to use as defaults (if the view did not already exist) the info I could extract from the MySQL DESCRIBE command.

    I could then build a CGI::App module that used a specific view (the views info kept in another table), and build as many module/view combinations as I needed.

    To try to make that make more sense, say there is a user_info table. Each "view" defines which fields can be seen, and which can be edited (the rest are invisible). The "user view" allows the user to update certain fields, see certain fields but not update them, the rest are invisible to them. The sysadmin could edit and view some fields. The HR folks could view/update certain fields, etc. I know -- this is a dumb example, but it does describe what I am wanting to do with the views.

    My goal is one plugin that can automagically pull all of this off.

    While casting about for ideas and/or an existing plugin, I found the BREAD plugin named above. I decided to try it out, and it failed. I spent a few hours tinkering about trying to get it to work. I just kept running into undocumented requirements.

    In my research into this plugin, I noted it does not seem to have had any real work done on it in 8 years. So I am guessing it is no longer valid.

    So my questions:

    • Has anyone used this plugin recently (currently)? What did you have to do to make it work?
    • Is there a more complete plugin available?
    • Is someone working on a plugin close enough to this that we can cartel our efforts?

    I cannot imagine I am the first one to think of this idea and/or want to pull this kind of thing off, so I'm betting someone reading this has already invented the wheel, and is happily using it. Any help/pointers/etc would be greatly appreciated.

    Thanks muchly!

    Lee Crites
    lee@xpeerant.com

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 browsing the Monastery: (13)
    As of 2013-06-18 06:29 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How many continents have you visited?









      Results (597 votes), past polls