Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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
RFC: A call to bioinformationalists for some generic information.
No replies — Read more | Post response
by BrowserUk
on May 27, 2015 at 23:59

    I don't need or want anything proprietary! (But accuracy would help!)

    If you have recently run a fuzzy search for short sequences (primers?) (<32 bases) against a (publicly available) long sequence (~1GB or bigger), and have the knowledge/information available to answer the following questions, it would be greatly appreciated.

    1. How long was the big sequence?

      (And preferably -- though not absolutely necessary -- where can I download a copy.)

    2. How many short sequences, and their length(s).

      Figures like approx. 200 around 25-bases is better than nothing.

      205 x average length 19 ranging from 14 to 25 is better.

      A list of exact lengths better yet.

      (Best of all would be a file of the actual sequences used; but I realise that might be verboten.)

    3. How fuzzy?

      Ie. What Hamming distance was acceptable for a match?

      If your run used more complex rules (eg. < 3 insert or deletes and upto 5 transpositions), those details would help.

      Also, if you used one of the BLASTx programs with a minimum "word length"; details of that setting would be important.

    4. How long did the run take?

      Here I really need more than just elapsed (wall clock) time.

      Perfection would be the number of clock cycles or cpu seconds; which would be further enhanced if details of the CPU(s) used was available.

    5. How many match sites were discovered?

      Just the overall number of match sites would suffice.

      Match sites per short sequence would be ideal, assuming that I can have the input sequences as well.

    6. What hardware was the run performed on?

      In some ways this is the most important criteria. CPU type(s); no. of cores/type & clock speeds would be best.

    The reason:

    I think I've found a better (more accurate and much faster) way to do such fuzzy searches; but before expending lots of effort on putting together a proper package for CPAN -- this is a pure, for fun, home project; not work -- then I'd really like to make some detail comparisons with the current state-of-the-art to convince myself that it a) works; b) is sufficiently faster to warrant the effort.

    Basically, I want to run my crude prototype code against a few real (or at least realistic) testcases with known results and timings to see how it stands up before taking it any further.

    Thanks for any help you can provide.

    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'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
Replace specific matching word with differnt word
3 direct replies — Read more / Contribute
by leelu
on May 27, 2015 at 23:38
    Please need some help how to replace only "text" with "update" Eg: i have data as below and first record "text" need to change to "update" and not other records input file ------------ text -> only this record need to replace text name text city text address output file ------------- update text name text city text address I have tried with s/text/update/g; all records are updated instead of first record
XML Parsing
2 direct replies — Read more / Contribute
by RJP_NxtGam
on May 27, 2015 at 22:58

    I have this XML string which I need to know the root name to parse the remaining elements. How can I parse the root name? Note: I need to parse several different string with different root names. Sample String: <Meter_Request Name="CREDIT"/>

