I am having problems with creating this two dimensional array and need to create it for several different lines of this data file. If any of you could please look at this code and help me out, I would be a smiling monk...
#!/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 = &quotewords('\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"; } }
This is the data file that I am using...
"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"
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

In reply to Help with creating and passing of an array... by basicdez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.