Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
hexadecimal division
9 direct replies — Read more / Contribute
by holandes777
on Dec 15, 2017 at 18:16

    Lift the veil of ignorance from my eyes

    I am trying to follow am LRC computation (Longitudinal CRC computation) and have hit a bump

    # Calculating the exclusive or of "202005" # V= X32 .XOR. X30 .XOR. X32 .XOR. X30 .XOR. X30 .XOR. X35 + = X05 my $command = '202005'; print "$command length=" . length($command) . "\n"; my $result = substr($command,0,1); for (my $i=1; $i<length($command); $i++) { my $c = substr($command,$i,1); print "$i) " . sprintf("%02X ", ord($result)) . " xor ". sprintf(" +%02X ", ord($c)); $result = $result ^ $c; print " gives " . sprintf("%02X ", ord($result)) . "\n"; } print sprintf("%02X ", ord($result)) . "\n"; if ( $result == "\x05" ) { print ":-)\n"; } else { print ":-(\n"; } print "====\n"; # THIS IS WHERE THE PROBLEM BEGINS: # Divide by X10: # Y = INT ( X05 / X10 ) = X00 my $dividend = $result; my $divisor = "\x10"; my $result2; #$result2 = int($dividend/$divisor); #print sprintf("%02X ", ord($result2)) . "\n"; # results in Illegal division by zero at line 22. # and this results in character zero, not NUL: $result2 = int(ord($dividend)/ord($divisor)); print sprintf("%02X ", ord($result2)) . "\n";

    What concept did I miss? Thank you.

    It has been pointed out I was noyt clear as to what I needed, and it is true! So allow me to clarify:

    The result of the xor-ing is correct according to the API doc: they expect X'05' and if you run the code we have a display of 05 which is 0x05. It is the next step, where we divide this 0x05 result by X'10' (0x10). The code says:<\p> $result2 = int($dividend/$divisor);

    what I expect is 5/16 converted to an int which is the NUL characted (0x00) which the API show as X'00'. The result I AM getting is 30 (0x30 or the ascii charated zero). This is where I need your help, on the last statement.

Appconfig module question
4 direct replies — Read more / Contribute
by hveneticus
on Dec 15, 2017 at 10:34

    I have to read a configuration file that contains lines like these ones:

    VAR=/path/to/ AMB=cer DIRSKE=${VAR}${AMB} SCRIPT=${DIRSKE}/

    After a search, I found that module Appconfig can be the right one. I've read its documentation more and more, but I think I don't really understand how it works (honestly, it is a bit harder to read). Consider also that I'm only a beginner in Perl. My problem is the variable named DIRSKE. Appconfig can expand the value as in a shell script, but I can't understand how do it when I have two of them in the same line.

    #!/usr/bin/perl use strict; use warnings; use AppConfig qw(:expand); my $config = AppConfig->new({ CASE => 1, GLOBAL => {EXPAND => EXPAND_ALL} }); $config->define("VAR=s"); $config->define("AMB=s"); $config->define("DIRSKE=s"); # Maybe this is wrong, but what else? $config->define("SCRIPT=s"); #read configuration file $config->file("./file.conf"); #some print print "Valore VAR -> ".$config->VAR()."\n"; print "Valore AMB -> ".$config->AMB()."\n"; print "Valore DIRSKE -> ".$config->DIRSKE()."\n"; print "Valore SCRIPT -> ".$config->SCRIPT()."\n";

    The output is:
    Valore VAR -> /path/to/ Valore AMB -> cer Valore DIRSKE -> Valore SCRIPT -> /

    I'd like to have something like:
    Valore VAR -> /path/to/ Valore AMB -> cer Valore DIRSKE -> /path/to/cer Valore SCRIPT -> /path/to/cer/

    Am I using the correct module?
    If yes, can I have a suggestion on how to do it?


