CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: How to append or prepend a string to a variable : Edit Log



Tejas
User

Nov 18, 2014, 11:06 PM


Views: 12893
How to append or prepend a string to a variable

The problem has nt so easy as i have written in the subject

The task is to create a workbook for 14 differennt countries in one go


Code
 
use strict;
use warnings;

use Excel::Writer::XLSX;
use Spreadsheet::XLSX;


my $US_workbook = Excel::Writer::XLSX->new( "US_GL_SL.xlsx");
my $US_GL_Sheet = $US_workbook->add_worksheet("GL_Sheet");
my $US_SL_Sheet = $US_workbook->add_worksheet( "SL_Sheet" );

my $GB_workbook = Excel::Writer::XLSX->new( "GB_GL_SL.xlsx");
my $GB_GL_Sheet = $GB_workbook->add_worksheet("GL_Sheet");
my $GB_SL_Sheet = $GB_workbook->add_worksheet( "SL_Sheet" );

my $DE_workbook = Excel::Writer::XLSX->new( "DE_GL_SL.xlsx");
my $DE_GL_Sheet = $DE_workbook->add_worksheet("GL_Sheet");
my $DE_SL_Sheet = $DE_workbook->add_worksheet( "SL_Sheet" );

my $FR_workbook = Excel::Writer::XLSX->new( "FR_GL_SL.xlsx");
my $FR_GL_Sheet = $FR_workbook->add_worksheet("GL_Sheet");
my $FR_SL_Sheet = $FR_workbook->add_worksheet( "SL_Sheet" );

my $ES_workbook = Excel::Writer::XLSX->new( "ES_GL_SL.xlsx");
my $ES_GL_Sheet = $ES_workbook->add_worksheet("GL_Sheet");
my $ES_SL_Sheet = $ES_workbook->add_worksheet( "SL_Sheet")


Now iam trying to set the columns for all the worksheet in one go appending _workbook with @Orgs value linearly



Code
my @Orgs = ("US","GB","DE","ES","IT","FR","GB","MX","BR","AU"); 

or(my $col = 0 ;$col < scalar @Orgs ; $col++ ){
my $workbook = $Orgs[$col];
$workbook .= "_workbook";
print "$workbook \n";
foreach my $worksheet ($workbook->sheets())
{
$worksheet->set_column( 'A:Q', 20 ); # Column E width set to 20
}
}


Though it is able to convert the variable name to worksheet name and prints = > US_workbook

Error

Quote

Can't call method "sheets" without a package or object reference at ./GL_SL_Final_Test.pl line 48.


What is missing ? Is something wrong in code or in understanding.
Is it possible in any other way to do it one go


And the same isssue with the code below


Code
open $gl_fh, '<', $gl_file or die "could not open $gl_fh <$!>"; 
open $sl_fh, '<', $sl_file or die "could not open $sl_fh <$!>";
while (my $my_line = <$gl_fh>) {
my $Sheet = (split /,/, $my_line)[0];
$Sheet .= "_GL_Sheet";
my @gl_line = (split /\|/, $my_line);
for(my $col=0 ;$col < scalar @gl_line ; $col++ ){
$Sheet->write_string ($gl_row, $col, $gl_line[$col],$frmt);
}
$gl_row++;
}



(This post was edited by Tejas on Nov 18, 2014, 11:15 PM)


Edit Log:
Post edited by Tejas (User) on Nov 18, 2014, 11:13 PM
Post edited by Tejas (User) on Nov 18, 2014, 11:15 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives