Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: How to embed a tool in my script

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

in reply to How to embed a tool in my script

If you just want to pass these files one by one to your "tool", and you don't care about any output, then you can use system

However, if your "tool" produces output that you want to capture and process, then you'll probably want to use backticks, eg:

$output_from_my_precompiled_tool = `/path/to/my/tool $file`;

Replies are listed 'Best First'.
Re^2: How to embed a tool in my script
by angel_perl (Initiate) on Feb 12, 2012 at 13:43 UTC

    Thanks @Darren, will the code look like this? and also i want the output to be printed for respective files as different files in different directory

    my $dir = '/path/to/dir'; # read only pd files: opendir DIR, $dir or die "read dir $dir - $!"; my @pdb_files = grep /\.pdb/, readdir DIR; closedir DIR; foreach my $file (@pdb_files) { open( FH,"$dir\\$file") while(<FH>) { $output_from_my_precompiled_tool = `/path/to/my/tool $file`; } close(FH); }
      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 #!/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 Content of 1.pdb is some text Content of 2.pdb is some more text
      That should be enough to get you going?

        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?

        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"; } } 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

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://953290]
[Corion]: ambrus: Well, for mathematical notation, I find blackboard much more convenient than a computer. But when inserting text or moving text around, the computer wins obviously
[ambrus]: But either of these is a big problem in practice, so I'd need to spend like thirty years of my life to solve (a) and five more years to solve (b)
[ambrus]: Corion: yes, CURRENTLY the blackboard is more convenient
[ambrus]: and it's not like I want to ban blackboards anyway
[ambrus]: you already have blackboards and a canvas for projector or overhead transparencies (or positive film slide projector, not used for maths) canvas in the same lecture halls today, and switch in a few minutes between presentations,
[ambrus]: they're only difficult to use together.
[ambrus]: overhead transparencies are a nice convenience by the way that mix the two slides, because you can write them in advance and edit them during the presentation easily. but they're not very much in fasion these days.
[ambrus]: you can even print them.
[Discipulus]: ambrus i'm trying out MremoteNG which wrap putty and rdp and many other things..
[Corion]: ambrus: Yes, ideally you would have the ease of overhead projection transparencies and pens drawing on them, combined with the computer generated slide text...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2017-09-26 10:23 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (293 votes). Check out past polls.