0

I am writing a perl script and I am trying to read two diff files..

first file

open my $data1, "<", "/tmp/CSI_to_PROD_111111_20141004_225038/att_application.properties"
    or die "Unable to open prod file";

while (<$data1>) {
    chomp();
    foreach $line (<$data1>) {
        next if ( $line =~ /(^\s*#|^$)/ );
        chomp($line);
        foreach $token (@csitokens) {
            if ( $line =~ /$token=/ ) {
                my ( $tok, @val ) = split( /=/, $line, 2 );
                print "@val\n";
            }
        }
    }
}
close($data1) or warn "Not able to close fil: \n";

second file

open my $data2, "<", "/opt/app/d1ebl1m5/dv02/cingbt02/J2EEServer/config/AMSS/application/properties/att_application.properties_try"
    or die "unable to open file: $!";

while (<$data2>) {
    foreach $line1 (<$data2>) {
        print "$line1";
    }
}
close($data2) or warn "Not able to close fil: \n";

The loop for first file is working fine and displaying the output but the second loop doesnt display anything..

1
  • 1
    while reads a line at time from the file. Foreach does the same. So you're jumping the tracks. Commented Oct 5, 2014 at 8:54

1 Answer 1

3

There are too many while and foreach loops. You need only one of them:

open my $data2, "<" , "/opt/app/d1ebl1m5/dv02/cingbt02/J2EEServer/config/AMSS/application/properties/att_application.properties_try"  
   or die "unable to open file: $!";

while( my $line1 = <$data2> ) {
    print "$line1";
} 
close($data2);

The same is applicable for the first loop. Yo have also an error on your die-check after the file open

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.