Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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
Math::BigFloat bnok() question
1 direct reply — Read more / Contribute
by azheid
on Aug 27, 2015 at 14:15

    I have an issue that I think is probably a simple one. I do not know how to use Math::BigFloat::bnok(). I get the following error message "Can't call method "Math::BigInt::bnok" without a package or object reference at hexamer_rarity_codonusage.pl line 67."

    Despite reading the Math::BigFloat page and extensive googling, the solution seems beyond my ability to comprehend. Please help. I will post the files that this code uses if necessary, just ask.

    #!/usr/bin/perl use Getopt::Long; use Math::BigFloat; use Math::BigInt; my $codon_fname="codons.txt"; my $n_amer_fname="codon_pair.txt"; my $codon_usage_fname=""; my $mfactor=100; my $codon_usage_per=100; GetOptions( "c=s" => \$codon_usage_fname, ) or die ("Error in command line arguments\n"); open(CODON,'<',$codon_fname)||die "No $codon_fname file available\n"; my %codon_counts; while (my $line=<CODON>){ chomp $line; $codon_counts{$line}= 0 ; } close CODON; open(NAMER,'<',$n_amer_fname)||die "No $n_amer_fname file available\n" +; my @namer; while (my $line=<NAMER>){ chomp $line; push @namer, $line; } close NAMER; my %cd_lookup; open(CLT,'<',$codon_usage_fname)||die "Cannot find codon score lookup +table file $codon_usage_fname\n"; while(my $line=<CLT>){ chomp $line; my @array=split(/\t/,$line); $cd_lookup{$array[0]}=$array[1]; } close CLT; Math::BigFloat->accuracy(40); my $x=Math::BigFloat->new(40); my $y=Math::BigFloat->new(40); my $z=Math::BigFloat->new(40); my $d=Math::BigFloat->new(40); for(my $i=0;$i<@namer;++$i){ my $pvalue=0; my @choose_numerator_array; my %cchash=%codon_counts; for(my $j=0;$j<length($namer[$i])-2;++$j){ ++$cchash{substr($namer[$i],$j,3)}; } foreach my $codon(%cchash){ if($cchash{$codon}){ $x=$cchash{$codon}; $y=$cd_lookup{$codon}*$mfactor; $z=$y->Math::BigInt::bnok($x); push @choose_numerator_array,$z->copy(); } } $x=$choose_numerator_array[0]; for(my $j=1;$j<scalar(@choose_numerator_array);++$j){ $y=$choose_numerator_array[$j]; $x=$x*$y; } $y=$codon_usage_per*$mfactor; $z=scalar(@choose_numerator_array); $d=$y*$z; $x=$x/$d; print $namer[$i],"\t",$x,"\n"; }
Message Queue in Perl
4 direct replies — Read more / Contribute
by QuillMeantTen
on Aug 27, 2015 at 11:06

    Greetings,
    Thanks to the comment of a more experienced monk I have been made aware of a vast field of software engineering known as message queue.
    After a bit of googling and a lot of stackoverflowing I went to have a look at Spread. Since it has a package on cpan I decided to install it (using someone else's better built code would save me a lot of debugging and rewriting). Then I got this :

    I'm using debian wheezy, it seems other peoples have encountered the same problem but I had no luck finding an answer, so if anyone here used that package successfully I'd love to know how (sh|h)e did it.
    Cheers!

Outputting Unicode to DOS
3 direct replies — Read more / Contribute
by thekestrel
on Aug 27, 2015 at 10:04
    Hi, It's been a while since I've used Perl / Perlmonks and most useful knowledge has long since eroded its way through my skull and dribbled onto the floor.
    I'm using Active Perl (perl 5, version 20, subversion 2 (v5.20.2) built for MSWin32-x64-muli-thread) and want to be able to output some unicode characters (specifically ) so that I can automate some Imagemagick'ing.
    At the DOS prompt i can type just fine (German keyboard) and can create things manually.
    I 'assumed' something like the following would print out the same as seen in quotes, but it doesn't, it is replaced with other ASCII art.
    #!/usr/bin/perl use strict; use warnings; use encoding 'utf8'; my $str = "abc123"; print $str;
    I read through...
    http://perldoc.perl.org/perluniintro.html
    http://www.perlmonks.org/?node_id=930785
    http://perlmonks.org/?node_id=799088
    ..and have tried a number of the listed variants, but I'm missing something because nothing is working (I always get other characters).
    Any hints at what I'm sure is a trivial problem would be appreciated.

    Paul.
SOAP::Lite - a hyphen in method name
1 direct reply — Read more / Contribute
by TheNode
on Aug 27, 2015 at 09:08
    Hello Monks,

    I'm new to SOAP::Lite.

    I have to write SOAP client for third party software. It seems pretty straightforward, but there's one obstacle. There is a hyphen in method name I want to invoke.

    I've copied wsdl to local filesystem and modified method name there - of course it returns an error - but the syntax is ok. Output works when sending it through SoapUI when I change the method name back.

    Method name: bpi-request

    When trying to run my script I got an error:
    Bad stub: Bareword "bpi" not allowed while "strict subs" in use at (ev +al 92) line 6. at /usr/lib/perl5/site_perl/5.8.8/SOAP/Lite.pm line 2921.
    It seems that SOAP:Lite have problem with hyphens in wsdl files. Is there a way to modify xml before sending? Then I could change 'bpi-request' in wsdl to 'bpirequest' and then before sending change all 'bpirequest' to 'bpi-request'.

    Regards,

    TheNode

rename zip files and folders inside zip files
2 direct replies — Read more / Contribute
by mariog
on Aug 27, 2015 at 08:57

    Hello

    I have to rename the file inside a zip archive as well as the zip archive itself. the zip file and folder is called ATP.xxxxxx.zip and a file inside the zip is called identically ATP.xxxxx and I need to rename both the zip and the file inside the zip and remove the "ATP."

    I tried this code but it does not work
    #!/usr/bin/perl -w use warnings; use strict; use Archive::Zip qw( :ERROR_CODES ); my @files; @files = <ATP.xxxxxx*.zip>; foreach my $file (@files){ my $zip = Archive::Zip->new(); $zip->read('$file') == AZ_OK or die "read error $!"; $file=~ s{\.[^.]+$}{}; my $m1 = $zip->memberNamed('$file'); $file=~s/^.{4}//s; $m1->fileName('$file'); $zip->overwriteAs('$file.zip') == AZ_OK or die "write error $!\n" }
    the zip file cannot be read..
[OT] A C-language parser test file?
3 direct replies — Read more / Contribute
by BrowserUk
on Aug 27, 2015 at 08:54

    Does anyone know of a publicly available C source file specifically constructed for testing the edge cases of C-language parsers?

    I'm writing a parser for the C-language (and yes; I need to write my own), and I sat down to think of a good way to test it.

    My conclusion is that rather than just feeding it it reams and reams of C sources; most of which will simply be re-exercising the same paths; it would be better to try and construct a single, preferably relatively small, C-source that doesn't necessarily have to do anything useful, but simply uses all the constructs and language features that I need to support. (Which isn't the full standard; any of them.)

    I started to try and write notes on everything I think need to be in this file -- and I will continue that -- but then I thought maybe such a file already exists. I've done a few half-hearted searches for something that might fit the bill; but its proven to be a difficult thing to construct a discriminative search criteria for.

    So, this is just a hope that maybe someone here has knowledge of something that might lend itself to my purpose.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
    I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
