
7stud
Enthusiast
Jan 3, 2013, 1:50 PM
Post #7 of 10
(3015 views)
|
Re: [Stefanik] Print Hash Keys
[In reply to]
|
Can't Post
|
|
...because you only assign a new value to @Parse_Arr when there is no match, yet you print every time through the loop. So if there is a match, you don't assign a new value to @Parse_Arr, and so @ParseArr has the old value, i.e. from the previous line, which you then print. You want something like this:
next if $FirstPar =~ /Mystring1|Mystring2/ ; print @Parse_Arr; That way the print statement is skipped if there is a match. By the way, your variable names are terrible. See how much clearer this code is:
use strict; use warnings; use 5.012; my $fname = 'data.txt'; open my $INFILE, "<", $fname or die "Couldn't open $fname: $!"; while (my $line = <$INFILE>){ next if $line =~ /string1|string2/; print $line; } close $INFILE; Generally, you don't capitalize your variable names. Some people capitalize variable names that contain references to file handles, so that they look similar to bareword filehandles(which you shouldn't be using).
(This post was edited by 7stud on Jan 3, 2013, 2:11 PM)
|