CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
help with filehandle

 



alikto
Novice


Oct 21, 2008, 5:48 AM

Post #1 of 6 (1243 views)
help with filehandle Can't Post

Hello!
I'm trying to make my start to the Perl world with the help of a O'Reilly Book (Beginning Perl for Bioinformatics). So I'm at the (early) point of getting to know with filehandles and the example of the book (4-5 for those who read the book) is quite simple but cannot work on my MacBook for some reason...

Here is the script which can also be downloaded from the http://examples.oreilly.com/begperlbio/begperlbio_all.zip:

#!usr/bin/perl -w
#reading protein sequence data from a file

#the filename of the file containing the protein sequence data
$proteinfilename= 'NM_021964fragment.pep';


#first we have to open the file and associatea filename with it.
#we choose the file name PROTEIN FILE for readibility
open (PROTEINFILE, $proteinfilename);

#now we do the actual reading of the protein sequence data from the file by using the
#angle brackets < and > to get the input from the filehandle. we store the data into our variable
# $protein
$protein = <PROTEINFILE>;

#now that we've got our data we can close the file
close PROTEINFILE;

#print the protein onto screen
print "Here is the protein:\n\n";
print $protein;

exit;

I'm suppose to have the v5.8.8 built for darwin-thread-multi-2level version of perl.
the terminal gives the results shown at the attached picture.
can somenone help me please?

Crazy
Attachments: terminal.png (44.7 KB)


KevinR
Veteran


Oct 21, 2008, 1:28 PM

Post #2 of 6 (1239 views)
Re: [alikto] help with filehandle [In reply to] Can't Post

try this:

open (PROTEINFILE, $proteinfilename) or die "$!";

rerun the code and see what message "die" returns.
-------------------------------------------------


alikto
Novice


Oct 21, 2008, 1:40 PM

Post #3 of 6 (1238 views)
Re: [KevinR] help with filehandle [In reply to] Can't Post

nope!
didn't work
"No such file or directory"

Frown


KevinR
Veteran


Oct 21, 2008, 1:52 PM

Post #4 of 6 (1237 views)
Re: [alikto] help with filehandle [In reply to] Can't Post

Thats the point. perl can't find the file thus it can not open the file. Maybe you need to use a path to the file:


Code
$proteinfilename= 'path/to/NM_021964fragment.pep';



When you use just the filename to open a file you have to be in the directory where the file is, otherwise you have to add the path to the file when trying to open it.
-------------------------------------------------


alikto
Novice


Oct 22, 2008, 5:57 AM

Post #5 of 6 (1215 views)
Re: [KevinR] help with filehandle [In reply to] Can't Post

YES!!!
That's it! So simple! Thank you so much!
I still wonder... Why it's not working while being in the same folder with the script?
...
anyway,
thanks a lot!


KevinR
Veteran


Nov 17, 2008, 10:06 AM

Post #6 of 6 (1160 views)
Re: [alikto] help with filehandle [In reply to] Can't Post

I don't know why it does not work if the file and script are in the same folder. As far as I know it should. Sorry for the late reply.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives