Hi perlmonks.... I want to ask concerning a flat file database whose records are separated by "//\n" ( double slash and new line). I have a very huge database (input.db) looks partly like:
COMMERCIAL SUPPLIERS SEQUENCE /toxin_start="19-94" /translation="MKFFLMCLIIFPIMGVLGKKNGYPL + CWGACYCFGLEDDKPIGPMKDITKKYCDVQIIPS" AA ALIGNMENT full-length{%scorpProtein}, sodium-family{%scorpNA}, putative-group1{% +Nag01}, putative-group1c{%Nag01c} ORIGIN 1 acaaaataaa gtgaacttct gaaatcagca cgataaaaag aaacgaaaat gaaatttttc // COMMERCIAL SUPPLIERS SEQUENCE /toxin_start="19-94" /fragment_start="?" CWGACYCFGLEDDKPIGPMKDITKKYCDVQIIPS" AA ALIGNMENT full-length{%scorpProtein}, sodium-family{%scorpNA}, putative-group1{% +Nag01}, putative-group1c{%Nag01c} ORIGIN 1 aaaataaagt gaacttctga aatcagcacg ataaaaagaa acgaaaatga aattt +ttctt 61 aatgtgtctt atcatcttcc caattatggg agtgcttggc aaaaagaacg gatat +cctct //
I'm going to read the input, make some changes and then write it back to the output files. I am a little bit confused with the input separator since at first I have set it to //\n and then for each records I want to examine it line by line.

I have tried to put a counter in my code but there the program never stop running.

I compile the prog using: perl prog.pl input.db result #!/usr/bin/perl my $input = $ARGV[0]; my $output = ">" . $ARGV[1]; my $counter=1; open(INPUT, $input) or die "Can't open $input."; open(OUTPUT, $output) or die "Can't open $output."; $/="\/\/\n"; # Use shorthand for reading file. while (<>) { print OUTPUT $_; print $counter; $counter++; } print "Success\n"; close (INPUT); close (OUTPUT);
I have tried to do
> while(<INPUT>)
instead of just while(<>) but it only print the counter once. Is there something wrong with the code? And if I want to read/modify each line in the record where should I set the $\ back to \n? Thank you in advanced.

Sincerely


In reply to about separator by agustina_s

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.