Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

OK, but I am still struggling a little bit - what is the actual contents of @Colum_A?:

use Data::Dumper qw/Dumper/; my $xls_path = "c:/path_to_xls.xlsx"; my $xls = $excel->Workbooks->Open("$xls_path"); foreach my $sheet ( in $xls->Worksheets ) { $San ={}; $San->{name} = $sheet->Name, $/; my $San_data = $xls->Worksheets("$San->{name}"); my @Colum_A = $San_data->UsedRange->{'Value'}; ## what datastructure are we working with? print "SAN : $San->{name}\n"; print Dumper \@Colum_A; }

If it is a long array like you say then why not take a simple approach?:

use strict; use warnings; use Data::Dumper qw/Dumper/; #my $xls_path = "c:/path_to_xls.xlsx"; #my $xls = $excel->Workbooks->Open("$xls_path"); ## just for testing my $xls = [qw/san1 san2/]; my $data; #foreach my $sheet ( $xls->Worksheets ){ for my $sheet ( @$xls ){ print "Data in SAN : $sheet\n"; ## store each san as a hashref my $San ={}; #$San->{name} = $sheet->Name, $/; $San->{name} = $sheet; #my $San_data = $xls->Worksheets("$San->{name}"); #my @Colum_A = $San_data->UsedRange->{'Value'}; ## again, just for testing my @Colum_A = qw/ RDUB010 34:34:36:7U 87:23:89:6C RDUB090 90:39:12:6U 34:34:36:7Z 87:23:89:6N 34:38:36:7U /; ## process each array element and print something appropriate ## also store data into a HoH / HoA my $current = 'not_defined'; # place holder foreach my $element (@Colum_A){ if ($element =~ /^RD/){ print "\tSAN : $San->{name}\n\t - LUN : $element\n"; $current = $element; } elsif ( $element =~ /^(?:[^:]{2}:){3}[^:]{2}$/){ # untested! should match # 60:05:08:b2:00:bb:b6:93 print "\t\tWW : $element\n"; push @{ $San->{LUN}->{$current} }, $element; } else { warn "Unrecognised input : \'$element\'\n"; } } ## add San to data push @$data, $San; } ## print out data structure print "\n-----> DATA\n"; print Dumper $data; ## and again print "\n-----> OUTPUT\n"; foreach my $san (@$data){ print "SAN : $san->{name}\n"; foreach my $lun( keys %{ $san->{LUN} } ){ print " - LUN : $lun\n"; print "\tWW : $_\n" for @{ $san->{LUN}->{$lun} } } }

This produces what you seem to be looking for:

Data in SAN : san1 SAN : san1 - LUN : RDUB010 WW : 34:34:36:7U WW : 87:23:89:6C SAN : san1 - LUN : RDUB090 WW : 90:39:12:6U WW : 34:34:36:7Z WW : 87:23:89:6N WW : 34:38:36:7U Data in SAN : san2 SAN : san2 - LUN : RDUB010 WW : 34:34:36:7U WW : 87:23:89:6C SAN : san2 - LUN : RDUB090 WW : 90:39:12:6U WW : 34:34:36:7Z WW : 87:23:89:6N WW : 34:38:36:7U -----> DATA $VAR1 = [ { 'LUN' => { 'RDUB090' => [ '90:39:12:6U', '34:34:36:7Z', '87:23:89:6N', '34:38:36:7U' ], 'RDUB010' => [ '34:34:36:7U', '87:23:89:6C' ] }, 'name' => 'san1' }, { 'LUN' => { 'RDUB090' => [ '90:39:12:6U', '34:34:36:7Z', '87:23:89:6N', '34:38:36:7U' ], 'RDUB010' => [ '34:34:36:7U', '87:23:89:6C' ] }, 'name' => 'san2' } ]; -----> OUTPUT SAN : san1 - LUN : RDUB090 WW : 90:39:12:6U WW : 34:34:36:7Z WW : 87:23:89:6N WW : 34:38:36:7U - LUN : RDUB010 WW : 34:34:36:7U WW : 87:23:89:6C SAN : san2 - LUN : RDUB090 WW : 90:39:12:6U WW : 34:34:36:7Z WW : 87:23:89:6N WW : 34:38:36:7U - LUN : RDUB010 WW : 34:34:36:7U WW : 87:23:89:6C

Update bugfixed code... Note to self - DO NOT POST UNTESTED REGEXES...

Just a something something...

In reply to Re^3: Creating a table from raw data! by BioLion
in thread Creating a table from raw data! by blackadder

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-12 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found