Re: Align Text

2003-12-29 Thread Bill Jastram
Thanks, that's just what I was trying to figure out, only I'd gone about 
it with the m// command to little or no avail. Your idea is of course much 
better.

I'll leave you alone for awhile. You given me plenty to think about.

Much appreciated!

Bill J.
__

On Mon, 29 Dec 2003, James Edward Gray II wrote:

> On Dec 29, 2003, at 11:31 AM, Bill Jastram wrote:
> 
> > 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!  
> 
> > 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?  
> 
> 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 =  ;
> >>>
> >>> 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]
 




Re: Align Text

2003-12-29 Thread Bill Jastram
Bingo! James. That takes care of label issue. 

I was even able to make it three columns instead of three. And change the 
space between columns. You've obviously been at this for a while and use 
the tightest code concepts I've seen.

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?

Thanks James, you've been of meg-assistance.

Bill
__

On Wed, 24 Dec 2003, James Edward Gray II wrote:

> On Dec 23, 2003, at 11:29 PM, Bill Jastram wrote:
> 
> > Yes, this helps tremendously. Actually, your suggestions helped me 
> > make,
> > what for me is, a quantum leap in the use of Perl.
> 
> Good news.  Always happy to help.
> 
> > I am stuck, however, on the loop you suggested to output the processed
> > @col arrays. I understand how you loaded them. And that, apparently, 
> > they
> > are ready to be output. But the closest I've come getting anything out 
> > of
> > them is the following:
> 
> Well, let's see if we can come up with something...
> 
> > #!/usr/bin/perl
> >
> > # use with:
> > # perl jamescolumnsample testing.txt
> >
> > use strict;
> > use warnings;
> >
> > #open CON, 'testing.txt' or die "File error:  $!";
> >
> > #my @CON =  ;
> >
> > my(@col1, @col2, @col3);
> >
> > my $col = 1;
> > while (<>) {
> 
> I forgot to remove the newlines here and we probably should:
> 
>   chomp;
> 
> > 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__
> 
> Unfortunately, I'm not where I can test code this morning, so I'll have 
> to just hope that works.  Let me know if I made a mistake though and 
> I'll fix it as soon as I'm back at a compiler.
> 
> Hope that helps you along, Bill.  Keep working at it.
> 
> James
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Align Text

2003-12-29 Thread James Edward Gray II
On Dec 29, 2003, at 11:31 AM, Bill Jastram wrote:

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!  

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?  

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

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]
 



Re: Align Text

2003-12-24 Thread James Edward Gray II
On Dec 23, 2003, at 11:29 PM, Bill Jastram wrote:

Yes, this helps tremendously. Actually, your suggestions helped me 
make,
what for me is, a quantum leap in the use of Perl.
Good news.  Always happy to help.

I am stuck, however, on the loop you suggested to output the processed
@col arrays. I understand how you loaded them. And that, apparently, 
they
are ready to be output. But the closest I've come getting anything out 
of
them is the following:
Well, let's see if we can come up with something...

#!/usr/bin/perl

# use with:
# perl jamescolumnsample testing.txt
use strict;
use warnings;
#open CON, 'testing.txt' or die "File error:  $!";

#my @CON =  ;

my(@col1, @col2, @col3);