Array Plus Operator
2 direct replies — Read more / Contribute
by SleepyJay
on Dec 15, 2017 at 09:41
    I am deep in some legacy code (not written by me) that looks like this (it's surrounded by an if):
    @{ $self->bar || +[] }

    What's with that '+' in there? I mean, I get that it is usually used for disambiguation (e.g. @{ $self->bar || +shift }). But, what makes this plus needed?

    (I'm not a Perl beginner, but I have never seen Perl like this: is this a dumb question?)

DBIx::Class 'select.... for update' confusion
1 direct reply — Read more / Contribute
by tomgracey
on Dec 14, 2017 at 16:17

    Hello all

    I am confused about the mechanics of 'select.. for update' under DBIx::Class (I'm using MySQL but I suppose that shouldn't matter.) So I have reduced it down to the following test case:

    my $guard = $schema->txn_scope_guard; my $rs = $schema->resultset('TestTable')->search({ status => 'available' }, { rows => 1, 'for' => 'update' }); my $id_before_update = $rs->first->id; my $updated = $rs->update({ status => 'reserved' }); $guard->commit; my $id_at_end = $rs->first->id; print "id before update: $id_before_update\nid at end: $id_at_end\n";
    The table looks like this initially:
    +----+-----------+ | id | status | +----+-----------+ | 1 | available | | 2 | available | | 3 | available | +----+-----------+

    and after execution like this:

    +----+-----------+ | id | status | +----+-----------+ | 1 | reserved | | 2 | available | | 3 | available | +----+-----------+

    The schema was created by DBIx::Class::Schema::Loader and looks like this:

    __PACKAGE__->table("test_table"); __PACKAGE__->add_columns( "id", { data_type => "bigint", is_nullable => 0 }, "status", { data_type => "varchar", is_nullable => 1, size => 255 }, );
    (with boilerplate removed). When I run the above code I get the following:
    id before update: 1 id at end: 2

    To me this seems like odd behaviour, because after $rs is selected with rows=1 it surely should only contain a single row with a single id...?

    Any idea what stupid thing have I (not) done this time?

Lingua::EN::Tagger adapting to other language
No replies — Read more | Post response
by Anonymous Monk
on Dec 13, 2017 at 10:15


    I am trying a quite (for me) difficult task: adapt the module Lingua::EN::Tagger to be used with another language. To do so I need to train the probability values with a corpus in my language. The probability values are saved in several YAML files. Unfortunately there is 0 documentation, as far as I can say, describing how to do this. Actually, I have problems understanding how the probabilities are saved. I have some background in linguistics and in corpus linguistics. However, without documentation it is a hard task for me. I have seen that there is also a German version (Lingua::EN::Tagger) derived from the EN one. So the task, provided a corpus and some manual tagging to train the model, should be doable. I've written to the authors to get some info on how to proceed, but no response. Has somebody already tried to do something like this? If yes, have you found some documentation online on how to train the model? Any suggestion would be very much appreciated. Best.

C headers not found when installing Sys::Virt on CentOS
3 direct replies — Read more / Contribute
by chrestomanci
on Dec 12, 2017 at 12:05

    Greetings wise brothers, I am trying to install Sys::Virt on a CentOS box. but perl cannot find the necessary header files.

    I have installed the libvirt-devel package using yum, it has installed a number of header files in sensible places, as reported by "rpm -q -l libvirt-devel".

    I have attemped to install Sys::Virt package both using cpanminus, and by hand (unpack the tarball run Makefile.PL, run the generated Makefile). Either way it reports that libvirt is not installed.

    The check inside Makefile.PL is done using pkg-config. I have run that by hand and it also reports that libvirt is missing.

    I tried editing Makefile.PL to remove the check, and running it anyway. It then spits out a Makefile, which when I run creates lots of errors about missing macros and symbols that are defined in the libvirt headers.

    So in summary I have a situation where the CentOS core packaging system thinks the package has been installed, and has written the headers to the correct places. Meanwhile both pkg-config and the perl build system cannot find the package or the required header files, and so the build fails.

    I know that the build system for compiling XS modules in C is correctly setup, because I have successfully installed other XS based modules including XML::LibXML and JSON::XS

    At this point, I am stuck, so I am asking for help. Please bear in mind that I am not that familiar with CentOS (My preferred Distro is Debian), so I might have missed something obvious in the way that RedHat derived distros lay out files or configure libraries.

Converting fasta (with multiple sequences) into tabular using perl
5 direct replies — Read more / Contribute
by rarenas
on Dec 12, 2017 at 11:57

    Hello. I started learning perl two weeks ago and I have a practice assignment to convert fasta files into tabular format using perl. I managed to write a program that converted a fasta into tbl but only when there is one sequence in the fasta file. If I have multiple sequences in a fasta file, I cannot manage to convert them to tbl properly. This is the code I wrote that works with one sequence in the fasta:

    #!/usr/bin/perl # use strict; use warnings; die "Please specify suitable file\n" if (@ARGV != 1); my ($fasta) = @ARGV; my $outfile = "$fasta.tbl"; open(my $in, "<", "$fasta") or die "error reading $fasta. $!"; open(my $out, ">", "$outfile") or die "error creating $outfile. $!"; my $identifier = ""; my $union = ""; while (<$in>) { chomp; next unless m/\w/; if ($_ =~ m/>/) { # Identifier! $_ =~ s/>//; ($identifier) = split /\:|\s|\||,|;/, $_; print "$identifier\n"; } else { # We have a line with sequence $union = $union . $_; } } print $out "$identifier\t$union\n"; close($in); close($out);

    I realized that it would be a lot better to use hashes instead of arrays to separate the different sequences. I want to have the sequence title/name be the key and the sequence be the value. I also thought it would be good to use the local command so that I can separate based on ">" symbol instead of by line because all fasta file titles start with that symbol. I am stuck on actually implementing those realizations and then using a loop to edit the formatting for each sequence. Any suggestions? Thank you in advance!

    I am using the simple fasta file below for practice but do note that many fasta files contain extra information in the title and may have a space between the title and the sequence. We only want the name in tbl and not the extra information. The code above takes care of those extras only for one sequence.

    Fasta format


    Tabular format

DBD::Sqlite queries slow - and gives wrong results
6 direct replies — Read more / Contribute
by astroboy
on Dec 11, 2017 at 14:42

    Ok, this is pretty weird IMHO. I have some Perl code written to create and populate a SQLite database. It's very simple - a list of users and their AD groups in two different tables. It's been running ok for at least 18 months. I have some other Perl code that will query the database. This querying code has started running slowly, and in some cases returns no results where I know there are records - I can test it by pasting the SQL in to the SQLiteStudio v2.1.5 editor. It returns the results instantly.

    Here's an example of some Perl query code:

    #!/usr/bin/perl -w use strict; use DBI; my $dbfile = 'C:/db/employee.db'; my $dbh = DBI->connect( "dbi:SQLite:dbname=$dbfile", "", "", { RaiseError => 1, AutoCommit => 0, } ); my $sql = q{ select e.* from employees e, groups g where e.sam_account_name = g.sam_account_name and g.group_name = 'Group Name' order by last_name, first_name }; foreach my $emp (@{$dbh->selectall_arrayref($sql, {Slice => {}})}) { printf( "\t\t%-15s %-15s: (%s)\n", $emp->{first_name}, $emp->{last_name}, $emp->{sam_account_name}, ); } $dbh->rollback;

    The query in $sql is copied and pasted into the SQLiteStudio editor. Regardless of the group name I choose, the editor returns rows in approximately 0.001 seconds. Perl takes several seconds may return no rows, even where there are matching candidates. If I change the group name, it may return the same rows as the editor but it can take 10+ seconds. The result set is always small 2 - 20 rows depending on the group. The database is 520MB.

    Note the code above was written to simplify my problem. The actual code has the group name as a placeholder, and I simply fetch each row rather than returning everything into an array as I do above. Regardless, the results are the same.

    This is running on Windows 7. I was using DBD::SQLite 1.54 - As a test this morning I upgraded to 1.55_04 to see if there were any fixes in the developer version. I recreated the database, but the results are still the same

unique sequences
8 direct replies — Read more / Contribute
by Anonymous Monk
on Dec 10, 2017 at 18:31

    I am really new to perl and am taking a course on it. I wrote the following program for an assignment and am getting the incorrect output. I'm getting over a million lines while the expected output is closer to 250,000. The last 12 nts need to be unique to the genome. I have a feeling it's due to my regex. Any advice would be greatly appreciated. Thankyou.

    #!/usr/bin/perl use strict; use warnings; my %windowSeqScore = (); my $input_file = '/scratch/Drosophila/dmel-all-chromosome-r6.02.fasta' +; my $sequenceRef = loadSequence($input_file); my $output_file = 'unique12KmersEndingGG.fasta'; open (KMERS,">", $output_file) or die $!; my $windowSize = 21; my $stepSize = 1; for ( my $windowStart = 0 ; $windowStart <= ( length ( $$sequenceRef ) + - $windowSize ); $windowStart += $stepSize ) { my $windowSeq = substr ( $$sequenceRef, $windowStart, $windowS +ize); if ($windowSeq =~ /([ATCG]{10}GG$)/) { $windowSeqScore{$windowSeq}++; } } my $count = 0; for (keys %windowSeqScore){ $count ++; if ($windowSeqScore{$_} == 1 ) { print KMERS ">crispr_$count", "\n", $_, "\n"; } } sub loadSequence { my ($sequenceFile) = @_; my $sequence = ""; unless ( open( FASTA, "<", $sequenceFile ) ) { die $!; } while (<FASTA>){ my $line = $_; chomp ($line); if ($line !~ /^>/ ) { $sequence .= $line; } } return \$sequence; }

    This is some of the output I'm getting


    this is some of the expected output I should be getting

New Meditations
RTFM!!!!! (but if you didn't, no biggie)
5 direct replies — Read more / Contribute
by nysus
on Dec 15, 2017 at 08:12

    I was recently involved in a debate with marto. On the whole it was mild and though it started to go in circles, I think productive. I have no interest in rehashing the particulars of that debate. It's over. And this post is not directed specifically at marto and I thank him for his time and consideration. But I did want to add a few thoughts to this very age old, and probably tired, discussion about RTFM.

    I'll first say that yes, I agree, "RTFM" is very good advice. It was advice that was pounded into me probably within days of me joining the PM community 17 years ago. It is advice that I reflect upon quite often. One interpretation of it boils down to: "Be self sufficient. Don't expect others to do your work for you. Be very respectful of others' time and effort and don't expect an answer if you can't be bothered to put some work in for yourself."

    But like all rules of thumb, "RTFM" is open to wide interpretation. And so I offer another interpretation: "Learn how to figure things out for yourself, you'll be a better programmer for it. But if you feel like you are in over your head and you're feeling frustrated, go ahead and ask. It can't hurt. We'll try to be helpful, within reasonable limits, and you'll get the benefit of the doubt that you put in some effort into trying to figure it out."

    I would like to encourage Monks to provide that benefit of the doubt. It's most people's instinct to want to reciprocate when they see others being generous with help. And so I think erring on the side of generosity and helpfulness does a lot to enhance and build the reputation of Perl. Sure, there will be some takers who don't reciprocate or who constantly ask questions that can be answered with just a cursory read of the manual or google search. But we should be careful not to be so guarded against them that they prevent us from helping those who genuinely need a helping hand and that will be very appreciative of any specific guidance they receive.

    It's not easy advice to follow. We live in a dog-eat-dog, kill-or-be-killed kind of society that values hyper efficiency. Going out of your way to look something up for someone that strikes you as a lame brain does not seem like a very good use of your time. But I think, in the end, having faith in the good will of others gets us further down the road of progress. And I think that spirit of gift giving and reciprocation is what makes PM such a great community and Perl such a great programming language. I will do my absolute best to carry on the tradition.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Log In?

What's my password?
Create A New User
and a moth chases the moon...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2017-12-17 01:48 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (460 votes). Check out past polls.