Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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
Detecting memory leaks.
3 direct replies — Read more / Contribute
by Steve_BZ
on May 04, 2015 at 10:28

    Hi Monks,

    I have a fairly mature but functionally independent, piece of code that precedes a call to a video player in wxPerl.

    When this code is not called the video (gstreamer) never crashes. When the code is called the video crashes occasionally, maybe 10% of the time.

    This issue is of fairly long standing, but because it is sporadic, no-one is quite sure when it started.

    While watching this happen in a performance monitor, I noticed that the memory utilisation was not stable and that it gradually increased over time. I tried tracking this through Valgrind and Valgrind showed some kilobytes of memory leaks, but didn't specify when they occurred (ie in real time). Just at the end in the leak summary.

    I have been using Memory::Usage as shown in http://perlmaven.com/eliminate-circular-reference-memory-leak-using-weaken to try to find trhe leak, but without much success. Every time I think I have found it, I modify the code only to find the Memory 'diff' move down the script.

    Here is a sample of the output:

    time vsz ( diff) rss ( diff) shared ( diff) code ( diff) + data ( diff) 0 774028 ( 774028) 193524 ( 193524) 43648 ( 43648) 8 ( + 8) 368928 ( 368928) before i_Booking->new 0 774028 ( 0) 193524 ( 0) 43648 ( 0) 8 ( +0) 368928 ( 0) after i_Booking tbl_patient_exam 0 774028 ( 0) 193524 ( 0) 43648 ( 0) 8 ( +0) 368928 ( 0) before i_Booking SetScreenHeader 0 774028 ( 0) 193524 ( 0) 43648 ( 0) 8 ( +0) 368928 ( 0) after i_Booking SetScreenHeader 0 774028 ( 0) 193524 ( 0) 43648 ( 0) 8 ( +0) 368928 ( 0) after i_Booking set focus 0 774028 ( 0) 193524 ( 0) 43648 ( 0) 8 ( +0) 368928 ( 0) before i_Booking i_staticText 1 0 774028 ( 0) 193524 ( 0) 43648 ( 0) 8 ( +0) 368928 ( 0) after i_Booking i_staticText 1 0 774648 ( 620) 193524 ( 0) 43648 ( 0) 8 ( +0) 368928 ( 0) before i_Booking Ctl_Booking_Referring_Doctor_Ref +_4_Lbl 0 774648 ( 0) 193524 ( 0) 43648 ( 0) 8 ( +0) 368928 ( 0) before i_Booking i_staticText 2 0 774648 ( 0) 193524 ( 0) 43648 ( 0) 8 ( +0) 368928 ( 0) after i_Booking i_staticText 2 0 774648 ( 0) 193800 ( 276) 43924 ( 276) 8 ( +0) 368928 ( 0) before i_Booking health plan providor 0 774648 ( 0) 193800 ( 0) 43924 ( 0) 8 ( +0) 368928 ( 0) at i_Booking mid point 0 774648 ( 0) 193804 ( 4) 43924 ( 0) 8 ( +0) 368928 ( 0) at i_Booking DatePickerCtrl 0 774780 ( 132) 193932 ( 128) 43924 ( 0) 8 ( +0) 369060 ( 132) at i_Booking Examining Doctor Search 0 774912 ( 132) 194172 ( 240) 43924 ( 0) 8 ( +0) 369192 ( 132) at i_Booking Patient details 0 774912 ( 0) 194172 ( 0) 43924 ( 0) 8 ( +0) 369192 ( 0) before i_Booking $loc_window_layout->SetFooter 0 774912 ( 0) 194172 ( 0) 43924 ( 0) 8 ( +0) 369192 ( 0) after i_Booking $loc_window_layout->SetFooter 0 774912 ( 0) 194172 ( 0) 43924 ( 0) 8 ( +0) 369192 ( 0) at i_Booking exit

    I am suspicious of a number of pieces of code, but like bubbles in the wall-paper the bubble just moves when I press it. For instance in the above output, we see :

    0 774648 ( 620) 193524 ( 0) 43648 ( 0) 8 ( +0) 368928 ( 0) before i_Booking Ctl_Booking_Referring_Doctor_Ref
    The total code between this line and the previous output is shown here, together with the surrounding lines:
    # Referring Dr details from Dr file $booking_dlg->{Ctl_Booking_Referring_Doctor_Lbl} = Wx::StaticText- +>new($booking_dlg->{booking_main}, wxID_ANY, __t('Referring Doctor'), + wxDefaultPosition, wxDefaultSize, ); $mu->record('before i_Booking i_staticText 1'); $booking_dlg->{Ctl_Booking_Referring_Doctor_Txt} = i_staticText->n +ew($booking_dlg->{booking_main}, wxID_ANY, "", wxDefaultPosition, wxD +efaultSize, ); $mu->record('after i_Booking i_staticText 1'); $booking_dlg->{Ctl_Booking_Referring_Doctor_Txt}->SetFont(Wx::Font +->new($gl_cfg->{client_point_size}, wxMODERN, wxFONTSTYLE_ITALIC, wxF +ONTWEIGHT_BOLD, 0, $gl_cfg->{client_font})); $mu->record('before i_Booking Ctl_Booking_Referring_Doctor_Ref_4_L +bl'); $booking_dlg->{Ctl_Booking_Referring_Doctor_Ref_4_Lbl} = Wx::Stati +cText->new($booking_dlg->{booking_main}, wxID_ANY, __t("Ref 4"), wxDe +faultPosition, wxDefaultSize, ); $mu->record('before i_Booking i_staticText 2'); $booking_dlg->{Ctl_Booking_Referring_Doctor_Ref_4_Txt} = i_staticT +ext->new($booking_dlg->{booking_main}, wxID_ANY, "", wxDefaultPositio +n, __xy_size(100), ); $mu->record('after i_Booking i_staticText 2'); $booking_dlg->{Ctl_Booking_Referring_Doctor_Ref_4_Txt}->SetFont(Wx +::Font->new($gl_cfg->{client_point_size}, wxMODERN, wxFONTSTYLE_ITALI +C, wxFONTWEIGHT_BOLD, 0, $gl_cfg->{client_font}));

    But really the code here looks quite innocent.

    Any ideas would be welcome.

    Regards

    Steve.

