Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: hm strange loop for me..

by pjf (Curate)
on Jan 24, 2002 at 09:30 UTC ( #141151=note: print w/replies, xml ) Need Help??

in reply to hm strange loop for me..

This shouldn't make a difference to how your loop works, but it does make it easier for humans to read. You can replace:

$/ = "\/\/\n";


$/ = "//\n";

Besides from that, your code looks fine, and works perfectly for the sample file you have provided. I suspect what might be happening is somewhere in your file you have the sequence "//\n" at say the end of a line inside a record, when you only really want to catch "//" appearing on a line by itself. You might try $/ = "\n//\n" to force this.

Be aware that you may end up reading an extra "empty" record at the end of your file if the last thing in your file is the input record separator.


Paul Fenwick
Perl Training Australia

Replies are listed 'Best First'.
Re: Re: hm strange loop for me..
by agustina_s (Sexton) on Jan 24, 2002 at 10:52 UTC
    Hi... thanks for the answer.. Actually the problem is the are a few blank lines at the end of the input file.. So after the last // there are a few blank lines which is impossible to be deleted for every case. eg:
    DR Pfam; PF00087; toxin; 1. DR PRINTS; PR00282; CYTOTOXIN. DR ProDom; PD000206; Snake_toxin; 1. DR PROSITE; PS00272; SNAKE_TOXIN; 1. KW Venom; Cytotoxin; Cardiotoxin; Multigene family; 3D-structure; Si +gnal. FT SIGNAL 1 21 FT CHAIN 22 81 CYTOTOXIN 2. FT DISULFID 24 42 // RA Jeyaseelan K., Armugam A., Lachumanan R., Tan C.H., Tan N.H.; RT "Six isoforms of cardiotoxin in malayan spitting cobra (Naja naja RT sputatrix) venom: cloning and characterization of cDNAs."; RL Biochim. Biophys. Acta 1380:209-222(1998). RN [6] RP SEQUENCE FROM N.A. RC SPECIES=N.n.kaouthia; TISSUE=Venom gland; RA Li K.J., Wei J.F., Jin Y., Lu Q.M., Xiong Y.L., Wang W.Y.; RT "Molecular cloning and sequence analysis of cDNA of cytotoxin ana +log RT of Naja kaouthia."; // ##there are a few blank lines here
    When I eliminated the blank line... things goes just as expected. Is there something to handle this kind of situation? Thanks a lot..
      It's easy enough to check for a blank record:

      $/ = "\n//\n"; # Or whatever is appropriate. while (<>) { chomp; # Removes the field separator. next if /^\s*$/; # Skip "space-only" records. # Do stuff here. }

      This means if there's a blank record at the end (or in the middle, for that matter) it will get skipped instead of processed.


      Paul Fenwick
      Perl Training Australia

        Thanks... it works..

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://141151]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2018-06-24 03:47 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.