Thanks a Lot John... I appreciate your feedback which helps me to improve myself...
Cheers. Sridhar Reddy -----Original Message----- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Saturday, October 15, 2005 11:05 AM To: Perl Beginners Subject: Re: I need help here Sreedhar reddy wrote: > Finally I finished this program like this... You should have these two lines at the beginning of your program: use warnings; use strict; as they will help you find some mistakes and enforce better coding practices. > $inputfile= shift; > $outputfile = shift; > open(FILE1,"<$inputfile"); You should *ALWAYS* verify that the file was opened coreectly. open FILE1, '<', $inputfile or die "Cannot open $inputfile: $!"; > @lines=<FILE1>; There is no good reason to read all the lines into memory as you only need to process one line at a time. > close(FILE1); > open(FILE2,">$outputfile"); You should *ALWAYS* verify that the file was opened coreectly. open FILE2, '>', $outputfile or die "Cannot open $outputfile: $!"; > foreach $line (@lines) { > if($line =~ m/(\d+) ([a-z,A-Z,_,0-9]+)/) /* to write Perl provides the escape sequence \w that represents the character class [a-zA-Z0-9_] so your regular expression could be written /(\d+) ([\w,]+)/ although I didn't see any commas in your data so you probably really want /(\d+) (\w+)/. Also perl doesn't understand /* C style comments */. > this line I have taken lot of time as I know basics in Regular Expressions > */ > { > print FILE2 "$2 $1\n"; > } > } > close(FILE2); > print "\n" John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>