Reading a huge input line in parts
9 direct replies — Read more / Contribute
by kroach
on May 04, 2015 at 09:20

    I need to read a line of numbers separated by spaces and ending with a 0, like this:

    1 2 3 4 7 20 12334 0

    Each number needs to only be processed individually, so I don't have to keep them all in memory. The problem is, input lines can be very long and reading them with <> and splitting consumes a lot of memory.

    I tried setting a space as the input record separator, but it doesn't get the last number correctly.

    use strict; use warnings; sub do_something { print '{', $_[0], "}\n" } local $/ = ' '; while (<>) { do_something($_); }

    I also tried to simulate C++ cin behaviour with the following function:

    sub cin_read { my $inchar = getc; $inchar = getc while $inchar =~ /^\s$/; my $result = ''; while ($inchar =~ /^\S$/) { $result .= $inchar; $inchar = getc; } return $result; }

    However, it's overly complicated and slow.

    How else could I go about doing this?

    EDIT: Updated sample input to include multi-digit numbers
Comparison between a string and an array
4 direct replies — Read more / Contribute
by Eth443
on May 04, 2015 at 06:32

    Hi, I'm learning Perl, and I've got a question, how could I compare a STDIN from the user and a string inside an array like I tried to do. I did this but doesn't work -->

    my @answer=( "Bad", "Good", "Not good enough" ); chomp(my $user_answer=<STDIN>); if ($user_answer eq @answer){ print "Ok\n"; }

    I know that I can print a value inside the array with [] , but I don't know if there's any way to try them all...

