Roy.Amitabh has asked for the wisdom of the Perl Monks concerning the following question:
well i am writing a simple code in which the file contents of .txt file are read into an array. Next the contents of this array are copied into another array . When the contents of the new arrray are modified, the changes are also visible in the old array from which the data was copied from. This new array is then written to the same file. As a result, file data duplication is occuring......
Any help will be appreciated. Thanks.
################### Code Snippet#########################!/usr/bin/perl #************* File Header ****************************** # File Name : nas_add_new_operation_url_logic.cgi # Module : WebInterfaces # Notes : Logic page for writing new Oeration URL along with ac +cess rules # into Rules.txt # History : $Date: 26/01/05 12:34 $ $Revision: 3 $ # All Rights Reserved, Copyright (C) 2004, Hitachi, Ltd. #********************************************************* use CGI qw/:standard/; my @dataWrite; my @dataRead; my $x; undef @dataWrite; undef @dataRead; open (fileReadWrite,"../Rules1.txt"); my @dataRead = <fileReadWrite>; foreach my $value1 (@dataRead) { push @dataWrite , $value1; } push @dataWrite, "Code1\n"; open(fileOUT,">../Rules1.txt") or dienice("Can't open counter.txt: $!" +);; flock(fileOUT,2); seek(fileOUT,0,0); foreach my $value3 (@dataWrite) { print fileOUT $value3; } close(fileOUT); print "Content-type: text/html\n"; print("\n"); ###########################################################
20050201 Janitored by Corion: Added formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: file duplication error
by bart (Canon) on Feb 01, 2005 at 13:16 UTC | |
|
Re: file duplication error
by borisz (Canon) on Feb 01, 2005 at 13:07 UTC | |
|
Re: file duplication error
by holli (Abbot) on Feb 01, 2005 at 13:14 UTC | |
|
Re: file duplication error
by blazar (Canon) on Feb 01, 2005 at 14:01 UTC | |
|
Re: file duplication error
by vek (Prior) on Feb 02, 2005 at 05:24 UTC |