Solved - Using a module under VMS
2 direct replies — Read more / Contribute
by Laurent_R
on May 27, 2015 at 18:01
    Hello dear fellow monks,

    I have a problem with using a module under VMS, but my problem is not necessarily due to VMS, but maybe to me not understanding fully the way the use lib qw/path_to_my_modules; and use mymodule; work.

    Just to be clear, I have written at least two dozens other modules (mostly for various brands of Unix) and always succeeded to use them, but this is my first try under VMS and I am stuck.

    I wrote a relatively complex application, which includes 3 large Perl programs, some DCL command files (equivalent of shell scripts under Unix) launching proprietary software applications for database access, etc. Just to give the overall context, in total about 30 different programs working together, but that's not my problem

    For the three Perl programs that I wrote (which refactor and replace about 25 other existing programs), I also wrote a module containing some helper functions and some hashes of hashes describing the environment (IP addresses of the various platforms, batch queue name, and so on).

    I originally wrote my programs and the common module all in my home directory (SYS$LOGIN under VMS), and got to the point where the whole thing is compiling and working exactly as expected.

    The (simplified) syntax for the top pragmas was essentially as follows:

    use strict; use warnings; use VMS_UTILS qw (wait_for log_info check_valid_date (...) say); # ...
    Notice that I have a say function defined in this module; on VMS, I am stuck Perl 5.8, so I wrote my own say sub because it is quite practical, this will be important below.

    But I then needed to prepare for the production environment. Programs and modules should not be in the private home directory of a user, but in special directory called programs or PROGAMS, VMS being case insensitive (it's not the real name, but let's say that's what it is), which is a logical name (i.e. an environment variable in Unix terms) pointing to a directory.

    So, I moved the Perl programs and my module to the PROGRAM directory and modified the Perl program as follows:

    use strict; use warnings; use lib qw/programs; # also tries PROGRAMS, just in case, but equivale +nt result use VMS_utils qw (... say); #using VMS_UTILS also does not change the +result
    And I got the following message:
    Can't locate in @INC (@INC contains: programs perl_root:[ +lib.VM S_IA64.5_8_6] perl_root:[lib] perl_root:[lib.site_perl.VMS_IA64] perl_ +root:[lib. site_perl] /perl_root/lib/site_perl .) at ...
    So, I thought, OK, may be Perl cannot resolve the program symbol (it normally can without having to use the %ENV hash, because VMS does the transcription under the scene without Perl knowing, at least that's what I understand, but, maybe, in a use lib pragma it does not work), so I changed the use lib pragma to the content of the program symbol.

    And that's where the result is really puzzling to me:

    # use lib ('DISK$ECD:[DMC]'); # does not work use lib 'DISK$ECD/DMC/'; # does not work either use VMS_UTILS qw (...);
    Now, I get a totally different type of errors:
    perl -c String found where operator expected at ecd_programs:all_cra_chcoex126 line 19, near "say "Environnement $plt incorrect !!"" (Do you need to predeclare say?) ... many other compile errors
    The compiler did not fail on loading the module, but failed on using the say subroutine defined in aforesaid module.

    Basically, to make things simple, what I do not understand is this:

    - In one case, the program does not find the module, so that compilation fails. Fair enough.

    - In the other case, it seems that the compiler was able to find the module, but apparently did not load it correctly. And everything works correctly if all the software components are in the home directory of the user.

    Update: fixed a couple of formatting issues and one typo.

hashref return fails
2 direct replies — Read more / Contribute
by Anonymous Monk
on May 27, 2015 at 17:47
    I have class with a method ( non moose, just blessed ), that fills a hash, basically so:
    sub foo { my ($self,$input) = @_; my @ymd = split("-",$input); my $date = { day => $ymd[2], month => $ymd[1], year => $ymd[0], }; my $dt = eval{DateTime->new($date)}; return unless $dt; $date->{dt} = $dt; print "date: ".dump($date)."\n"; return $date; }
    and call it so in another package:
    my $result = $date_thingy->foo("2000-01-01");

    Amazingly, dump outputs all as expected ( hash with year,month,day set to the expected values, and datetime with expected values ). But $result is undef in the calling function. How could that possibly happen?

    $date_thingy exists btw, after and before the call.

    using perl 5.18.2

    This is driving me insane, and no, there is absolutely no further line between print and return, and removing the print changes nothing.

Question about parentheses in regex
2 direct replies — Read more / Contribute
by Von_Halen
on May 27, 2015 at 15:07

    Oh wise seekers of the Perl Wisdom, I come seeking help. This is, I am sure, a novice question and most likely a stupid one... But I've tried everything I can think of and can't seem to get this to work. I ran into an issue where words in parentheses are not being removed from a regex as wanted... The goal is to have anything inside of the curly braces (including the curly braces themselves) to disappear from the string. This works for all circumstances except for when there is a set of parentheses in the text.. I tried escaping the parentheses "\( and \)", but it was to no avail.. I understand that the parentheses are grouping tools in regex, but I figured escaping them would fix that problem, and it did not...

    my $text = "to { (This Word) }"; my $remove = "{ (This Word) }"; $text =~ s/\R//g; $text =~ s/$remove//; print $remove, $/, $/; print $text;
    { (This Word) } to { (This Word) }
    Looking for someone to shed some light on the situation, as it's holding up my production. Again, I'm sorry for I'm sure this is a simple thing to fix..
Where is implementation of $0 in Perl source code
2 direct replies — Read more / Contribute
by salavyan2
on May 27, 2015 at 14:05

    God bless you, oh Monks!

    I am meditating on the following not so complex only at first glance piece of code:

    (caller)[1] eq $0

    Is this always true within single perl script file?

    It is very interesting to see the implementation in Perl source code of the following things:

    1) internal function caller()

    2) variable $0

    So can you please give a guidance where to look in Perl source for them?

