Hi Charles,

This is the code which I have written to finish my small task...


$inputfile= shift;
$outputfile = shift;
        open(FILE1,"<$inputfile");
        @lines=<FILE1>;
        close(FILE1);
        open(FILE2,">$outputfile");

foreach $line (@lines) {
        if($line =~ m/(\d+) ([a-z,A-Z,_,0-9]+)/)             /*  to write
this line I have taken lot of time as I know basics in Regular Expressions
*/
        {
                print FILE2 "$2 $1\n";
        }
}
close(FILE2);
print "\n"



In attached mail you can find some comments from john also. If you have any
comments, pls let me know...    



-----Original Message-----
From: Charles K. Clarkson [mailto:[EMAIL PROTECTED] 
Sent: Saturday, October 15, 2005 4:27 PM
To: 'Perl Beginners'
Subject: RE: I need help here

Sreedhar reddy <mailto:[EMAIL PROTECTED]> wrote:

: Charles <> wrote:

: :     A working perl script should not be your only concern
: : when just learning the language. It is equally, no, more
: : important that you learn how to write your code well. Show
: : us your entire working script. I think you are using some
: : very poor techniques, but we need to see everything to
: : see just what help you need.
:
:       Definately I need the help of well experienced people like
: you moving forward..
:
: Can you suggest me some good links to learn PERL in depth....

    You don't need another link or source. Show us the complete
code for your solution and HUMAN BEINGS from across the world will
review it and tell you where you need improvement. No web site can
do that for you.

    Come on, cough up the code. It will only hurt a little.


Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


--- Begin Message ---
Title: RE: I need help here

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>



--- End Message ---
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Reply via email to