HJ has asked for the wisdom of the Perl Monks concerning the following question:
File1 :
a
File2 :
a|12
a[11]|1
a[11][11]|0
b|2
c|0
Output should hence be File3:
a|12
a[11]|1
a[11][11]|0
open FILE2, "$f2" or die "Could not open file: $! \n"; //Corrected >$f +2 foreach my $var (keys %results) { while( my $attr_line=<FILE2>) { if($attr_line =~ m/(.*?)\[/ ) { if (exists $results{$1}) { print $attr_line; } } } }
but my Output is
a|12
I even tried this and I see no output for this though( logical more sensible than the prev scrpt?
open FILE2, "$f2" or die "Could not open file: $! \n"; foreach my $var (keys %results) { while( my $attr_line=<FILE2>) { if($attr_line =~ /^\$var/ ) { print $attr_line; <strike>print $var."\n"; </strike> } } } close(FILE2);
I understand the output is so because 'if exists' statement is true only for a|12. How do I make sure other any 'a*' be printed out too?
Thanks in advance, HJ
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing for [] in a file
by toolic (Bishop) on Nov 17, 2011 at 17:53 UTC | |
by MidLifeXis (Monsignor) on Nov 17, 2011 at 17:57 UTC | |
by HJ (Novice) on Nov 17, 2011 at 18:56 UTC | |
by HJ (Novice) on Nov 17, 2011 at 18:58 UTC | |
|
Re: Parsing for [] in a file
by JavaFan (Canon) on Nov 17, 2011 at 20:21 UTC | |
|
Re: Parsing for [] in a file
by Not_a_Number (Prior) on Nov 17, 2011 at 18:38 UTC | |
by HJ (Novice) on Nov 17, 2011 at 18:55 UTC | |
|
Re: Parsing for [] in a file
by aaron_baugher (Curate) on Nov 17, 2011 at 19:00 UTC | |
|
Re: Parsing for [] in a file
by Marshall (Canon) on Nov 17, 2011 at 18:53 UTC |