Hi all, i have a question hoping you can answer me: I have a tk script with 2 Buttons and a Scrolled text windows: 1. Button ("OPEN") 2. Button ("Get Statistics") When i push the "Open" button i choose a .txt file and then the content is printed out in the Scrolled windows. Up to now no problem! The difficulty is this: When i push the "Get Statistic Button" it should call an external Script (that works fine alone) but i wish it worked on the opened file. (opened before with the "Open" button. Can you help me, please ? Here is the tk code and the script i would like to integrate into. The Tk script:
#The Open button: $mw-> Button (-text =>'Open',-command=>\open_file)->place(-x=>240, -y= +>35); sub open_file {my $open = $mw->getOpenFile( -filetypes => $types_OPEN, -defaultextension => '.sff'); $te->Load( "$open");} #The Get Statistic button: $mw-> Button (-text =>'Get Statistics', -command =>\&get_statistics); sub get_statistics {-------Here i need your help----}; # The Scrolled windows: $te = $mw->Scrolled( q/TextUndo/, -scrollbars => 'se', -background.... +.......);
The External (get_statistic.pl) Script (it works fine like: "perl get_statistic.pl filename.txt")
# The get_statistic.pl script: use Statistics::Descriptive; my $stat = Statistics::Descriptive::Full->new(); my (%distrib); my @bins = qw/18 19 20 21 22 23 24 25 26 27 28/; my $fastaFile = shift; open (FASTA, "<$fastaFile"); $/ = ">"; my $junkFirstOne = <FASTA>; while (<FASTA>) { chomp; my ($def,@seqlines) = split /\n/, $_; my $seq = join '', @seqlines; $stat->add_data(length($seq));} %distrib = $stat->frequency_distribution(\@bins); print "Total reads:\t" . $stat->count() . "\n"; print "Total nt:\t" . $stat->sum() . "\n"; print "Mean length:\t" . $stat->mean() . "\n"; print "Median length:\t" . $stat->median() . "\n"; print "Mode length:\t" . $stat->mode() . "\n"; print "Max length:\t" . $stat->max() . "\n"; print "Min length:\t" . $stat->min() . "\n"; print "Length\t# Seqs\n"; foreach (sort {$a <=> $b} keys %distrib) { print "$_\t$distrib{$_}\n"; }
Now i would like to run this script on the $open file and see the result in a dialog box windows. Please help !!! Thank you very much as always.

In reply to Perl tk - How to integrate external scripts by Giorgio C

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.