CSV files compare
5 direct replies — Read more / Contribute
by PERL_fresher
on May 03, 2015 at 23:54
    Hello Few Perl monks, I have very urgent requirement to perform below changes. I have one master file a csv file delimited by commas and a directory which has several files 8 to be precise. Master file has fields such as employee ID and name, surname of employee and other fields as well. Similarly other csv files in directory have employee ID's and name and surnames in it. what I need to do is using master file as source search employee ID's in all files in that directory and replace name and surname in the directory. for ex. Master file employee ID, name, surname, other fields 1,nitin, abc,... 2, aa, bb,.. 3,cc,dd,.. 4, ee, ff directory files employee ID, name, surname, other fields 1,nitin1, abc1,... 2, aa1, bb1,.. 3,cc1,dd1,.. 4, ee11, ff1 I need to replace this with the data in master file for all files in directory. positions of the fields in target directory are same as I have described. I am fairly new to perl and just making my way through it. any help is greatly appreciated. sample master file Employee Number~Category Number~Forename~Surname~Initials~NI Number~Title~Gender~Marital Status~Date of Birth~Home Address Line 1~Home Address Line 2~Home Address Line 3~Home Town/City~Home County~Home Post Code~Employee Contribution %~Employer Contribution %~Annual Salary~Date of Joining Scheme~Date of Joining Company~Exchanged %~Scheme Joiner D51231~ORDM~Charles~Smith~C T~NP307342C~Mr~Male~S~15/10/1971~45 Board Walk~Springer Lane~Mundesley~Norfolk~~NR28 3JK~0.00~8.00~72800.00~01/09/2014~04/08/2014~2.00~N F78321~SMG1~Janet~Patterson~J M~AA112233A~Ms~Female~~21/07/1975~12 Sheringham Way~Cromer~~~~NR21 9BG~0.00~31.00~320000.00~01/09/2014~25/08/2014~0.00~N Sample files which is to be replaced by master file Employee Number~Category Number~Forename~Surname~Initials~NI Number~Title~Gender~Marital Status~Date of Birth~Home Address Line 1~Home Address Line 2~Home Address Line 3~Home Town/City~Home County~Home Post Code~Employee Contribution %~Employer Contribution %~Annual Salary~Date of Joining Scheme~Date of Joining Company~Exchanged %~Scheme Joiner D51231~ORDM~Nitin~Rane~C T~NP307342C~Mr~Male~S~15/10/1971~45 Board Walk~Springer Lane~Mundesley~Norfolk~~NR28 3JK~0.00~8.00~72800.00~01/09/2014~04/08/2014~2.00~N F78321~SMG1~AAA~BBB~J M~AA112233A~Ms~Female~~21/07/1975~12 Sheringham Way~Cromer~~~~NR21 9BG~0.00~31.00~320000.00~01/09/2014~25/08/2014~0.00~N Here D51231 F78321 are employee nos and in master file D51231 Forename = CHARLES surname = SMITH I need to do this to sample file where D51231 Forename = Nitin surname = Rane Output should be D51231 Forename = CHARLES surname = SMITH. what I was hoping with below code is when I give directory name all files in that directory are accessible to me as tables so that I can simply use simple SQL to update source file.
    my $dbh = DBI->connect('dbi:CSV:', "", "", { f_dir => "$_ENV::LogsFilesDIR/", f_ext => ".txt", eol => "\n", sep_char => "~", RaiseError => 1, }) or die $DBI::errstr; print $ceridian_raw_files; if ($ceridian_raw_files =~ m/^$_ENV::new_entrants/i) { print "inside dbi $ceridian_raw_files\n"; my $sth = $dbh->prepare("select forename from $ceridian_raw_files"); $sth->execute(); my $res = $sth->fetchall_arrayref(); use Data::Dumper; print $res;
    However in my case Im not able to even initiate the object $sth. any suggestions? I tried this method with some comments from below members. apologies for any ignorance on my part as name suggests Im newbie in Perl world and relying on help from fellow perl monks :) Hello Monks Issue is now resolved. thanks for your help if anyone is intrested then below is the code
    my $dbh = DBI->connect("dbi:CSV:f_dir=$_ENV::LogsFilesDIR;csv_sep_cha +r=\\~") or die $DBI::errstr; $dbh->{'csv_tables'}->{'prospects'} = { 'file' => 'cimp_new_entrant.tx +t'}; $dbh->do("UPDATE prospects SET Forename = 'Nitin'"); my $sth = $dbh->prepare("select Forename from prospects"); $sth->execute(); while (@row = $sth->fetchrow_array) { print @row; } $sth->finish( ); $dbh->disconnect( );
