Thanx Clarles.This code is really cool.
I was looking something like this .


-----Original Message-----
From: Charles K. Clarkson [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 22, 2006 10:22 PM
To: beginners@perl.org
Subject: RE: Trying to add hyperlink

chen li wrote:

: How to convert the format above into an OOP style when
: adding a hyperlink? I am afraid  many people might
: have typo if they follow the format above.


    First, let's fix a few things with this implementation. Use the -w
or the warnings pragma, not both. The preference is for the pragma. Read
pererllexwarn in the docs for details. Always use strict.

: #!/usr/bin/perl -w
: use warnings;

#!/usr/bin/perl

use strict;
use warnings;


: use CGI qw/:standard/;
: print header, start_html("Stsd ILO Links"), h1("Stsd ILO Links");
:
: print table({-border=>undef,,-width=>'75%', -height=>'70%'},

    Under xhtml there is no height attribute for tables, you are
required to present a summary and 'border' cannot be undef under CGI.pm.
You also have an extra comma up there, though I don't think it hurts
anything.

print
    header(),
        start_html( 'Stsd ILO Links' ),
        h1( 'Stsd ILO Links' ),
        table(
            {
                -border  => 0,
                -width   => '75%',
                -summary => 'Table of Enclosure features',
            },

:         caption(strong('Web Page Under construction?')),
:         Tr({-align=>CENTER,-valign=>TOP},

    Under 'use strict', CENTER and TOP are illegal barewords. Put them
in quotes. Valid xhtml requires 'center' and 'top' (no capitilization).

            Tr(
                {
                    -align  => 'center',
                    -valign => 'top'
                },


:         [
:            th(['','Network Switch','Bay 1','Bay 2','Bay 3' ,'Network
Switch' ]),
:            th('Enclosure 1').td(['Bl20p G2','yes','yes']),
:            th('Enclosure 2').td(['no','no','yes'])


                    th( 'Enclosure 1' ) .
                    td(
                        [
                            a( { -href => '/' }, 'Bl20p G2' ),
                            a( { -href => '/' }, 'yes' ),
                            a( { -href => '/' }, 'yes' ),
                        ]
                    ),

                    th( 'Enclosure 2' ) .
                    td(
                        [
                            a( { -href => '/' }, 'no' ),
                            a( { -href => '/' }, 'no' ),
                            a( { -href => '/' }, 'yes' ),
                        ]
                    ),


:         ]
:   )
: );

    Use a comma here instead of a semicolon or add a print statement to
the next line. As Prabu already mentioned, you need to add an anchor to
each box you want to link from. There's no easy way around it.

    We could use a subroutines to eliminated some typing.

use strict;
use warnings;

use CGI qw/:standard/;
print
    header(),
        start_html( 'Stsd ILO Links' ),
        h1( 'Stsd ILO Links' ),
        table(
            {
                -border  => 0,
                -width   => '75%',
                -summary => 'Table of Enclosure features',
            },
            caption( strong( 'Web Page Under construction?' ) ),
            Tr(
                {
                    -align  => 'center',
                    -valign => 'top'
                },
                [
                    th(
                        [
                            '',
                            'Network Switch',
                            'Bay 1',
                            'Bay 2',
                            'Bay 3',
                            'Network Switch'
                        ]
                    ),

                    row(
                        'Enclosure 1',
                        '/' => 'Bl20p G2',
                        '/' => 'yes',
                        '/' => 'yes',
                    ),

                    row(
                        'Enclosure 2',
                        '/' => 'no',
                        '/' => 'no',
                        '/' => 'yes',
                    ),
                ]
            )
        ),
    end_html();

sub row {
    my $name = shift;
    return
        th( 'Enclosure 2' ) .
        td( anchors( @_ ) );
}

sub anchors {
    my @anchors = @_;

    my @return;
    while ( @anchors ) {
        push @return, a( { -href => shift @anchors }, shift @anchors ),
    }

    return [EMAIL PROTECTED];
}

__END__


    In OO style.

use strict;
use warnings;

use CGI;
my $q = CGI->new();

print
    $q->header(),
        $q->start_html( 'Stsd ILO Links' ),
        $q->h1( 'Stsd ILO Links' ),
        $q->table(
            {
                -border  => 0,
                -width   => '75%',
                -summary => 'Table of Enclosure features',
            },
            $q->caption(
                $q->strong( 'Web Page Under construction?' )
            ),
            $q->Tr(
                {
                    -align  => 'center',
                    -valign => 'top'
                },
                [
                    $q->th(
                        [
                            '',
                            'Network Switch',
                            'Bay 1',
                            'Bay 2',
                            'Bay 3',
                            'Network Switch'
                        ]
                    ),

                    row(
                        'Enclosure 1',
                        '/' => 'Bl20p G2',
                        '/' => 'yes',
                        '/' => 'yes',
                    ),

                    row(
                        'Enclosure 2',
                        '/' => 'no',
                        '/' => 'no',
                        '/' => 'yes',
                    ),
                ],
            ),
        ),
    $q->end_html();

sub row {
    my $q = CGI->new();

    my $name = shift;
    return
        $q->th( 'Enclosure 2' ) .
        $q->td( anchors( @_ ) );
}

sub anchors {
    my $q = CGI->new();

    my @anchors = @_;

    my @return;
    while ( @anchors ) {
        push @return, $q->a( { -href => shift @anchors }, shift @anchors
),
    }

    return [EMAIL PROTECTED];
}

__END__

HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.


--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/>
<http://learn.perl.org/first-response>



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to