Bingo! James. That takes care of label issue.
Good news. Glad I could help
I was even able to make it three columns instead of three. And change the
space between columns.
Oh no, I've created a monster! <laughs>
You've obviously been at this for a while and use the tightest code concepts I've seen.
Na, you need a "Perl Golf Contest" for that. Thanks for the praise though.
By the way, how would you 'search' the incoming file to restrict what gets
displayed? i.e. display only the labels for the Johnson's?
Well, you're just never satisfied, are you? <laughs>
See code below:
On Wed, 24 Dec 2003, James Edward Gray II wrote:
On Dec 23, 2003, at 11:29 PM, Bill Jastram wrote:
#!/usr/bin/perl
# use with: # perl jamescolumnsample testing.txt
use strict; use warnings;
#open CON, 'testing.txt' or die "File error: $!";
#my @CON = <CON> ;
my(@col1, @col2, @col3);
my $col = 1; while (<>) {
I forgot to remove the newlines here and we probably should:
chomp;
We could add filtering pretty easily right here. I'll use your example, and leave it for you to expand on:
next unless /^[^\t]+\tJohnson\t/;
How's that for simple? If we skip a line here, it'll never get added to the col# arrays and we can forget about it. That leaves the only task as finding the right lines to skip, or in this case, not skip.
Your lines are tab delimited and they begin with the first and last name. So the first chunk of non-tab characters we need to skip, followed by a tab, and then we've found the important part to match.
Good luck.
James
if ($col == 1) { push @col1, $_ } elsif ($col == 2) { push @col2, $_ } else { push @col3, $_; $col = 1; next; } $col++; }
# that should load @col1, @col2 and @col3 # can you come up with an output loop for them that goes here?
# col1 will be the last to empty, so loop until it's gone while (@col1) { my(@names, @addresses, @cities); # make lists for the output lines # fill those lists foreach (shift(@col1), shift(@col2), shift(@col3)) { next unless defined $_; my($first, $last, $address, $city, $state, $zip) = split /\t/, $_; push @names, "$first $last"; push @addresses, $address; push @cities, "$city, $state $zip"; }
# print one row of contacts foreach ([EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED]) { printf join(' ', ('%-30s') x scalar(@$_)) . "\n", @$_; } print "\n" if @col1; # add a separator } # rinse, repeat...
__END__
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>