niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Perl
start printing at the end of the previous line
Post new topic   Reply to topic Page 1 of 1 [8 Posts] View previous topic :: View next topic
Author Message
weberw@adelphia.net
*nix forums beginner


Joined: 09 Jul 2006
Posts: 22

PostPosted: Tue Jul 18, 2006 2:37 pm    Post subject: start printing at the end of the previous line Reply with 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
Back to top
Jürgen Exner
*nix forums Guru


Joined: 09 Apr 2005
Posts: 514

PostPosted: Tue Jul 18, 2006 2:59 pm    Post subject: Re: start printing at the end of the previous line Reply with quote

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

PostPosted: Tue Jul 18, 2006 3:06 pm    Post subject: Re: start printing at the end of the previous line Reply with quote

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

PostPosted: Tue Jul 18, 2006 4:50 pm    Post subject: Re: start printing at the end of the previous line Reply with quote

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

PostPosted: Tue Jul 18, 2006 6:05 pm    Post subject: Re: start printing at the end of the previous line Reply with quote

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

[...]
Quote:
print end_hmtl;


--
Glenn Jackman
Ulterior Designer
Back to top
weberw@adelphia.net
*nix forums beginner


Joined: 09 Jul 2006
Posts: 22

PostPosted: Tue Jul 18, 2006 9:07 pm    Post subject: Re: start printing at the end of the previous line Reply with quote

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

PostPosted: Tue Jul 18, 2006 10:35 pm    Post subject: Re: start printing at the end of the previous line Reply with quote

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

PostPosted: Tue Jul 18, 2006 11:32 pm    Post subject: Re: start printing at the end of the previous line Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [8 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 6:36 am | All times are GMT
navigation Forum index » Programming » Perl
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Printing from different browsers Godzilla Suse 0 Fri Jul 21, 2006 12:22 pm
No new posts bind keyboard POWER button to start some program Vladi Lemurov Debian 1 Fri Jul 21, 2006 6:00 am
No new posts PS-printing Bernstein Suse 0 Fri Jul 21, 2006 5:45 am
No new posts number of words in a line Fred J. C++ 3 Fri Jul 21, 2006 3:52 am
No new posts setting serial start value Greg Philpott PostgreSQL 4 Fri Jul 21, 2006 1:32 am

Bankruptcy | Loans | Credit Cards | 0 Credit Cards | Fish Tank Help
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1318s ][ Queries: 16 (0.0416s) ][ GZIP on - Debug on ]