[16414] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3826 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 27 18:20:50 2000

Date: Thu, 27 Jul 2000 15:20:34 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <964736433-v9-i3826@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 27 Jul 2000     Volume: 9 Number: 3826

Today's topics:
        Writing HTML within Perl (BUCK NAKED1)
        Writing HTML within Perl <Seb.Erlhofer@evc.net>
    Re: Writing HTML within Perl <aqumsieh@hyperchip.com>
    Re: Writing HTML within Perl (BUCK NAKED1)
    Re: Writing HTML within Perl <tony_curtis32@yahoo.com>
    Re: Writing HTML within Perl <uri@sysarch.com>
    Re: Writing HTML within Perl <mjcarman@home.com>
    Re: Writing HTML within Perl (Abigail)
        XSUB returning a LoL (Alex Graf)
        XSUB returning a LoL (Alex Graf)
    Re: XSUB returning a LoL (Greg Bacon)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 27 Jul 2000 14:02:41 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Writing HTML within Perl
Message-Id: <15512-39808751-7@storefull-242.iap.bryant.webtv.net>

Why does a print statement not always work when coded like this:

print <<HTML;
<html><head><title>HTML Page</title></head><body><font size='3'
color='#000066'>You are the  $num visitor to this
website.</font><BR></body></html>
HTML;

but seems to work fine if I code it like this: 
print "<html><head><title>HTML Page</title></head><body><font size='3'
color='#000066'>You are the  $num visitor to this
website.</font><BR></body></html>";

I thought they were supposed to work the same? 

Thanks,
Dennis



------------------------------

Date: Thu, 27 Jul 2000 23:12:36 +0200
From: Sebastian Erlhofer <Seb.Erlhofer@evc.net>
Subject: Writing HTML within Perl
Message-Id: <kc91os0hn4isj9o1n4mulvc5nlkdr4fgfv@4ax.com>


I use this...  and it works

print qq!
<HTML>
text
</HTML>
!;


hope that helps
Seb

On Thu, 27 Jul 2000 19:30:43 GMT, Ala Qumsieh <aqumsieh@hyperchip.com>
wrote:

>
>dennis100@webtv.net (BUCK NAKED1) writes:
>
>> Why does a print statement not always work when coded like this:
>> 
>> print <<HTML;
>> <html><head><title>HTML Page</title></head><body><font size='3'
>> color='#000066'>You are the  $num visitor to this
>> website.</font><BR></body></html>
>> HTML;
>> 
>> but seems to work fine if I code it like this: 
>> print "<html><head><title>HTML Page</title></head><body><font size='3'
>> color='#000066'>You are the  $num visitor to this
>> website.</font><BR></body></html>";
>> 
>> I thought they were supposed to work the same? 
>
>Because you didn't read the docs properly. Your end tag contains a
>semicolon while it shouldn't. Please try to read the docs carefully
>before posting.
>
>--Ala




------------------------------

Date: Thu, 27 Jul 2000 19:30:43 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Writing HTML within Perl
Message-Id: <7azon3fk0q.fsf@merlin.hyperchip.com>


dennis100@webtv.net (BUCK NAKED1) writes:

> Why does a print statement not always work when coded like this:
> 
> print <<HTML;
> <html><head><title>HTML Page</title></head><body><font size='3'
> color='#000066'>You are the  $num visitor to this
> website.</font><BR></body></html>
> HTML;
> 
> but seems to work fine if I code it like this: 
> print "<html><head><title>HTML Page</title></head><body><font size='3'
> color='#000066'>You are the  $num visitor to this
> website.</font><BR></body></html>";
> 
> I thought they were supposed to work the same? 

Because you didn't read the docs properly. Your end tag contains a
semicolon while it shouldn't. Please try to read the docs carefully
before posting.

--Ala


------------------------------

Date: Thu, 27 Jul 2000 15:24:21 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Writing HTML within Perl
Message-Id: <29809-39809A75-29@storefull-247.iap.bryant.webtv.net>

Sorry about that. I thought I had tested it without the semi(;) also.
While we're on the subject though, what is the preferred way? It seems
to me that 

print("This is a test for printing HTML inside of perl");   

