Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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
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)?

Heap structure for lookup?
5 direct replies — Read more / Contribute
by BrowserUk
on May 27, 2015 at 04:13

    If you have 150e6 64-bit values to store for efficient lookup, perl's hashes(~14GB) and arrays(~5GB) are very expensive of memory, and a bitmap is out of the question.

    The array is feasible, but to do lookups (binary search) requires it be sorted, and that's quite expensive for this size of array, even when using one of salva's in-place, XS modules.

    The values are generated at runtime, and discarded at program end, so DBs are pointless. Even an in-memory sqlite DB which stores numbers as strings is off the cards.

    I'm going to have to drop into Inline::C for this for both space and performance reasons.

    A straight C array of 64-bit ints is ~1.2GB which is fine; but again sorting it so I can to O(logN) lookups is expensive.

    I keep thinking about heaps (or Beaps or B-heaps or other variations), structures that "order" the values as they are inserted; but once built, can any of them be used for efficient (O(logN) or better) lookup?

    Wikipedia isn't giving me much on the subject of lookup/searches.


    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
Strange behavior with List::Util qw{first} on perl >= 5.20
7 direct replies — Read more / Contribute
by papioko
on May 26, 2015 at 16:18
    Hi monks Today when a try to run some of my work code on perl 5.20 (before that i used 5.18) i encountered a strange behavior that i can't understand. The Sample code is:
    #!/usr/bin/env perl use strict; use warnings; use List::Util qw{ first }; my %hash = ( ASD => 1, ZXC => 2, QWE => 3, TYU => 4 ); my $val = "qwe"; if(my $res = first { lc $_ eq $val } keys %hash) { print "Found: $res\n"; } else { print "Not found\n"; };
    On perl version prior 5.20 result will be "Found: QWE" (as i expected), but when i run this code on perl 5.20 and beyound, result will be "Found: qwe". What is that ? Bug? Or i missed something ?
Permission denied to module
2 direct replies — Read more / Contribute
by zdavek
on May 26, 2015 at 15:26

    We upgraded from perl 5.14.2 to perl 5.20.2 and updated most of our modules this last weekend. Our programming staff have no problems running anything but our end users are all getting messages like:

    Can't locate MIME/Lite.pm:   Permission denied at /path_to_script/msg_send.pl line 18.
    BEGIN failed--compilation aborted at /path_to_script/msg_send.pl line 18.
    
    I'm guessing something has the wrong perms but cannot track it down. MIME::Lite is installed and the permissions are:
    drwxr-sr-x  3 root common     96 May 23 12:49 lib/site_perl/
    drwxr-sr-x 56 root common   8192 May 24 11:11 lib/site_perl/5.20.2/
    drwxr-sr-x  2 root common   8192 May 23 13:16 lib/site_perl/5.20.2/MIME/
    -r--r--r--  1 root common 105117 Nov  3  2013 lib/site_perl/5.20.2/MIME/Lite.pm
    
    I'll note that every normal user of our system is in the common group. Also end users have no problems if no modules are used.

