Hi Sunita.

A few comments on your code.

On Sunday 10 Apr 2011 11:03:51 Sunita Rani Pradhan wrote:
> Hi All
> 
> 
> 
>             I have following simple code :
> 
> 
> 
> ===================
> 
> use warnings;
> 

Add "use strict;".

> 
> 
> sysopen(DATA,"list1.txt",O_RDWR|O_TRUNC);

1. Don't use typeglob filehandles - use lexical ones.

2. Check for a successful return or throw an exception.

3. You need to import the module with the constants.

<CODE>

use Fcntl;

sysopen(my $data_fh, "list1.txt", O_RDWR|O_TRUNC)
        or die "Cannot open - $!";

</CODE>

> 
> 
> 
> @array1=<DATA>;
> 

1. Declare the variable using my.

2. Perhaps you don't want to slurp the entire file.

> 
> 
> 
> 
> foreach $i (@array1){
> 

foreach my $i - and it should not be really called "$i", but rather $line or 
whatever.

> 
> 
>             $i =~ s/d|b/G/ig;
> 

Thsi should be :

        $line =~ s/[db]/G/ig;

>             print DATA $i;
> 
> }
> 
> 
> 
> close DATA;
> 

Seems like you're trying to modify the file in place. The problem is that 
you've read it all and are trying to modify it. The best way would probably be 
to write this from the command line:

perl -pi.bak -e 's/[db]/G/ig' list1.txt # Untested

For more information see:

http://perl-begin.org/tutorials/bad-elements/

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Apple Inc. is Evil - http://www.shlomifish.org/open-source/anti/apple/

*shlomif:* hack, hack, hack ; save ; make ; make test; commit. And start over.

*mrjink:*hack, hack, hack; save; make; swear; fix typos; save; make; make
test; swear some more; hack some more; save; make; make test; cheer; commit.

*meep:* hack, make, test, segfault, oh noes, revert to previous revision

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to