start printing at the end of the previous line

W

weberw

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
 
J

Jürgen Exner

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
 
D

David Squire

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
 
W

weberw

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;
 
W

weberw

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 [....].
 
T

Tad McClellan

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.
^
^ there's the ending quote,
^ where is the beginning quote?

Then you should fix it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top