Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple columns?

Status
Not open for further replies.

oh5yw

Technical User
Dec 1, 2008
7
FI
I have this little script which prints all files from directory as links.

How can I modify it to print in 2 or 3 columns?

Kari

#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use strict;
use warnings;


use CGI qw:)all);


print header(),
ul( map li( a( {href => $_ }, $_ )), <*.*> )
;

 
After 'print header();' you could do something like:
Code:
my @parts;	# Partitioned list of files
{
	my @list = (<*.*>);
	for my $i (0..$#list) {
		push @{$parts[int($i / (scalar @list / 3) )]}, $list[$i];
	}
}
	
print table( {-border=>0 },
	Tr ( {-valign=>"top"}, 
		td( ul( li( [map {a( {-href=>$_}, $_ )} @{$parts[0]}] ))),
		td( ul( li( [map {a( {-href=>$_}, $_ )} @{$parts[1]}] ))),
		td( ul( li( [map {a( {-href=>$_}, $_ )} @{$parts[2]}] ))),
	) 
);
 
Thank you. That just what I needed. But it arise new questions...

Now ir brings files with names ie. 06122008.htm, 07122008.htm etc.

Can I make a filter which take in that name, rip off extension and put dots into right places so that 07122008.htm displays as 07.12.2008 ???

Thank you forehand

Kari
 
Have you tried to write any code to resolve the quesiton? You could use a regexp.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I am not familiar with perl code at all...I can make minor modifications to code with trial and error but that is all...sorry

Kari
 
If you're going to be doing much of this, you'll probably want to get a bit more familiar with perl.

In the mean time, see if this helps:
Code:
my @parts;	# Partitioned list of files
{
	my @list = (<*.*>);
	for my $i (0..$#list) {
		(my $temp = $list[$i]) =~ s/^(\d{2})(\d{2})(\d{4}).+/$1\.$2\.$3/;
		push @{$parts[int($i / (scalar @list / 3) )]}, [$list[$i],$temp];
	}
}

print table( {-border=>0 },
	Tr ( {-valign=>"top"}, 
		td( ul( li( [map {a( {-href=>$_->[0]}, $_->[1])} @{$parts[0]}] ))),
		td( ul( li( [map {a( {-href=>$_->[0]}, $_->[1])} @{$parts[1]}] ))),
		td( ul( li( [map {a( {-href=>$_->[0]}, $_->[1])} @{$parts[2]}] )))
	) 
);
 
This forum is superb!

ABove code nearly solved my problem. I had to use my script in upper directory, so had to change

my @list = (<*.*>); to my @list = (<NAME/*.*>);

now result is NAME/07122008.htm and that script can not do anything with it.

If I move 07122008.htm in to upper directory, everything works ok. So how can I remove NAME/ away before running that 07.12.2008 making script

sorry my bad english....

Kari
 
Did you try making any changes to the code to see if you could get it working?

Change:
Code:
(my $temp = $list[$i]) =~ s/[red]^(\d{2})(\d{2})(\d{4}).+[/red]/$1\.$2\.$3/;
to
Code:
 (my $temp = $list[$i]) =~ s/[blue][b].+\/(\d{2})(\d{2})(\d{4})\.htm/$1.$2.$3/[/b][/blue]
 
instead of:

Code:
my @list = (<*.*>);   to   my @list = (<NAME/*.*>);

try:

Code:
chdir('path/to/NAME') or die "$!";
my @list = (<*.*>);

If there is no other directory specific issues in your code that should work.


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
rhasrh, your code works fine. I tried to make modifications myself, but got always 500 Server Internal Error. But now everything is working just what I wanted.
Maybe it is now good time to download good Perl documentation.


KevinADC, your code worked also but link it made pointed to the root directory, not /NAME-directory. Luckily got rhasrh code working

Thank you both of you

Kari

in cold Finland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top