Why does every value of the array get replaced?
2 direct replies — Read more / Contribute
by andybshaker
on May 27, 2015 at 13:40

    Hi everyone, I have the following chunk of code:

    foreach $G (@array1){ for $x (0..$#array2){ if($array2[$x] =~ /$G/){ push(@Coordinates,"$array2[$x]"); } } }

    I would expect this to create the array "Coordinates" with every value of array2 that matches array1, but what ends up happening is that the array only contains one value, the last value of array1--which indicates that it gets continuously replaced. How can I fix this?

Gtk2::Notebook with large tabs
1 direct reply — Read more / Contribute
by Anonymous Monk
on May 27, 2015 at 13:37

    This script displays a Gtk2::Notebook with several tabs.

    The tab labels are actually quite big - there's a lot of empty space above and below the words 'Hello world'. Vertical space is at a premium, and I would prefer the tab labels to be about half the height that they actually are.

    Is there any way in which I can reduce the empty space above and below the words 'Hello world'?

    #!/usr/bin/perl package biglabel; use strict; use diagnostics; use warnings; use Gtk2 '-init'; use Glib qw(TRUE FALSE); # Create the window my $window = Gtk2::Window->new(); $window->set_title('Notebook'); $window->set_position('center'); $window->set_default_size(800, 500); $window->set_border_width(5); $window->signal_connect (destroy => sub { Gtk2->main_quit; }); # Add a VBox with a VPaned, containing a notebook at the top and an en +try at the bottom my $vBox = Gtk2::VBox->new(FALSE, 0); my $vPaned = Gtk2::VPaned->new(); $vPaned->set_position(400); $vBox->pack_start($vPaned, TRUE, TRUE, 0); my $noteBook = Gtk2::Notebook->new(); $noteBook->set_scrollable(TRUE); $noteBook->can_focus(FALSE); $vPaned->add($noteBook); my $entry = Gtk2::Entry->new(); $entry->can_focus(TRUE); $vPaned->add2($entry); # Add three tabs to the notebook for (my $num = 0; $num < 3; $num++) { my ($buffer, $tabNum) = openTab($noteBook); } # Open the window $window->add($vBox); $window->show_all(); Gtk2->main(); #################### sub openTab { # Create a tab in the notebook, containing a textview my ($noteBook) = @_; # The vertical packing box contains only a textview my $vBox = Gtk2::VBox->new(FALSE, 0); # The horizontal packing box is used as the tab's label (in pl +ace of a Gtk2::Label) my $hBox = Gtk2::HBox->new(FALSE, 0); my $label = Gtk2::Label->new('Hello world'); $hBox->pack_start($label, FALSE, FALSE, 0); my $button = Gtk2::Button->new(); $button->set_image(Gtk2::Image->new_from_stock('gtk-close', 'b +utton')); $button->set_relief('none'); $button->signal_connect (clicked => sub { # (Do nothing special) }); $hBox->pack_start($button, FALSE, FALSE, 0); $label->show(); $button->show(); my $tabNum = $noteBook->append_page($vBox, $hBox); # Add a textview to the tab my $frame = Gtk2::Frame->new(undef); $frame->set_border_width(0); my $scroll = Gtk2::ScrolledWindow->new(undef, undef); $scroll->set_shadow_type('etched-out'); $scroll->set_policy('automatic', 'automatic'); $scroll->set_border_width(0); my $textView = Gtk2::TextView->new(); my $buffer = Gtk2::TextBuffer->new(); $textView->set_buffer($buffer); $textView->set_editable(FALSE); $textView->set_cursor_visible(FALSE); # Invisible cursor $textView->can_focus(FALSE); $textView->set_wrap_mode('word-char'); # Wrap words if possib +le, characters if not $textView->set_justification('left'); $scroll->add($textView); $frame->add($scroll); $vBox->pack_start($frame, TRUE, TRUE, 0); $window->show_all(); # The new tab should be the visible (current) one $noteBook->set_current_page($tabNum); return ($buffer, $tabNum); }
xml dateTime format pattern violation when using DateTime::Format::XSD
1 direct reply — Read more / Contribute
by dlinetsk
on May 27, 2015 at 13:03

    Hello Monks,

    we are using XML::Compile::WSDL11 to compile our schema, and trying to send a message to a webservice. The Message Header has a dateTime parameter (xs:dateTime) that has a pattern .+T.+Z.

    We tried setting this parameter to "2006-10-06T00:23:02Z" but got error error: string `2006-10-06T00:23:02Z' does not match pattern `.+T.+Z'

    our XSD for this parameter is:
    <xs:simpleType name='DateTimeWithTimezoneInfo'> <xs:annotation> <xs:documentation>Designates a date/time stamp in UTC format. Th +e following formats are accepted: YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDT +hh:mm:ss.xxxZ Where : - YYYY indicates the year - MM indicates the month - DD indicates the day - T is a fixed character, indicating the time section - hh indicates the hour, zero pre-pended - mm indicates the minute, zero pre-pended - ss indicates the second, zero pre-pended - xxx indicates the millisecond, zero pre-pended - Z is a fixed character, indicating UTC time zone</x +s:documentation> </xs:annotation> <xs:restriction base='xs:dateTime'> <xs:pattern value='.+T.+Z'/> </xs:restriction> </xs:simpleType>

    using print $wsdl->explain we get the following example for this parameter
    # is a xs:dateTime # Pattern: .+T.+Z dateTimeStamp => "2006-10-06T00:23:02Z"
    Any tips? Thank you.

Add your question
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?

    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 meditating upon the Monastery: (8)
    As of 2015-05-28 08:31 GMT
    Find Nodes?
      Voting Booth?

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

      Results (550 votes), past polls