in reply to Building a dynamic array or some other method?

If what I think you are trying to do is correct, it can't be done because the fields following the username are also different, so there is no way to combine lines.

However, here's code to build a nested structure (with common parents) from the sample data you provided, and also a way to print that nested structure in indented form.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11159049 use warnings; use Text::CSV; $SIG{__WARN__} = sub { die @_ }; my %database; my $csv = Text::CSV->new; my @headers = $csv->getline( *DATA )->@*; while( my $fields = $csv->getline( *DATA ) ) { my $ref = \%database; $ref = $ref->{$_} //= {} for @$fields; } #use Data::Dump 'dd'; dd \%database; print "\n\n------ Indented Form ----------\n\n", show( \%database ); sub show { my $db = shift; my $answer = ''; for my $key ( sort keys %$db ) { $answer .= join '', "$key\n", show($db->{$key}) =~ s/^(?=.)/ /gm +r; } return $answer; } __DATA__ File Server,Access Path,Current Permissions,Logon Name,Inherited From +Folders,Flags,User/Group,Classification Results,Classification Result +s by Category (Including Nested),Total Hit Count 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,FMRWX,@FOO NOW Onsite Support,\Common,This folder only, +Pathway12.My.Corp.com\@FOO NOW Onsite Support,IRS Data (1/1),PII (1), +1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,FMRWX,Administrators,\Common,This folder only,10.15.106 +.71\Administrators,IRS Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,FMRWX,Creator Owner,\Common,This folder only,Abstract\C +reator Owner,IRS Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,FMRWX,FP NOW BMG FSE NTFS Admins,\Common,This folder on +ly,Pathway12.My.Corp.com\FP NOW BMG FSE NTFS Admins,IRS Data (1/1),PI +I (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,FMRWX,ClusterSvcDIR,\Common,This folder only,Pathway12. +My.Corp.com\ClusterSvcDIR,IRS Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,FMRWX,SYSTEM,\Common,This folder only,Abstract\SYSTEM,I +RS Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,FMRWX,MiJim,<not inherited>,This folder only,"Pathway12 +.My.Corp.com\Michaels, Jim@My",IRS Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,MRWX,@FP DIR BMG,\Common,This folder only,Pathway12.My. +Corp.com\@FP DIR BMG,IRS Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,RX,&CDAdmin,\Common,This folder only,Pathway12.My.Corp. +com\&CDAdmin,IRS Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,RX,@FOO DSMS Admins,\Common,This folder only,Pathway12. +My.Corp.com\@FOO DSMS Admins,IRS Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,RX,FOO BMG FS Support,\Common,This folder only,Pathway1 +2.My.Corp.com\FOO BMG FS Support,IRS Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,RX,DPeterso,\Common,This folder only,"Pathway12.My.Corp +.com\Peterson, Dan@My",IRS Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Rene +wal FINAL.pdf,RX,FP BMG IMG Read Access,\Common,This folder only,Path +way12.My.Corp.com\FP BMG IMG Read Access,IRS Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/My-B8245.pdf,FMRWX,@FOO NOW Onsite Support,\Com +mon,This folder only,Pathway12.My.Corp.com\@FOO NOW Onsite Support,IR +S Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/My-B8245.pdf,FMRWX,Administrators,\Common,This +folder only,10.15.106.71\Administrators,IRS Data (1/1),PII (1),1 10.15.106.71,/Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subs +cription Renewal Docs/My-B8245.pdf,FMRWX,Creator Owner,\Common,This f +older only,Abstract\Creator Owner,IRS Data (1/1),PII (1),1

Outputs:

------ Indented Form ---------- 10.15.106.71 /Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subscription R +enewal Docs/Axidome Quote My Corp 2020211 KnowBe4 2-yr Renewal FINAL. +pdf FMRWX @FOO NOW Onsite Support \Common This folder only Pathway12.My.Corp.com\@FOO NOW Onsite Support IRS Data (1/1) PII (1) 1 Administrators \Common This folder only 10.15.106.71\Administrators IRS Data (1/1) PII (1) 1 ClusterSvcDIR \Common This folder only Pathway12.My.Corp.com\ClusterSvcDIR IRS Data (1/1) PII (1) 1 Creator Owner \Common This folder only Abstract\Creator Owner IRS Data (1/1) PII (1) 1 FP NOW BMG FSE NTFS Admins \Common This folder only Pathway12.My.Corp.com\FP NOW BMG FSE NTFS Admins IRS Data (1/1) PII (1) 1 MiJim <not inherited> This folder only Pathway12.My.Corp.com\Michaels, Jim@My IRS Data (1/1) PII (1) 1 SYSTEM \Common This folder only Abstract\SYSTEM IRS Data (1/1) PII (1) 1 MRWX @FP DIR BMG \Common This folder only Pathway12.My.Corp.com\@FP DIR BMG IRS Data (1/1) PII (1) 1 RX &CDAdmin \Common This folder only Pathway12.My.Corp.com\&CDAdmin IRS Data (1/1) PII (1) 1 @FOO DSMS Admins \Common This folder only Pathway12.My.Corp.com\@FOO DSMS Admins IRS Data (1/1) PII (1) 1 DPeterso \Common This folder only Pathway12.My.Corp.com\Peterson, Dan@My IRS Data (1/1) PII (1) 1 FOO BMG FS Support \Common This folder only Pathway12.My.Corp.com\FOO BMG FS Support IRS Data (1/1) PII (1) 1 FP BMG IMG Read Access \Common This folder only Pathway12.My.Corp.com\FP BMG IMG Read Access IRS Data (1/1) PII (1) 1 /Common/Awareness and Training/KnowBe4/2020- KnowBe4 Subscription R +enewal Docs/My-B8245.pdf FMRWX @FOO NOW Onsite Support \Common This folder only Pathway12.My.Corp.com\@FOO NOW Onsite Support IRS Data (1/1) PII (1) 1 Administrators \Common This folder only 10.15.106.71\Administrators IRS Data (1/1) PII (1) 1 Creator Owner \Common This folder only Abstract\Creator Owner IRS Data (1/1) PII (1) 1

Replies are listed 'Best First'.
Re^2: Building a dynamic array or some other method?
by CAdood (Acolyte) on Apr 23, 2024 at 20:50 UTC
    You're right that there are some differences after the unique names. I think the most likely part to change is also the more descriptive name of the user mentioned earlier, and can be dismissed. The types of data found, and the hit counts stay the same for each file, and are important to keep.

    I have a question about notation or elements found within this line, which I'm unfamiliar with.
    I'm unsure what they'd be called to even look them up
    my @headers = $csv->getline( *DATA )->@*;

    What is this called? *DATA? In C (ancient class I took) it looks like a pointer, but what is DATA? It's not defined previously.

    And what does ->@* do after that, as I see the assignment going left into @headers? Is that an array wildcard?
      *DATA is a file handle, pointing to the part of the source file after the __DATA__ mark.

      The ->@* is a post-dereference, it's an alternative way of writing

      my @headers = @{ $csv->getline( *DATA ) };

      The getline method returns an array reference, by dereferencing it we get an array which we (shallow) copy into @headers.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        I'm coming back to this pretty late.

        I wanted to say thank you for explaining those items. I'll look further into the __DATA__ mark thing. I didn't understand that, but at least there's enough unique characters to search for it within the perl documentation.