Form authentication for .NET sites
1 direct reply — Read more / Contribute
by Charli
on May 03, 2015 at 22:49
    Hi, I am new in Perl and I am trying to go through a login page and going to the actual site. For example, to be able to check emails in Yahoo, one must go through the Yahoo log in to enter credentials for username and password. I used WWW::Mechanize to go through the login page, see code snippet below:
    my $mech = WWW::Mechanize->new(); $mech->get($url); $mech->field("UserName", $username); $mech->field("Password", $password); $mech->submit_form();
    But with the code above, I am unable to go through the actual page and stuck in the login page. Any thoughts or suggestions?
[emacs] auto-completion of Perl code
1 direct reply — Read more / Contribute
by LanX
on May 03, 2015 at 17:37
    Hi

    I'm playing around with auto-complete.el combined pos-tip.el but it seems Perl isn't properly supported yet.

    see this picture PosTipScreenshotAutoComplete for motivation.

    I tried making perl-completion.el work but it had too many prerequisites und didn't seem well supported.

    Any other way?

    I can see that ECB is able to parse Perl using imenu and/or etags, would be nice to feed this into auto-complete. :)

    (update: I know that only perl can parse perl for 100%, but 90% is better than nothing)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Compare variables when the number of them vary
3 direct replies — Read more / Contribute
by stroke
on May 03, 2015 at 12:52

    Hi, this script queries the defined list of DNS servers and grabs the serial numbers for the listed zones. It then compares them against each other and logs if they match or not. It may not be pretty, but it works !

    But, the bit I'm struggling with now is how best to do the serial number comparison if the number of DNS server in the list changes - that is if I add in more or remove DNS server IPs to the list, I don't have to manually go and add/remove the serial number references for the check - I want to make the serial compare "dynamic", based on the number of DNS servers.

    I'm okay with just comparing all other serials to the first serial number, rather than comparing all possible combinations.

    fyi - I'm writing all the results out to a file for reference, in addition to sending errors only to STDOUT. Thanks

    #!/usr/bin/env perl use strict; use warnings; use Net::DNS; use 5.010; my @nameservers = qw(8.8.8.8 4.2.2.2); my @errors; open(my $resultsfh, '>', "results-serials.csv") or die "cannot open > results-serials.csv: $!"; print $resultsfh "Result,Zone"; foreach (@nameservers) { print $resultsfh ",Serial for: $_"; } print $resultsfh "\n"; while (<DATA>) { my $fqdn = $_; chomp $fqdn; my @serials; my $res = Net::DNS::Resolver->new; $res->tcp_timeout(2); $res->udp_timeout(2); foreach my $ns (@nameservers) { $res->nameservers($ns); my $reply = $res->query("$fqdn", "SOA"); if ($reply) { push(@serials, ($reply->answer)[0]->serial); } else { push(@serials, $res->errorstring); } } # Compare Serials no warnings 'numeric'; if ($serials[0] == $serials[1]) { say $resultsfh "MATCH,$fqdn,$serials[0],$serials[1]"; } else { say $resultsfh "MISMATCH,$fqdn,$serials[0],$serials[1]"; push @errors, "MISMATCH.$fqdn,$serials[0],$serials[1]"; } } if (@errors) { say "ERRORS:"; foreach (@errors) { say "$_"; } } __DATA__ google.com apple.com
