Re: php like behavior for my perl CGI

2003-02-24 Thread Todd W
f'ups rearranged

  [EMAIL PROTECTED] wadet]$ perl
  sub box {
return('img src=p.gif height='.$_[0].' width='.$_[1].'');
  }
  print eot;
  table
tr
  td${\box(5,10)}/td
  td${\box(7,10)}/td
/tr
  /table
  eot
  Ctrl-D
  table
tr
  tdimg src=p.gif height=5 width=10/td
  tdimg src=p.gif height=7 width=10/td
/tr
  /table
 
  see:
 
  [EMAIL PROTECTED] wadet]$ perldoc perlref

Peter Kappus [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
...
 Aha!  This is exactly the kind of solution I was looking for.  I guess
what
 I'm doing here is passing a reference to a subroutine call?  \box(5,10)
and
 then turning it into a scalar?  ${}

Almost. In most contexts in perl, a { } construct is a BLOCK, and all code
in between the braces will be evaluated. So for our example, we call box
then return a reference to box()'s return value.

if a reference logically follows a $ in an interpolated string, the the
reference will be dereferenced.

Hence the desired results.

If (for some reason) we were passing a reference to the subroutine, it (
may ) look like this:

[EMAIL PROTECTED] wadet]$ perl
sub box {
  return('img src=p.gif height='.$_[0][0].' width='.$_[0][1].'');
}
print eot;
table
  tr
td${\box( [5,10] )}/td
td${\box( [7,10] )}/td
  /tr
/table
eot
Ctrl-D
table
  tr
tdimg src=p.gif height=5 width=10/td
tdimg src=p.gif height=7 width=10/td
  /tr
/table

and if you want to go OO:

package My::Img;

sub new {
  my($class, %params) = @_;
  return( bless( { %params }, $class ) );
}

sub box {
  my($self) = shift();
  return('img src=p.gif height='.$self-{height}.'
width='.$self-{width}.'');
}

package main;

print eot;
table
  tr
td${\ My::Img-new(height =5, width = 10)-box() }/td
td${\ My::Img-new(height =10, width = 5)-box() }/td
  /tr
/table
eot
Ctrl-D
table
  tr
tdimg src=p.gif height=5 width=10/td
tdimg src=p.gif height=10 width=5/td
  /tr
/table

but thats just silly ;0)

dont forget:

  see:
 
  [EMAIL PROTECTED] wadet]$ perldoc perlref

and for a real good time, check out

[EMAIL PROTECTED] wadet]$ perldoc perllol

 Quite ingenious.  While I'm sure I'll regret it later (and curse your good
 name as I'm wishing I'd taken the time to learn Mason or HTML::Template)
 this seems like a great quick fix for the time being.  And it never hurts
to
 learn a few new tricks!

Unfortunately theres nothing there I came up with on my own, and yes, new
tricks are always good for the 'ol grab bag =0).

HTH,

Todd W.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: php like behavior for my perl CGI

2003-02-20 Thread fliptop
On Thu, 20 Feb 2003 at 09:41, Peter Kappus opined:

[snip]
PK:Quite ingenious.  While I'm sure I'll regret it later (and curse your good
PK:name as I'm wishing I'd taken the time to learn Mason or HTML::Template)
PK:this seems like a great quick fix for the time being.  And it never hurts to
PK:learn a few new tricks!

mason and html::template are (imho) not similar.  mason is a mechanism for
embedding perl in your html (similar to the way php works), while
html::template is a way to dynamically stuff scalars and arrays into
static html files.

based on your original question, mason is probably more close to what your 
looking for as a php replacement than html::template is.

of course, you could probably use mason to call a cgi that outputs an
html::template, but i digress.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: php like behavior for my perl CGI

2003-02-19 Thread Todd W

Peter Kappus [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]
...
 Thanks to all who have responded to my rather vague request.  Indeed, I
 should clarify a bit what I'm looking for.

 Because I'm extremely lazy, I'd like to use certain formatting shortcuts
in
 my HTML.  In a given document, I might have 15 different spacer gifs of
 different sizes to aid in precise formatting that would look something
like
 this:

 img src=spacer.gif height=50 width=10/

no offense, but when I see blank gifs, I see anti-lazy...


 In PHP, or ASP, for example, I would write a spacer(height,width)
function
 and call it in my block of HTML like so:

 ?spacer(50,10)?

 which would create and send the image tag for me.
 I'd like, in perl, to do the following:

 printeob;
 table border=0
 TR
 TD?spacer(10,50)?/TD
 /TR
 /TABLE
 eob

 Ideally, I would overload the print function so that it would search for
 statements between ?? delimeters and execute them.
 Of course, I could also say:

 my $spacer1=spacer(10,50);
 my $spacer2=spacer(50,100);

 printeof;
 table
 TR
 TD$spacer1/TD
 TDsome stuff/TD
 TD$spacer2/TD
 /TR
 /TABLE
 eof

 but it seems like there should be an easier way with fewer keystrokes and
 fewer intermediate variables.


Well, you can save yourself a bundle of keystrokes and use a templating
system and cascading stylesheets, but heres a quick fix:

[wadet@ecg-redhat wadet]$ perl
sub box {
  return('img src=p.gif height='.$_[0].' width='.$_[1].'');
}
print eot;
table
  tr
td${\box(5,10)}/td
td${\box(7,10)}/td
  /tr
/table
eot
Ctrl-D
table
  tr
