in reply to Re^3: Print Color Format
in thread Print Color Format

Good webpage..never seen it before thanks. I should of posted more code including the "split" section.

foreach my $Name2 (@lines) { my @field = split(':',$Name2); if ($field[1] =~ /(?<![\w-])$Name(?![\w-])/i) { my $format = " %-4s %-11s %-13s %-10s %-7s %0s\n"; print color 'bold green'; printf ($format, $field[0], $field[1], $field[2], $field[3], $field[4] +, $field[5]); } }

Complete Code

Replies are listed 'Best First'.
Re^5: Print Color Format
by toolic (Bishop) on Jun 16, 2015 at 18:24 UTC
    This is incomplete because I don't know what the @lines array contains (or $Name). I suspect some of your lines have fewer than 6 fields. See also the basic debugging checklist

      @lines is data retrieved from the data file and Name is the query used to pull from the data file...complete code below:

      open(MYINPUTFILE, "namedata.txt"); my @lines = <MYINPUTFILE>; close (MYINPUTFILE); my $Name = <STDIN>; $Name = <STDIN> until defined $Name; chomp($Name); foreach my $Name2 (@lines) { my @field = split(':',$Name2); if ($field[1] =~ /(?<![\w-])$Name(?![\w-])/i) { my $format = " %-4s %-11s %-13s %-10s %-7s %0s\n"; print color 'bold green'; printf ($format, $field[0], $field[1], $field[2], $field[3], $field[4] +, $field[5]); } } __DATA__ ID:Name:Last:Birthday:Phone:Email:Website