CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Stefanik] Print Hash Keys: Edit Log



7stud
Enthusiast

Jan 3, 2013, 1:50 PM


Views: 1370
Re: [Stefanik] Print Hash Keys

...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:


Code
 

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:


Code
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)


Edit Log:
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 1:52 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 1:52 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 1:53 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 1:53 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 1:54 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 1:56 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 1:57 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 1:59 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 1:59 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 2:00 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 2:07 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 2:08 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 2:09 PM
Post edited by 7stud (Enthusiast) on Jan 3, 2013, 2:11 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives