--- Lawrence Statton XE2/N1GAK <[EMAIL PROTECTED]>
wrote:
> If you're dealing with variable length strings,
> separated by some kind
> of character, then regexp is the tool you want, not
> substr.
> 
> This snippet will work so long as hostname and
> platform name are made
> up of \w ... if not, substitute in an appropriate
> character class.
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> foreach my $filename (qw (
>                          /home/dbsmith/passwd.dubhpr01.sun
>                          /some/other/path/passwd.fizzbox.hpux
>                          /yet/another/path/passwd.gronko.aix
>                          /still/more/paths/to/passwd.foohost.linux
>                       )
>                    ) {
>   my ($hostname, $platform) = $filename =~
> m|\.(\w+)\.(\w+)$|;
>   print "Hostname: $hostname, Platform:
> $platform\n";
> }


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, 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.  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.


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];

#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
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);
}

I then tried 

$worksheet->write_col('A2',@{$aref},$sheet_format);

and I get error:

Not an array ref in call to write_row()No such file or
directory at uid_check.pl line 121
        main::__ANON__('Not an array ref in call to
write_row()No such file or direct...') called at
/opt/perl/lib/5.8.2/Carp.pm line 191
        Carp::croak('Not an array ref in call to
write_row()No such file or directory') called at
/opt/perl/lib/site_perl/5.8.2/Spreadsheet/WriteExcel/Worksheet.pm
line 1354
       
Spreadsheet::WriteExcel::Worksheet::write_col(1,0,'Spreadsheet::WriteExcel::Format=HASH(0x40610804)')
called at uid_check.pl line 121


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>


Reply via email to