Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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
get each column key/value
1 direct reply — Read more / Contribute
by Peamasii
on May 30, 2015 at 10:38
    Hello, I have been trying to figure out how to do this with DBI. I have a few tables each containing different fieldnames and just one row of values. I'd like to write a sub which stores the column name and corresponding value in row, in a hash, in the order they are in. The I want to loop over the hash and retrieve the key/value pairs. How can I do this? I looked at at fetchrow_hashref and fetchrow_arrayref but the columns were not returned in order. Any help would be appreciated. Update: I found the answer
    sub print_stats { my($table) = @_; my $sth = $dbh->prepare('SELECT * FROM '.$table) or die "Couldn't prepare statement: " . $dbh->errstr; $sth->execute # Execute the query or die "Couldn't execute statement: " . $sth->errstr; my $names = $sth->{NAME}; # or NAME_lc or NAME_uc while( my $report_row = $sth->fetchrow_arrayref() ) { for my $col_idx ( 0 .. $#{$names} ) { print "$names->[$col_idx]: $report_row->[$col_idx]\n"; } } }
decimal to binary conversion
3 direct replies — Read more / Contribute
by mp0065789
on May 30, 2015 at 07:10

    Can anyone help here:

    #!/usr/bin/perl -w use strict; use warnings; print "Enter decimal number less than 256:"; my $decimal; $decimal=<STDIN>; #chomp $decimal; print $decimal & 128 <=> 0; print $decimal & 64 <=> 0; print $decimal & 32 <=> 0; print $decimal & 16 <=> 0; print $decimal & 8 <=> 0; print $decimal & 4 <=> 0; print $decimal & 2 <=> 0; print $decimal & 1 <=> 0 ;
    output: F:\Perl\code>chap2ex3.pl Enter decimal number less than 256:255 11111111 F:\Perl\code>chap2ex3.pl Enter decimal number less than 256:12 00000000 F:\Perl\code>chap2ex3.pl Enter decimal number less than 256:8 00000000

    output is coming wrong for all except 255. Frown

tie variable
2 direct replies — Read more / Contribute
by grasshopper!!!
on May 29, 2015 at 17:31

    Is it possible to tie a scalar to Tk entry and a subroutine as to return length of input on each letter input. Writting twitter client and wish to display number of characters input to entry in label on each keystroke at a loss. thank you

what are my options with perl, sybase dblib?
1 direct reply — Read more / Contribute
by taiq_m
on May 29, 2015 at 15:42
    i am on solaris 10 using sybase dblib on most of my perl scripts. we are now moving to RHEL 6. Pls note I have no root access, can i get sybase dblib to work on rhel? we have DBI on rhel but no dbd sybase. can i have dbd sybase installed on one of my custom libraries? below is what i have. perl -v This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
Threads From Hell #3: Missing Some Basic Prerequisites
2 direct replies — Read more / Contribute
by karlgoethebier
on May 29, 2015 at 14:43

    Hi all,

    I try to create a queue for multithreaded processing of a huge image file.

    Here is what i figured out:

    #!/usr/bin/env perl use strict; use warnings; use Data::Dump; use Time::HiRes qw(time); # use feature qw(say); my $start = time; my @queue; my @line; # ratio 1.25 - i guess 160 pixel # my $width = 20; # my $height = 8; # my $qsize = 4; # same ratio - i guess 20 MP my $width = 1280 * 4; my $height = 1024 * 4; my $qsize = 32; for my $x ( 0 .. $width - 1 ) { for my $y ( 0 .. $height - 1 ) { my $coords = [ $x, $y ]; push @line, $coords; if ( scalar @line == $width ) { push @queue, [@line]; @line = (); # audacious actions start here if ( scalar @queue == $qsize ) { # dd \@queue; @queue = (); } } } } printf "Took %.3f seconds\n", time - $start; __END__ karls-mac-mini:monks karl$ ./queue.pl Took 13.531 seconds

    It looks like it works as designed.

    But i can't suppress the vague feeling that this solution is ungeschickt.

    How can i improve this code?

    Thank you very much for any hint and best regards,

    Karl

    «The Crux of the Biscuit is the Apostrophe»

Serverspec, but using Perl?
2 direct replies — Read more / Contribute
by neilwatson
on May 29, 2015 at 09:33

    Greetings,

    Do you know if there is a Perl equivilant to Serverspec? If you were to build such tool in Perl how you go about it?

    Neil Watson
    watson-wilson.ca

system stdout redirected ok to a file but not to a variable.
5 direct replies — Read more / Contribute
by guybrush
on May 28, 2015 at 16:56

    Hi, I'm trying to run a command on a unix box using system because I need the exit code. but I also need the stdout and stderr. so I try some STDOUT redirection unfortunatelly it works if I redirect to a file:

    open(STDOUT, '>' ,"kk.txt" ) or die "Can't redirect stdout: $!";

    But not when I do it to a variable:

    open(STDOUT, '>' ,\$output ) or die "Can't redirect stdout: $!";

    This is my Testing code:

    #!/usr/bin/perl my $exitcode ; my $output=''; my $error=''; # take copies of the file descriptors open(OLDOUT, ">&STDOUT"); open(OLDERR, ">&STDERR"); #close current outs as per manual of open close(STDOUT) or die "Can't close STDOUT: $!"; close(STDERR) or die "Can't close STDERR: $!"; # redirect stdout and stderr open(STDOUT, '>' ,\$output ) or die "Can't redirect stdout: $!"; #open(STDOUT, '>' ,"kk.txt" ) or die "Can't redirect stdout: $!"; open(STDERR, '>' ,\$error ) or die "Can't redirect stderr: +$!"; printf "Before system\n"; # run the program system("echo I cant get this into a variable"); $exitcode=($? >>8); printf "After System\n"; # close the redirected filehandles close(STDOUT) or die "Can't close STDOUT: $!"; close(STDERR) or die "Can't close STDERR: $!"; # restore stdout and stderr open(STDOUT, ">&OLDOUT") or die "Can't restore stdout: $!"; open(STDERR, ">&OLDERR") or die "Can't restore stderr: $!"; # avoid leaks by closing the independent copies close(OLDOUT) or die "Can't close OLDOUT: $!"; close(OLDERR) or die "Can't close OLDERR: $!"; printf "Exitcode: %d\n" ,($exitcode); printf "still here\n"; print $output ; print $error ;

    Please any help on why it does not work the redirection when is a variable?

    Also if posible. how can I do this without system. remember I need exitcode stdout and stderr and I do not want to do any alter to the actual command to do unix redirections.

    Many many thanks.

    Guybrush.

WebService::Plotly dies with HTTP::Response=HASH(...)
1 direct reply — Read more / Contribute
by docdurdee
on May 28, 2015 at 14:12
    Dearest Monks, I'm trying to use the WebService::Plotly module. It works great on two computers (running p5.20.1 on OS X 10.10.3), but it dies without warnings on three other computers (running p5.20.1 on OS X 10.8.4) dumping: HTTP::Response=HASH(0x7f87ba65afe0) Do you have any suggestions as to how to solve this problem? Here is the code:
    use Modern::Perl; use WebService::Plotly; my $plotly = WebService::Plotly->new( un => $user, key => $key); my @ss = map {[split]}( '2.1120 0.0047', '2.1160 0.0045', '2.1200 0.0058', '2.1240 0.0045', '2.1280 0.0036', '2.1320 0.0029', '2.1360 0.0024', '2.1400 0.0032', '2.1440 0.0020', '2.1480 0.0014', ); my @ds = map{$_->[0]} @ss; my @ps = map{$_->[1]} @ss; my $response = $plotly->plot( \@ds, \@ps ); print "url is: $response->{url} \n"; print "filename on our server is: $response->{filename} \n";
    For the computers that it works, I can dump $response:
    $VAR1 = { 'filename' => 'plot from API (7)', 'warning' => '', 'url' => 'https://plot.ly/~demianriccardi/113', 'message' => '', 'error' => '' };
    Thanks! D
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
Checking Variable for Not Null
5 direct replies — Read more / Contribute
by dirtdog
on May 27, 2015 at 10:49

    Hi Monks, Can anyone tell me if the following 2 statements would be equivalent as far as checking that a variable is not null.

    next unless ! $ex_date; next unless !defined($ex_date);

    Basically, i would like to go to the next record if the variable $ex_date is null. any help is much appreciated. thanks Tony

Data Move
2 direct replies — Read more / Contribute
by PilotinControl
on May 27, 2015 at 09:36

    Good Morning Monks!
    The sub routine code posted below does what I want except it copies all lines over to a new file instead of one line based on its unique key. What the code does is remove a line from one file however it copies All lines instead of the updated line to the new file. What am I missing? The update code works as it updates a record. What my focus is on is moving that updated line from the original cardata.txt to the updatedcardata.txt Thanks in advance!

    use strict; use warnings; use File::Copy;

    UPDATE
    This is the code that calls the sub below just for clarification

    my ($rcid,$car,$owner); print "\nSelect Value To Edit: "; chomp(my $enter=<STDIN>); if ($enter) { if ($enter) { print "\nEnter New Value: "; chomp(my $new_value=<STDIN>); if ($new_value) { if ($enter == 1) { update_record_now($rcid,$new_value,$owner); } elsif ($enter == 2) { update_record_now($rcid,$car,$new_value); } } } } sub update_record_now { my ($rcid,$car,$owner) = @_; open my $infile, '<','cardata.txt' or die $!; open my $outfile, '>', 'cartemp.txt' or die $!; while (<$infile>) { s/^$rcid\:.*/$rcid\:$car\:$owner/g; print $outfile $_; } my $pinfile = "cardata.txt"; my @data; { open(my $data_file_handle, '<', "$pinfile") or die("Can't open file: $ +pinfile"); @data = <$data_file_handle>; close($data_file_handle); close $pinfile; } chomp(@data); open(my $out_file_handle,'>', $pinfile) or die("Can't open file: $pinf +ile"); foreach my $line_from_file ( @data ) { my @field = split( /\:/, $line_from_file ); next if( $field[0] == $rcid ); print $out_file_handle $line_from_file, "\n"; } close $pinfile; close $out_file_handle; close $infile; close $outfile; move 'cartemp.txt', 'updatedcardata.txt'; } __DATA__ 1:Chevy:Bob 2:Ford:Tom 3:Fiat:Dave
How smart is 'seek $fh, $pos, 0'?
3 direct replies — Read more / Contribute
by Monk::Thomas
on May 27, 2015 at 08:36
    Hello

    If the filehandle is at position X and I want to go to position Y: Does 'seek $fh, $pos, 0' rewind to the begin and then skip ahead to $pos or does it optimize automatically and just moves from the current position to the intended position?

    In other words:

    a) Does it actually make a difference if I calculate the difference and use 'seek $fh, $delta, 1' or if I simply use 'seek $fh, $abs, 0'?

    b) Is there a difference between going back (Y<X) and skipping ahead (Y>X)?

New Meditations
Perl monks vs other sites
3 direct replies — Read more / Contribute
by f77coder
on May 23, 2015 at 23:09
    Hello All,

    I wasn't sure where to post this, so apologies if this is not the place.

    I wanted to say how great Perl Monks is at helping out noobs compared with knuckle dragging neanderthals at place like stack overflow. People here are generally orders of magnitude nicer.

    Cudos to the site.

New Monk Discussion
Can I please have multiple downvotes per (certain monk's) posts.
8 direct replies — Read more / Contribute
by BrowserUk
on May 29, 2015 at 10:30

    I'd willing give up 5 XP per downvote to do it. 10 even.


    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
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 chilling in the Monastery: (8)
As of 2015-05-30 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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









    Results (599 votes), past polls