OR

print "This is a test for printing HTML inside of perl";

is much easier to write than having to write the HTML inside of
container tags such as:

print <<EOF;
This is a test for printing HTML inside of perl<BR>
EOF

I couldn't find a section in the perl FAQ that gives several examples of
printing, and compares the different methods. Any direction(a URL
maybe?) to a good website tutorial on this would be appreciated.

Thanks again,
Dennis



------------------------------

Date: 27 Jul 2000 15:50:58 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Writing HTML within Perl
Message-Id: <87n1j3jo0d.fsf@limey.hpcc.uh.edu>

>> On Thu, 27 Jul 2000 15:24:21 -0500 (CDT),
>> dennis100@webtv.net (BUCK NAKED1) said:

> I couldn't find a section in the perl FAQ that gives
> several examples of printing, and compares the different
> methods. Any direction(a URL maybe?) to a good website
> tutorial on this would be appreciated.

Well, I always use the HTML shortcuts in CGI.pm, or
sometimes from HTML::AsSubs.  It gets rid of (most)
quoting problems where perl and HTML conflict.  It also
has that "objecty" and hierarchical feel as I like to
remember that HTML is about structured documents rather
than linear text.

But maybe that's just me.

t
-- 
"With $10,000, we'd be millionaires!"
                                           Homer Simpson


------------------------------

Date: Thu, 27 Jul 2000 21:21:03 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Writing HTML within Perl
Message-Id: <x7ya2n5kxs.fsf@home.sysarch.com>

>>>>> "BN" == BUCK NAKED1 <dennis100@webtv.net> writes:

  BN> print("This is a test for printing HTML inside of perl");   

  BN> OR

  BN> print "This is a test for printing HTML inside of perl";

  BN> is much easier to write than having to write the HTML inside of
  BN> container tags such as:

  BN> print <<EOF;
  BN> This is a test for printing HTML inside of perl<BR>
  BN> EOF

typical newbie confusion. here docs (the <<TOKEN thingy) HAS NOTHING TO
DO WITH THE PRINT COMMAND!!

<and who says i don't know where the shift key is?>

here docs are an alternate way of quoting multiline strings and they
have many advantages over double quotes in particular when printing
html.

first, since the delimiter is a bare toen on a line, you can use any
quote chars in the strings you want. no more backwahcked quotes when
printing hrefs. i HATE escaped quotes. they should never be done in perl
as there are too many good ways around it.

second, most html is multiple lines so you would have to do either
multiple print calls or a single long quote string instead of one here
doc. multiple print calls are slow and very ugly. one long quoted string
still needs the ; after it in a print statement and that is prone to
errors. and it still can't handle embedded doubel quote chars like a
here doc.

here docs have some minor problems too. they must be a complete set of
lines. you cannot have a partial line (no trailing newline) in a here
doc. and of course you can't have the token as a single line in the
text, but that should not be an issue. just pick a better token.

here is one use of here docs you rarely see:

	@paras = ( <<PARA, <<PARA, <<PARA ) ;
this is paragraph 1
PARA
this is paragraph 2
which has more lines than 1
PARA
this is paragraph 3
which has more lines than 1 and 2
since i made it that way
PARA


it is just a very useful multiline quote mechanism. it is NOT a part of
print.

GRRRR!!!

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


------------------------------

Date: Thu, 27 Jul 2000 16:28:47 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Writing HTML within Perl
Message-Id: <3980A98F.F80CAE6@home.com>

BUCK NAKED1 wrote:
> 
> what is the preferred way? It seems to me that
> 
> print("This is a test for printing HTML inside of perl");
> 
> OR
> 
> print "This is a test for printing HTML inside of perl";
> 
> is much easier to write than having to write the HTML inside of
> container tags such as:
> 
> print <<EOF;
> This is a test for printing HTML inside of perl<BR>
> EOF
> 

It depends on what you're printing. For single-lines, I agree but
here-docs are much nicer when printing out multiple lines of text. For
HTML, it's a little irrelevant, since it ignores linefeeds, but it's
quite useful when generating text files.

-mjc


------------------------------