DBD::Oracle installation problem - "Can't load Oracle.dll" / "Exec format error"
1 direct reply — Read more / Contribute
by topbanana
on May 26, 2015 at 15:07
    Hi, I'm trying to install DBD::Oracle on cygwin. I am only a beginner with perl, and the whole cpan/make/build thing is entirely new to me also. So to the problem. in cpan I run: cpan[2]> install DBD::Oracle and a load of guff is spewed out. All is well until the following lines:
    t/00versions.t ................ Can't load '/home/J/.cpan/build/DBD-Or +acle-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll' for module DBD +::Oracle: Exec format error at /usr/ lib/perl5/5.14/i686-cygwin-threads-64int/DynaLoader.pm line 190. at t/00versions.t line 10. Compilation failed in require at t/00versions.t line 10. BEGIN failed--compilation aborted at t/00versions.t line 10. # Looks like your test exited with 8 before it could output anything. t/00versions.t ................ Dubious, test returned 8 (wstat 2048, +0x800)
    Now, I don't really know what I'm doing here because it's all new to me, but I've had a go and so far all I can say is that /home/J/.cpan/build/DBD-Oracle-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll does exist:
    J-PC:J >ls -l /home/J/.cpan/build/DBD-Oracle-1.74-nSxxhX/blib/arch/aut +o/DBD/Oracle/Oracle.dll -rwxr-xr-x 1 J None 721811 May 26 15:07 /home/J/.cpan/build/DBD-Oracle +-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll
    The failing code is in .cpan/build/DBD-Oracle-1.74-nSxxhX/t/00versions.t:
    use DBD::Oracle qw/ ORA_OCI /;
    which is called by (or perhaps vice versa) the following code in /usr/lib/perl5/5.14/i686-cygwin-threads-64int/DynaLoader.pm
    my $libref = dl_load_file($file, $module->dl_load_flags) or croak("Can't load '$file' for module $module: ".dl_error());
    So that module exists. Can anybody tell me what I can do here? By the way, I don't know what it does but I saw somebody somewhere mention ldd to check a library for links or something, so I did that:
    J-PC:J >ldd /home/J/.cpan/build/DBD-Oracle-1.74-nSxxhX/blib/arch/auto/ +DBD/Oracle/Oracle.dll ntdll.dll => /cygdrive/c/Windows/SysWOW64/ntdll.dll (0x779d000 +0) kernel32.dll => /cygdrive/c/Windows/syswow64/kernel32.dll (0x7 +72f0000) KERNELBASE.dll => /cygdrive/c/Windows/syswow64/KERNELBASE.dll +(0x75810000) ??? => ??? (0x6f640000)
    There's nothing that I can see in the cpan output that says a variable doesn't exist. Can anybody help me here? Any help is greatly appreciated as I'm totally in the dark. Thanks. ===================================================== EDIT: ===================================================== Here is some more of the cpan output, which suggests that the shared library isn't where it ought to be (although as I have said, it is where it is supposed to be, or at least, something is there):
    t/000-report-versions-tiny.t .. ok t/00versions.t ................ Can't load '/home/J/.cpan/build/DBD-Or +acle-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll' for module DBD +::Oracle: Exec format error at /usr/ lib/perl5/5.14/i686-cygwin-threads-64int/DynaLoader.pm line 190. at t/00versions.t line 10. Compilation failed in require at t/00versions.t line 10. BEGIN failed--compilation aborted at t/00versions.t line 10. # Looks like your test exited with 8 before it could output anything. t/00versions.t ................ Dubious, test returned 8 (wstat 2048, +0x800) Failed 2/2 subtests t/01base.t .................... 1/6 # Failed test 'install_driver' # at t/01base.t line 24. # got: 'install_driver(Oracle) failed: Can't load '/home/J/.c +pan/build/DBD-Oracle-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll +' for module DBD::Oracle: Exec forma t error at /usr/lib/perl5/5.14/i686-cygwin-threads-64int/DynaLoader.pm + line 190. # at (eval 11) line 3. # Compilation failed in require at (eval 11) line 3. # Perhaps a required shared library or dll isn't installed where expec +ted # at t/01base.t line 21. # ' # expected: '' # Failed to load Oracle extension and/or shared libraries # Looks like you failed 1 test of 6.
Do i need really to update perl 5 to perl 6?
7 direct replies — Read more / Contribute
by Muskovitz
on May 26, 2015 at 12:13
    Hi Monks! is it a must to update perl 5 to perl 6? There's a lot of changes in Perl 6 and also some said that learning perl 6 is like learning another language do i need really to update and learn perl 6 for future developing in perl?
Passing a file handle and two arrays to a function by reference.
5 direct replies — Read more / Contribute
by subr01
on May 26, 2015 at 09:28

    How to pass a filename or a filehandle, two arrays to a function? I have done this:

    open INPUT,"$old"; my (@arrayold,@arraynew); myfunc(*INPUT,\@arrayold,\@arraynew) sub myfunc { my ($file,@array1,@array2) = @_ ; my $j = 0; my $k = 0; while (my $line = <$file) { my($word1,$word2) = split(",",$line); $array[$j++] = $word1; $array[$k++] = $word2; } }

    As you can guess, my function reads a file which has info like:

    1,//http:abcd 2,//http:avcd

    into two arrays one containing the number and the other containing the address. I am only getting blank arrays. Am I passing it wrong? Kindly help.

New Meditations
Perl monks vs other sites
1 direct reply — 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.

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 chanting in the Monastery: (10)
As of 2015-05-29 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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









    Results (580 votes), past polls