Suppressing Warning/Error messages
1 direct reply — Read more / Contribute
by intoperl
on Aug 27, 2015 at 06:11

    Hi Monks, I want perl to NOT to display its own error messages, when i am handling it myself. Pls suggest me any way to suppress that. Below is the error messege i get from perl, followed by my own error message

    Argument "hu" isn't numeric in numeric gt (>) at ./cpu_chk.pl line 120, <STDIN> line 3. ---->(Perl Error)

    Bad Choice...Try again now.. ----> (my error msg)

    The condition i have in my code is as below :

    if(($SRVCH > 22)||($SRVCH < 1)||($SRVCH =~ /(\s+)/)||($SRVCH =~ /[a-z +A-Z]/)) { message("Bad Choice...Try again now.."); system("sleep 1.5"); disp_menu(); }
howto map/grep a complex structure
7 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 27, 2015 at 00:40
    dear monks, i have the following neested loops to search something in a more or less complex hashref of hashes with arrays:
    foreach $hk (keys %$hash) { foreach $m (@{$hash->{$hk}->{member}}) { if($m eq $search) { print "$hk\n"; } } }
    this works well. but because you can do it in perl in so many ways, i look forward to learn how to make it more elegant with map and grep. is there a tutorial to learn how to translate this 'foreach / if' combination into 'map / grep'? how would you translate this? thanks.
RPC with Perl
3 direct replies — Read more / Contribute
by glasswalk3r
on Aug 26, 2015 at 18:23

    Greetings monks,

    I'm looking for some options to implement a client/server RPC application.

    The requirements for such application are:

    1. Fast data serialization (no need to have compatibility with other programming languages)
    2. Be small in terms of memory requirements
    3. Use Unix socket instead of INET
    4. Queue the requests, they are not suppose to be handled in parallel (at least right now)

    I did some research and it seems that Sereal for serialization is the way to go, but documentation says it should not be considered yet stable. Other problem is to implement a RPC protocol itself.

    I also considered the JSON RPC implementations available on CPAN, but all of them seems to be have assumptions as using PSGI or HTTP.

    XML RPC is an overhead that I just don't need.

    While I already assumed that I'll need to write a client and server using Unix socket from scratch I would like to avoid reinventing the wheel how the messages (probably Perl objects) need to be formatted, specially when it is necessary to deal with exceptions.

    Do you have any suggestions to give of modules that could be used? Another candidate might be RMI but the distribution have a fair number of failures reported, looking as not being maintained anymore.

    Thanks!

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Loop function in Javascript fails when combined with perl array
4 direct replies — Read more / Contribute
by ash1351
on Aug 26, 2015 at 18:00

    Hi, I am taking backend perl variables and using it at the front end for display. Here is the code. head1 and head2 are the header names taken from perl script. I use that and display those headers of grid on webpage.

    var headname1= "@head1"; var headname2= "@head2";
    Now, if there are 100 headers, i would have to assign variables 100 times separately. so its better to make it dynamic. Taking values from backend and assigning it to javascript variable. This task will be dynamic. Here is my attempted code for that. I hav taken all the headers from backend and assigned it to line_array. @line_arry is the name of that array. If i do @line_arry[0] and so on. appropriate values will be displyaed.
    var headname=[]; for(var i=0;i<total_columns;i++) { headname[i+1]= "@line_arry[(i)]"; }
    This code doesnot work. It displays only the first column. i.e.
    headname[1] = "Order"; headname[2] = "Order";
    Order is the name of the first header. In headname2, header of second column should be displayed. but it still displays "Order" If i write the below code, it displays first and second header.
    headname[i+1]= "@line_arry[(0)]"; headname[i+1]= "@line_arry[(1)]"; "@line_arry[i]" doesnt work whereas "@line_arry[0], @line_arry[1] works.
    Can anyone suggeest why it is not performing looping action using variable i

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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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 exploiting the Monastery: (10)
    As of 2015-08-27 19:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The oldest computer book still on my shelves (or on my digital media) is ...













      Results (330 votes), past polls