> --- Lawrence Statton XE2/N1GAK <[EMAIL PROTECTED]> > I am using Spreadsheet::WriteExcel to populate certain > columns which is working, but in column A for example > I am using the method write_col which requires a > reference,
Not just "a reference" but an ARRAY reference for all the values that will go into that column (or a reference to an array of arrayrefs to write a rectangular area in one shot). The example about a fifth of the way through the Spreadsheet::WriteExcel pod shows it pretty clearly. > I am printing the absolute path > /home/dbsmith/passwd.dubhpr01.sun when all I need to > print is sun and in column B all I will need is > dubhpr01 or the hostname. So stop printing what you don't need, and start printing what you do need :) :) :) This code is not writing itself -- you have to take a smidgeon of responsibility for its output. > For this reason I am trying > to use a regexp to grab $1 and $2 or sun and dubhpr01 > then use write_col method. This is not working and in > my test code I want to know what data structure to > use. > Are you sure that write_col is the method you want to use in this case? > use strict; > use warnings; > use Data::Dumper; > my $string = qw(/home/dbsmith/passwd.dubhpr01.sun); > my ($host,@OS) = $string =~ m|\.(\w+\d+)\.(\w+)$|i; > my $aref = \$host; > my $aref2 = [EMAIL PROTECTED]; Slow down a bit -- think about what you are writing. I don't want to seem bitchy, but you often post code that looks like you just keep throwing code into the file willy-nilly trying to see what sticks. This code CLEARLY has that feel. > > #print $1,"\n"; > #print $2,"\n"; > if (ref ($aref) eq "SCALAR") { > print "yes\n"; > } > print "newline\n"; > > if (ref ($aref2) eq "ARRAY") { > print "YES\n"; > } > print ${$aref},"\n"; > print @{$aref2}[0],"\n"; > > __OUTPUT__ > > yes > newline > YES > dubhpr01 > sun > > so my question 1 is what is @{$aref2}[0] and $aref2 is [ 'sun' ] @{$aref2} is ( 'sun' ) @{$aref2}[0] is 'sun' Perhaps the reason you find yourself getting confusing output is your confusing variablenames. "aref2" says nothing about the data it contains, and is dangerously similar to "aref". If you are debugging something, you are going to see what SHOULD be there instead of what IS there. > why isn't write_col writing its data from my code > below: > > ##-- Write data from ref and format cells A2 and down > --## > > my $string = qw(/home/dbsmith/passwd.dubhpr01.sun); > my @host = $string =~ m|\.(\w+\d+)$|i; > my $aref = [EMAIL PROTECTED]; > > print @{$aref},"\n"; > if (ref ($aref) eq "ARRAY") { > print "YES\n"; > $worksheet->write_col('A2',$aref,$sheet_format); > } It worked for me. (Outside of the fact I had to redact the $sheet_format because you didn't post a complete runnable program.) > > I then tried > > $worksheet->write_col('A2',@{$aref},$sheet_format); > > and I get error: > [error redacted] Well, the documentation pretty clearly calls for an arrayref in the second argument to write_col, so I have no idea why you tried passing in an array. > > > thank you > derek > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>