in reply to print the values

Why an array has the name names_hash? You are correct you want hash there, so define hash, not array:

#!/usr/bin/perl use strict; use warnings; my $names; my @name; while(<DATA>) { if(/{(.*)}/) { $names = $1; my %names_hash = qw{NAME 1 AGE 1}; push @name, $names; next if ! exists $names_hash{$names}; print $names; } } print @name; __DATA__ {NAME} {AGE} {SEX} {ADDRESS} {ADDRESS}

Replies are listed 'Best First'.
Re^2: print the values
by Anonymous Monk on Nov 05, 2009 at 09:02 UTC
    Thanks but the $names prints the names which exists in the %names_hash.
    How to print the values which doesnot exists in the %names_hash

      Don't push them into @names if they already exist in %names_hash; add a conditional to the line with the push.

      Change skip condition to the opposite, from

      next if ! exists $names_hash{$names};

      to

      next if exists $names_hash{$names};