List Info

Thread: Newbie question: Where do I place the "print results to file statement" in Perl?




Newbie question: Where do I place the "print results to file statement" in Perl?
country flaguser name
United States
2007-10-17 09:17:17

Hello all, I am teaching myself some programming.
I know to get the filename via STDIN. My question: I want the
contents processed via a small subroutine.

Where do I place the open file and print staements?

Here is the code:
#usr/bin/local;
use strict;
use warnings;

print "PLEASE ENTER THE FILENAME OF THE YOUR SEQUENCE:=";
chomp($seq_filename=<STDIN>);
#
open(PROTFILE,$seq_filename) or die "unable to open the file";
seq=<PROTFILE>;
close PROTFILE;
#
#
foreach $newline (seq) {
#
## discard blank newline
if ($newline =~ /^s*$/) {
next;

## discard comment newline
} elsif($newline =~ /^s*/) {
next;

# discard fasta header newline
} elsif($newline =~ /^>/) {
next;

## keep newline, add to sequence string
} else {
$sequence1 .= $newline;
}

}

# remove non-sequence data (in this case, whitespace) from $sequence
string
#Remove whitespace
$newline =~ s/s//g;
seq=split("&quot;,$newline); #splits string into an array

print " nThe original file is:n$sequence1 n";

exit;

__._,_.___
.

__,_._,___
Re: Newbie question: Where do I place the "print results to file statement" in Perl?
country flaguser name
United States
2007-10-17 11:08:08

Hello all, now my code says: print on closed file handle at line in yourcode.pl
any ideas why this is happening?

mj4chem < mj4chem%40yahoo.com">mj4chemyahoo.com> wrote:
Hello all, I am teaching myself some programming.
I know to get the filename via STDIN. My question: I want the
contents processed via a small subroutine.

Where do I place the open file and print staements?

Here is the code:
#usr/bin/local;
use strict;
use warnings;

print "PLEASE ENTER THE FILENAME OF THE YOUR SEQUENCE:=";
chomp($seq_filename=&lt;STDIN>);
#
open(PROTFILE,$seq_filename) or die "unable to open the file";
seq=<PROTFILE>;
close PROTFILE;
#
#
foreach $newline (seq) {
#
## discard blank newline
if ($newline =~ /^s*$/) {
next;

## discard comment newline
} elsif($newline =~ /^s*/) {
next;

# discard fasta header newline
} elsif($newline =~ /^>/) {
next;

## keep newline, add to sequence string
} else {
$sequence1 .= $newline;
}

}

# remove non-sequence data (in this case, whitespace) from $sequence
string
#Remove whitespace
$newline =~ s/s//g;
seq=split("&quot;,$newline); #splits string into an array

print " nThe original file is:n$sequence1 n";

exit;

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )