On Dec 18, 2007 1:48 PM, minky arora <[EMAIL PROTECTED]> wrote: > !/usr/bin/perl
I think you meant for that to begin with #!, not to nitpick.... > foreach my $line(<FILE>){ That should run your loop once for each line in the file. But I prefer this line: while (my $line = <FILE>) { That should also run the loop once for each line in the file. But because it uses <FILE> in scalar context, it will read one line, run the loop, then go back to read another line. Using <FILE> in list context (as foreach does) means to read the entire file at once, but there's no need to bring what may be a large file into memory if you'll be processing it a line at a time. (To be sure, perl may optimize this code; but it's safer in general to use while.) > $fname=substr($line,0,10); > $lname=substr($line,10,15); > $address=substr($line,16,25); > > $lline=substr($line,59,13); That doesn't add up right, unless you're not using substr() correctly. http://perldoc.perl.org/functions/substr.html For the kind of thing you're looking to do, unless you really do want overlapping fields, I think you want unpack(). http://perldoc.perl.org/functions/unpack.html http://perldoc.perl.org/functions/pack.html > Now each record as I calculated is of a fixed lenght of 75 chars.I > need some idea as to how to run the Loop to print all such > records.Right now I am only able to print the first record, Perhaps your data file isn't organized in lines? The readline operator (angle brackets around a filename, like <FILE>) reads a text file a line at a time, but it's not usually appropriate for non-text files. You probably want the read() operator. http://perldoc.perl.org/functions/read.html Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/