in reply to Is it possible to get the inverse of a square matrix to be input as a text file using STDIN?
Hi, supriyoch_2008,
- Please you may use strict in your script.
- Replace these lines in inv2.pl:
with these:## Input the matrix text file: print "\n\n Please type the filename(.txt) i.e. d1.txt: "; $DNAfilename = <STDIN>; chomp $DNAfilename; ## To remove white space: $DNAfilename=~ s/\s//gis; # open the file, or exit unless ( open(DNAFILE, $DNAfilename) ) { print "Cannot open file \"$DNAfilename\"\n\n"; exit; } # Line 10 @a = <DNAFILE>; @m2=@a;my @m2; ## Input the matrix text file: print "\n\n Please type the filename(.txt) i.e. d1.txt: "; chomp( my $filename = <STDIN> ); open my $fh, '<', $filename or die "can't open file $!"; while (<$fh>) { push @m2, [ split /,/, $_ ]; } close $fh or die "can't close file: $!";
Ofcourse, your script(s) can be improved upon, but these should give you what you want to start with.
Hope it helps.
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Is it possible to get the inverse of a square matrix to be input as a text file using STDIN?
by supriyoch_2008 (Monk) on Nov 09, 2012 at 04:25 UTC |
In Section
Seekers of Perl Wisdom