Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Underlining in Perl and Python - the x and * operator in use

Perl's x operator - yes, that is the letter x - is used to replicate the string on the left the number of times given to the right. "What use is THAT" I have been asked in the past, by delegates feeling that it's a solution looking for a problem. Well - as an example, it's a great way to output just enough "-" characters - or anything else in a fixed with font - to underline a title.


print "Your name? " ;
chop ($name = <STDIN>);
 
print $name,"\n";
print "-" x length($name),"\n";


And here I am testing that ...

Dorothy:qc2 grahamellis$ perl titlit
Your name? Graham
Graham
------
Dorothy:qc2 grahamellis$ perl titlit
Your name? Graham Ellis
Graham Ellis
------------
Dorothy:qc2 grahamellis$


In Python, the * operator on a string object will achieve the same goal:

line = raw_input("your name ")
print line
print "-" * len(line)


And running that ...

Dorothy:qc2 grahamellis$ python pytit
your name Python Trainer
Python Trainer
--------------
Dorothy:qc2 grahamellis$ python pytit
your name Perl Trainer
Perl Trainer
------------
Dorothy:qc2 grahamellis$





(written 2008-04-12 04:59:58)

 
Associated topics are indexed under
P205 - Perl - Initial String Handling
Y108 - Python - String Handling

Back to
Learning to program in Perl
Previous and next
or
Horse's mouth home
Forward to
Chew Valley Lakes
Some other Articles
Comfy Chair - Floating Harbour, Bristol
Gauging point at entrance to Bristols Floating Harbour
PHP course dot co, dot uk
Chew Valley Lakes
Underlining in Perl and Python - the x and * operator in use
Learning to program in Perl
Sheep Shearers, Marathon Runners and Ocean Sailors
Learning and understanding scripting programming techniques
M25 / South Mimms Service Area
Do not SHOUT and do not whisper
2259 posts, page by page
Link to page ... 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 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2009: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho