Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Parsing Sequence Records

by farang (Chaplain)
on May 08, 2014 at 01:07 UTC ( #1085399=note: print w/ replies, xml ) Need Help??


in reply to Parsing Sequence Records

I'm guessing that the reason for the open failure is that the correct path should be something like this.

/Users/lomSpace/Desktop/Pipelines/
I'll assume that below. The advice other monks have given is excellent if you are using the traditional open function, but in the spirit of "there is more than one way to do it" here is another approach.

The module Path::Tiny is great, and I tend to look to it first when opening files. After installing it, the following could be done.

... use Path::Tiny; my $in = path('/Users/lomSpace/Desktop/Pipelines/fungi.1.aa.hypothetic +al.faa')->slurp; my $out = path('/Users/lomSpace/Desktop/Pipelines/fungi.1.aa.hypotheti +cal50.faa')->openw; my @chunks = split(/>/, $in); ...
The slurp method on the input file path eliminates the need for local $/ = undef; in your code and the readline, that is the angle bracket pair inside the split. It does mean that $in is no longer a filehandle while $out still is so it might be worth renaming one of the variables to make that clear.

Path::Tiny also croaks automatically on failure with good error messages. One small downside to it may be that it is not in the core and must be installed from CPAN. Besides opening files, Path::Tiny performs other useful functions as well.


Comment on Re: Parsing Sequence Records
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1085399]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2014-12-28 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls