in reply to File Handling problem

Consider use strict; at the top of your code.

my $second_file, my $counter etc are also good ideas.

Try print $second_file just before the open statement. Does it actually contain a filename?

Appears you're opening this file for output only. That's going to clobber whatever you got in there, so the next couple of <FH_SECOND> will have nothing to read as the file is opened for writing only - those lines will actually generate warnings.

Is the file actually "writable"? (Though I'm quite sure that's not your intention). When you do fix your open statement, ensure that the file's permissions are appropriate.

Replies are listed 'Best First'.
Re^2: File Handling problem
by girish_01 (Initiate) on Aug 28, 2011 at 17:47 UTC

    Thanks a lot for your help

    .

    i have modified it now and trying to resolve other problems in my code looking forward for more help

      Depending on the exact format of your text file you may be able to reduce the code to something like this ;
      #!perl use strict; open FH_SECOND,"<",$ARGV[0] or die $!; my @setting = ('Port Speed','Duplex Setting','Switchport Access Mode', +'Spanning Tree Mode'); my $line1 = <FH_SECOND>; if ($line1 =~ /description xxxxxxxxx/){ while (<FH_SECOND>){ my $msg = 'Gigabit '.shift @setting; if(/speed 1000|duplex full|switchport mode access|spanning-tree po +rtfast/){ print $msg." is OK!!!\n"; } else { print $msg." is WRONG!!!\n"; } } } else { print "The Configuration File $ARGV[0] is NOT the RIGHT FILE \n"; } close(FH_SECOND); # test file #description xxxxxxxxx #speed 1000 #duplex full #switchport mode access #spanning-tree portfast
      poj
        That seems really charming i am gonna definitely try this approach... Thanks..