User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 423,562 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,639 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser: Programming Forums
Views: 1585 | Replies: 14
Reply
Join Date: Oct 2007
Posts: 41
Reputation: mank is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
mank mank is offline Offline
Light Poster

Re: print, number of character from a file

  #11  
Mar 26th, 2008
thanks
this is what my current code looks like.
But I still cant make it stop once it gets a (">") and then output the result
and then again start concatenating till it finds the next ('>') or stop if end of file is reached

#!/usr/bin/perl -w

use strict;
use warnings;

	my ($fileName, $firstSequence, $lastSequence) = @ARGV;

	open (IN, "<$fileName") || die "Can't open $fileName";

     
	my $line;
        my @line=();
OUTER2:	while (my $l = <IN>){
        if($l eq ""){last EXIT2;}
	if ($l =~ />/) {  
             print "$l\n";
	       next;
	    }

	chomp($l);
	$line .= $l;
	}
	@line = split(//, $line);  
	print @line[$firstSequence-1..$lastSequence-1];
        last OUTER2;
EXIT2:	close(IN);
Reply With Quote  
Join Date: Jan 2006
Posts: 221
Reputation: katharnakh is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 20
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: print, number of character from a file

  #12  
Mar 26th, 2008
Hello Mank,
I think you have not understood what last LABEL in perl does. Why are you using last in your code? I dont understand this in your code
...
last OUTER2; # why?

Probably you have to read documentation before you start doing it again. Type this in your command prompt and go through it, perldoc -f last.

katharnakh.
Last edited by katharnakh : Mar 26th, 2008 at 6:17 am.
challenge the limits
Reply With Quote  
Join Date: Oct 2007
Posts: 41
Reputation: mank is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
mank mank is offline Offline
Light Poster

Re: print, number of character from a file

  #13  
Mar 26th, 2008
yes
I dont want to use that label there, its just going to re-read my file,
I dont want to do that, I just want to make sure @line has all the sequence after line containng ">" to line containing ">"

so its like

>label1
data1.....
data2......
data3......
>label2
data1....
data2...
data3...

so I want
>label1
data1.....data2.....data3.....
>label2
data1.....data2.....data3.....

then @line[$seq1..$seq2] wiill contain all data from data2 to data3 for each sequence
Reply With Quote  
Join Date: Jan 2006
Posts: 221
Reputation: katharnakh is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 20
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: print, number of character from a file

  #14  
Mar 26th, 2008
then you got to do within your while loop itself. Because, within the while loop itself you will read entire file.
So while reading the file itself you will you print whatever you want. If you want to re read the file, then you must either seek() the start of the file or close the file and reopen and read the file.

Hope you understand.
katharnakh.
Last edited by katharnakh : Mar 26th, 2008 at 8:00 am.
challenge the limits
Reply With Quote  
Join Date: Mar 2006
Posts: 618
Reputation: KevinADC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 33
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Master Poster

Re: print, number of character from a file

  #15  
Mar 26th, 2008
Mank,

learn how to use hashes, this could be done pretty easy using a hash.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Perl Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Perl Forum

All times are GMT -4. The time now is 6:37 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC