s0ttle has asked for the wisdom of the Perl Monks concerning the following question:

Here is my snippet:
my $entry = CGI->new(); $entry->p($font_o,'---[', b('Handle: '),$gbdata->{'handle'},br(),'----[', b('Email: '),$gbdata->{'email'},br(),'-----[', b('Website: '),$gbdata->{'url'},br(),'------[', b('IP: '),remote_host(),':',server_port(), br(),'-------[', b('Browser: '),user_agent(),br(),'--------[', b('Date & Time: '),$time, br(),br(),'[', b('Message'),']',br(), hr(),$gbdata->{'comments'},br(),hr(),'</font>',), end_html();
I want to take the above data and assign it to @contents below
unshift (@contents, $header, $entry);
obviously that assignment will not give the desired results. My question is, how can I get my data into @contents? I previously had the raw html assigned to $entry like so.
$entry = " <P>\n <FONT FACE=\"Verdana\" SIZE=\"1\"> ---[<B>Handle:</B> $GBINFO{'handle'}<BR> ----[<B>Email:</B> $GBINFO{'email'}<BR> -----[<B>Website:</B> $GBINFO{'url'}<BR> ------[<B>IP:</B> $ENV{'REMOTE_ADDR'}:$ENV{'REMOTE_PORT'}<BR> -------[<B>Browser:</B> $ENV{'HTTP_USER_AGENT'}<BR> --------[<B>Date&Time:</B> $hour:$min:$sec $end $days[$day2] $months[$ +month] $day\, $year<BR> <B>[Message]</B><BR> <HR> $GBINFO{'comments'}<BR> <HR>\n </P>\n </FONT>\n ";
but I rewrote the whole thing using CGI and this is the only part that I am in conflict with, any/all help much appreciated.

Replies are listed 'Best First'.
(Ovid) Re: Assigning CGI object data
by Ovid (Cardinal) on Dec 29, 2001 at 04:28 UTC

    I'm confused by your question. If you're using the function oriented interface (and you appear to be), instantiating a CGI object is useless. Try this:

    use CGI qw/:standard/; # vvv note the equals sign my $html = p($font_o,'---[', b('Handle: '),$gbdata->{'handle'},br(),'----[', b('Email: '),$gbdata->{'email'},br(),'-----[', b('Website: '),$gbdata->{'url'},br(),'------[', b('IP: '),remote_host(),':',server_port(), br(),'-------[', b('Browser: '),user_agent(),br(),'--------[', b('Date & Time: '),$time, br(),br(),'[', b('Message'),']',br(), hr(),$gbdata->{'comments'},br(),hr(),'</font>',), end_html(); unshift (@contents, $header, $html);

    That's what I think you mean. If you want to know how to assign separate HTML elements to an array, one way to do it is to use CGI::Pretty and split on the newlines.

    use strict; use CGI::Pretty qw/:standard/; use Data::Dumper; my @contents = split /\n/, b('<font face="arial">','---[', b('Handle: '),'Ovid',br(),'----[', b('Email: '),'ovid@ovidinexile.com',br(),'-----[', b('Website: '),'http://www.ovidinexile.com/',br(),'------[', b('IP: '),remote_host(),':',server_port(), br(),'-------[', b('Date & Time: '),scalar localtime, br(),br(),'[', b('Message'),']',br(), hr(),'Comments, anyone?',br(),hr(),'</font>',), end_html(); print Dumper \@contents;

    The second answer isn't perfect, but I don't think it was what you were looking for, anyway :)

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      The answer was so close, yet I was so distant. Thanks

      This first is what I needed:
      my $html = p($font_o,'---[', b('Handle: '),$gbdata->{'handle'},br(),'----[', b('Email: '),$gbdata->{'email'},br(),'-----[', b('Website: '),$gbdata->{'url'},br(),'------[', b('IP: '),remote_host(),':',server_port(), br(),'-------[', b('Browser: '),user_agent(),br(),'--------[', b('Date & Time: '),$time, br(),br(),'[', b('Message'),']',br(), hr(),$gbdata->{'comments'},br(),hr(),'</font>',), end_html(); unshift (@contents, $header, $html);


      -tengo mas que aprender