Re: php like behavior for my perl CGI

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

> > [EMAIL PROTECTED] wadet]$ perl
> > sub box {
> >   return('');
> > }
> > print < > 
> >   
> > ${\box(5,10)}
> > ${\box(7,10)}
> >   
> > 
> > eot
> > Ctrl-D
> > 
> >   
> > 
> > 
> >   
> > 
> >
> > 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('');
}
print <
  
${\box( [5,10] )}
${\box( [7,10] )}
  

eot
Ctrl-D

  


  


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('');
}

package main;

print <
  
${\ My::Img->new(height =>5, width => 10)->box() }
${\ My::Img->new(height =>10, width => 5)->box() }
  

eot
Ctrl-D

  


  


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-20 Thread Peter Kappus
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?  ${}

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!

Thanks All.

-Original Message-
From: Todd W [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 19, 2003 12:32 PM
To: [EMAIL PROTECTED]
Subject: Re: php like behavior for my perl CGI


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('');
}
print <
  
${\box(5,10)}
${\box(7,10)}
  

eot
Ctrl-D

  


  


see:

[wadet@ecg-redhat wadet]$ perldoc perlref

-- 
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:
>
> 

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:
>
> 
>
> which would create and send the image tag for me.
> I'd like, in perl, to do the following:
>
> print< 
> 
> 
> 
> 
> 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);
>
> print< 
> 
> $spacer1
> some stuff
> $spacer2
> 
> 
> 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('');
}
print <
  
${\box(5,10)}
${\box(7,10)}
  

eot
Ctrl-D

  


  


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 Phil Fickas
Try the HTML::Template module.  See cpan.org to get the module.  It's sort
of what you are looking for.  Not too functional, but a start.  I use it to
separate my graphic/html coders from my cgi guys.

The documentation can be found here.

http://www.perldoc.com/cpan/HTML/Template.html

--Phil

-Original Message-
From: Peter Kappus [mailto:[EMAIL PROTECTED]] 
Sent: Monday, February 17, 2003 1:27 PM
To: [EMAIL PROTECTED]
Subject: RE: php like behavior for my perl CGI

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:



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



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

print<




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);

print<

$spacer1
some stuff
$spacer2


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]

-- 
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 fliptop
On Mon, 17 Feb 2003 at 10:26, Peter Kappus opined:

[snip]
PK:which would create and send the image tag for me.
PK:I'd like, in perl, to do the following:
PK:
PK:print<
PK: 
PK: 
PK: 
PK: 
PK:eob
PK:
PK:Ideally, I would overload the print function so that it would search for
PK:statements between  delimeters and execute them.
[snip]

you probably want to look at mason:

http://search.cpan.org/author/DROLSKY/HTML-Mason-1.18/lib/HTML/Mason.pm


-- 
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:



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



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

print<




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);

print<

$spacer1
some stuff
$spacer2


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){
	?>
}
[..]

i'd like to be able to use the  "print<
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 "print<' ;
	}

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]




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

2003-02-14 Thread Peter Kappus
Thanks to Rob for his Class::DBI suggestion earlier.  Looks like what I
needed was simply:

my %hash;
return $sth->fetchall_arrayref(\%hash);

to return an array of hashes...

As I'm continuing with my latest project, I'm finding myself wishing I could
do some PHP type things...specifically, as I'm formatting the HTML there's
often a need to throw in spacer gifs of various dimensions to make things
look pretty...

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){
?>  

and it would throw in an image tag with a height of 10 and a width of
50...or whatever.


My question is this:

i'd like to be able to use the  "print