Ask a Question related to PERL Beginners, Design and Development.
-
James Edward Gray II #21
Re: Align Text
On Dec 29, 2003, at 11:31 AM, Bill Jastram wrote:
Good news. Glad I could help> Bingo! James. That takes care of label issue.
Oh no, I've created a monster! <laughs>> I was even able to make it three columns instead of three. And change
> the
> space between columns.
Na, you need a "Perl Golf Contest" for that. Thanks for the praise> You've obviously been at this for a while and use the tightest code
> concepts I've seen.
though.
Well, you're just never satisfied, are you? <laughs>> 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?
See code below:
We could add filtering pretty easily right here. I'll use your> 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;
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 (\@names, \@addresses, \@cities) {
>> printf join(' ', ('%-30s') x scalar(@$_)) . "\n", @$_;
>> }
>> print "\n" if @col1; # add a separator
>> } # rinse, repeat...
>>
>> __END__James Edward Gray II Guest
-
Text Align is Grayed Out
I am having an issue with one particular site. The site was created in DW CS3 using the built in style sheet templates. When I try to edit the site... -
text fields: no right align ???
Hi, I can't seem to make text align to the right (or to the center) in a text field. Am I blind or is it just not possible ? In any case, such an... -
How could i align the text in a column?
All the columns in my I'd like to align the columns to the right, left or center but i don't find a property to do it. Is it possible? Thanks -
how to Align text left & vertical align middle
Hello, I have a asp lable control, which I use to display text in, I would like to have the text display aligned in the center and vertical... -
Text Align
When I install my accesss 2000 application on some machines the application ignores the "Text Align" Property Setting in some Activex Controls(List... -
Bill Jastram #22
Re: Align Text
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! <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 (\@names, \@addresses, \@cities) {
> >> printf join(' ', ('%-30s') x scalar(@$_)) . "\n", @$_;
> >> }
> >> print "\n" if @col1; # add a separator
> >> } # rinse, repeat...
> >>
> >> __END__Bill Jastram Guest



Reply With Quote