my $col = 1;
while (<>) {
I forgot to remove the newlines here and we probably should:

	chomp;

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__

Unfortunately, I'm not where I can test code this morning, so I'll have 
to just hope that works.  Let me know if I made a mistake though and 
I'll fix it as soon as I'm back at a compiler.

Hope that helps you along, Bill.  Keep working at it.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Align Text

2003-12-24 Thread Bill Jastram
Yes, this helps tremendously. Actually, your suggestions helped me make, 
what for me is, a quantum leap in the use of Perl.

I am stuck, however, on the loop you suggested to output the processed 
@col arrays. I understand how you loaded them. And that, apparently, they 
are ready to be output. But the closest I've come getting anything out of 
them is the following:
__

#!/usr/bin/perl

# use with:
# perl jamescolumnsample testing.txt

use strict;
use warnings;

#open CON, 'testing.txt' or die "File error:  $!"; 

#my @CON =  ;

my(@col1, @col2, @col3);

my $col = 1;
while (<>) {
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?

my($first, $last, $add, $city, $state, $zip) = split /\t/, $col1[$col]; 

printf  "\n%s %s\n%s\n%s %s %s\n", $first, $last, $add, $city, $state, 
$zip; 

Any futher help with this would be appreciated.

Bill J.
__


On Tue, 23 Dec 2003, James Edward Gray II wrote:

> On Dec 23, 2003, at 12:17 AM, Bill Jastram wrote:
> 
> > After taking a look at your last suggested script I have a short
> > question:
> >
> > At what point does this script read in information from the
> > source file 'testing.txt'?
> >
> > Is it during the 'while (<>)' statement? If so what would the syntax 
> > be?
> 
> Yes, you've got it.
> 
> while (<>) {
> 
> }
> 
> is a construct for writing Unix-like filter apps.  It reads one line at 
> a time, from all the files passed as args to the script or STDIN, if 
> none are given.  This is extremely handy.
> 
> For example, if you wanted to combine two text files for your mailing 
> labels, you would just need to change how you call it:
> 
> perl script_name testing.txt other_file.txt
> 
> ...or even...
> 
> perl script_name *.txt
> 
> ...for all the .txt files in the current working directory.
> 
> Hope that helps.
> 
> James
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Align Text

2003-12-23 Thread James Edward Gray II
On Dec 23, 2003, at 12:17 AM, Bill Jastram wrote:

After taking a look at your last suggested script I have a short
question:
At what point does this script read in information from the
source file 'testing.txt'?
Is it during the 'while (<>)' statement? If so what would the syntax 
be?
Yes, you've got it.

while (<>) {

}

is a construct for writing Unix-like filter apps.  It reads one line at 
a time, from all the files passed as args to the script or STDIN, if 
none are given.  This is extremely handy.

For example, if you wanted to combine two text files for your mailing 
labels, you would just need to change how you call it:

perl script_name testing.txt other_file.txt

...or even...

perl script_name *.txt

...for all the .txt files in the current working directory.

Hope that helps.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Align Text

2003-12-23 Thread Bill Jastram
After taking a look at your last suggested script I have a short 
question:

At what point does this script read in information from the 
source file 'testing.txt'?

Is it during the 'while (<>)' statement? If so what would the syntax be?

Thanks again for your help.

Bill J.
__

On Mon, 22 Dec 2003, James Edward Gray II wrote:

> On Dec 21, 2003, at 10:47 PM, Bill Jastram wrote:
> 
> > James:
> >
> > Thanks for the sample and I agree it does work.
> >
> > How can I create an array of just the first names for a file?
> >
> > This is what I have so far:
> 
> Let's take a look at what you have first.
> 
> You're missing two very important lines right here:
> 
> use strict;
> use warnings;
> 
> These promise Perl you'll play by the good programmer rules, so it can 
> help you find problems.  That's a good deal.
> 
> > open (A, "testing.txt");
> 
> Always check if an open succeeded.  There are plenty of reasons it may 
> not.
> 
> Also, you'll generally stay more sane if you use better names for file 
> handle/variables than A.
> 
> open CONTACTS, 'testing.txt' or die "File error:  $!";
> 
> > @A = ;
> 
> my @A = ;
> 
> We're reading the whole file here, but you only need one line at a 
> time.  We can do better.
> 
> > foreach ($n = 0; $n<10; $n++)
> > {
> >
> > #Split each record into its fields
> > $item =  $A[$n];
> 
> These two lines can be simplified:
> 
> for my $item (@A[0..9]) {  # if you really only wanted the first ten 
> lines
> 
> # or...
> 
> for my $item (@A) {  # if you wanted them all
> 
> > @addArray = split( "\t", $item); #Splits each line into its tab fields
> > $first = $addArray[0]; #Breaks down array into proper fields
> > $last = $addArray[1];
> > $add  = $addArray[2];
> > $city = $addArray[3];
> > $state = $addArray[4];
> > $zip = $addArray[5];
> 
> my($first, $last, $add, $city, $state, $zip) = split /\t/, $item;
> 
> > printf  "\n%s %s\n%s\n%s %s %s\n", $first, $last, $add, $city, $state,
> > $zip;
> > _
> 
> Let's try something simpler:
> 
> #!/usr/bin/perl
> 
> # use with:
> # perl this_script_name testing.txt
> 
> use strict;
> use warnings;
> 
> while (<>) {  # process args line by line
>   printf "\n%s %s\n%s\n%s %s %s\n", split /\t/, $_;
> }
> 
> __END__
> 
> > What it seems I need now is to create arrays for each of the fields, 
> > so I
> > can proceed to make three columns of labels.
> 
> That's a little trickier, but let's see if we can keep it pretty simple:
> 
> #!/usr/bin/perl
> 
> # use with:
> # perl this_script_name testing.txt
> 
> use strict;
> use warnings;
> 
> my(@col1, @col2, @col3);
> 
> my $col = 1;
> while (<>) {
>   if ($col == 1) { push @col1, $_ }
>   elsif ($col == 2) { push @col, $_ }
>   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?
> 
> __END__
> 
> Does that help you along?
> 
> James
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Align Text

2003-12-23 Thread Bill Jastram
Wow! That's a lot to take in, but consider it, and I'll get back 
to you with the results of my considerations.

Thanks much.

Bill J.
__

On Mon, 22 Dec 2003, James Edward Gray II wrote:

> On Dec 21, 2003, at 10:47 PM, Bill Jastram wrote:
> 
> > James:
> >
> > Thanks for the sample and I agree it does work.
> >
> > How can I create an array of just the first names for a file?
> >
> > This is what I have so far:
> 
> Let's take a look at what you have first.
> 
> You're missing two very important lines right here:
> 
> use strict;
> use warnings;
> 
> These promise Perl you'll play by the good programmer rules, so it can 
> help you find problems.  That's a good deal.
> 
> > open (A, "testing.txt");
> 
> Always check if an open succeeded.  There are plenty of reasons it may 
> not.
> 
> Also, you'll generally stay more sane if you use better names for file 
> handle/variables than A.
> 
> open CONTACTS, 'testing.txt' or die "File error:  $!";
> 
> > @A = ;
> 
> my @A = ;
> 
> We're reading the whole file here, but you only need one line at a 
> time.  We can do better.
> 
> > foreach ($n = 0; $n<10; $n++)
> > {
> >
> > #Split each record into its fields
> > $item =  $A[$n];
> 
> These two lines can be simplified:
> 
> for my $item (@A[0..9]) {  # if you really only wanted the first ten 
> lines
> 
> # or...
> 
> for my $item (@A) {  # if you wanted them all
> 
> > @addArray = split( "\t", $item); #Splits each line into its tab fields
> > $first = $addArray[0]; #Breaks down array into proper fields
> > $last = $addArray[1];
> > $add  = $addArray[2];
> > $city = $addArray[3];
> > $state = $addArray[4];
> > $zip = $addArray[5];
> 
> my($first, $last, $add, $city, $state, $zip) = split /\t/, $item;
> 
> > printf  "\n%s %s\n%s\n%s %s %s\n", $first, $last, $add, $city, $state,
> > $zip;
> > _
> 
> Let's try something simpler:
> 
> #!/usr/bin/perl
> 
> # use with:
> # perl this_script_name testing.txt
> 
> use strict;
> use warnings;
> 
> while (<>) {  # process args line by line
>   printf "\n%s %s\n%s\n%s %s %s\n", split /\t/, $_;
> }
> 
> __END__
> 
> > What it seems I need now is to create arrays for each of the fields, 
> > so I
> > can proceed to make three columns of labels.
> 
> That's a little trickier, but let's see if we can keep it pretty simple:
> 
> #!/usr/bin/perl
> 
> # use with:
> # perl this_script_name testing.txt
> 
> use strict;
> use warnings;
> 
> my(@col1, @col2, @col3);
> 
> my $col = 1;
> while (<>) {
>   if ($col == 1) { push @col1, $_ }
>   elsif ($col == 2) { push @col, $_ }
>   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?
> 
> __END__
> 
> Does that help you along?
> 
> James
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Align Text

2003-12-22 Thread James Edward Gray II
On Dec 21, 2003, at 10:47 PM, Bill Jastram wrote:

James:

Thanks for the sample and I agree it does work.

How can I create an array of just the first names for a file?

This is what I have so far:
Let's take a look at what you have first.

You're missing two very important lines right here:

use strict;
use warnings;
These promise Perl you'll play by the good programmer rules, so it can 
help you find problems.  That's a good deal.

open (A, "testing.txt");
Always check if an open succeeded.  There are plenty of reasons it may 
not.

Also, you'll generally stay more sane if you use better names for file 
handle/variables than A.

open CONTACTS, 'testing.txt' or die "File error:  $!";

@A = ;
my @A = ;

We're reading the whole file here, but you only need one line at a 
time.  We can do better.

foreach ($n = 0; $n<10; $n++)
{
#Split each record into its fields
$item =  $A[$n];
These two lines can be simplified:

for my $item (@A[0..9]) {  # if you really only wanted the first ten 
lines

# or...

for my $item (@A) {  # if you wanted them all

@addArray = split( "\t", $item); #Splits each line into its tab fields
$first = $addArray[0]; #Breaks down array into proper fields
$last = $addArray[1];
$add  = $addArray[2];
$city = $addArray[3];
$state = $addArray[4];
$zip = $addArray[5];
my($first, $last, $add, $city, $state, $zip) = split /\t/, $item;

printf  "\n%s %s\n%s\n%s %s %s\n", $first, $last, $add, $city, $state,
$zip;
_
Let's try something simpler:

#!/usr/bin/perl

# use with:
# perl this_script_name testing.txt
use strict;
use warnings;
while (<>) {  # process args line by line
printf "\n%s %s\n%s\n%s %s %s\n", split /\t/, $_;
}
__END__

What it seems I need now is to create arrays for each of the fields, 
so I
can proceed to make three columns of labels.
That's a little trickier, but let's see if we can keep it pretty simple:

#!/usr/bin/perl

# use with:
# perl this_script_name testing.txt
use strict;
use warnings;
my(@col1, @col2, @col3);

my $col = 1;
while (<>) {
if ($col == 1) { push @col1, $_ }
elsif ($col == 2) { push @col, $_ }
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?
__END__

Does that help you along?

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Align Text

2003-12-22 Thread Bill Jastram
James:

Thanks for the sample and I agree it does work.

How can I create an array of just the first names for a file? 

This is what I have so far:
__

open (A, "testing.txt");

@A = ;

foreach ($n = 0; $n<10; $n++)
{

#Split each record into its fields
$item =  $A[$n];
@addArray = split( "\t", $item); #Splits each line into its tab fields
$first = $addArray[0]; #Breaks down array into proper fields
$last = $addArray[1]; 
$add  = $addArray[2]; 
$city = $addArray[3]; 
$state = $addArray[4]; 
$zip = $addArray[5]; 

printf  "\n%s %s\n%s\n%s %s %s\n", $first, $last, $add, $city, $state, 
$zip; 
_

What it seems I need now is to create arrays for each of the fields, so I 
can proceed to make three columns of labels.

Thanks for any assistance you can give me with this.

Bill J. 
__

On Fri, 19 Dec 2003, James Edward Gray II wrote:

> On Dec 19, 2003, at 12:04 PM, Bill Jastram wrote:
> 
> > We're getting closer. But lets say the first name of the first field 
> > in the first row is 'Bill'. And the first name of the first field in 
> > the second row is 'Lanette'. This command will not compensate for the 
> > difference in the length of the two first names. So, the alignment of 
> > the second fields in each row will not be correct. And so on ...
> >
> > Does this help you understand where I'm headed?
> 
> No sir, I'm afraid I don't:
> 
> perl -e '@names = (["Bill", "Gray"],["Lanette", "Jones"]); printf 
> "%-20s %-20s\n", $$_[0], $$_[1] foreach @names'
> 
> Bill Gray
> Lanette  Jones
> 
> The above DOES line up correctly, with a fixed width font.
> 
> If you need to adjust the size of the fields based on the names, you'll 
> need to make two passes.  First, find the longest lengths.  Then print.
> 
> printf() is doing the right thing though, as you can see above.
> 
> James
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Align Text

2003-12-19 Thread R. Joseph Newton
Bill Jastram wrote:

> We're getting closer. But lets say the first name of the first field in the first 
> row is 'Bill'. And the first name of the first field in the second row is 'Lanette'. 
> This command will not compensate for the difference in the length of the two first 
> names. So, the alignment of the second fields in each row will not be correct. And 
> so on ...
>
> Does this help you understand where I'm headed?
>
> Bill

Yes.  And printf, sprintf, or the perl format/write function pair should be able to 
help with this.  They should at least give you a starting point, because there are 
many ways to accomplish this task.  I prefer the printf, mostly because I'd rather 
just say expplictly how many spaces each field should occupy.  Others prefer using the 
format
function to provide a parameter for write(), because they see it as WYSIWYG.  Try them 
both and see which you feel more comfortable with for any given context.

Joseph



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Align Text

2003-12-19 Thread Eric Walker
I have use the FORMAT function in perl. Its pretty nice.
perldoc -f format.

Hope that helps
perlknucklehead

On Fri, 2003-12-19 at 14:20, Rob Dixon wrote:
Bill Jastram wrote:

> We're getting closer. But lets say the first name of the first
> field in the first row is 'Bill'. And the first name of the
> first field in the second row is 'Lanette'. This command will
> not compensate for the difference in the length of the two
> first names. So, the alignment of the second fields in each
> row will not be correct. And so on ...
>
> Does this help you understand where I'm headed?

Hi Bill.

What James wrote still applies I think. See the code below,
which does what I think you want?

HTH,

Rob


foreach ('Bill Jastram', 'Lanette Smith') {
  printf "%-20s %-20s\n", split;
}

**OUTPUT

Bill Jastram
Lanette  Smith



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Align Text

2003-12-19 Thread Rob Dixon
Bill Jastram wrote:

> We're getting closer. But lets say the first name of the first
> field in the first row is 'Bill'. And the first name of the
> first field in the second row is 'Lanette'. This command will
> not compensate for the difference in the length of the two
> first names. So, the alignment of the second fields in each
> row will not be correct. And so on ...
>
> Does this help you understand where I'm headed?

Hi Bill.

What James wrote still applies I think. See the code below,
which does what I think you want?

HTH,

Rob


foreach ('Bill Jastram', 'Lanette Smith') {
  printf "%-20s %-20s\n", split;
}

**OUTPUT

Bill Jastram
Lanette  Smith



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Align Text

2003-12-19 Thread Tom Kinzer
say wha?  show me, please.

-Original Message-
From: Bill Jastram [mailto:[EMAIL PROTECTED]
Sent: Friday, December 19, 2003 10:04 AM
To: Tom Kinzer
Cc: James Edward Gray II; Perl List
Subject: RE: Align Text


We're getting closer. But lets say the first name of the first field in the
first row is 'Bill'. And the first name of the first field in the second row
is 'Lanette'. This command will not compensate for the difference in the
length of the two first names. So, the alignment of the second fields in
each row will not be correct. And so on ...

Does this help you understand where I'm headed?

Bill
__

>yes, and if that won't work for you, check out the 'format' command,
>you can
>do lots of slick stuff with it, like centering.
>
>-Tom Kinzer
>
>-Original Message-
>From: James Edward Gray II [mailto:[EMAIL PROTECTED]
>Sent: Friday, December 19, 2003 9:16 AM
>To: Bill Jastram
>Cc: Perl List
>Subject: Re: Align Text
>
>
>On Dec 19, 2003, at 8:29 AM, Bill Jastram wrote:
>
>> James:
>>
>> A coupe of things.
>>
>> #1. Pardon my ignorance, but I'm not sure how to use the list
>where I
>> found the reply button to e-mail you directly. I could not find a
>way
>> to
>> add to the already existing 'thread'. Your help would be
>appreciated.
>
>The list is just another address you can send your messages too:
>
>[EMAIL PROTECTED]
>
>A lot of people just hit "Reply All" if their mail client has such a
>button.  In the case of this message, that would send your answer to
>me
>and the list.
>
>> #2. The challenge with the use of %20s is that in the next row of
>> records
>> the names will not be aligned (flush left) with the row above, if the
>> names are not the same length. This is my dilemma.
>
>Correct, but they will be aligned flush right.  For flush left, we just
>change the pattern a little:
>
> > perl -e 'printf "%-20s %-20s %-20s\n", "James", "Edward", "Gray"'
>JamesEdward   Gray
>
>Does that answer your question?
>
>James
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
><http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Align Text

2003-12-19 Thread James Edward Gray II
On Dec 19, 2003, at 12:04 PM, Bill Jastram wrote:

We're getting closer. But lets say the first name of the first field 
in the first row is 'Bill'. And the first name of the first field in 
the second row is 'Lanette'. This command will not compensate for the 
difference in the length of the two first names. So, the alignment of 
the second fields in each row will not be correct. And so on ...

Does this help you understand where I'm headed?
No sir, I'm afraid I don't:

perl -e '@names = (["Bill", "Gray"],["Lanette", "Jones"]); printf 
"%-20s %-20s\n", $$_[0], $$_[1] foreach @names'

Bill Gray
Lanette  Jones
The above DOES line up correctly, with a fixed width font.

If you need to adjust the size of the fields based on the names, you'll 
need to make two passes.  First, find the longest lengths.  Then print.

printf() is doing the right thing though, as you can see above.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Align Text

2003-12-19 Thread Jeff Westman
Bill Jastram <[EMAIL PROTECTED]> wrote:

Can you give an example of what you want your output to look like?

>From what I am hearing you say, you probably should be using 'format', as one
already responded.


-Jeff


> We're getting closer. But lets say the first name of the first field in the
> first row is 'Bill'. And the first name of the first field in the second row
> is 'Lanette'. This command will not compensate for the difference in the
> length of the two first names. So, the alignment of the second fields in
> each row will not be correct. And so on ...
> 
> Does this help you understand where I'm headed?
> 
> Bill 
> __
> 
> >yes, and if that won't work for you, check out the 'format' command, 
> >you can
> >do lots of slick stuff with it, like centering.
> >
> >-Tom Kinzer
> >
> >-Original Message-
> >From: James Edward Gray II [mailto:[EMAIL PROTECTED]
> >Sent: Friday, December 19, 2003 9:16 AM
> >To: Bill Jastram
> >Cc: Perl List
> >Subject: Re: Align Text
> >
> >
> >On Dec 19, 2003, at 8:29 AM, Bill Jastram wrote:
> >
> >> James:
> >>
> >> A coupe of things.
> >>
> >> #1. Pardon my ignorance, but I'm not sure how to use the list 
> >where I
> >> found the reply button to e-mail you directly. I could not find a 
> >way
> >> to
> >> add to the already existing 'thread'. Your help would be 
> >appreciated.
> >
> >The list is just another address you can send your messages too:
> >
> >[EMAIL PROTECTED]
> >
> >A lot of people just hit "Reply All" if their mail client has such a
> >button.  In the case of this message, that would send your answer to 
> >me
> >and the list.
> >
> >> #2. The challenge with the use of %20s is that in the next row of
> >> records
> >> the names will not be aligned (flush left) with the row above, if the
> >> names are not the same length. This is my dilemma.
> >
> >Correct, but they will be aligned flush right.  For flush left, we just
> >change the pattern a little:
> >
> > > perl -e 'printf "%-20s %-20s %-20s\n", "James", "Edward", "Gray"'
> >JamesEdward   Gray
> >
> >Does that answer your question?
> >
> >James
> >
> >
> >--
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> ><http://learn.perl.org/> <http://learn.perl.org/first-response>
> >
> >
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 


__
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Align Text

2003-12-19 Thread Bill Jastram
We're getting closer. But lets say the first name of the first field in the first row 
is 'Bill'. And the first name of the first field in the second row is 'Lanette'. This 
command will not compensate for the difference in the length of the two first names. 
So, the alignment of the second fields in each row will not be correct. And so on ...

Does this help you understand where I'm headed?

Bill 
__

>yes, and if that won't work for you, check out the 'format' command, 
>you can
>do lots of slick stuff with it, like centering.
>
>-Tom Kinzer
>
>-Original Message-
>From: James Edward Gray II [mailto:[EMAIL PROTECTED]
>Sent: Friday, December 19, 2003 9:16 AM
>To: Bill Jastram
>Cc: Perl List
>Subject: Re: Align Text
>
>
>On Dec 19, 2003, at 8:29 AM, Bill Jastram wrote:
>
>> James:
>>
>> A coupe of things.
>>
>> #1. Pardon my ignorance, but I'm not sure how to use the list 
>where I
>> found the reply button to e-mail you directly. I could not find a 
>way
>> to
>> add to the already existing 'thread'. Your help would be 
>appreciated.
>
>The list is just another address you can send your messages too:
>
>[EMAIL PROTECTED]
>
>A lot of people just hit "Reply All" if their mail client has such a
>button.  In the case of this message, that would send your answer to 
>me
>and the list.
>
>> #2. The challenge with the use of %20s is that in the next row of
>> records
>> the names will not be aligned (flush left) with the row above, if the
>> names are not the same length. This is my dilemma.
>
>Correct, but they will be aligned flush right.  For flush left, we just
>change the pattern a little:
>
> > perl -e 'printf "%-20s %-20s %-20s\n", "James", "Edward", "Gray"'
>JamesEdward   Gray
>
>Does that answer your question?
>
>James
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
><http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Align Text

2003-12-19 Thread Tom Kinzer
yes, and if that won't work for you, check out the 'format' command, you can
do lots of slick stuff with it, like centering.

-Tom Kinzer

-Original Message-
From: James Edward Gray II [mailto:[EMAIL PROTECTED]
Sent: Friday, December 19, 2003 9:16 AM
To: Bill Jastram
Cc: Perl List
Subject: Re: Align Text


On Dec 19, 2003, at 8:29 AM, Bill Jastram wrote:

> James:
>
> A coupe of things.
>
> #1. Pardon my ignorance, but I'm not sure how to use the list where I
> found the reply button to e-mail you directly. I could not find a way
> to
> add to the already existing 'thread'. Your help would be appreciated.

The list is just another address you can send your messages too:

[EMAIL PROTECTED]

A lot of people just hit "Reply All" if their mail client has such a
button.  In the case of this message, that would send your answer to me
and the list.

> #2. The challenge with the use of %20s is that in the next row of
> records
> the names will not be aligned (flush left) with the row above, if the
> names are not the same length. This is my dilemma.

Correct, but they will be aligned flush right.  For flush left, we just
change the pattern a little:

 > perl -e 'printf "%-20s %-20s %-20s\n", "James", "Edward", "Gray"'
JamesEdward   Gray

Does that answer your question?

James


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Align Text

2003-12-19 Thread James Edward Gray II
On Dec 19, 2003, at 8:29 AM, Bill Jastram wrote:

James:

A coupe of things.

#1. Pardon my ignorance, but I'm not sure how to use the list where I
found the reply button to e-mail you directly. I could not find a way 
to
add to the already existing 'thread'. Your help would be appreciated.
The list is just another address you can send your messages too:

[EMAIL PROTECTED]

A lot of people just hit "Reply All" if their mail client has such a 
button.  In the case of this message, that would send your answer to me 
and the list.

#2. The challenge with the use of %20s is that in the next row of 
records
the names will not be aligned (flush left) with the row above, if the
names are not the same length. This is my dilemma.
Correct, but they will be aligned flush right.  For flush left, we just 
change the pattern a little:

> perl -e 'printf "%-20s %-20s %-20s\n", "James", "Edward", "Gray"'
JamesEdward   Gray
Does that answer your question?

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Align Text

2003-12-18 Thread James Edward Gray II
On Dec 18, 2003, at 12:03 AM, Bill Jastram wrote:

James:
I'm happy to help, but keep your replies on the list so we can all 
learn/help.

Can printf set the value in spaces of tab (\t)? I need to do three 
column
output with perl for mailing labels.
You bet:

>perl -e 'printf "%20s %20s %20s\n", "James", "Edward", "Gray"'
   James   Edward Gray
Three columns of 20 character width right there.  Does that answer your 
question?

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Align text

2003-12-16 Thread James Edward Gray II
\On Dec 16, 2003, at 1:39 PM, Hemond, Steve wrote:

Hi again,

Thanks for you help with my data structure problem, a hash of hashes
problem did the job :-)
I would like to know how to align text with the print command.

I have four scalar variables to print but I want them to follow their
header's size.
So, if the header is 8 chars long, I would like the output of $user
(which is paul (4 chars) to print 4 more spaces)
How could I do that?
You're looking for printf().  See if this documentation fixes you up:

perldoc -f printf

perldoc -f sprintf

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]