Re: FW: Html within code

2007-08-01 Thread Jay Savage
On 7/31/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote:


 Programming is a rigorous discipline.  Learning to do things right the first 
 time around achieves two things:

 1. You don't have to unlearn bad habits before you learn the good ones.

 2. Understanding the concepts behind the practice is easier.



Shawn,

This list isn't about programming. It's about Perl. That's a subtle,
but important difference. Programming is a discipline, a profession,
even. It is a set of techniques, communities of use, and best
practices that very only very slightly from application to
application.

Perl is a language. It is a collection of functions, operators, and
features. Those features are a fact, a pre-existing condition. And on
this list, at least, questions about them--even questions about the
ones that you, personally don't happen to like--need to be answered in
the spirit spirit in which they are asked. That is, in a spirit of
openness and learning. And perhaps most importantly, in the spirit of
Perl and the Perl community whose motto is TIMTOWTDI. In case you've
forgotten, there that means There Is More Than One Way To Do It.

Keeping that distinction in mind, it is usually inadvisable to respond
to a question about Perl with an answer about programming, and vice
versa. It's okay to mention your opinions about Current Best
Practices, of course, but then leave it at that.***  We're not here
to be programming Czars.

The beginner's list certainly isn't an appropriate place to get into
esoteric flame wars over 2 argument vs. 3 argument versions of open
and indirect filehandles. Save that for comp.lang.perl.misc.

Best,

-- jay

***Current Best Practices (CBP) are (c)2007 the current poster. CBP
are personal opinion of the current poster and do not necessarily
reflect the views of this station. Subject to change without notice.
Void where prohibited. CBP not valid in Vermont, New York, or the
Republic of Sealand.




