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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:


New User

Jun 21, 2010, 11:47 AM

Post #1 of 3 (4150 views)
Parse Can't Post

I'm looking for a script to test a proof of concept using an example excel file. I need to copy rows of data X amount of time relative to the number of IDs it has in a certain column.

ex of starting XLS is:

Key Name KeyIDs

mpd-1 test mpd-4, mpd-54, mpd-123

mpd-2 test2 mpd-3, mpd-44

INTO a new xls of:

Key Name KeyIDs

mpd-1 Test mpd-4

mpd-1 Test mpd-54

mpd-1 Test mpd-123

mpd-2 test2 mpd-3

mpd-2 test2 mpd-44

Any thoughts?

(This post was edited by traizenne on Jun 21, 2010, 1:14 PM)


Jul 27, 2010, 11:11 AM

Post #2 of 3 (3991 views)
Re: [traizenne] Parse [In reply to] Can't Post

I need details about file names and blank lines. Here is my first try at it. By default, it reads from testing.xls and writes to testing_new.xls.


use strict;
use warnings;
my $file_name = $ARGV[0] || 'testing';
my $in_file = $file_name. "\.XLS";
my $out_file = $file_name. "_new.XLS";

open my $IN , '<', "$in_file" or die "Cannot open input file";
open my $OUT, '>', "$out_file" or die "Cannot open ouptput file";

while (my $in_line = <$IN>) {
chomp $in_line;
next if $in_line =~ /\A\s*\Z/;
if ($in_line =~ /\AKey /xms) {
print {$OUT} $in_line, "\n\n";
$in_line =~ s/\,//xmsg;
my ($key, $test, @ids) = split /\s/, $in_line;
foreach my $id (@ids) {
print {$OUT} "$key $test $id\n\n";
close $IN;
close $OUT;

Good Luck,

Veteran / Moderator

Jul 27, 2010, 11:42 AM

Post #3 of 3 (3989 views)
Re: [BillKSmith] Parse [In reply to] Can't Post

I could be wrong, but when someone says excel file, I think they are working with a binary spreadsheet file not a plain text file. On the other hand, there are lots of people that think an .xls file is an excel spreadsheet no matter what format is being used to store the data. Those people would be wrong.


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

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