Error on Windows 7: Message: The application has failed to start because its side-by-side configuration is incorrect.
2 direct replies — Read more / Contribute
by psiciliano
on May 03, 2015 at 10:22

    Hi Monks,

    I'm modifying an open source program (Slic3r) and when I've successfully package my new program with citrus perl 5.16 and CAVA packager on windows

    But when I tried to run it on my client's machine the program fail with the error "Message: The application has failed to start because its side-by-side configuration is incorrect.". If I understand it correctly, it's caused because some library version on my client's machine are diferent from the libraries that I've used to compile XS modules. It not surprices me, because I've compiled it with Mingw, and they has installed Visual Studio.

    I think it can be solved compiling it statically (Including all libraries on the .exe file) but there is a question ... How can I do that?

    Sorry for my bad English (It's not my first language) or if it's not specifically a Perl question ... But really I think this needs Perl wisdom

    Regards.
    Pablo.

EXTRACT FASTA SEQUENCE FROM ORIGINAL FASTA FILE DEPENDING ON ANOTHER SEQUENCE HEDAER FILE
2 direct replies — Read more / Contribute
by rameshchand123
on May 03, 2015 at 10:20
    I have two files: File 1: contain many FASTA sequences >84C2_Locus_14_Transcript_1/3_Confidence_0.571_Length_1244 AAACTAGTCAATAGAGAAAATCCAAAGTGGATGAAATTGAAGTGATTGTATGGCACAAGT...so on

    >84C2_Locus_14_Transcript_2/3_Confidence_0.857_Length_1961 AAACTAGTCAATAGAGAAAATCCAAAGTGGATGAAATTGAAGTGATTGTATGGCACAAGT...so on

    >84C2_Locus_15_Transcript_1/9_Confidence_0.190_Length_757 ATTTGCTCGGAAAAACACTTCTCGTGGAACTTGTTAGCGCTGAGCTTGATCCCAAGACGA.....so on

    >84C2_Locus_15_Transcript_5/9_Confidence_0.333_Length_1841 ATTTGCTCGGAAAAACACTTCTCGTGGAACTTGTTAGCGCTGAGCTTGATCCCAAGACGA....so on

    File2: only the sequence headers so many

    84C2_Locus_14_Transcript_1/3_Confidence_0.571_Length_1244 84C2_Locus_14_Transcript_2/3_Confidence_0.857_Length_1961 84C2_Locus_14_Transcript_3/3_Confidence_0.571_Length_1248 84C2_Locus_15_Transcript_1/9_Confidence_0.190_Length_757 ........ many more

    my output file should be contain the sequence associated with header. i.e. matching the sequence header file (file2) header portion with original fasta sequence file (file1) and those headers match the fasta sequence header in file 1 only those sequences store in another output file containing header with sequence.Just like this: Original output file should like this:

    >84C2_Locus_15_Transcript_5/9_Confidence_0.333_Length_1841 ATTTGCTCGGAAAAACACTTCTCGTGGAACTTGTTAGCGCTGAGCTTGATCCCAAGACGA......so on

    Please suggest me the way in perl which is applicable for my problem.

Proper location of module required for test scripts
2 direct replies — Read more / Contribute
by gflewis
on May 03, 2015 at 10:10
    I am trying to package my first module for CPAN distribution. It is pretty simple: just a single module; but there are about 20 test scripts. I am using Module::Build. I have a small file ("test.config") of configuration data that is required for most of my test scripts, and a small module ("TestUtil.pm") that reads this configuration data. Currently these two files are in the "t" directory. However, when I type ./Build test it can't locate TestUtil.pm. What is the proper location for a module whose only purpose is to support the test scripts?

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 rifling through the Monastery: (5)
    As of 2015-05-06 02:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

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









      Results (130 votes), past polls