Date: 27 Jul 2000 18:03:05 EDT
From: abigail@foad.org (Abigail)
Subject: Re: Writing HTML within Perl
Message-Id: <slrn8o1cch.vcg.abigail@alexandra.foad.org>

Sebastian Erlhofer (Seb.Erlhofer@evc.net) wrote on MMDXXII September
MCMXCIII in <URL:news:kc91os0hn4isj9o1n4mulvc5nlkdr4fgfv@4ax.com>:
// 
// I use this...  and it works
// 
// print qq!
// <HTML>
// text
// </HTML>
// !;


Untill you put an exclamation mark in your HTML.



Abigail
-- 
perl -we'$;=$";$;{Just=>another=>Perl=>Hacker=>}=$/;print%;'


------------------------------

Date: Thu, 27 Jul 2000 18:18:36 GMT
From: alex.graf@.....ec.gc.ca (Alex Graf)
Subject: XSUB returning a LoL
Message-Id: <3980762b.237410670@morgoth.sfu.ca>


Hello all,

Can someone please help me understand how to return an array with
RETVAL from an XSUB.

Attached is the XSUB I am working on.  It seems to work, but returns
an array reference instead of an array.  (Test output also follows)

Thanks in advance for any help

Alex.




AV *
cmdly_fetch (db_num, year, month)
   int db_num
   int year
   int month
   PREINIT:
   AV * ret;
   AV * valflag_pair;
   SV * val_sv;
   SV * flag_sv;
   SV * valflag_pair_ref;
   CMDLY_record rec;
   int d;
   float val;
   char flag[1];
   INIT:
   ret = newAV();
   CODE:
   if (db[db_num] && elems[db_num])
   {
      if (cmdly_fetch (db[db_num], year, month, &rec, elems[db_num])
== CM_OK)
      {
         for (d=0; d<31; d++)
         {
            flag[0] = rec.flag[d];
            if (flag[0] == 'M')
               val = -99999;
            else if (flag[0] == 'T')
               val = 0.0;
            else
               val = rec.data[d] * factors[(elems[db_num]->shift)+3];
            val_sv = newSVnv(val);
            flag_sv = newSVpvn(flag,1);
            valflag_pair = newAV();
            av_push (valflag_pair, val_sv);
            av_push (valflag_pair, flag_sv);
            valflag_pair_ref = newRV_inc((SV *)valflag_pair);
            av_push (ret, valflag_pair_ref);
         }
      }
      else
         printf ("cmdly_fetch failed\n");
   }
   else
      printf ("db, elem are null\n");
   RETVAL = ret;
   OUTPUT:
   RETVAL


-----------------part of  of test.pl:

