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: Re: [Tejas] How to append or prepend a string to a variable : Edit Log



Zhris
Enthusiast

Nov 19, 2014, 4:23 AM


Views: 35376
Re: [Tejas] How to append or prepend a string to a variable

As per above:


Code
# define workbooks state hash.  
my %workbooks;

# open input filehandle.
open $gl_fh, '<', $gl_file or die "could not open $gl_fh <$!>";

# read input data.
while ( my $line = <$gl_fh> )
{
# remove newline character from end of line.
chomp $line;

# split the line up into org and column data.
my ( $org, @data ) = split /\|/, $line;

# define variables we require in order to write column data to appropriate worksheet.
my ( $workbook, $gl_sheet, $gl_row, $sl_sheet, $sl_row );

# we have seen this org before.
if ( defined $workbooks{$org} )
{
# assign each variable FROM the workbook state hash. Increment row numbers.
$workbook = $workbooks{$org}{workbook};
$gl_sheet = $workbooks{$org}{worksheets}{gl}{worksheet};
$gl_row = ++$workbooks{$org}{worksheets}{gl}{row};
$sl_sheet = $workbooks{$org}{worksheets}{sl}{worksheet};
$sl_row = ++$workbooks{$org}{worksheets}{sl}{row};
}
# we haven't seen this org before.
else
{
# assign each variable FROM the instantiated Excel::Writer::XLSX object. 0 row numbers.
$workbook = Excel::Writer::XLSX->new( "${org}_GL_SL.xlsx" );
$gl_sheet = $workbook->add_worksheet( 'GL_Sheet' );
$gl_row = 0;
$sl_sheet = $workbook->add_worksheet( 'SL_Sheet' );
$sl_row = 0;

# assign each variable TO the workbook state hash, in preparation for the next time we see this org.
$workbooks{$org}{workbook} = $workbook;
$workbooks{$org}{worksheets}{gl}{worksheet} = $gl_sheet;
$workbooks{$org}{worksheets}{gl}{row} = $gl_row;
$workbooks{$org}{worksheets}{sl}{worksheet} = $sl_sheet;
$workbooks{$org}{worksheets}{sl}{row} = $sl_row;
}

# write column data to appropriate worksheet.
for my $gl_col ( 0 .. $#data )
{
$gl_sheet->write_string( $gl_row, $gl_col, $data[$gl_col], $frmt );
}
}

# close input filehandle.
close $gl_fh;



(This post was edited by Zhris on Nov 19, 2014, 4:27 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 4:24 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 4:27 AM


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

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