Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 200003

[PHP3] RE: [CGI] formatting text question:PERL From: Arjen Bax (arjen.bax <email protected>)
Date: 03/21/00

Aloha Dean,

> From: Dean James [mailto:sacramone <email protected>]

> I need the info formatted with each value
> (from the name value pairs) to be printed at certain spaces. this way
> all entries align up left on each column..
>
> name: Dean|email: dean <email protected>|city: Los Angeles
>
> If I need it like this:
>
> Dean Los Angeles dean <email protected>
>
> Meaning: If I need "Dean" to start printing on the 20th space, "los
> Angeles" to start printing at the 60th space and the
> "dean <email protected>" to
> start at the 150th place.

As usual, TIMTOWTDI (There is more than one way to do it)...

A straightforward way:

Split the input lines on the pipe symbols:

    ($name, $email, $city) = split '|', $inputline;

Remove the words ending in ':' at the beginning of each item:

    for ($name, $email, $city) {
        s/^\w+:\s*//;
    }

Format the output line:

    $outputline = ' 'x19.sprintf '%-40.40s%-90.90s%s', $name, $city, $email;

In the sprintf format, %-40.40s means
- left align (-)
- using at least 40 positions (the first 40 of the two)
- using at most 40 positions (the .40)
- a string (s)
Precede the name by 19 spaces (' 'x19) in order to start at position 20.

HTH,
Arjen Bax

CMG Noord-Nederland B.V.
Sector Telecommunications & Utilities
Postbus 70237, 9704 AE Groningen
Tel. (050)52 19 500, Fax (050)52 19 503

Press Ctrl-Alt-Del for free IQ-test

> -----Original Message-----
> From: Dean James [mailto:sacramone <email protected>]
> Sent: Tuesday, March 21, 2000 8:08 AM
> To: cgi-list <email protected>; php3 <email protected>
> Subject: [CGI] formatting text question:PERL
>
>
> Hello,
>
> I have a question regarding formatting entries from a
> flatfile database
> that is pipe deliminated. I need the info formatted with each value
> (from the name value pairs) to be printed at certain spaces. this way
> all entries align up left on each column..
>
> name: Dean|email: dean <email protected>|city: Los Angeles
>
> If I need it like this:
>
> Dean Los Angeles dean <email protected>
>
> Meaning: If I need "Dean" to start printing on the 20th space, "los
> Angeles" to start printing at the 60th space and the
> "dean <email protected>" to
> start at the 150th place.
> The data will be pretty spread out. I only want the value
> printed, not
> names((name, email, city etc..))..HOW WOULD I DO THIS. I AM VERY
> CONFUSED AS TO STRING HANDLING WITH PERL
>
> thanks in advance.
> dean
>
> -----------------------------------------------------------------
> To unsubscribe, send mail to "majordomo <email protected>" with
> "unsubscribe cgi-list"
> in the body.
>
> CalendarPlus v3.0 with JavaPlus is available NOW!
> http://www.calendarplus.com/
>
> The CGI Tips & Tricks website (and archive of the list) is located
> at http://perl.jann.com/
> -----------------------------------------------------------------
>

-- 
PHP 3 Mailing List <http://www.php.net/>
To unsubscribe, send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
To search the mailing list archive, go to: http://www.php.net/mailsearch.php3
To contact the list administrators, e-mail: php-list-admin <email protected>