@a = &CM::cmdly_fetch(1, 1999, 1);
print "@a\n";
print "$#a\n";
if ($#a >= 0)
 {
   for $aref (@a)
   {
      print "\t [ @$aref ],\n";
   }
   print "ok 3", "\n";
}
else
{
   print "not ok 3", "\n";
}


---------------- its output

ARRAY(0x4001a160)
0
         [ ARRAY(0x4001a220) ARRAY(0x40025340) ARRAY(0x4001f984)
ARRAY(0x4001f9b4) ARRAY(0x4001f9e4)
ARRAY(0x4001fa14) ARRAY(0x4001fa44) ARRAY(0x4001fa74)
ARRAY(0x4001faa4) ARRAY(0x4001fad4) ARRAY(0x400
1fb04) ARRAY(0x4001fb34) ARRAY(0x4001fb64) ARRAY(0x4001fb94)
ARRAY(0x4001fbc4) ARRAY(0x4001fbf4) ARRA
Y(0x4003d438) ARRAY(0x4003d468) ARRAY(0x4003d498) ARRAY(0x4003d4c8)
ARRAY(0x4003d4f8) ARRAY(0x4003d52
8) ARRAY(0x4003d558) ARRAY(0x4003d588) ARRAY(0x4003d5b8)
ARRAY(0x4003d5e8) ARRAY(0x4003d618) ARRAY(0x
4003d648) ARRAY(0x4003d678) ARRAY(0x4003d6a8) ARRAY(0x4003d6d8) ],
ok 3






------------------------------

Date: Thu, 27 Jul 2000 18:19:43 GMT
From: alex.graf@.....ec.gc.ca (Alex Graf)
Subject: XSUB returning a LoL
Message-Id: <39807d37.239214859@morgoth.sfu.ca>


Hello all,

Can someone please help me understand how to return an array with
RETVAL from an XSUB.

Attached is the XSUB I am working on.  It seems to work, but returns
an array reference instead of an array.  (Test output also follows)

Thanks in advance for any help

Alex.




AV *
cmdly_fetch (db_num, year, month)
   int db_num
   int year
   int month
   PREINIT:
   AV * ret;
   AV * valflag_pair;
   SV * val_sv;
   SV * flag_sv;
   SV * valflag_pair_ref;
   CMDLY_record rec;
   int d;
   float val;
   char flag[1];
   INIT:
   ret = newAV();
   CODE:
   if (db[db_num] && elems[db_num])
   {
      if (cmdly_fetch (db[db_num], year, month, &rec, elems[db_num])
== CM_OK)
      {
         for (d=0; d<31; d++)
         {
            flag[0] = rec.flag[d];
            if (flag[0] == 'M')
               val = -99999;
            else if (flag[0] == 'T')
               val = 0.0;
            else
               val = rec.data[d] * factors[(elems[db_num]->shift)+3];
            val_sv = newSVnv(val);
            flag_sv = newSVpvn(flag,1);
            valflag_pair = newAV();
            av_push (valflag_pair, val_sv);
            av_push (valflag_pair, flag_sv);
            valflag_pair_ref = newRV_inc((SV *)valflag_pair);
            av_push (ret, valflag_pair_ref);
         }
      }
      else
         printf ("cmdly_fetch failed\n");
   }
   else
      printf ("db, elem are null\n");
   RETVAL = ret;
   OUTPUT:
   RETVAL


-----------------part of  of test.pl:

@a = &CM::cmdly_fetch(1, 1999, 1);
print "@a\n";
print "$#a\n";
if ($#a >= 0)
 {
   for $aref (@a)
   {
      print "\t [ @$aref ],\n";
   }
   print "ok 3", "\n";
}
else
{
   print "not ok 3", "\n";
}


---------------- its output

ARRAY(0x4001a160)
0
         [ ARRAY(0x4001a220) ARRAY(0x40025340) ARRAY(0x4001f984)
ARRAY(0x4001f9b4) ARRAY(0x4001f9e4)
ARRAY(0x4001fa14) ARRAY(0x4001fa44) ARRAY(0x4001fa74)
ARRAY(0x4001faa4) ARRAY(0x4001fad4) ARRAY(0x400
1fb04) ARRAY(0x4001fb34) ARRAY(0x4001fb64) ARRAY(0x4001fb94)
ARRAY(0x4001fbc4) ARRAY(0x4001fbf4) ARRA
Y(0x4003d438) ARRAY(0x4003d468) ARRAY(0x4003d498) ARRAY(0x4003d4c8)
ARRAY(0x4003d4f8) ARRAY(0x4003d52
8) ARRAY(0x4003d558) ARRAY(0x4003d588) ARRAY(0x4003d5b8)
ARRAY(0x4003d5e8) ARRAY(0x4003d618) ARRAY(0x
4003d648) ARRAY(0x4003d678) ARRAY(0x4003d6a8) ARRAY(0x4003d6d8) ],
ok 3






------------------------------

Date: Thu, 27 Jul 2000 19:09:58 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: XSUB returning a LoL
Message-Id: <so1286u43j148@corp.supernews.com>

In article <3980762b.237410670@morgoth.sfu.ca>,
    Alex Graf <alex.graf@.....ec.gc.ca> wrote:

: Can someone please help me understand how to return an array with
: RETVAL from an XSUB.

You have an XY problem.  RETVAL is for returning single values.  If
you want to return a list of values, extend the stack and populate
it.  Look at the examples that use the EXTEND() and PUSHs() macros
in the perlxs manpage.

Greg
-- 
Never call a man a fool.  Borrow from him.


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 3826
**************************************


home help back first fref pref prev next nref lref last post