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
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
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., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho