Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2023 - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Odd linebreak

Posted by TedH (TedH), 7 March 2008
Hi, when running some code result through an HTML validator I discovered a linebreak that shouldn't be there. I've looked at this from every angle I can possibly think of and can find no obvious reason for this happening.

 foreach $arcdir (@lines) {
 ## Monthnames
 @months = qw(January February March April May June July August September October November December);
 $aa = substr($arcdir, 0, 4);
 $bb = substr($arcdir, 4, 6);
 $macvm = $months[$bb-1];
 $macvy = $aa;
print qq ~&nbsp;<a href="$urlcgi/$arcdir" onFocus="if(this.blur)this.blur()">$macvy</a>&nbsp;~;

The linebreak occurs in the HTML output like this:
<a href="/cgi-bin/news/

The arcdir variable is defined right in the foreach and looks okay in the substring. Is Perl doing something I am not aware of here?

Any ideas?
- Ted

If I've mentioned something like this before and forgotten about it, put it down to age (silly grin)

Posted by george_Ball (george), 7 March 2008
The newline appears to be in the variable $arcdir, which is the loop control variable stepping through the array @lines.

Now I'm guessing that you have filled the array using the <> operator in array context:-

 @lines = <INPUT>;

or something like that. The < > operator leaves the newline on each of the lines that it reads, so you will probably have one of these "phantom" newlines here...

My suggestion is to use chomp() to remove the newline (if it's there) on the variable $arcdir before you use it to build the href in your <a> tag. Remember to that chomp() doesn't return the chomped string though, so you can't use the function call in an expression as you may expect. You'll have to do

chomp ($arcdir);
print qq ....

Hope that makes sense.

Posted by TedH (TedH), 7 March 2008
A great big THANK YOU George.

The validator returned no errors upon check. Worked a treat.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2023: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho