| Author |
Message |
weberw@adelphia.net *nix forums beginner
Joined: 09 Jul 2006
Posts: 22
|
Posted: Tue Jul 18, 2006 2:37 pm Post subject:
start printing at the end of the previous line
|
|
|
Does anyone know who to tab to then end of the previous line in Perl?
apple, banana and orange would start on the next line where the "s" in
fruits ends.
Example, Output to the screen would look like this..
fruits
apple
banana
orange |
|
| Back to top |
|
 |
Jürgen Exner *nix forums Guru
Joined: 09 Apr 2005
Posts: 514
|
Posted: Tue Jul 18, 2006 2:59 pm Post subject:
Re: start printing at the end of the previous line
|
|
|
weberw@adelphia.net wrote:
| Quote: | Does anyone know who to tab to then end of the previous line in Perl?
apple, banana and orange would start on the next line where the "s" in
fruits ends.
Example, Output to the screen would look like this..
fruits
apple
banana
orange
|
use strict; use warnings;
print "fruits\n";
print ' 'x (length('fruits')-1), "apple\n";
print ' 'x length('fruits'), "banana\n";
print ' 'x length('fruits'), "orange\n";
jue |
|
| Back to top |
|
 |
David Squire *nix forums Guru Wannabe
Joined: 08 Apr 2006
Posts: 197
|
Posted: Tue Jul 18, 2006 3:06 pm Post subject:
Re: start printing at the end of the previous line
|
|
|
weberw@adelphia.net wrote:
| Quote: | Does anyone know who to tab to then end of the previous line in Perl?
apple, banana and orange would start on the next line where the "s" in
fruits ends.
Example, Output to the screen would look like this..
fruits
apple
banana
orange
|
Hmmm. Do you really want not to use standard tabs? If so:
----
#!/usr/bin/perl
use strict;
use warnings;
my $category = 'fruits';
my @members = qw(apple banana orange);
print "$category\n";
for (@members) {
print ' ' x length $category;
print "$_\n";
}
----
Output:
fruits
apple
banana
orange |
|
| Back to top |
|
 |
weberw@adelphia.net *nix forums beginner
Joined: 09 Jul 2006
Posts: 22
|
Posted: Tue Jul 18, 2006 4:50 pm Post subject:
Re: start printing at the end of the previous line
|
|
|
Thanks David, It still prints everything on one line. Can you take
a look at my code...
#!C://Perl/bin/perl
use CGI ':standard';
use CGI::Carp 'fatalsToBrowser';
use strict;
use warnings;
use File::Find;
my $file_count = 0;
my $dir_count = 0;
my $title;
my $directorylen;
$title = "Find Files";
print header,
start_html($title),
h1($title);
find ( {
wanted => \&wanted}, 'C:/Documents and
Settings/whatever/Desktop/test');
printf "\nThere are %d files in %d directories.\n",
$file_count,
$dir_count;
sub wanted {
if(-d){
return if $File::Find::name =~ /test3/;
#get the length of the directory
#so the files contained in the folder
#can start printing at the end
#of the directory name
$directorylen = length($_);
print "$_\n\n";
$dir_count++;
}
elsif (-f _) {
return if $File::Find::name =~ /test3/;
print ' ' x ($directorylen-1), $_;
print ("\n\n\n")
$file_count++;
}
}
print end_hmtl; |
|
| Back to top |
|
 |
Glenn Jackman *nix forums addict
Joined: 19 Apr 2005
Posts: 97
|
Posted: Tue Jul 18, 2006 6:05 pm Post subject:
Re: start printing at the end of the previous line
|
|
|
At 2006-07-18 12:50PM, weberw@adelphia.net <weberw@adelphia.net> wrote:
| Quote: | Thanks David, It still prints everything on one line. Can you take
a look at my code...
[...] |
That's how browsers render multiple whitespace in HTML.
| Quote: | print header,
start_html($title),
h1($title);
|
print "<pre>";
| Quote: | find ( {
wanted => \&wanted}, 'C:/Documents and
Settings/whatever/Desktop/test');
printf "\nThere are %d files in %d directories.\n",
$file_count,
$dir_count;
|
print "</pre>";
[...]
--
Glenn Jackman
Ulterior Designer |
|
| Back to top |
|
 |
weberw@adelphia.net *nix forums beginner
Joined: 09 Jul 2006
Posts: 22
|
Posted: Tue Jul 18, 2006 9:07 pm Post subject:
Re: start printing at the end of the previous line
|
|
|
Hi Glen-you have been really helpful! How do you incorporate the print
' ' x line with a hyperlink? It works fine when it is not a hyperlink
for example
print "<pre>";
print ' ' x ($directorylen-5), $_;
print "</pre>";
but print ' ' x ($directorylen), <a
href=\"$File::Find::name\">$_</a>\n"; has a syntax error. How would I
incorporate my hyplerlink tags into the print ' ' x line?
Also, not clear what you meant by [....]. |
|
| Back to top |
|
 |
Tad McClellan *nix forums Guru
Joined: 09 Mar 2005
Posts: 1647
|
Posted: Tue Jul 18, 2006 10:35 pm Post subject:
Re: start printing at the end of the previous line
|
|
|
weberw@adelphia.net <weberw@adelphia.net> wrote:
| Quote: | How do you incorporate the print
' ' x line with a hyperlink? It works fine when it is not a hyperlink
for example
print "<pre>";
print ' ' x ($directorylen-5), $_;
print "</pre>";
|
You cannot have hyperlinks in <pre> elements.
| Quote: | but print ' ' x ($directorylen), <a
href=\"$File::Find::name\">$_</a>\n"; has a syntax error.
^ |
^ there's the ending quote,
^ where is the beginning quote?
Then you should fix it.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas |
|
| Back to top |
|
 |
John Bokma *nix forums Guru
Joined: 23 Feb 2005
Posts: 1136
|
Posted: Tue Jul 18, 2006 11:32 pm Post subject:
Re: start printing at the end of the previous line
|
|
|
Tad McClellan <tadmc@augustmail.com> wrote:
| Quote: | weberw@adelphia.net <weberw@adelphia.net> wrote:
How do you incorporate the print
' ' x line with a hyperlink? It works fine when it is not a hyperlink
for example
print "<pre>";
print ' ' x ($directorylen-5), $_;
print "</pre>";
You cannot have hyperlinks in <pre> elements.
|
Since when?
<!ENTITY % pre.exclusion "IMG|OBJECT|BIG|SMALL|SUB|SUP">
http://www.w3.org/TR/html4/sgml/dtd.html#pre.exclusion
(HTML 4.01 strict assumed).
Another way to get PRE behavior is to use the P element + CSS to make it
"pre"
--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/ |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|