Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entering filename upon run of script... 2

Status
Not open for further replies.

Captainrave

Technical User
Nov 16, 2007
97
0
0
GB
How do i change this script so that it will ask the user what the filename is rather than having to go into the code each time and change the path of the filename?

The code is:

Code:
use strict;
use warnings;

open(OUTPUT,"+>insertorganismname_REPEAT_DISTRIBUTION.csv");

open BIG, 'f:\PhD\Data (D)\Scripts\Repeatdistribution\BOGAR_CDS_LOCATION.xls' or die "$!";
my @big = map {[split/\s+/]} <BIG>;
close BIG;

open SMA, 'f:\PhD\Data (D)\Scripts\Repeatdistribution\BOGAR_REPEAT_LOCATION.csv' or die "$!";
LOOP: while (<SMA>) {
   my ($s,$e) = split(/\,/);
   foreach my $array (@big) {
      if ($s >= $array->[0] && $e <= $array->[1]) {
         calculate($s,$e,$array->[0],$array->[1],$.);
         next LOOP;
      }
   }
}
close SMA;
close OUTPUT;
exit;

sub calculate {
   my ($small_start, $small_end, $big_start, $big_end, $line_num) = @_;
   my $calculation = ( ( ($big_start/$big_end) / ($small_start/$small_end) ) * 100 );
   print OUTPUT "small_start,$small_end,$big_start,$big_end,$calculation,/n";
}


THANKS!!!!!
 
How about:
[tt]
print "Enter filename: ";
$filename=<>;
chomp $filename;
[/tt]
Of course, you'll have to validate the filename entered.
 
When it comes to filename input, I prefer to use windows open dialog box.

Code:
use strict;
use Tk;
my $filename;
open_dialog_box();
print "Filename:$filename\n";

# ###################################################################
# Sub Routine Open Dialog Box
# ###################################################################

sub open_dialog_box{
    my $mainwindow = new MainWindow();
    $mainwindow->withdraw;
    my $types = [
                ["Excel Files", ['.xls']],
                ["CSV Files", ['.csv'] ],
    ];
               
    $filename = $mainwindow ->getOpenFile(-filetypes => $types, -title => "Desired message");
    $filename =~s/\//\\/g; # For windows case
        
 }
# ////////////////////////////////////////////////////////////////////

dmazzini
GSM/UMTS System and Telecomm Consultant

 
just an FYI.

Tk no longer comes with activestate perl 5.10, it has been replaced with Tkx.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Should it be possible to use Tk library in perl 5.10?

It's gonna be a pain to re-write all previous Tk code.

Specially when you have created all fancy stuff with Tk and it took some time to collect all templates...

Cheers

dmazzini
GSM/UMTS System and Telecomm Consultant

 
Sometimes progress is a bitch. I beleive Perl 5.8.x had Tk and Tkx, so there was a period of transition.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top