|
I have a question about how unix system commands work in perl. I have my PATH environment variable set to the directory of a program I want to run. I can type: > my_program my_program executed However, if I try the same thing in my perl script with this line: print `my_program`; I get the error message, "Can't exec "my_program": No such file or directory at ../test.pl line 11." Why is this so?
|
# ¿ Nov 9, 2009 00:49 |
|
|
# ¿ May 2, 2024 03:22 |
|
ShoulderDaemon posted:What? No, UNIX doesn't exec programs from the cwd unless "." is a member of the PATH environment variable. It has everything to do with his PATH. I had perl print the $ENV{"PATH"} and it did show up correctly. I also checked and "." is on my PATH environment variable. I'm really stumped whether this is a perl problem or a unix problem.
|
# ¿ Nov 9, 2009 02:08 |
|
ShoulderDaemon posted:I'd check for something like an invisible unicode character or similar in the `` in your perl program. If you use something like `/full/path/to/my_program` does it work? I checked for any invisible characters and couldn't find any. I also tried using the full path, and it worked correctly. Very strange. Here's the error message I am receiving: #This works print `~/programs/my_program/bin/my_program -help`; #This doesn't work print `my_program -help` Can't exec "my_program": No such file or directory at ./test.pl line 15. #This works on the unix command line in any other directory > my_program -help I also removed the "." from my path. I only added to test if that could've been a problem. Thanks for all your help, though. It's just that this problem doesn't make too much sense to me.
|
# ¿ Nov 9, 2009 03:24 |
|
ShoulderDaemon posted:Well, when perl handles backticks it invokes a subshell; it's possible that the subshell's init process is overwriting your PATH variable. I checked that, and the program does display on the correct path. Since I'm on such a tight time constraint, and I am only verifying another project, I think I'll hardcode in the path for now. I will need to figure out why this isn't working later. Thank you for all your help, though. Mario Incandenza posted:FindBin (part of the core) will be useful here, if the script you're trying to run is located in the same directory as your Perl: I will try this later tonight once I read more about how FindBin works. Thanks for the link.
|
# ¿ Nov 9, 2009 23:05 |
|
I've build a helper.pm full of helpful functions. I'm now working on an interactive command line that allows me to easily call functions from helper.pm. However, I'm having problems getting the syntax down. For example, if I have a defined function test which prints "Hello world", then the following would call that function: my $function = "test" &{$function}(); However, if I have a defined function test in helper.pm, I don't know how to call it from another file. All the following fail: &{Helper::$function}(); &Helper::{$function}(); Helper::&{$function}(); $Helper::&{$function}(); Does anyone know the solution to this problem? Thanks!
|
# ¿ Sep 22, 2010 01:45 |
|
Mario Incandenza posted:Well, calling functions indirectly and tightly coupled like that is kinda asking for trouble, but here's how to do it (even when using strict): Yeah, this isn't the best solution. I am using this for testing my in house development tools and haven't had time to come up with a more elegant method due to other pressing issues. My main problem was my subroutines are in a different file, so I'm not sure how to call those functions. I was unclear about the syntax to make the call. However, I've figured it out. code:
code:
|
# ¿ Sep 22, 2010 21:45 |
|
I'm trying to extract names out of a tree structure and replace the labels with my own labels. The format is called newick, so this represents a full binary tree: ((A,B),(C,D)). Here's my code to get the names and make a rename map. code:
EDIT: Never mind, I figured it out. It doesn't feel very elegant, but I think it works: code:
octobernight fucked around with this message at 05:10 on Apr 22, 2011 |
# ¿ Apr 22, 2011 04:52 |
|
qntm posted:That solution does work, but I foresee problems if the existing tree already contains elements ending in "_foo", e.g. "A" and "A_foo". The existing "A" will be converted to "A_foo" on the first pass, while the existing "A_foo" will be left alone. On the second pass, you will end up with "A_foo_foo" and "A_foo_foo" respectively, which is wrong. Ah, you're correct. I didn't realize that problem. Thank you for pointing that out! I'll try your code snippet.
|
# ¿ Apr 26, 2011 08:02 |
|
I'm working with large 200-500 Gb text files, and I want to find lines that match a pre-defined list line ids and return the next line following the match. Here's my starting code:code:
|
# ¿ Aug 1, 2016 20:48 |
|
Thanks for the replies all.John Big Booty posted:This code won''t work. Thanks! I meant to use exists, not defined, and I left out the code that trims the lines so that all whitespace is removed from the ends. I wasn't planning on start exactly at a particular line, rather I was going to jump to XXXX byte location for each thread. I would then throw away whatever line it read it and find the first complete line that has the line start identifier (in my file, the id format is $id). It was something off the top of my head, though. homercles posted:You can make threads work, certainly you can. (well I'd use Parallel::ForkManager mostly because true threads aren't needed) Yes, there is. Id lines start with "$" so it makes it easy to figure out if it's an id line or value line. I'll probably try my seek strategy then. quote:Alternately, maybe you can use gnu parallel for this. Thanks for this, too. I've never used the parallel in GNU before, but I'm reading over it now. Mithaldu posted:There's one thing you need to be aware of: Thanks for the advice. I did not know that the threads duplicate of the memory of the motherthread. I don't think this will be an issue since the motherthread shouldn't be using much memory, but I will keep an eye on it, as well as any unexpected behavior from threads.
|
# ¿ Aug 2, 2016 18:57 |
|
John Big Booty posted:With a bit of massaging, that could be a workable approach. That's for the suggestion. I'll be testing this implementation today. I greatly simplified the data description to get a general algorithm, but basically I'm working with next generation sequencing data, and I'm trying to find specific reads in a file that I've identified through a different analysis. Basically, I had a huge sequencing file, I run the whole file through a program that identifies key sequences (but only their names, not the original sequences). Thus, I need to pull the raw reads from the file which are then fed to another program. I've never worked with sequencing data before, nor am I too familiar with working on multi-threaded/multi-core programming, however it's a requirement I pick this up quickly due to the amount of data I'm processing (~hundreds of TBs).
|
# ¿ Aug 3, 2016 18:37 |
|
I'm going nuts over the most bizarre issue regarding reading gzipped files using PerlIO-gzip-0.19 module. I have a gzip file that's about 30GB in size. I read 4 lines at a time from it, and print out the total number of 4x lines read, and I get 46,285,997. However, if I decompress the file from the command line, I see that there's actually 462,843,365 4x lines in the file. How am I off by an order of magnitude in the number of 4x lines. Here's my code:code:
|
# ¿ Feb 7, 2017 17:25 |
|
Mithaldu posted:That looks like an early stop. Make sure you verify the error conditions of all the system calls you're doing after you do them. By early stop, do you mean my script terminates incorrectly? As far as I can tell, that's not the case because I have a print statement outside the loop that shows that it completed the loop. The only other thing I can think of is, is it possible that my while condition is incorrect? code:
I should've done this from the beginning. The error happens across different file systems, always on the same line. I was too lazy to actually open the file and look at that line to see if there's something wrong with it. If there is (i.e., a blank line throwing off the reader), that would really suck because we would need to re-verify terabytes of data. I do recall that the person that had originally generated the data had issues putting the original file together (a bunch of separate gzip files that they parrallel-ly recombined into a single file). If they had inserted some unexpected blank line in there, that's going to screw up everything. Thanks!
|
# ¿ Feb 7, 2017 18:31 |
|
|
# ¿ May 2, 2024 03:22 |
|
Mithaldu posted:See http://perldoc.perl.org/functions/readline.html for more detail. But basically, readline() doesn't throw exceptions. It sets an error variable. So if readline errors out your while loop ends because it returned something undef. The linked article also shows ways to do this safer. Thank you! That's super helpful. I'll make sure to update all my scripts to follow these practices.
|
# ¿ Feb 7, 2017 18:44 |