This is the data file that I am using...#!/usr/bin/perl-Tw use strict; use Text::ParseWords; my $fname = "CommaSample.dat"; my $pretty = 1; my $ADR_Ind = 0; my $PER_Ind = 0; my $EMP_Ind = 0; my @PER_Data; my @major_PER_Data; BARE: { my ($toggle, @data) = (''); open FH, "< $fname" or die "Cannot open datfile: ", $!; while (<FH>) { if (/"PER"/) { $toggle = 1, next if /^"PER"\s*$/; } elsif (/^"EMP"\s*$/) { $toggle = 2, next if /^"EMP"\s*$/; } elsif (/^"ADR"\s*$/) { $toggle = 3, next if /^"ADR"\s*$/; } last if /^"EOS"\s*$/; die "Unknown or missing record tag: Got $_ on line $., datafil +e $fname.$/" if $toggle eq ''; chomp; @data = "ewords('\s+', 0, $_); if ($toggle == 1) { my $Per_Entity = $data[0]; my $Name = $data[1]; my $Color = $data[2]; my $Date = $data[3]; $toggle = 0; @PER_Data = ($Per_Entity, $Name, $Color, $Date); push @major_PER_Data, \@PER_Data; } $toggle = ''; print $/ if $pretty; } print $/; } print "Personal Data...\n"; foreach my $item (@major_PER_Data) { foreach my $subitem (@{$item}) { print $subitem,"\n"; } }
If you run this program you will see that what is happening is it is creating a two dimensional array with double values of A2 PER info being pushed into the array. Ideally I would like A1 PER info and then A2 PER info. If you have any advice that would help, please help me out. peace, LOVE and ((code)) basicdez"PER" "A1" "Denise Johnson" "red,orange,yellow,green,blue,purple" 09/25/2001 "PER" "A2" "Suzanne Summers" "blue,green,yellow,blue-green" 07/24/1995 "EMP" "A1" "X & Y Bank" "Teller" 05/17/1994 "Brian's Point" "WI" 54997 24000 +.00 "EMP" "A2" "Acme Corp" "Computer Programmer" 07/24/1997 "Maxwell" "WI" 53224 + 45000.00 "ADR" "A1" "264 E Dekora St NO 1" "Saukville" "WI" 53080 3 6 "ADR" "A2" "111 E Dogwood St NO 1" "Pittsville" "WA" 46758 4 8 "EOS"
In reply to Help with creating and passing of an array... by basicdez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |