Ask a Question related to PERL Beginners, Design and Development.

  1. #21

    Default Re: Align Text

    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__
    James Edward Gray II Guest

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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
    4. 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...
    5. 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...
  3. #22

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139