--
This email and attachment(s): [ x ] blogable; [  ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!


Re: FW: Html within code

2007-08-01 Thread Rob Dixon

Mr. Shawn H. Corey wrote:


Rob Dixon wrote:


When someone is trying very hard to learn to write Perl that works at
all, I think it is /not/ the time to regale him with the rigours of
professional programming.


Programming is a rigorous discipline.  Learning to do things right the 
first time around achieves two things:


1. You don't have to unlearn bad habits before you learn the good ones.

2. Understanding the concepts behind the practice is easier.


I disagree, but I can see I'm not going to change your mind.

I'm just glad you didn't teach me to program.

Rob

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




Re: FW: Html within code

2007-07-31 Thread Mr. Shawn H. Corey

Rob Dixon wrote:

When someone is trying very hard to learn to write Perl that works at
all, I think it is /not/ the time to regale him with the rigours of
professional programming.

Rob



Programming is a rigorous discipline.  Learning to do things right the first 
time around achieves two things:

1. You don't have to unlearn bad habits before you learn the good ones.

2. Understanding the concepts behind the practice is easier.


--
Just my 0.0002 million dollars worth,
  Shawn

For the things we have to learn before we can do them, we learn by doing them.
 Aristotle

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




Re: FW: Html within code

2007-07-30 Thread Jay Savage
On 7/29/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote:
 The recommended usage of open is:

   open my $omarfh, '', 'junk' or die Input file 'junk' cannot be opened: 
 $!;

 The three argument is preferred as a malicious user could enter a file name 
 that starts with ''

It is preferred in code that accepts file names as user input and
doesn't perform taint checking. If the program uses a hard-coded
filenames, then no hurt, no foul. There can be no malicious user until
there is first a user.

Now OP knows at least three ways to tackle the problem. Yay! We're
learning! That's what this list is for.


if ( $my_way eq $only_way) {
 die PEBCAK error: programmer malfunction
} else {
 print EOF;
 Rule #1: TIMTOWTDI.
 Rule #2: If someone tells you otherwise, see rule #1.
EOF
}


-- jay
--
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!


Re: FW: Html within code

2007-07-30 Thread Mr. Shawn H. Corey

Jay Savage wrote:

On 7/29/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote:

The recommended usage of open is:

  open my $omarfh, '', 'junk' or die Input file 'junk' cannot be opened: $!;

The three argument is preferred as a malicious user could enter a file name that 
starts with ''


It is preferred in code that accepts file names as user input and
doesn't perform taint checking. If the program uses a hard-coded
filenames, then no hurt, no foul. There can be no malicious user until
there is first a user.


There's no time like the present to learn good habits.


--
Just my 0.0002 million dollars worth,
  Shawn

For the things we have to learn before we can do them, we learn by doing them.
 Aristotle

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




Re: FW: Html within code

2007-07-30 Thread Rob Dixon

Mr. Shawn H. Corey wrote:

Jay Savage wrote:

On 7/29/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote:

The recommended usage of open is:

  open my $omarfh, '', 'junk' or die Input file 'junk' cannot be 
opened: $!;


The three argument is preferred as a malicious user could enter a 
file name that starts with ''


It is preferred in code that accepts file names as user input and
doesn't perform taint checking. If the program uses a hard-coded
filenames, then no hurt, no foul. There can be no malicious user until
there is first a user.


There's no time like the present to learn good habits.


When someone is trying very hard to learn to write Perl that works at
all, I think it is /not/ the time to regale him with the rigours of
professional programming.

Rob

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




Re: FW: Html within code

2007-07-29 Thread Ken Foskey
On Thu, 2007-07-26 at 20:42 -0400, Mr. Shawn H. Corey wrote:
 Tom Phoenix wrote:
  On 7/25/07, Johnson, Reginald (GTI) [EMAIL PROTECTED] wrote:
  
  open (OMARFILE, junk || die input file cannot be openned:$!\n);

The brackets are in the wrong place.

The other answers were just far to clever  cryptic.

-- 
Ken Foskey
FOSS developer


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




Re: FW: Html within code

2007-07-29 Thread Rob Dixon

Ken Foskey wrote:


On Thu, 2007-07-26 at 20:42 -0400, Mr. Shawn H. Corey wrote:


Tom Phoenix wrote:


On 7/25/07, Johnson, Reginald (GTI) [EMAIL PROTECTED] wrote:


open (OMARFILE, junk || die input file cannot be openned:$!\n);


The brackets are in the wrong place.

The other answers were just far to clever  cryptic.


Hehe how true.

What this 


 open (OMARFILE, junk || die input file cannot be openned:$!\n);

does is

 open(OMARFILE, (junk || die input file cannot be openned:$!\n));

and because junk is true, die is never called and we have just

 open(OMARFILE, junk);

What I recommend instead is

 open OMARFILE, 'junk' or die Input file cannot be opened: $!;

Rob



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




Re: FW: Html within code

2007-07-29 Thread Mr. Shawn H. Corey

Rob Dixon wrote:

What I recommend instead is

 open OMARFILE, 'junk' or die Input file cannot be opened: $!;


The recommended usage of open is:

 open my $omarfh, '', 'junk' or die Input file 'junk' cannot be opened: $!;

The three argument is preferred as a malicious user could enter a file name that 
starts with ''

The lexically scoped file handler is preferred since it won't interfere with 
other file handlers.


--
Just my 0.0002 million dollars worth,
  Shawn

For the things we have to learn before we can do them, we learn by doing them.
 Aristotle

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




Re: FW: Html within code

2007-07-29 Thread Rob Dixon

Mr. Shawn H. Corey wrote:


Rob Dixon wrote:


What I recommend instead is

 open OMARFILE, 'junk' or die Input file cannot be opened: $!;


The recommended usage of open is:

 open my $omarfh, '', 'junk' or die Input file 'junk' cannot be 
opened: $!;


The three argument is preferred as a malicious user could enter a file 
name that starts with ''


The lexically scoped file handler is preferred since it won't interfere 
with other file handlers.


Sure, I agree Shawn, but I also think it's nice to change the OP's code
as little as possible to turn it into something that works as well as
possible.

Plus most of the published literature still uses bareword filehandles
and offering something different unnecessarily complicates things for
beginners.

And there is no way that line of code could be compromised so the mode
parameter is unnecessary.

Rob

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




Re: FW: Html within code

2007-07-26 Thread Mr. Shawn H. Corey

Tom Phoenix wrote:

On 7/25/07, Johnson, Reginald (GTI) [EMAIL PROTECTED] wrote:


open (OMARFILE, junk || die input file cannot be openned:$!\n);


No matter what virtues your technique has or lacks, this particular
line is surely broken; it will never die, even if the file can't be
opened. Check the table of precedence in the perlop manpage. Cheers!


Wow, lots of words; no help.

Things that are not in the documentation:

 open my $omarfile, '', junk or die input file \junk\ cannot be opened; 
$!;

Note the use of the lexical, 'my $omarfile', file handler.

Note the use of the tri-argument open.

Note the use of 'or die'.

(Note the correct spelling.)

Reading documentation is good; but it out of date with respect to best 
practices.  Reading `perldoc perlop` will not correct the errors in the 
statement.  Reading `perldoc -f open` will tell you what's possible but not 
what's the best practice.


--
Just my 0.0002 million dollars worth,
  Shawn

For the things we have to learn before we can do them, we learn by doing them.
 Aristotle

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




Re: FW: Html within code

2007-07-26 Thread Tom Phoenix

On 7/25/07, Johnson, Reginald (GTI) [EMAIL PROTECTED] wrote:


open (OMARFILE, junk || die input file cannot be openned:$!\n);


No matter what virtues your technique has or lacks, this particular
line is surely broken; it will never die, even if the file can't be
opened. Check the table of precedence in the perlop manpage. Cheers!

--Tom Phoenix
Stonehenge Perl Training

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




FW: Html within code

2007-07-25 Thread Johnson, Reginald \(GTI\)
  
 Is coding this way wrong? By this way I mean where you don't use a
 module to write html, but instead do it within the code by using print
 Content-type: text/html, \n\n;
 
 Example program
 
 #!/usr/bin/perl
 
 print Content-type: text/html, \n\n;
 
 open (OMARFILE, junk || die input file cannot be openned:$!\n);
 
 print EOF
 html
   head
titleOmar Metrics/title/head
  body
 div align=center
   h1TSM OMAR STATISTICS/h1
 /div
 EOF
 ;
   while ( $line =OMARFILE) {
chomp($line);
 if ($line ne  ) {
 ($fdt,$tod,$cap,$util,$actnodes,$gb,$att,$comp,$comppct,$bdays,$restor
 ecnt,$req,$setups) = split(/  /,$line);
 
 print EOF
 
 div align=center
 table border=1 cellspacing=0 cellpadding=0 width=50%
   tr
 td align=center valign=middle colspan=2bOMAR Metrics
 for $fdt to $tod /b/td
   /tr
   tr
 td valign=middle bgcolor=#00Backup Completion
 Percentage/td
 EOF
 ;
 if ($comppct = 98) {
 print EOF
 btd bgcolor=00FF99$comppct/td/b
   /tr
   tr
 EOF
 ;
 } #end if
 else {
 print EOF
 btd bgcolor=YELLOW$comppct/td/b
   /tr
   tr
 EOF
 ;
 } #end else
 print EOF
 
 td valign=middle bgcolor=#00Total Backup
 Attempts/td
 tdb$att/b/td
   /tr
   tr
 td valign=middle bgcolor=#00Total Backup
 Completions/td
 tdb$comp/b/td
   /tr
   tr
 td valign=middle bgcolor=#00Total Client Disk
 Capacity/td
 tdb$cap/b/td
   /tr
   tr
 td valign=middle bgcolor=#00Total Client Disk
 Utilization/td
 tdb$util/b/td
   /tr
   tr
 td valign=middle bgcolor=#00Total Active Client
 Nodes/td
 tdb$actnodes/b/td
   /tr
   tr
 td valign=middle bgcolor=#00Total Restores/td
 tdb$restorecnt/b/td
   /tr
   tr
 td valign=middle bgcolor=#00Total Business Days/td
 tdb$bdays/b/td
   /tr
   tr
 td valign=middle bgcolor=#00FFFGigabytes Written To
 Tape/td
 tdb$gb/b/td
   /tr
   tr
 td valign=middle bgcolor=#00FFFRemedy Client
 Request/td
 tdb$req/b/td
   /tr
   tr
 td valign=middle bgcolor=#00FFFNew Client Setups/td
 tdb$setups/b/td
   /tr
 /table
   br
 /div
 /body
 /html
 
 EOF
 ;
 } #end if
 else {
 next;
 } #end else
 
  } #end while
 close(OMARFILE);
 
 Sample junk file
 
 '06/01/2007 00:00'  '06/30/2007 23:59'  235 118.75  566
 43  11  10  98.900  21  204 2
 
 '05/01/2007 00:00'  '05/31/2007 23:59'  230 113 560
 41  12,324  12,025  97.500  23  33  21
 
 '04/01/2007 00:00'  '04/30/2007 23:59'  227 107 552
 38,807.011  11,784  98.300  21  15  24


This message w/attachments (message) may be privileged, confidential or 
proprietary, and if you are not an intended recipient, please notify the 
sender, do not use or share it and delete it. Unless specifically indicated, 
this message is not an offer to sell or a solicitation of any investment 
products or other financial product or service, an official confirmation of any 
transaction, or an official statement of Merrill Lynch. Subject to applicable 
law, Merrill Lynch may monitor, review and retain e-communications (EC) 
traveling through its networks/systems. The laws of the country of each 
sender/recipient may impact the handling of EC, and EC may be archived, 
supervised and produced in countries other than the country in which you are 
located. This message cannot be guaranteed to be secure or error-free. This 
message is subject to terms available at the following link: 
http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you 
consent to the foregoing.


Please consider the environment before printing this email.
inline: RecyclingSymbolGreen.jpg

Re: FW: Html within code

2007-07-25 Thread Ovid

--- Johnson, Reginald (GTI) [EMAIL PROTECTED] wrote:

   
  Is coding this way wrong? By this way I mean where you don't use
 a
  module to write html, but instead do it within the code by using
 print
  Content-type: text/html, \n\n;
  
  Example program
  
  #!/usr/bin/perl
  
  print Content-type: text/html, \n\n;
  
  open (OMARFILE, junk || die input file cannot be
 openned:$!\n);
  
  print EOF
  html
head

snip

It's definitely not recommended.  There are a number of issues with
this, but regarding the HTML, if you produce it, put it in a template
such as HTML::Template, Template Toolkit or similar.  With that, you
can just pass the relevant data to your template and keep your Perl
code clean.  It makes it easier to debug both the HTML *and* the Perl.

If you *must* have self-contained HTML (not recommended), then at least
encapsulate it into subroutines which don't obscure the main flow of
the program.

Cheers,
Ovid

--
Buy the book  - http://www.oreilly.com/catalog/perlhks/
Perl and CGI  - http://users.easystreet.com/ovid/cgi_course/
Personal blog - http://publius-ovidius.livejournal.com/
Tech blog - http://use.perl.org/~Ovid/journal/