Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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
[C Question] Determine if gcc provides erfl() function
3 direct replies — Read more / Contribute
by syphilis
on May 28, 2015 at 09:22
    I have a module that assumes that the compiler provides the erfl() function.
    The assumption is obviously wrong.
    What's the best way of determining, during the 'perl Makefile.PL' stage of the build, whether the compiler does, in fact, provide the erfl() function ?

    The cpan-tester FAIL reports that I'm receiving en-masse wrt BSD systems all seem to relate to gcc compilers. (I don't think there's a FAIL report there for anything other than BSD && gcc.)
    Therefore, I'm quite happy (for the moment, anyway) to limit this question/discussion to gcc compilers only.

DBD::CSV Update
3 direct replies — Read more / Contribute
by PERL_fresher
on May 28, 2015 at 05:46

    Hello Fellow monks I need some help with the update of one of the CSV files that Im trying to do. Basically one of the file has set of records which I dont want to update for example

    Souce Data X~Y~Z 1~2~3 col1~col2~col3~col4~col5 A~B~C~D~E
    Above is the file format. what i need to do is to start updating this table from row 3 where the actual data is

    my $dbh = DBI->connect("dbi:CSV:",undef,undef,{ f_dir => $_ENV::TempFilesDIR, csv_sep_char => "~", csv_quote_space => 0}) or die $DBI::errst +r; $dbh->{'csv_tables'}->{'cimp_money'} = { 'file' => 'Aviva_cimp_ +money_positive.txt', col_names => [qw(rcrd_typ +e seq_no emp_no forename surname initial ni_no ttl gender dob emp_cnt +rbtn emplyr_ctr tax_peri +od tax_yr exch_amt)] $dbh->do('UPDATE cimp_money SET forename=?,surname=? WHERE emp_no=?',u +ndef,$wrk_forename,$wrk_surname,$wrk_emp_no) or die $DBI::errstr;

    Basically updates are happening correctly but the issue Im facing is since the header records i.e. first 2 lines are just 3 columns and details records has 4 columns its assuming that even in first 2 rows also it has a header and its updating ~ to row 1 and 2 which is what I want to remove now

    Output Data X~Y~Z~~ 1~2~3~~ col1~col2~col3~col4~col5 A~B~C~D~E
RFC: A call to bioinformationalists for some generic information.
3 direct replies — Read more / Contribute
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
3 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 PROGRAMS, 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 PROGRAMS directory and modified the Perl program as follows:

    use strict; use warnings; use lib qw/programs/; # also tried PROGRAMS, just in case, but equival +ent 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 programs 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 programs 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 typos. Also, sorry if this is long, I tried to explain as much as possible the context.

hashref return fails
3 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?

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 romping around the Monastery: (14)
    As of 2015-05-29 13:25 GMT
    Find Nodes?
      Voting Booth?

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

      Results (584 votes), past polls