Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: How to embed a tool in my script

by McDarren (Abbot)
on Feb 12, 2012 at 16:48 UTC ( #953322=note: print w/ replies, xml ) Need Help??


in reply to Re^2: How to embed a tool in my script
in thread How to embed a tool in my script

Well, no. Probably not.

I'm not exactly clear whether you want to pass each entire file to your external tool, or whether you want to open each file and then pass it line by line. I guess probably the former. If that's the case, then perhaps this example will help.

$ echo 'some text' > 1.pdb $ echo 'some more text' > 2.pdb
Lets say for example your external tool is /bin/cat, and you want to cat each file and capture the output.
$ cat foo.pl #!/usr/bin/perl use strict; use warnings; my $dir = '.'; my $cat = '/bin/cat'; opendir DIR, $dir or die "Cannot open directory $dir:$!\n"; my @pdb_files = grep { -f $_ && $_ =~ /\.pdb$/ } readdir DIR; closedir DIR; for my $file (@pdb_files) { my $content = `$cat "$dir/$file"`; chomp $content; print "Content of $file is $content\n"; }
$ perl foo.pl Content of 1.pdb is some text Content of 2.pdb is some more text
That should be enough to get you going?


Comment on Re^3: How to embed a tool in my script
Select or Download Code
Re^4: How to embed a tool in my script
by angel_perl (Initiate) on Feb 14, 2012 at 02:49 UTC

    Sorry @Darren the program doesn't seems to work because its asking for two input files first input file is the exterior script(written already)and the second input is the PDB files. So,i think incorporating a function which calls the script file first followed by the PDB files will help. So, could you please tell me how to do this?

      I'm sorry, but I'm a bit lost.

      I understand that English might not be your first language, but you're not doing a very good job of explaining what you need (no offense intended).

      This is what I understand from your posts so far:

      • You have a number of files with a .pdb extension
      • You have a tool that processes these files in some way
      • You want to use perl to feed these files to this tool
      Now, assuming that the above is correct - I have a couple of questions for you.
      Firstly, how do these files need to be passed to your external tool? Do you need to a) just pass the name and location of the file, or b) open the file within perl and then pass it line by line?

      And secondly, does this external tool produce any output? And if it does, what should be done with that output?

      Perhaps if you can describe as best you can the steps you would take if you were going to process one of these files manually (from start to finish), then that might help me to understand a bit better what it is you need.

Re^4: How to embed a tool in my script
by angel_perl (Initiate) on Feb 14, 2012 at 04:54 UTC

    will the code look like this? after embedding the external script ?

    #!/usr/bin/perl use strict; use warnings; my $dir = '.'; #for embeding the mcsearch percompile version my $mcsearch = '/bin/mcsearch'; #to read the PDB files from the directory opendir DIR, $dir or die "Cannot open directory $dir:$!\n"; my @pdb_files = grep { -f $_ && $_ =~ /\.pdb$/ } readdir DIR; closedir DIR; print "Enter the script file"; $a=<>; open(IN,$a) or die; #giving each file as a input to mcsearch for my $file (@pdb_files) { while(<>) { my $content = `$mcsearch "$dir/$file"`; chomp $content; print "Content of $file is $content\n"; } }
Re^4: How to embed a tool in my script
by angel_perl (Initiate) on Feb 14, 2012 at 13:55 UTC

    http://www.major.iric.ca/MajorLabEn/MC-Tools_files/MC-Annotate.zip here is the tool, i want to embed this tool and give the inputs to the tool, the web version of this tool looks like http://www.major.iric.ca/MC-Search/

    So looking at the web version i was trying to provide two inputs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://953322]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-12-20 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (99 votes), past polls