tdimg src=p.gif height=5 width=10/td
tdimg src=p.gif height=7 width=10/td
  /tr
/table

see:

[wadet@ecg-redhat wadet]$ perldoc perlref


 Perhaps, my dream is completely quixotic, but so far, it seems like the
kind
 of thing that must be very easy if only I knew the right trick...

You need to understand references and the underlying semantics of computer
data structures. Set theory dosent hurt either. Then you dont even have to
think about it. Like breathing.

Also the
 only real benefit I've seen of PHP over perl-cgi is the ease with which
one
 can mix HTML and code (Naturally, most web architects will jump at the
 opportunity to tell you why this is a very bad idea but it often makes
life
 easier for small projects)

Ive never had a project stay small for long.


 I hope this clarifies things a bit.  If not..I guess I'll just need to do
a
 few extra keystrokes :)

 Many thanks!

no prob,

Todd W.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: php like behavior for my perl CGI

2003-02-17 Thread Peter Kappus
Thanks to all who have responded to my rather vague request.  Indeed, I
should clarify a bit what I'm looking for.

Because I'm extremely lazy, I'd like to use certain formatting shortcuts in
my HTML.  In a given document, I might have 15 different spacer gifs of
different sizes to aid in precise formatting that would look something like
this:

img src=spacer.gif height=50 width=10/

In PHP, or ASP, for example, I would write a spacer(height,width) function
and call it in my block of HTML like so:

?spacer(50,10)?

which would create and send the image tag for me.
I'd like, in perl, to do the following:

printeob;
table border=0
TR
TD?spacer(10,50)?/TD
/TR
/TABLE
eob

Ideally, I would overload the print function so that it would search for
statements between ?? delimeters and execute them.
Of course, I could also say:

my $spacer1=spacer(10,50);
my $spacer2=spacer(50,100);

printeof;
table
TR
TD$spacer1/TD
TDsome stuff/TD
TD$spacer2/TD
/TR
/TABLE
eof

but it seems like there should be an easier way with fewer keystrokes and
fewer intermediate variables.

Of course, the larger issue here, is that I'd like to learn to temporarily
re-rout STDOUT to a subroutine that will manipulate whatever I send to a
print statement, before actually sending it to my desired output stream.


Perhaps, my dream is completely quixotic, but so far, it seems like the kind
of thing that must be very easy if only I knew the right trick...  Also the
only real benefit I've seen of PHP over perl-cgi is the ease with which one
can mix HTML and code (Naturally, most web architects will jump at the
opportunity to tell you why this is a very bad idea but it often makes life
easier for small projects)

I hope this clarifies things a bit.  If not..I guess I'll just need to do a
few extra keystrokes :)

Many thanks!

-peter


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: php like behavior for my perl CGI...and DBI followup

2003-02-15 Thread drieux

On Friday, Feb 14, 2003, at 19:02 US/Pacific, Peter Kappus wrote:
[..]

In PHP this can be streamlined by creating a function which prints out 
your
image tag for your and accepts the height and width as parameters. 
like so:

function spacer($y,$x){
	?img src=spacer.gif height=?=$y? width=?=$x??
}
[..]

i'd like to be able to use the  printeof; behavior to send large 
blocks
of HTML to the browser.  Is there A way that I can reroute that 
statement to
send my string through a sub that basically does the following:

sub sendit{
	my $txt = shift;
	$txt =~ s/\?(.+?)\?/(?{eval($1)})/g;  #evaluate what's between my
?? delimeters and print the result
	print $txt;
}
[..]

What I think you have stumbled into is the problem of wanting
on the one hand to pack php/javascript INTO the html that is to
be sent, while at the same time wanting to 'pre-process' the
text of the html page PRIOR to sending it that happens then to
want to 'evaluate' your php/javascript

I'll confess to being mostly confused by what you have
and what you want. The idea of the printeof;  which
you lay out a solution for, and then reject, because of the
typing count

So it's not clear which 'saving' you are really after.

I had a function

	sub set_image($$$)
	{
		my ($height, $width,$gif) = @_;
		$gif ||= 'spacer.gif';
		my $p = 'img src=' . $gif . ' heignt=' .
	$height .  width= . $width . '' ;
	}

which you would call with

	my $image = set_image(50, 128);

if you wanted to use the 'default' gif...
So that I could build up other things, one of which is
how I plonk them into a scalar called $page with gags like

	my $page = start_page($header, $meta, $jscripts);

	$page .= $foo . $image . $bar;

	$page .= do_end_of_page();

I of course 'collect' all of this into the scalar $page
which has all of the html - and then do something like

	make_header_and_send($page_type, \$page);

where that is defined as

#
#
sub make_header_and_send
{
	my ($type, $page_ref ) = @_;
	
	my $len = ($$page_ref) ? length($$page_ref): 0;
	
	my $head = simple_cgi_header($type, $len);
	
	if ( $len  0 ) {
		print $head . $$page_ref  ;
	}else{
		print $head ;
	}

} # end of make_header_and_send

#
#
sub simple_cgi_header($$)
{
	my ($type, $len) = @_;
	
	my $header = Content-Type: $type . $CRLF .
Content-Length: $len . $CRLF . $CRLF;

} # end of simple_cgi_header


As you will notice, I'm NOT trying to evaluate the '$page'
prior to sending Stuff that needs to get to the browser
so that it can solve 'browser side' reality, goes to the
browser, and we leave it to be happy there...

So you might want to resolve which 'saving' you are
trying to make in the process...


ciao
drieux

---


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]