RE: br -- problem caused by "Package"?

2003-06-07 Thread Charles K. Clarkson
Rob Richardson <[EMAIL PROTECTED]> wrote:
: 
: Here is the entire program:
: 
: #!/usr/bin/perl
: 
: use warnings;
: use strict;
: use CGI qw/:standard center *big delete_all/;

All the above functions from CGI.pm are imported
to 'main'. They are available as, for example,
'main::br' which can be written as 'br' or 'br()'.

: use ScheduleDay;
: use Train;
: 
: package Brtest;

We have left package main and are now in package
'Brtest'.

: my $testString = br;

There is no subroutine defined as 'br' which is
shorthand for 'Brtest::br'. So 'br' must be a bareword
which is not allowed under strict.


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328




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



RE: Subroutine Syntax

2003-06-15 Thread Charles K. Clarkson
david Greenhalgh <[EMAIL PROTECTED]> asked:
: 
: Been banging my head on this, I'm obviously missing
: something obvious, but I can't see what. Would someone
: put me out of my misery?
: 
: My code checks the value of a variable $status.
: $status can have three values, 0,1,2. 0 is good, 1
: and 2 are errors. So:
: 
: use strict;
: 
: if ($status) {
:   error($status);
: }
: 
: < DO STUFF>

Comments in perl begin with #, not <
Perl probably thinks you're referring to a
file handle in angle brackets.

: sub error {
: 
: 
: 
:   if ($_[0]=1) {

'=' is an assignment operator. You're testing if
$_[0] can be set equal to 1. Guess what? It can! It
will always be true.

if ( $_[0] == 1 ) {

:   
:   }
:   else {
:   
:   }
: }
: 
: With all of the sub definition commented out the code
: checks OK with perl -cT (Q. should that happen if I
: call a sub that I comment out when I'm using strict?)

-c checks syntax, it doesn't check to see if the
error sub was defined.

: But with the sub definition back in, perl -cT throws 
: up a  syntax error at sub error {,

The previous line doesn't end with ';'.


: and another syntax error at if($_[0]=1){

This is because warnings is on (see above).

HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328






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



RE: Some Qs about the -w switch and initializing vars.

2003-06-17 Thread Charles K. Clarkson
Daedalus <[EMAIL PROTECTED]> wrote:
: 
: Hi all,
: 
: I have a cgi prog that complains about uninitialized
: values when I use the -w switch. To avoid those errors
: I have done stuff like this:
[snip]

I think the best solution is a sub routine re-write.
I don't play with DBI much but I think bind-columns is
a poor choice for your fetch. (This is untested.)

sub address {
my $query   =  CGI->new;

my $searchid=  $query->param( 'searchid' );
   $searchid=~ s/\D//g;

my $sql = qq{
SELECT
name,
address1,
address2,
address3,
address4
FROM
db.addresses
WHERE
id = $searchid
};

#
# Assumes constants named
#   CONNECT_STRING, USER, PASSWORD
#   do exist
#
my $dbh = DBI->connect( CONNECT_STRING, USER, PASSWORD )
|| die "Unable to connect: $DBI::errstr";

my $sth = $dbh->prepare($sql) || die "Prepare failed: $dbh->errstr";

$sth->execute() || die "Execute failed for data retrieval:
$dbh->errstr";

my @address =  $sth->fetchrow_array
|| die "A record was not found for that ID";

my $address;
foreach my $line ( @address ) {

#
# This sets the undefined values returned
# by the query to ''
#
$line||= '';

$address  .= "$line\n";
}

return $address;
}

To get this to work in your program you would need
to call it as below. Having your sub routines return
values instead of performing output will aid you down
the road.

print address(); # instead of get_address();


: # Up near the top with a bunch of other defs and the main prog...
: my @init_array = ("","","","","","","","","","");

I wouldn't suggest using global variables.

: sub get_address
: {my ($dbh, $sth, $searchid, $name, $address1, $address2, 
: $address3, $address4) = @init_array;

Whenever you see variables followed by consecutive
numbers think: ARRAY. 


: 1. I am using the @init_array to avoid the
:majority of uninitialization errors.
:Is there a better way to do this?

Rule of thumb: A subroutine shouldn't use
variables that were not passed to it. (There
are exceptions - like constants.) This is easier
to read and tells the next programmer what your
doing.

my( $dbh, $sth, $searchid, @address ) = ('') x 8;

But, $dbh, $sth, and $searchid are
initialized later and 'fetch_array' will
over-write any initialization of @address.


Use 'my' to declare each variable the first
time a variable is used instead of at the
beginning of each code block. Try to maintain
the smallest scope possible. Don't litter your
file scoped variables with those used for
smaller scopes.
In fact, try to eliminate file scoped
variables. Constants are available across the
file and other programmers expect that they
will be used throughout the program.

 
: 2. Is there a better to handle the re-init
:of $address4? (DBD::Oracle must  return
:UNDEF or some such for an empty address4
:field.)

I would recommend either 'map' or the example
above on all suspect fetches or finding a query
that returns undef as ''.

my $address .= "$_\n" foreach map $_ ||= '', @address;


: 3. Are both of these questions moot because
:I should use -w  while developing the cgi,
:but remove it before actual use?

There is some debate whether removing
warnings is such a good thing. In a cgi program,
warnings go to the server logs and might
foretell a problem. I prefer using the module
to the command line switch. I leave warnings on
in production code as well as for testing. But
I'm not a full-time perl programmer. YMMV.


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328





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



RE: Problem with script headers.

2003-06-17 Thread Charles K. Clarkson
Nicholas Davey <[EMAIL PROTECTED]> wrote:
: 
: I hope I gave you enough info to maybe see
: why index.cgi is the only freaking page that
: doesnt work.

IMO you have two choices.

1 - Hire a programmer to debug it and
have her sign a confidentiality agreement.

2 - Post the code for index.cgi with the
confidential parts changed such that
it still generates the error.


Telling us about the code and about how paranoid
you are about your security won't aid us in solving
your problem. Scot's right, we need the code.



HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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



RE: Adding data to file

2003-06-18 Thread Charles K. Clarkson
Mike Blezien <[EMAIL PROTECTED]> wrote:

: I'm trying to change how data is currently being
: added to a file to condense it and make it easier
: to work with.
: 
: Below is the code snip that processes and adds
: the data to the appropriate file. The current
: Output to the file is what I am trying to change 
: and not having alot of luck.
: 
: The desired output to file is at the bottom of
: this post. Any suggestions or help to accomplish
: this would be much appreciated. Basically take
: the current output to file:
:
: IE:
[snip]

I think one problem is you need to convert all
the subcategory files to the new file format *before*
you start adding new keywords to the files.

 Another problem is that you are visualizing
your data as it is, instead of changing it to a
convenient perl data structure. This whole data set
is screaming hash, and you're using an array.
 Let me clarify. Each line of a subcategory file
looks like something this to you:

2D-Animals~animals
2D-Animals~bee
2D-Animals~whale

While I see:

categorykeyword
===
2D-Animals  animals
2D-Animals  bee
2D-Animals  whale


You want to end up with:

2D-Animals~animals::bees::whale

And I see:

2D-Animals => [ 'animals', 'bees', 'whale', ]


# load old file format
my $file = "$maincatlogs$MainCat.catlog";
open FH, $file or die "Cannot open $file: $!";
chomp( my @category =  );
close FH;

# change it to a perl data structure
#   a Hash of Arrays (HoA)
#   see perldsc
#
my %categories;
foreach ( @category ) {
my( $category, $keyword )= split /~/;
push @{ $categories{ $category } }, $keyword;
}

# change to the new file format
my @file;
foreach my $key ( keys %categories ) {
push @file, "$key~", join '::', @{ $category{ $key } };
}

# change the disk to the new format
open FH, ">$file" or die "Cannot open $file: $!";
    print sort @file;
close FH;

You can read more about perl data structures in
perldsc.


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328













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



RE: saving a textarea to a text file

2003-06-26 Thread Charles K. Clarkson
Camilo Gonzalez <[EMAIL PROTECTED]> top posted:
: 
: Andrew Brosnan wrote:
: 
: >use CGI;
: >my $q = new CGI;
: >my $record = $q-param('text_field');
: >open(OUTFILE, ">output.txt") or die "Can't open output.txt: $!";
: >print OUTFILE $record;
:
: Wrong. Try:

Besides the close, these look the same to me. How is
Andrews' solution wrong?
 
: use CGI;
: my $q = new CGI;
: my $record = $q->param('text_field');
: open(OUTFILE, ">output.txt") or die "Can't open output.txt: $!";
: print OUTFILE $record;
: close OUTFILE;


Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328




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



RE: Why should I create an object? (long)

2003-06-27 Thread Charles K. Clarkson
Greenhalgh David <[EMAIL PROTECTED]> wrote:
: 
: Bare in mind that I am still a beginner at coding. Why
: is it "good practice" to create an object when using
: CGI, rather than just diving in?
: 
: For example:
: 
: use CGI ':standard';
: my $q=new CGI;
: my $input=$q->param('input');
: 
: and
: 
: use CGI ':standard';
: my $input=param('input');
: 
: both put the contents of 'input' into $input and the
: last one has less lines and less opportunity for typos,
: but the first is better practice than the second.
: Gently, please; why?

Your first example is poorly written. It is better
written;

use CGI;
my $q = new CGI;


Understanding this will help you understand why
objects tend to present better programming practice.
I'll bet you have never looked under the hood of your
programs. Let's pop the bonnet and take a peek. There
is a special variable under the hood called "%main::"
or just "%::". It is also known as the symbol table.
Let's take a look at it:

#!/usr/bin/perl

#use strict;
#use warnings;
#use CGI qw(:standard);

printf "% 22s => % s\n", $_, $::{ $_ } foreach keys %::;

On my system this produces about 33 entries. Let's
add strict and warnings:

#!/usr/bin/perl

use strict;
use warnings;
#use CGI qw(:standard);

printf "% 22s => % s\n", $_, $::{ $_ } foreach keys %::;


Now I am up to 40 entries in %::. Let's see
what happens when we add CGI.pm:

#!/usr/bin/perl

use strict;
use warnings;
use CGI qw(:standard);

printf "% 22s => % s\n", $_, $::{ $_ } foreach keys %::;


I now show 194 entries in the symbol table. Now
let's look at the object-oriented method of using
CGI.pm:

#!/usr/bin/perl

use strict;
use warnings;
use CGI;

printf "% 22s => % s\n", $_, $::{ $_ } foreach keys %::;

Now I only have 55 entries. What are those
other 139 entries from ':standard'? They're mostly
subroutines that have been added to our script. So
we see that objects tend to import less into main.
They are (usually) better behaved.


Another important thing about objects is that
you can easily make them more robust. Let's say you
need to do provide a common object to a bunch of
scripts on a web site. They list the states
according to district. You also want to use the
same title, author, style sheet for each page.

For better or worse you decide to create an
object based on CGI.pm. Here's the object. I
didn't take the time to comment this just cut
& paste it into a file named My_CGI.pm.

package My_CGI;

use base CGI;

sub start_html {
my $self = shift;

# return regular call if arguments were passed
return
$self->SUPER::start_html( @_ ) if @_;

# return default call if no arguments were passed
return
$self->SUPER::start_html(

-head => $self->Link( {
-rel   => 'stylesheet',
-href  => 'css/district.css',
-type  => 'text/css'}),
-title   => 'District Form',
-author  => '[EMAIL PROTECTED]',
);
}

sub district_1_popup {
my $self= shift;
my $default = shift || 'TX';

# states in this district
my %states = (
AZ  => 'ARIZONA',
AR  => 'ARKANSAS',
OK  => 'OKLAHOMA',
LA  => 'LOUISIANA',
TX  => 'TEXAS',
);

# in case we pass in a state that is
#not in this district
$default = 'TX' unless $states{ $default };

$self->popup_menu( {
name=> 'district_1_state',
values  => [ keys %states ],
default => $default,
labels  => \%states }
);
}

sub district_2_popup {
my $self = shift;
my $default = shift || 'FL';

# states in this district
my %states = (
MS  => 'MISSISSIPPI',
GA  => 'GEORGIA',
FL  => 'FLORIDA',
);

# in case we pass in a state that is
#not in this district
$default = 'FL' unless $states{ $default };

$self->popup_menu( {
name=> 'district_2_state',
values  => [ keys %states ],
default => $default,
labels  => \%states }
    );

}

1;


And our script might look like:

#!/usr/bin/perl

use strict;
use warnings;

use My_CGI;

my $q = My_CGI->new();

print
$q->header(),
$q->start_html(),
$q->district_1_popup(),
$q->end_html();

__END__


When we call $q->start_html() our module
calls CGI.pm with default arguments. The new
method (district_1_popup) calls CGIs
popup_menu() method and returns the
pre-defined states.


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


































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



RE: Packages, run modes, and scopes, oh my

2003-06-27 Thread Charles K. Clarkson
Have you seen the tutorials at perlmonks?

http://www.perlmonks.com/index.pl?node=Tutorials


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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



RE: CGI Module Reference

2003-07-07 Thread Charles K. Clarkson
Shaw, Matthew [mailto:[EMAIL PROTECTED] 
: 
:   Could someone direct me to a reference that contains all of the
: available methods in the CGI module?

http://stein.cshl.org/WWW/software/CGI/cgi_docs.html

There is also one on the computer where you installed
perl, at perldoc.com, on CPAN, at ActiveState, etc. You
could probably find a whole bunch of links and other
information about CGI.pm from a google search, but you
probably did that before you asked.

HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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



RE: split function problem.

2003-07-09 Thread Charles K. Clarkson
Sara <[EMAIL PROTECTED]> wrote:
: 
: An input string like;
: 
: $name_with_id = "Deiley, Sara Jr., 1234";
: 
: another example could be
: 
: $name_with_id = "DEILEY SARA, Jr,. 123";
: 
: Two things are for sure in it always.
: 
: 1- First part contains the alphabets (caps or small) with any 
: number of commas and periods (full stops) in between or at the end.
: 
: and then always a white space, followed by:
: 
: 2- the last part contains the digit/number which could be 2 - 
: 5 digits long.


: I am trying this;
: 
: $name_with_id = "Deiley, Sara Jr., 1234";
: 
: split (/[^\d]+/, $name_with_id) = ($name,$id);

[^\d]+ will match anything that is *not* a
digit. and appears more that one time in the
search string. In our example string, it splits
on: "Deiley, Sara Jr., ". All of which is not a
digit.

To find the last part we could use: \d{2,5}
William of Occam gave pretty good advice:
"Entities should not be multiplied unnecessarily."

 
: print "name: $name and ID: $id";
: 
: Error: Can't modify split in scalar assignment at line 3;

Unlike 'substr', split can only be on the right
side of an equation. If you set split equal to
something, you'll get the error above. So this
would seem more logical:

my ($name,$id) = split (/\d{2,5}/, $name_with_id);

The problem is that split discards the
part we're looking for: \d{2,5} unless we
place it in parenthesis.

my( $name, $id ) = split / (\d{2,5})/, $name_with_id;

This should throw away the space and keep the
digits:

use strict;
use warnings;
use Data::Dumper;

my $name_with_id = "Deiley, Sara Jr., 1234";

print Dumper [ split / (\d{2,5})$/, $name_with_id ];

__END__

HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328






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



RE: split function problem.

2003-07-09 Thread Charles K. Clarkson
Sara <[EMAIL PROTECTED]> wrote:
: 
: One more question I searched the google for
: "HTH" abbreviation but didn't find anything.
: 
: Can you tell me what does it mean?

Hope That Helps

And sometimes:

Hotter Than Hell   :)




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



RE: Display timing

2003-07-10 Thread Charles K. Clarkson
Rod Jenkins <[EMAIL PROTECTED]> wrote:
: 
: First of all I just started using cgi last week.
: So, if you see something strange in my code it
: would be lack of knowledge.  
: Here is the
: question:
: 
: I have some lines that display stuff, then do
: more code, then display more stuff.  Is there
: a way to get the first stuff displayed before
: the other code runs?  here is an example:

Your running into a problem with the buffer.
Perl's buffer is controlled by the special perl
variable '$|'. You can read more about it in
'perlvar'.

Block buffered output is the default. To
set STDOUT to line buffer output change '$|' to
a non-zero value.

: #!/usr/bin/perl
: use strict;
: use warnings;
: use diagnostics;

Wow, you read the right books!


Add:

$|++;

Or:

$| = 1;

: use CGI qw(:standard);  #I really do not understand the qw
: use CGI::Carp qw(fatalsToBrowser);# or the qw here


'qw' is described in 'perlop' under the Quote and
Quote-like Operators section. I think of it as the
"quote word" function because it puts single quotes
around each word it finds.

The list following a 'use Module' call is sent to
a subroutine of the module called 'import'. import
usually imports something into the scripts namespace.



use CGI qw(:standard);

Imports a large group of functions. You can import
individual functions by not preceding them with ':'.
Take a look at the CGI.pm documentation to get all the
details. In your program the line is not needed. You
are not using CGI.pm functions.


use CGI::Carp qw(fatalsToBrowser);

This line will send your errors to the browser.
Normally they go to your logs and you get a 500
server error in the browser. This line is considered
insecure once your script goes into production.


Welcome to perl,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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



RE: checkbox label font

2003-07-11 Thread Charles K. Clarkson
Sawsan Sarandah <[EMAIL PROTECTED]> wrote:
: 
: Greetings,
: 
: In a checkbox form, how can I change the 
: attribute for the "label" text below to Arial
: instead of the default?

The  is deprecated. Use stylesheets (CSS)
or use the 'style' attribute.

: $cgi->checkbox(-name=>'checkboxname',-value=>'turned 
: on',-label=>"I want
: Arial here");

Option 1:

Wrap a span with an embedded style around
the checkbox. 

$cgi->span(
{ style => 'font-family: Arial' },
$cgi->checkbox(
-name   => 'checkboxname',
-value  => 'turned on',
-label  => 'I want Arial here',
),
);

Option 2:

Wrap a span around the checkbox with
a class name.

$cgi->span(
{ class => 'checkbox' },
$cgi->checkbox(
-name   => 'checkboxname',
-value  => 'turned on',
-label  => 'I want Arial here',
),
);

And in the stylesheet (html languages only):

span.checkbox {
font-family:Arial;
display:inline;
}


In the stylesheet (applies to all document
languages):

span[class=checkbox] {
font-family:Arial;
display:inline;
}


Check out http://www.w3.org/TR/REC-CSS2/
for more info on CSS. Note that font-family
should really include more than one font if
you want good control. Fortunately, there
is a whole chapter on fonts at the above
link.


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328






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



RE: File existence under Microsoft IIS

2003-09-06 Thread Charles K. Clarkson
Mike <[EMAIL PROTECTED]> wrote:

: To elaborate, I had to set 2 path variables. One to
: define the absolute path of the uploaded image files on
: the web server, and the other to define the relative
: path (from the perl program) to the image files.

There is no need to use relative paths from the perl
program. You can use absolute paths for the whole site
unless you move directories often. Define a subroutine
which adds the file system root to the absolute path
from the web root.

For example:

C:\example\home\ is web root on file system
/images/ is the image directory
/code/perl/  is where the perl code resides

A relative path might look like "../../image/file.png"
The absolute path would be: "/image/file.png"

In code you could write a sub routine for
existence:

sub exists {
return -e "C:/example/home$_[0]";
}

Feed it an absolute path from the web root:

$filename = '/images/file.jpg';

if ( exists( $filename ) ) {
#
    # Do something with $filename
#
}

HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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



RE: guestbook mySQL / PERL

2003-09-24 Thread Charles K. Clarkson
David Gilden <[EMAIL PROTECTED]> wrote:
: 
: Please let me know how I can Improve my script and if
: you see anything that is bad style/practice.

I just did a quick copy & paste. Here are my initial
reactions. You're using strict and warnings. Kudos. You
are using white space and indentation but you are not
using the same indentation throughout your program.

You are using all your variables at file scope. Try
to avoid this. Use the smallest scope possible and get
out of the habit of declaring your variables all at the
same time. declare them as you use them.

Call subroutines without the '&' prefix. Use
initialize_dbi() instead of &initialize_dbi. In fact it
would be best to return the database handle:

# line up like terms when appropriate
my $user_name = "";
my $user_password = "";
my $sql_server= "#";

# return the database handle rather that setting a
# global from within the sub
my $dbh = initialize_dbi( $sql_server, $user_name, $user_password )
.
.
.

sub initialize_dbi {
my( $sql_server, $user_name, $user_password ) = @_;

# I didn't know you had to this?
# I haven't done DBI much though.
my $drh = DBI->install_driver( 'mysql' );

my $dbh = DBI->connect("DBI:mysql:$user_name:$sql_server",
 $user_name, $user_password);

# Do not return this error message in production code.
die "Cannot connect: $DBI::errstr" unless $dbh;

return $dbh;
}

We now know where $dbh came from. And where $sql_server,
$user_name, and $user_password went to. In the sub we know
what was passed in and what was passed out.

In most functions you retrieve some data, process it,
and return a result. The processing should not affect
or be effected by an outside variable that was not passed
in (except in the case of constants, persistent variables,
and some rare occasions). Using global variables like
you're doing *will* bite you down the line.

Here's a conversion (I didn't test it) for
run_statement():


# Get total records
my $sth= run_statement( $dbh, "select * from guestbook;");
my $maxEntries = $sth->rows;

# This may also work. You'll need to test it.
my $maxEntries = run_statement( $dbh, "select * from guestbook;" )->rows;

sub run_statement {
my( $dbh, $statement ) = @_;
my $sth = $dbh->prepare( $statement );
$sth->execute;

return $sth;
}

Nothing in run_statement() is affected by or effects
variables outside its scope other than through its return
value.

Stick to the same style for separating words in your
variables and subs throughout the entire program. I prefer
using the underscore: run_statement(), not RunStatement().
Whichever you choose, stick to it. And try not to abbreviate
When you need help later on, it might be someone who doesn't
use English as a first language trying to help.



HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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



RE: Perl Script in Tables

2003-10-23 Thread Charles K. Clarkson
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
 
: I solved it by myself, just wanted to post the solution
: even if it's so simple, maybe it could useful for someone.
: I just forgot the first instruction of any perl script in
: HTML: print "Content-type: text/html\n\n";
: I put this instruction just after #!/usr/bin/perl, and
: now anything works correctly, no need to print hear,
: start_html and end_html.

So, each CGI program you have starts with:

#!/usr/bin/perl
print "Content-type: text/html\n\n";


That may be a really bad idea. If your program has an
error then the error might print to the browser and reveal
information to someone who shouldn't see it. As a perl
programmer, security is one of the things you should pay
attention to.

I start CGI programs with:

#!/usr/bin/perl -T

use strict;
use warnings;

use CGI;

The CGI.pm module, which is included with the perl
distribution, has some excellent examples. You can also
read Ovid's course on programming with CGI.pm:

http://users.easystreet.com/ovid/cgi_course/


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328













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



RE: Perl Script in Tables

2003-10-23 Thread Charles K. Clarkson
Paolo <[EMAIL PROTECTED]> wrote:
: 
: print table({-width=>'100%', -bgcolor=>'#DC00DC', -border=>3},
:   Tr([
:   td(['text left', 'text right']
:   ])
:   );
: How can I modify this commands to make the 'text left' 
: element width 20% of the table, and 'text right' element
: the rest?

 I don't think you can:

print
table( { -width => '100%', -bgcolor => '#DC00DC', -border => 3 },
Tr( [
td( { -width => '20%' }, 'text left'  ),
td( { -width => '80%' }, 'text right' ),
])
);

If you need to print a bunch of rows like this, create
a subroutine:

print
table( { -width => '100%', -bgcolor => '#DC00DC', -border => 3 },
row( 'text left', 'text right' ),
row( 'more text left', 'more text right' ),
        row( 'still more text left', 'still more text right' ),
);

sub row {
return
Tr( [
td( { -width => '20%' }, $_[0] ),
td( { -width => '80%' }, $_[1] ),
]);
}

HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328





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



RE: cgi script not workingI

2003-10-23 Thread Charles K. Clarkson
radhika sambamurti <[EMAIL PROTECTED]> wrote:
: 
: I am trying to include the file ra_require.pl in Alogin.pl - 
: details are below.
: 
: This script is calling a subroutine from the cgi script below
: They are both cgi scripts.
: When I submit my request via a html form (let us call it 
: login.html) - it is supposed to call Alogin.pl, but it is not working.

It works if you test it from the command line. It is
returning an error:

ra_require.pl did not return a true value at aa.pl line 7.


If you don't want it to do that, add "1;" to the end of
ra_require.pl:

.
.
.
: 
: 
: 
: EOF
: }

1;


For future reference it would be better to tell us
what error you receive rather than "it is not working".
You should also test from the command line as well as
from a browser. If you don't have access to your
server's command line, install perl locally on your
own computer.


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328









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



RE: Hit counter

2003-11-13 Thread Charles K. Clarkson
parvez mohamed <[EMAIL PROTECTED]> wrote:
 
: Andrew Gaffney <[EMAIL PROTECTED]> wrote:
:  
: : I want to write a CGI in perl that when called, grabs a
: : number from a MySQL db or a file, increments it, writes
: : the number back out, and then returns a GIF with that
: : number. I want to have 10 separate GIFs, each one
: : containing an image (that I have created to match the
: : site design) of a number, 0-9. I need to be able to piece
: : together any number of these GIFs from left to right into
: : one large (relatively) GIF. I know how to do everything
: : but actually create the GIF. Can anyone point me in the
: : right direction?: 
:
: Plaese use http://www.scriptarchive.com/readme/counter.html
:  

That's probably a quick solution, but not necessarily a
good idea. Below is header for counter.pl. While the script
is widely used, it is eight years old and has not been
updated in more than seven years. It teaches new perl
programmers (the focus of this list) some very poor habits.
I would not recommend it for a beginner perl programmer.

<<
#!/usr/local/bin/perl
###
# Counter   Version 1.1.1  
# Copyright 1996 Matt Wright[EMAIL PROTECTED]
# Created 10/27/95  Last Modified 4/25/96  
# Scripts Archive at:   http://www.scriptarchive.com/  
>>


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328






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



RE: Javascript problems with -script

2003-11-23 Thread Charles K. Clarkson
On Sunday, November 23, 2003 6:42 PM,
Mike Schienle <[EMAIL PROTECTED]> wrote:

[snip]
: Can someone point out what I'm missing in the -script section
: that's commented out that would make it not work correctly?
: The source of the file that's referenced is identical to what's
: in the JSCRIPT variable.

It works fine for me. Just to be certain let's see
if we are speaking of the same thing. There are three
ways to go here:

1. Generate a script tag:

-script => {
-language   => 'JAVASCRIPT',
-src=> '/delta/js/openWin.js'
},

  

2. Generate an inline script:

-script => $JSCRIPT,

  
  <!-- Hide script
  //<![CDATA[
 function OpenWin() {
   var myWindow;
   var width = parseInt(screen.availWidth/3*2);
   var height = parseInt(screen.availHeight/3*2);
   var left = parseInt((screen.availWidth/2) - (width/2));
   var top = parseInt((screen.availHeight/2) - (height/2));
   var windowFeatures = "width=" + width + ",height=" + height +
 ",status,resizable,left=" + left + ",top=" + top +
 ",screenX=" + left + ",screenY=" + top;
   myWindow = window.open("", "E-TimOutput", windowFeatures);
 }
  
  //]]> End script hiding -->
  


3. Generate both:
 
-script => [
$JSCRIPT,
{
-language   => 'JAVASCRIPT',
-src=> '/delta/js/openWin.js'
},
],


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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



RE: CGI Redirection

2003-11-26 Thread Charles K. Clarkson
Ash Singh <[EMAIL PROTECTED]> wrote:

: print $query->redirect('http://www.google.com ');
 
: Thanks a lot for your assistance, I need to redirect
: and the browser automatically go to that location,
: without any user intervention.  Is there any way to
: do this.

It depends upon your definition of user
intervention. If you show us more code and explain
what you are trying to do, I might be of more help.
Are you indicating that the code you give above isn't
working?


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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



RE: Script within a script

2004-01-14 Thread Charles K. Clarkson
Kenneth W. Craft MCP <[EMAIL PROTECTED]> wrote:
: 
: Is it possible to execute a perl script within another perl
: script?
: 
: I have advertisements on many of my pages of my site that
: are randomly picked using a random ad script. I am creating
: some pages that are dynamically being created, and I can't
: use ssi to pull the ads into the page (right now on my main
: page I use  to call the ad scripts.

Are you dynamically creating the content or the structure
of the web page? If the structure remains the same, you could
call the dynamic content from SSI and leave the rest of the
page as is. This might have the additional benefit of possibly
allowing the design to change independent of the content.


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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




RE: Tables

2004-01-22 Thread Charles K. Clarkson
Rod <[EMAIL PROTECTED]> wrote:
: 
: I am looking for an example of doing tables with cgi.pm.
: 
: I have done some looking but have not found any good 
: examples.  All my code so far uses OOP.  The examples I
: did find did not use OOP.


I don't really use tables much any longer, but if you
could send me an example you think is good, I could
translate from function oriented to OO and clean it up a
bit. Or you could just send a link.

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328






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




RE: Tables

2004-01-22 Thread Charles K. Clarkson
Chris Mortimore <[EMAIL PROTECTED]> wrote:
: 
: Charles <[EMAIL PROTECTED]> replies:
: >
: > I don't really use tables much any longer, but if
: > you could send me an example you think is good, I could
: > translate from function oriented to OO and clean it up
: > a bit. Or you could just send a link.
: 
: My question then becomes: what is the new and improved
: feature that takes the place of the old-fashioned tables?

That doesn't sound right. You are obviously reading what
I wrote and not what I mean. It sounded perfectly fine in my
head. :)

Yes, it should say I don't really produce tables with
CGI.pm much any longer. I tend to use HTML::Template since
I have graduated to "almost" programmer and since my web
page designer became a whole separate person instead of
that voice in my head. (Not that that voice has gone.)


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328




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




RE: using CGI to build a table

2004-01-25 Thread Charles K. Clarkson
smrtalec <[EMAIL PROTECTED]> wrote:
: 
: I am trying to scavange a example script I found on the
: web. The subroutine is below. Basically I want to extract
: data from a sql db then generate a table of values on the
: fly.  The script below keeps generating a malformed header
: error.

If you are getting a header error, you may not be
printing headers correctly. We'll need to see more of the
script than just this subroutine. This subroutine prints
fine, though it produces invalid HTML.

If the script is long, try sending everything up to
and including the first 'print' statement.

[snipped sub]


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328



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




RE: using CGI to build a table

2004-01-26 Thread Charles K. Clarkson
smrtalec <[EMAIL PROTECTED]> wrote:
: 
: #! /usr/bin/perl -w

You should add:

use strict;

: use DBI;
: use CGI qw/:standard :html3/;
: use CGI::Carp qw(fatalsToBrowser);

This is great for debugging. Make sure you remove it
once you go into production.


When outputting to the browser using the Common Gateway
Interface (CGI) you need to first send a header to tell the
client (or whatever is receiving the data) what the data is.
The header is separated from the content by a single blank
line. Whenever you get a header error, check to see if you
are printing them.

Since gen_table() is printing something, you need to
print headers before calling the sub. CGI.pm provides this
with the header() sub routine. Use it before you print
anything.

print header();

gen_table();


[snipped code - thank you]


I like to use the same idiom as CGI.pm when possible.
All of its subroutines return text and allow me to decide
what to do with the result. IMO, gen_table() should do
the same.

print
header(),
start_html( 'This page has no title' ),
gen_table( '%Ave%' ),
end_html();


sub gen_table {

my $search = shift;

# define table heading
my @rows= th( [ 'id no.', 'street no.', 'street name', 'city' ] );

# load 1 street per row
push @rows, td( $_ ) foreach @{ query_data( $search ) };

# produce table
return
table( {-border => 0,
-width  => '25%' },

caption( b( 'Wow. I can multiply!' ) ),
Tr( [EMAIL PROTECTED] ),
);
}


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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




RE: using CGI to build a table

2004-01-26 Thread Charles K. Clarkson
smrtalec <[EMAIL PROTECTED]> wrote:
: 
: before I begin thanks for taking the time to help me out.

You're welcome. That's what we are here for.


: > print
: > header(),
: > start_html( 'This page has no title' ),
: > gen_table( '%Ave%' ),
: > end_html();
: >
: >
: > sub gen_table {
: >
: > my $search = shift;
: >
: > # define table heading
: > my @rows= th( [ 'id no.', 'street no.', 'street 
: name', 'city' ] );
: >
: > # load 1 street per row
: > push @rows, td( $_ ) foreach @{ query_data( $search ) };
: >
:
: code wise I follow everything that you do up to the line
: above. it seems your doing the same thing however you've
: just truncated the code. the script runs however the table
: does not print beyond the header.

 The script you showed the second time use this push:

push(@rows,"td([$id,$str_no,$str_name,$city])"); <--- Notice the quotes

The message with just the subroutine had this:

push(@rows,td([$id,$str_no,$str_name,$city]));

Those quotes are making your table appear empty.


: unfortunately i'm having some problems writing in a check
: to verify the data is imported. could you include the
: longer version of the above code that I could understand
: a bit more whats happening.

Short Answer:

foreach my $fields ( @{ query_data( $search ) } ) {
push @rows, td( $fields );
}



Long Answer:

Let's look at the original lines you had:


my $array_ref=query_data('%Ave%');

foreach my $row_array (@$array_ref) {
my ($id,$str_no,$str_name,$city) = @$row_array;
push(@rows,td([$id,$str_no,$str_name,$city]));
}

In the 'foreach', @$array_ref is the same as
@{ query_data('%Ave%') }. So we can substitute and
rid ourselves of $array_ref:


foreach my $row_array ( @{ query_data('%Ave%') } ) {
my ($id,$str_no,$str_name,$city) = @$row_array;
push(@rows,td([$id,$str_no,$str_name,$city]));
}

@{ query_data('%Ave%') } is an array of arrays, so each
item in the top array is a reference to an array. The line:
"my ($id,$str_no,$str_name,$city) = @$row_array;" pulls the
fields out of the arrayref and then places them back into
an array ref on the next line:
push(@rows,"td([$id,$str_no,$str_name,$city])");

Since the fields are being pushed onto @row in the same
order as they appear in the array ref, there is no need to
place them in the fields to begin with.


foreach my $row_array ( @{ query_data('%Ave%') } ) {
push(@rows, td( $row_array ) );
}

Ideally, the table header information should also come
from the query_data() routine. If you ever add a field or
change field order, everything would be in the same place.

The other advantage is that gen_table() can produce
the table for results of any query. That eases the script's
ability to produce consistent output.


sub gen_table {

my $search = shift;

# load streets
my $results = query_data( $search );

# define table heading
my @rows = th( shift @$results );

# load one result per row
push @rows, td( $_ ) foreach @$results;

# produce table
return
table( {-border => 0,
-width  => '25%' },

caption( b( 'Wow. I can multiply!' ) ),
Tr( [EMAIL PROTECTED] ),
);
}


sub query_data {

my $user_entry  = @_;
my $dbh = connect_try( 'rowan', '**' );
my $user_quoted = $dbh->quote( $user_entry );
my $sth = $dbh->prepare( qq|
SELECT  id_pro, str_no_addr, str_name_addr, cit_addr
FROMs3a_inglewood_project_info
WHERE   str_name_addr LIKE $user_quoted;
|) or  err_trap( 'failed to prepare statement\n' );

$sth->execute or
err_trap( 'failed to execute statement\n' );

my $array_ref = $sth->fetchall_arrayref();

# place field names on top< I added these two lines
unshift @$array_ref, [ 'id no.', 'street no.', 'street name', 'city' ];

$dbh->disconnect or
err_trap( 'failed to disconnect at get_date statement\n' );

return $array_ref;
}


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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




RE: Automated script to connect to a web site and change the Password

2004-01-28 Thread Charles K. Clarkson
Mallik <[EMAIL PROTECTED]> posted this reply:
:
: : -Original Message-
: : From: Mallik [mailto:[EMAIL PROTECTED] 
: : Sent: Tuesday, January 27, 2004 5:26 AM
: : To: Perl Beginners
: : Subject: Automated script to connect to a web site and change 
: : the Password
: : 
: : Dear Friends,
: : 
: : I need to write a Perl CGI script that connects to
: : a website (like Yahoo) and change the Password for
: : my user. I don't want to do it manually. It should
: : be handled by the script.
: : 
: : Please suggest any idea/code available.
:  
: 
: Dear Friends,
: 
: I need to write a Perl CGI script that connects to
: a website (like Yahoo) and change the Password for
: my user. I don't want to do it manually. It should
: be handled by the script.
: 
: Please suggest any idea/code available.
: 
: Thanks in advance,
: Mallik.


You emailed three messages to two email newsgroups asking the
same question and then you replied with the same exact message
again to each of those messages. In all there are six messages
cross posted to two email newsgroups (that I know of) to ask one
question.

What are thinking???

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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




RE: Webhosting with good Perl support

2004-02-14 Thread Charles K. Clarkson
Jan Eden <[EMAIL PROTECTED]> wrote:
: 
: being unhappy with my ISP's Perl support, I decided to 
: switch. Wiggins and zentara already  recommended two 
: providers, Westhost and Affordable Host.
: 
: Does anyone have an additional recommendation, so I can 
: compare some more?

Try: http://www.tier1services.com/. If you need
something cheaper or a special plan, let me know and I'll
try to customize a plan just for you.


HTH,

Charles K. Clarkson
-- 
Mobile Home Specialist
254 968-8328



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




RE: running CGI locally??

2004-03-04 Thread Charles K. Clarkson
Freimuth,Robert <[EMAIL PROTECTED]> wrote:

: I have very little experience with web programming, and even less
: with CGI, so I'm really in need of help here.

Let's clarify some terminology. CGI is the Common Gateway
Interface. It is language independent. For the most part, web
programming is done through the CGI.


: I have an application that runs in batch mode and generates 5 output
: files for every input file (all are flat text, and each of the 5 is
: in a different directory).
: I would like to build a simple browser-based UI that provides links
: to each output file, so they can be opened and examined efficiently
: at the end of a run, without forcing the user to navigate through
: directories and search through output files from other runs.  In
: addition, I would like to include links to the most recent output
: file of each type, in the event that the user wants to review the
: results from an old run and then link to the most recent output.
: (Sorry if that's not clear ...)  I know how to collect the filenames
: I need - my problem is with the display.

You mention above that you have some web programming experience.
What are you experienced in?


: Since I'm trying to generate dynamic HTML pages, I thought CGI would
: be the way to go.  However, from what I understand of CGI, it
: requires a web server and can't be run locally.

Since CGI is an interface between a program on a server and a
browser it would by definition need a server. Many perl CGI programs
can be tested from the command line. I tested my perl programs from
the command line for about a year before I installed a local copy of
Apache.


: Since all of my code is in perl, I would prefer to stick with it, if
: possible.  A coworker suggested java as an alternative, but then I'd
: have to learn it first.  :)

Your Java program would still need the CGI to interact with the
browser.


: Any ideas on how to do something like this are appreciated.
: If this idea of a UI is ludicrous, I'm open to others!

You may be able to install a web server on your local computer.
You haven't mentioned the intended platform. Tell us what that
OS is and what OS is no your local box and we can help point you in
the right direction.

HTH,


Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: handling multiple select with CGI

2004-03-17 Thread Charles K. Clarkson
Andrew Gaffney [mailto:[EMAIL PROTECTED] 
: 
: I have a Perl script which uses the CGI module which needs to 
: be able to get all the 
: selected items in a SELECT. I see that the request comes in as 
: 'selectname=item1&selectname=item2&selectname=item3'. If I do 
: '$p = $cgi->Vars', wouldn't 
: I only get the last value?

In a quick test, I get a hash reference:

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper 'Dumper';

use CGI;
my $cgi = CGI->new( \*DATA );

my $p = $cgi->Vars;

print Dumper \$p;

__END__
selectname=item1
selectname=item2
selectname=item3


prints:
$VAR1 = \{
'selectname' => 'item1 item2 item3'
  };


Why use $cgi->Vars?

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper 'Dumper';

use CGI;
my $cgi = CGI->new( \*DATA );

my @p = $cgi->param( 'selectname' );

print Dumper [EMAIL PROTECTED];

__END__
selectname=item1
selectname=item2
selectname=item3


prints:

$VAR1 = [
  'item1',
  'item2',
  'item3'
];


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: hash hanging up browser

2004-03-22 Thread Charles K. Clarkson
Teresa Raymond <[EMAIL PROTECTED]> wrote:
: 
: Hi,
: 
: The following code is hanging up the browser and I think
: it has something to do with the hash having keys array
: and values array. There is no error message, just the
: browser taking a really long time. Any help would be 
: appreciated. Works fine with 3 line, 12 word 1 kb text
: file but not with 7 kb text file.

You may be timing out. That is your program may be
taking too long to parse a larger file and the browser
"thinks" the connection is down.

Add:
$|++;

near the top of your script. It will change the way
buffering works. Read "perlvar" for more info.


You have a lot unnecessary code. For example,
@countsArray and @uniqueArray are not needed. Here's the
block of code they are used in:

foreach $word (@totalArray)
{
$totalcount++;
$word = lc $word;
unless (exists $uniqueHash{"$word"} && $uniqueHash{$word} > 0)
{
$uniqueArray[$unique] = $word;
$countsArray[$unique] = 1;
$uniqueHash{$uniqueArray[$unique]} = $countsArray[$unique];
$unique++;
}#END UNLESS
else
{
$uniqueArray[$nonunique] = $word;
$countsArray[$nonunique] = $uniqueHash{$word} + 1;
$uniqueHash{$uniqueArray[$nonunique]} = $countsArray[$nonunique];
$nonunique++;
}#END ELSE
}#END FOREACH

First, we eliminate the @countsArray:

foreach my $word (@totalArray) {
$totalcount++;
$word = lc $word;
unless (exists $uniqueHash{$word} && $uniqueHash{$word} > 0) {
$uniqueArray[$unique] = $word;

#$countsArray[$unique] = 1;
#$uniqueHash{$uniqueArray[$unique]} = $countsArray[$unique];

$uniqueHash{$uniqueArray[$unique]} = 1;
$unique++;

} else {
$uniqueArray[$nonunique] = $word;

#$countsArray[$nonunique] = $uniqueHash{$word} + 1;
#$uniqueHash{$uniqueArray[$nonunique]} = $countsArray[$nonunique];

$uniqueHash{$uniqueArray[$nonunique]} = $uniqueHash{$word} + 1;
$nonunique++;
}
}

   Then @uniqueArray:

foreach my $word (@totalArray) {
$totalcount++;
$word = lc $word;
unless (exists $uniqueHash{$word} && $uniqueHash{$word} > 0) {
#$uniqueArray[$unique] = $word;

#$countsArray[$unique] = 1;
#$uniqueHash{$uniqueArray[$unique]} = $countsArray[$unique];

$uniqueHash{$word} = 1;
#$unique++;

} else {
#$uniqueArray[$nonunique] = $word;

#$countsArray[$nonunique] = $uniqueHash{$word} + 1;
#$uniqueHash{$uniqueArray[$nonunique]} = $countsArray[$nonunique];

$uniqueHash{$word} = $uniqueHash{$word} + 1;
#$nonunique++;
}
}

Next, we clean it up a bit and get rid of the test:

foreach my $word (@totalArray) {
$totalcount++;
$word = lc $word;
$uniqueHash{$word}++;
}

Here's everything with better scoped variables:

my %uniqueHash;
my $totalcount = 0;
while (<$file>) {
chomp( my @totalArray = split /\W+/ );

foreach my $word (@totalArray) {
$uniqueHash{lc $word}++;
}
$totalcount += @totalArray;
}
my $linescount = $.;



I assume the other arrays were used for testing. You
need to look through the rest of your code to see what
else can be cut. I didn't look through all of it, but as
others have pointed out, declaring variables outside the
smallest scope possible leads to problems in large
scripts. Perhaps others might learn from this.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: What to use for Perl form Validations?

2004-03-26 Thread Charles K. Clarkson
Kasturirangan Rangaswamy <[EMAIL PROTECTED]> wrote:
: 
:   I have created some HTML forms using the Perl CGI
: module. Now I need to perform client-side validations
: on those forms. Examples of these validations include
: checking if numbers alone have been entered in a price
: field, checking if the e-mail field is in the correct
: format etc.
: 
:   I am thinking of using JavaScript for these
: validations. Could anyone tell me if this is the best
: thing to use or is there some Perl-specific thing 
: available that would be easier. 

Data::FormValidator does both server-side and
client-side validation. I believe there is also a
mailing list for support.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: Calendar HTML Form

2004-03-29 Thread Charles K. Clarkson
B McKee <[EMAIL PROTECTED]> wrote:
:
:   I'm overhauling the website I run for a men's rec
: slopitch league.  It's all CGI.pm and mySQL. I'm
: adding a section to reschedule rain-out games. I want
: the users to pick the new date from a 'calendar'.
: I think this will be a more natural interface than
: drop-down menus.  The calendar would be a form that
: passes the date chosen along as a hidden param to the
: next invocation of the script.
:   I started to twiddle with ideas how to do this
: last night, but it now occurs to me I'm likely
: reinventing the wheel here - surely others have done
: this many times. A quick Google search buried me with
: irrelevant answers. Can someone point me towards an
: example/module/document/starting point?
:
:   I would prefer to not have to install extra
: modules (political reasons), and simpler is better
: than flexible for this.

So don't tell anyone you installed something. :)


: Any input appreciated

If you're just looking for a nice interface to input
dates and if you are certain javascript works, take a
look at jsCalendar.

http://dynarch.com/mishoo/calendar.epl

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: Streaming a file to a remote user

2004-03-30 Thread Charles K. Clarkson
binmode OUT if -B $file;

my $block_size = (stat OUT)[11] || 16384;

while ( my $length = sysread OUT, my $buffer, $block_size ) {
next unless defined $length;

my $offset = 0;
while ( $length ) {
my $written  = syswrite STDOUT, $buffer, $length, $offset;
$length -= $written;
$offset += $written;
}
}

close OUT;


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: Getting the values of some variables

2004-04-15 Thread Charles K. Clarkson
Octavian Rasnita <[EMAIL PROTECTED]> wrote:
:
: I have a text file that contains a text something like
: this:
:
: This text contains a $aa variable and a $bb variable
: and a $cc one.
:
: My program reads this text and I want to replace the
: variables with their values, then return the result
: string.
:
: How can I do this?
:
: Is using s/(\$\w+)/eval($1)/gse the only solution?
: (I haven't test it if it works this way yet, but I hope
: there is a simpler and easier method to evaluate the
: entire string.
: Is there such a way?

Octavian,

Have you looked at Text::Template? It does this (and some more)
but it requires delimiters around the variables.

HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328



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




RE: cgi retaining state (even though I don't want it to)

2004-04-19 Thread Charles K. Clarkson
John Kennedy <[EMAIL PROTECTED]> wrote:
: 
: just posting my code as requested by zentara

Stop top-posting.
 
: #!/usr/bin/perl -wT
: #
: #
: 
: use strict;
: use XML::DOM;
: use CGI qw/:standard -nosticky/;
: 
: my $q = new CGI;
[snipped helpful code -- Thanks.]

   Two items.

   1. You don't need to install the ":standard" subroutines
  (more than 100 of them) to use CGI.pm as an object.

   2. The "-nosticky" pragma doesn't do anything if you are
  not creating the form in this script.


What is generating the form?

It's not being generated from this script. Changing this
script will not affect the form.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: how to set env variables?

2004-05-10 Thread Charles K. Clarkson
Reynard Hilman <[EMAIL PROTECTED]> wrote:
:
: I have a perl script that runs just fine from command
: line but not when I run it as cgi. I think it's because
: there are some env variables that doesn't exist when I
: run it as cgi. Is there a way to set the variables from
: the perl script?
: I tried $ENV{'VAR'} = 'value';

That usually works.


: but it doesn't make a difference.

Perhaps it's not an environment variable problem.


: btw, I'm using Apache as the webserver. Should I set
: the env variables from Apache config instead?

That will set the variable across the entire server
and is one recommended way. What happened when you tried
that?


: any suggestion?

Show us your code. Let us confirm your reasoning.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: bad type of variable?

2004-05-14 Thread Charles K. Clarkson
Aben Siatris <mailto:[EMAIL PROTECTED]> wrote:
: 
: is this normal?

Is what normal? The output looks okay.

: what's wrong?

The script declares $number twice and your output
indicates you may not have warnings turned on.

   What were you expecting that didn't happen?

   Or what happened you didn't expect?


: my $number=(0.75-0.54)/0.03;
: print "$number\n";
: for (0..$number)
: {
:  print "$_ / $number\n";
: }
: 
: my $number=(75-54)/3;
: print "$number\n";
: for (0..$number)
: {
:  print "$_ / $number\n";
: }
: 
: output:
: 7
: 0 / 7
: 1 / 7
: 2 / 7
: 3 / 7
: 4 / 7
: 5 / 7
: 6 / 7
: 7
: 0 / 7
: 1 / 7
: 2 / 7
: 3 / 7
: 4 / 7
: 5 / 7
: 6 / 7
: 7 / 7


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: Displaying Data in a Table

2004-05-08 Thread Charles K. Clarkson
Baek, Steve <[EMAIL PROTECTED]> wrote:
: 
: I'm trying to break apart the command `df -k` data
: and display it into an html table:
: 
: Filesystemkbytesused   avail capacity  Mounted on
: /dev/dsk/c0t2d0s03008783   83669 2864939 3%/
: /dev/dsk/c0t2d0s34032654  886633 310569523%/usr
: /proc  0   0   0 0%/proc
: mnttab 0   0   0 0%/etc/mnttab
: fd 0   0   0 0%/dev/fd
: /dev/dsk/c0t2d0s719808378  250080 19360215 2%/var
: swap  594216 104  594112 1%/var/run
: swap  594448 336  594112 1%/tmp
: /dev/dsk/c0t2d0s61985487  532663 139326028%/export
: /dev/dsk/c0t2d0s51985487  356649 156927419%/opt
: /dev/dsk/c0t2d0s47057565  914628 607236214%/usr/local


: Would anyone happen to know the best way to do this?

Not the "best" way, No. 


: I'm thinking of putting each line into an array...

Sounds like a plan ...

The most obvious method to break this apart is using 'split'.
Since "Mounted on" contains a space we need to limit the split to
6 columns:

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper 'Dumper';

while (  ) {
chomp;
print Dumper [ split ' ', $_, 6 ];
}

__END__
Filesystemkbytesused   avail capacity  Mounted on
/dev/dsk/c0t2d0s03008783   83669 2864939 3%/
/dev/dsk/c0t2d0s34032654  886633 310569523%/usr
/proc  0   0   0 0%/proc
mnttab 0   0   0 0%/etc/mnttab
fd 0   0   0 0%/dev/fd
/dev/dsk/c0t2d0s719808378  250080 19360215 2%/var
swap  594216 104  594112 1%/var/run
swap  594448 336  594112 1%/tmp
/dev/dsk/c0t2d0s61985487  532663 139326028%/export
/dev/dsk/c0t2d0s51985487  356649 156927419%/opt
/dev/dsk/c0t2d0s47057565  914628 607236214%/usr/local



CGI.pm provides a td() function for cell data. It accepts
a reference to an array for multiple cells.

use CGI qw( table Tr td );

my @rows;
while (  ) {
chomp;
push @rows,
Tr(
td( [ split ' ', $_, 6 ] )
);
}
print table( @rows );


Or as a subroutine:

use CGI qw( table Tr td );

print table_ize( *DATA );

sub table_ize {
my $file_handle = shift;

my @rows;
while ( <$file_handle> ) {
chomp;
push @rows,
Tr(
td( [ split ' ', $_, 6 ] )
);
}
return table( @rows );
}


: Does anyone have any thoughts?

Not on a Saturday, no.

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: How do I document my perl code?

2004-06-05 Thread Charles K. Clarkson
Richard Heintze <mailto:[EMAIL PROTECTED]> wrote:

: Apparently there is some counterpart to javadoc for
: perl. I tried perldoc perldoc but that is not what I
: wanted. I want to know how I should be formating the
: comments for my perl code. What topic do I look under
: in perldoc?


 perldoc perlpod

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: help with adjusting log file data?

2004-06-08 Thread Charles K. Clarkson
Catriona Pure Scents <[EMAIL PROTECTED]> wrote:

: Hi guys,
: 
: Needing a little help with adjusting the data a log file reads to.
: 
: It goes like this currently
: @env_vars = keys(%ENV);
: 
: foreach $variable (@env_vars)
: {
: $log_entry .="$ENV{$variable}\|";
: }

There is no need to escape '|' in a double quoted string.

This is equivalent to the loop, though I don't know why the
extra '|' at the end would be wanted.

my $log_entry = ( join '|', values %ENV ) . '|';


: I am wanting to change this to include $http_referrer

If http_referer has anything in it it will be included
already.


: So,I am presuming that I should be doing this:
: 
: foreach $variable (@env_vars)
: {
: $log_entry .="$ENV{'http_referrer"}\|$ENV{$variable}\|"; }

There is a typo in there.

$log_entry .="$ENV{http_referrer}|$ENV{$variable}|";
}

: Is this correct??

My first thought was: What happened when you tried it? Then
I wondered what you meant by correct. In my mind, even after
fixing the typo this is incorrect.

You are defining every other pipe separated field with the
referrer. At some point, assuming the referrer is defined, there
may be three such fields in a row. I don't think that is
really what you want. This looks more like it:

my $log_entry = join '|', values %ENV );


The next thing I wondered was whether you were aware that
newlines are embedded in at least one Apache field
('SERVER_SIGNATURE'), thus $log_entry won't be one line in
the log and won't be able to be retrieved as one line.


Here's a script that generates $log_entry with newlines
("\n") instead of pipes ('|').

#!/usr/bin/perl

use strict;
use warnings;

use CGI;
my $q = CGI->new();

# bold the referrer if present
$ENV{http_referer} = $q->b( $ENV{http_referer} )
   if exists $ENV{http_referer};

my $log_entry = join "\n", values %ENV;

print
$q->header(),
$q->start_html(),
$q->pre(
qq|Referrer (if any): "$ENV{http_referer}"\n|,
$log_entry,
),
$q->br(),
$q->a( { href => $q->url() }, 'again' );
$q->end_html();

__END__

Type the url into the browser address bar the first time.
The second time, click the again link. When I tried it on my
local system (Apache on Windows) I got a referrer only after
clicking the link.

Notice that the referrer is included in the list when it
is defined.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: help with adjusting log file data?

2004-06-09 Thread Charles K. Clarkson
Catriona Pure Scents <[EMAIL PROTECTED]> wrote:

: I think I understand what you are getting at
: 
: I have no concept of "join"  that you use.

run this from the command line:

 perldoc -f join

Or read about join in the 'perlfunc' file that comes
with perl's standard documentation.

 
: But realising that this is a loop that I am attempting to
: alter, not quite what I was trying to do no.
: 
: so, @env_vars = keys(%ENV);  this from all I have read,
: takes the server dependant environment variables and holds
: them in memory.

Not exactly. They are already in memory in a hash
named %ENV. This hash is created by and maintained by
perl. "@env_vars = keys(%ENV);" copies the names of all
keys of the ENV hash (in memory) and places them into
an array (called @env_vars) which is also in memory.

It sounds like you are maintaining someone else's
code. Either the code was written long ago or the
original programmer wasn't very good or both.


: But the server I am using doesn't seem to have http_referrer
: as a env variable.  Doesn't show in the logs I am currently
: receiving anyway.

Your server may be configured not to show it. Check with
your Sys Admin.


: Therefore if the following stuff was a loop then I am presuming
: that I need to add another line to the details that I want to
: log, like
: 
: $log_entry .="$ENV{http_referrer}\|";

While the correct spelling for referrer uses four R's, HTTP
using only three:

$log_entry .="$ENV{http_referer}|";

: then go on with the
: 
: @env_vars = keys(%ENV);
: 
: foreach $variable (@env_vars)
: {
: $log_entry .="$ENV{$variable}\|";
: }
: 
: would this be better.

Yes, but what if there is nothing in $ENV{http_referrer}.
In its current state your script is probably not using warings,
but as you become more proficient in programming with perl,
you'll probably want to turn warnings on.

If you try to use an undefined value with warnings turned
on, you'll get a warning everytime you run the script. So, what
you propose is better, but not much better. And you are also
escaping '|' needlessly.

If there was a value in $ENV{http_referrer}, then keys %ENV
would have 'http_referrer' as one of its values. Otherwise it
won't. What you could do is add a default value to the referrer:

$ENV{http_referer} ||= 'no referrer';

@env_vars = keys(%ENV);

foreach $variable ( @env_vars )
{
$log_entry .= "$ENV{$variable}\|";
}

This way you have still only added one line and you won't
piss off the next person who has to maintain what looks like a
small portion of spaghetti code.

"$ENV{http_referer} ||= 'no referrer';" basically says "set
$ENV{http_referer} to 'no referrer' if it has a value that
evaluates to false. In perl, that would be: undef, '', or 0.
Each of which is unlikely to actually be valid http referrers.


: btw, I don't think apache is loaded on this server.  Not sure
: I didn't set it up, as a complete newbie you probably wouldn't
: want me to either  :-))

I have a tiny hosting service and you wouldn't want me
configuring servers either. :)

This script will give you a list of the keys in %ENV and
their values, including the server name. Don't leave it on
your server, though, it's a security risk.


#!/usr/bin/perl
$|++;

use CGI;

# find max key length
my $max;
foreach ( keys %ENV ) {
$max = length if length > $max;
}

my $q = CGI->new();
print
$q->header(),
$q->start_html( 'env.pl' ),
$q->pre(
"\n",
map {
sprintf "%-*s = %s\n",
$max, $_, $ENV{ $_ }
}
sort keys %ENV
),
$q->end_html(),

__END__


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: multiple images

2004-06-09 Thread Charles K. Clarkson
From: Johan Meskens CS3 jmcs3 <> wrote:

: # hello
: 
: # i don't know what comes first
: # , source or question
: 
: # thus
: 
: #!/usr/local/bin/perl
: 
: use CGI;
: use strict;
: use warnings;
: 
: my $q=CGI->new();
: 
: print $q->header;
: print $q->start_html;
: 
: # things
: 
: print "http://127.0.0.1/cgi-bin/image.cgi\";>"; # this works
: 
: # first question : what is the cgi-oop-way of dealing with images;
: $q->img ?? # i can't find dox on that

print $q->img( { -src => 'http://127.0.0.1/cgi-bin/image.cgi' } );

To get HTML, you'll have to change your call to CGI to:

use CGI qw( -noxhtml );


BTW, you don't need a full url for images from your own server:

print $q->img( { -src => '/cgi-bin/image.cgi' } );

 
: # second question : how can i insert more than one image # i tried
: the following: 
: 
: # foreach( 1..6 ){
: #print "http://127.0.0.1/cgi-bin/five.cgi\";>"; # }
: 
: # but this returns 6 times the same image

Well, that makes sense. What are the names of each image?
The loop above keeps suing the same name each time.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328

P.S.  CGI.pm doesn't need to document every function. Gerneral
rules to create any tag is in the section titled PROVIDING
ARGUMENTS TO HTML SHORTCUTS.

















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




RE: help with adjusting log file data?

2004-06-09 Thread Charles K. Clarkson
From: Catriona Pure Scents <mailto:[EMAIL PROTECTED]> wrote:

: Hi Charles,
: 
: thanks immensely.  As you can probably tell I am one of those
: people who pulled some scripts off the net to get me going,
: and insists on making alterations.

There is nothing wrong with that. Many people run very
successful sites using that plan. CREOnline.com is easily
the most visited RE site on line and they use an old Matt's
Script called WWW Board. It's old, its clunky, and hundreds
of posters a day don't seem to mind.

 
: Yes the script I am attempting to alter in this instance I
: located back in 1998.  I have made heaps of other
: alterations so it wouldn't be simple to go get the latest
: version.  :-((

I got that impression, but I am obligated to point out
the merits of warnings and strictures. I think others on this
list would be disappointed if I didn't at least nudge you a
little.

 
: By warnings I am presuming that you mean "use strict" etc...
: I have been asking on this list if someone can refer me to
: sites that have details on how to convert my current scripts
: and update them, it seems so totally different the way that
: scripts are written with the warnings.  any good books or
: sites that you can recommend?

   There's a book about this mentioned a few months ago on a
perl beginner list, but I can't find the post. Perhaps
someone else remembers the post or the book. I seem to recall
something about creating subs for each global variable.

You may be looking at diminishing returns. Many slower
sites are less likely to be affected by security problems.
Hackers seem to like bigger fish. Putting a lot of effort
into converting an old script might not be worth your time.
Unless you think the experience will help in the long run.


: I looked through the perl docs about that and couldn't find
: anything.  I haven't looked through about perl join though.

It sounds like you need to learn more of the basics before
you start converting a large script. If you have the time, try
to solve some of the problems asked on these perl beginner
lists and compare your answers with those given by the more
experienced contributors.


: I need to set up my old pc for that.  The site I have is run
: on Unix so I have a friend who is setting up the old pc for
: unix, perl php etc so that I can just go ballistic and test
: everything offline, make mistakes, try things, but at the
: moment I don't have that luxury while they have my old pc.

I do something similar, but with Apache on Windows XP.

 
: Theoretically if the site stats can tell where someone came
: from...then http_ referer would be env_var.  So why wouldn't
: it work throughout the site itself?

I'm not sure I understand your question. What do you mean
by "work throughout the site itself"?

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: multiple images

2004-06-10 Thread Charles K. Clarkson
From: Johan Meskens CS3 jmcs3 <> wrote:

: # here is what five.cgi consists of
: # ( it returns a random gif-image )
: 
: use warnings;
: use strict;
: 
: use CGI;
: 
: my $dirpath = '/Users/Shared/ChromaticSpaceAndWorld/INTRA';
: 
: opendir( DIR, $dirpath ) || die " espejo de vidrio $! ";
: my @files = grep ! /^[\._]/, readdir DIR;
: closedir DIR;
: 
: my $image = $files[ rand( $#files ) ];
: 
: my $img = CGI->new();
: 
: open( FILE, "$dirpath/$image" ) || die " espejo de vidrio $! ";
: 
: binmode FILE;
: binmode STDOUT;
: 
: print $img->header('image/gif');
: 
: print while ;
: 
: close FILE;
: 
: # so i remain with this second question
: # there is probably something fundamental i don't understand

It looks like a browser caching thing. The first random image
is downloaded and the browser assumes all other references to that
image are the same image.

You could do everything in the first program by avoiding the
actual delivery of the binary. This function will grab the image
file names when the program starts and load them into @files.
(@files is not directly available to the rest of the program.)

BEGIN {
# path
my $dir_path = '/Users/Shared/ChromaticSpaceAndWorld/INTRA';

# grab the files
opendir DIR, $dir_path or die "espejo de vidrio $!";
my @files = grep ! /^[\._]/, readdir DIR;
closedir DIR;

# return a random file
sub random_image_url {
return '/INTRA/' . $files[ rand @files ];
}
}

random_image_url() will return a random image file name from
that array each time it is called. Here we use it to return six
random file names.

push @random_images,
$q->img( { -src => random_image_url() } ) .
$q->br()
for 1 .. 6;


And print it:

print
$q->header(),
$q->start_html( 'Six Random Images' ),
@random_images,
$q->end_html();


Using it like this forces the browser to do the work. It
also gives the web surfer the option of turning off images or
using a proxy to rewrite them. Ultimately, I want to empower
the users of my site.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328








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




RE: Hijacking forms [was help with adjusting log file data?]

2004-06-13 Thread Charles K. Clarkson
From: Will Bontrager <mailto:[EMAIL PROTECTED]> wrote:

: At 6/13/2004 01:53 AM +, Ron Goral wrote:
:: Yet,
:: some cretin began using a form of mine for his spamming
:: campaign.
: 
: I've seen two hijacking methods used.
: 
: One is simply adding email addresses to a header line
: already being used (To:, Cc:, and/or Bcc:). This can be
: done by putting multiple comma-separated email address
: into an email form field, for example.

Why have a form on a site that allows people to email
anything in the first place?

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: beginning question for cgi

2004-07-05 Thread Charles K. Clarkson
Xiangli Zhang <[EMAIL PROTECTED]> wrote:

: Hi,all:
: 
: Can anybody help me the question?
: 
: I am using apache 2.0 in redhat 9.0. I put my perl
: cgi script under var/www/cgi-bin 
: 
: my souce code(simple.cgi)
: 
: #!/usr/local/bin/perl
: use CGI qw/:standard/;
: print header(),
:   start_html(-title=>'Wow!'),
:   h1('Wow!'),
:   'Look Ma, no hands!',
:   end_html();
: 
: I use Mozilla web browser, enter URL:
: http://localhost/cgi-bin/simple.cgi
: 
: It tell me the following error:
: 
: Internal Server Error

Set your file permissions for simple.cgi to 755.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: How to install packages?

2004-08-13 Thread Charles K. Clarkson
Siegfried Heintze <[EMAIL PROTECTED]> wrote:

: I'm trying to install bugzilla on Windows XP 2003 and the
: installation procedure says that I need to install AppConfig.
: So I point 
: my browser at
: http://ppm.activestate.com/PPMPackages/5.6plus/ and right
: mouse click on
: AppConfig.ppd (I'm using IE 6 as my browser). This saves an
: AppConfig.xml file! Hmmm. I try the "ppm AppConfig.ppd" but
: that command does not work.

It is generally easiest to use ppm to install modules for
ActiveState perl installations. Read details at
/html/faq/ActivePerl-faq2.html in your perl directory.

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: Finding date when a file was created

2004-08-17 Thread Charles K. Clarkson
Bill Stephenson <[EMAIL PROTECTED]> wrote:

: Does anyone have example code that loops through a
: directory of files and prints a list of those created
: within a user selected date range. 
: 
: Here's what I've got so far, but it doesn't get the
: date the file was created and I can't seem to find
: out how to do that:


The question we need to ask is "Does your file
system track File Creation Date?" Many file systems
don't. The -C function in perl does /not/ return
the file creation time.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: How to enumerate array elements?

2004-09-02 Thread Charles K. Clarkson
Gunnar Hjalmarsson <mailto:[EMAIL PROTECTED]> wrote:

: Siegfried Heintze wrote:
 
: : It produces this output:
: : 
: : len = 5
: :  v=
: :  v=
: :  v=5
: :  v=
: :  v=
: :  v=34
: 
: No, it doesn't. It produces a fatal error.

I got four warnings:

Use of uninitialized value in print at aa.pl line 20.
Use of uninitialized value in print at aa.pl line 20.
Use of uninitialized value in print at aa.pl line 20.
Use of uninitialized value in print at aa.pl line 20.
len = 5
 v=
 v=
 v=5
 v=
 v=
 v=34


: - Copy and paste code that you post, do not retype it!
: 
: - Enable warnings in your program!
: 
: : How do I modify the program so it only produces this
: : output:
: : 
: : len = 5
: :  v[2]=5
: :  v[5]=34
: 
: That output wouldn't be correct, since the array contains
: six elements, not five.
: 
: This code:
: 
:  my $ref = $me->{verd_result}->[0];
:  print "len = " . @$ref, "\n";
:  for ( 0 .. $#$ref ) {
:  defined $ref->[$_] and print " v[$_]=$ref->[$_]\n";   
: } 
: 
: outputs:
: len = 6
:   v[2]=5
:   v[5]=34


You are not answering the question:

print
q~len = 5
 v[2]=5
 v[5]=34~;

Sorry, I know its not helpful. I just couldn't
resist. :)


Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328







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




RE: which modules to use?

2004-09-06 Thread Charles K. Clarkson
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

: I am really new to CGI, my 1st question is, which
: Perl modules should I use for creating XHTML
: documents? Write me, which one are good, where I
: can read more about this...

CGI.pm is a good starting point. Some of us later
abandon it for a tem plate package like HTML::Mason
or HTML::Template which allows for CGI scripting
without embedded markup.

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328




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




RE: CGI.pm : Handling Carriage Returns from textarea()

2004-09-06 Thread Charles K. Clarkson
Robert Page IV <[EMAIL PROTECTED]> wrote:

: I am trying to write a simple weekly entry CGI script
: and I am trying to capture a the string returned from
: a textarea, assign the value to either a variable or
: array and output it to a web page with print or printf
: or sprintf/print.
: 
: When I do this, apparently carriage returns are either
: not captured in as part of the value returned from the
: textarea value, or I am not handling the value
: returned correctly to recognize carriage returns.
: 
: Does anyone have any recommendations as to how I can
: solve this issue?


Do you have an example to demonstrate the issue you
are having?

Are you using CGI.pm to process form fields or
another solution?

Did you set the "wrap" attribute of the textarea
tag?

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: table with variables

2004-09-09 Thread Charles K. Clarkson
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

: Hi CGIers!
: 
: I have small question about putting variables into CGI
: script, which produces table, here is snip of code:
: 
: use CGI qw(:standard);
: #...
: open FH, items.txt or die "Can't open $!";
: my @items = sort ;
: print table(
: {-border=>undef},
: caption('Choose your favourite brand:'),
: Tr({-align=>CENTER,-valign=>TOP},),

That doesn't look right. Are CENTER and TOP constants?
If not, you don't have warnings turned on.


: td($items[0], $items[1], $items[2]),
: td($items[3], $items[4], $items[5])
: );
: #...
: 
: But how to do that inside while loop? Can I use
: table() function, or I have to print it (like
: without CGI module)?

I don't understand the question. What while loop?
What would it be looping over?


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: table with variables

2004-09-09 Thread Charles K. Clarkson
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

: Charles K. Clarkson [CKC], on Thursday, September 9, 2004 at
: 17:37 (-0500) thinks about: 
: 
: : : print table(
: : {-border=>>undef},
: : : caption('Choose your favourite brand:'),
: : : Tr({-align=>CENTER,-valign=>TOP},),
: 
: : That doesn't look right. Are CENTER and TOP constants?
: : If not, you don't have warnings turned on.
: 
: i've turned warnings and everythings ok it prints me out:
: Choose your favourite brand:
: 

   Hmph. You're right. It's a 'strict' error.

#!/usr/bin/perl

use strict;
use warnings;

use CGI 'Tr';

print Tr({-align=>CENTER,-valign=>TOP},);

__END__

Bareword "CENTER" not allowed while "strict subs" in use at aa.pl line 8.
Bareword "TOP" not allowed while "strict subs" in use at aa.pl line 8.


: : : td($items[0], $items[1], $items[2]),
: : : td($items[3], $items[4], $items[5])
: : : );
: : : #...
: : : 
: : : But how to do that inside while loop? Can I use
: : : table() function, or I have to print it (like
: : : without CGI module)?
: 
: : I don't understand the question. What while loop?
: : What would it be looping over?
: 
: I want print all items into table, table should have 3 columns.
: I don't know how to do it.

But your file only seems to have 6 fields in it. Where is
the data for the other fields coming from and what is be looped
over in the while loop?

Closer inspection shows the above code doesn't work (right).
I think you wanted this.

use CGI qw( table Tr td caption );

my @items = ( 1 .. 6 );
print
table(
caption( 'Choose your favourite brand:' ),
Tr(
{ -align  => 'CENTER',
  -valign => 'TOP'},
td( @items[0 .. 2] ),
        td( @items[3 .. 5] )
)
);


Which produces something like this (edited).


  Choose your favourite brand:
  
1 2 3
4 5 6
  




HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328





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




RE: table with variables

2004-09-09 Thread Charles K. Clarkson
Charles K. Clarkson <mailto:[EMAIL PROTECTED]> wrote:

: Closer inspection shows the above code doesn't work (right).
: I think you wanted this.
: 
: use CGI qw( table Tr td caption );
: 
: my @items = ( 1 .. 6 );
: print
: table(
: caption( 'Choose your favourite brand:' ),
: Tr(
: { -align  => 'CENTER',
:   -valign => 'TOP'},
: td( @items[0 .. 2] ),
: td( @items[3 .. 5] )
: )
: );

Or perhaps you are after this.

print
table(
caption( 'Choose your favourite brand:' ),
Tr(
{ -align  => 'CENTER',
  -valign => 'TOP'},
td( [ @items[0 .. 2] ] ),
),
Tr(
{ -align  => 'CENTER',
  -valign => 'TOP'},
td( [ @items[3 .. 5] ] )
)
);


Which produces something like this (edited).


  Choose your favourite brand:
  
1
2
3
  
  
4
5
6
  


: 
: 
: Which produces something like this (edited).
: 
: 
:   Choose your favourite brand:
:   
: 1 2 3
: 4 5 6
:   
: 
: 
: 
: 
: HTH,
: 
: Charles K. Clarkson
: --
: Mobile Homes Specialist
: 254 968-8328



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




RE: getting files from the internet

2004-10-14 Thread Charles K. Clarkson
Jeff Herbeck <[EMAIL PROTECTED]> wrote:

: Hello,
: 
: I want to be able to have a user login with apache
: authentication (which I have that part working) and then
: take a URL from a form and download the file in that url
: and put it in a directory for that user. Here is what I
: have so far.  It runs, but it doesn't do anything but
: display "aaa"
: 
: #!/usr/bin/perl
: 
: $URL = "http://www.jeffherbeck.com/arch.doc";;
: $remote_user = $ENV{REMOTE_USER};
: use LWP::Simple;
: 
: getstore("$URL", "/var/www/html/$remote_user/");
: 
: print "Content-type: text/html\n\n";
: 
: print "aaa";

Perhaps better written like this.

#!/usr/bin/perl

use strict;
use warnings;

use HTTP::Response;
use LWP::Simple 'getstore';

my $url = 'http://www.jeffherbeck.com/arch.doc';
my $remote_user = $ENV{REMOTE_USER} || 'unknown_user';
my $response= HTTP::Response->new(
getstore(
$url,
"/var/www/html/$remote_user/arch.doc" ) );

print
"Content-type: text/html\n\n",
$response->status_line();

__END__

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




Re: undefined value error

2004-10-02 Thread Charles K. Clarkson
Xiangli Zhang <[EMAIL PROTECTED]> wrote:

: It does not work, instead HTTP 500 - Internal server
: error happened.Page "test.cgi" cannot even display. 

Show us the updated code you are using. We'll also
need to see the modules you are using. They don't seem
to be from CPAN. Either provide their source or a url
where we can view them.


: Note: forwarded message attached.

Attaching forwarded messages is annoying. Just
post below the pertinent information and delete
everything else. Like I did here.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328





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




RE: foreach to generate parameter calls

2004-10-05 Thread Charles K. Clarkson
Rick Triplett <[EMAIL PROTECTED]> wrote:

: I am trying to turn a repetitive assignment into a loop
: for HTML::Template (a Perl loop, not an HTML::Template
: Loop). I'm given a series of scalars (three shown below)
: and I have commented out the $tmpl->param calls (also
: below, which worked fine). I intended the foreach loop
: to replace the long list of calls, but it didn't 
: work, nor did several variations I tried. Most of the
: variations died with the error that a scalar was found
: when an operator was expected. The variation below
: plugged into the template the literal '$student_id'
: instead of its value' trip304.' I've run out of ideas
: to try and books to look in. Anyone's advice would be
: most welcome!
: 
: $student_id = "trip304";
: $name_full = "John Smith";
: $name_nick = "Johnny";
: . . .
: # Assign template parameters
: foreach (@info_prams) {

What's in @info_prams? How did it get in there?


:   $tmpl->param( $_ => ("\$$_") );
: }
: #$tmpl->param( student_id => $student_id  );
: #$tmpl->param( name_full  => $name_full   );
: #$tmpl->param( name_nick  => $name_nick   );

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: corrected: foreach to generate parameter calls

2004-10-05 Thread Charles K. Clarkson
Rick Triplett <[EMAIL PROTECTED]> wrote:

: Sorry; I forgot to include all the code:
: 
: I am trying to turn a repetitive assignment into a loop for
: HTML::Template (a Perl loop, not an HTML::Template Loop).
: I'm given a series of scalars (three shown below) and I
: have commented out the $tmpl->param calls (also below,
: which worked fine). I intended the foreach loop to replace
: the long list of calls, but it didn't work, nor did several
: variations I tried. Most of the variations died with the
: error that a scalar was found when an operator was expected.
: The variation below plugged into the template the literal
: '$student_id' instead of its value 'trip304.' I've run out
: of ideas to try and books to look in. Anyone's advice would
: be most welcome!
: 
: my @info_prams = qw(
:   student_id
:   name_full   enroll_type
:   name_nick   account_number
:   name_last   password
:   date_birth  student_email
:   sex mentor_email
:   date_enteredsuspended
:   date_withdrawn
: );
: 
: $student_id = "trip304";
: $name_full = "John Smith";
: $name_nick = "Johnny";

It looks like you need a hash.

my $template = HTML::Template->new(
filename=> $template_file,
die_on_bad_params   => 0,
);

my %student = (
student_id  => 'trip304',
name_full   => 'John Smith',
name_nick   => 'Johnny',
name_last   => undef,
date_birth  => undef,
sex => undef,
date_entered=> undef,
date_withdrawn  => undef,
enroll_type => undef,
account_number  => undef,
password=> undef,
    student_email   => undef,
mentor_email=> undef,
suspended   => undef,
);

$template->param( \%student );


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: Variables taken from browser "stuck"

2004-11-15 Thread Charles K. Clarkson
Michael Kraus <[EMAIL PROTECTED]> wrote:

: G'day...
: 
: I've got a perl script that reads in variables from a web
: page using CGI
: and CGI::Untaint.
: 
: The only problem is that after changing a check box's
: value from being "As_Above" to "on" (in the HTML, for the
: purpose of compatibility with CGI::Untaint) it did not
: appear the browser was giving a different value (ie. it
: was still reading the value as "As_Above" rather than
: "on").
: 
: I checked and double-checked the HTML, I restarted apache,
: I simplified apache's configuration, I restarted my client
: PC... nothing seems to change it using Firefox and I
: discovered with IE that the value changed when (whilst
: filling out the form) I checked a different check box (as
: well as the problematic one) and it started working for
: me. I still don't know how to remedy Firefox though.

That sounds like a caching problem. Did you clear the
browser cache between tries?

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: Variables taken from browser "stuck"

2004-11-16 Thread Charles K. Clarkson
Michael S. E. Kraus <[EMAIL PROTECTED]> wrote:

: G'day...
: 
: 
: : That sounds like a caching problem. Did you clear the
: : browser cache between tries?
: 
: Thanks - that sounds about right... Err... how do I clear the
: browser's cache?

For Mozilla:
Edit > Preferences > Advanced > Cache

: (I was refreshing the browsers whilst holding down the shift to
: do a total refresh...) 

I think that only works on IE.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: Extracting links.

2005-01-16 Thread Charles K. Clarkson
Sara <[EMAIL PROTECTED]> wrote:

: I am trying to extract links along with HTML tags  from a list, but it's not working on my XP machine
: with Active State Perl 5.0.6 Kindly help.
: 

While Randy already addressed using HTML::LinkExtractor to
retrieve links, you should also hop over to ActiveState. 5.0.6
is a pretty old version of perl.

 http://www.activestate.com/Products/ActivePerl/


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: Module confusion

2005-02-08 Thread Charles K. Clarkson
Scott R. Godin <[EMAIL PROTECTED]> wrote:

: No problem as long as they still provide secure-shell access
: via ssh. It's completely sensible to close down the use of
: telnet. Too insecure for today's environment, however ssh is a
: viable alternative. 

I resell server space and I have one provider which allows
shell access and one which doesn't. The one which does requires
an initial reason why such access is necessary. In the hands of
an inexperienced or malicious person, shell access can hurt all
users on that physical server. We have some controls in place,
but disallowing shell access is still the most secure route.


Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: Formatting Labels with CGI.pm

2005-03-25 Thread Charles K. Clarkson
Bill Stephenson <mailto:[EMAIL PROTECTED]> wrote:
: I'm trying to format the text used in my labels for a radio box group
: created with CGI.pm... Among other things, I've tried:
: 

I'm guessing that you have something like this somewhere.

use CGI qw/:standard/;
my $Q = CGI->new();

It is not good idea to mix the function and object oriented calls
to CGI.pm.


:   my $payPal_label= b(Pay Online with PayPal)," (Use this for instant
: access)";

You should consider enabling strict and warnings. There are a few
problems up there.

my $payPal_label = $Q->b( 'Pay Online with PayPal.' ) .
   ' (Use this for instant access)';


:   my $check_label=qq~ Send a Check in the Mail. (If you're
: having a difficult time making a payment with PayPal use this option
: instead.)~;
: 
:   my %payment_labels = ('PayPal'=>"$payPal_label",
:  'Check' =>"$check_label");

Do not quote variables. ( Perlfaq4 ).

my %payment_labels = (
PayPal  => $payPal_label,
Check   => $check_label
);



:   my $payment_type=$Q->radio_group(-name=>'payment_type',
:-values=>['PayPal',
'Check'],
:-default=>'PayPal',
:-linebreak=>1,
:
-labels=>\%payment_labels);
: 
: # end code
: 
: The "Bold" text doesn't work on either of the labels. As I said, I've
: tried to do this in a variety of ways, but I keep getting an error or
: the browser displays the "" tags because CGI.pm converts it to
: this, "<b>".

 In the CGI.pm docs, read the section on AUTOESCAPING HTML.

$Q->autoEscape(0);

my @payment_type = $Q->radio_group(
-name   => 'payment_type',
-values => ['PayPal', 'Check'],
-default=> 'PayPal',
-linebreak  => 1,
-labels => \%payment_labels
);

$Q->autoEscape(1);

Or (better):

my @payment_type;
{
my $flag = $Q->autoEscape(0);

@payment_type = $Q->radio_group(
-name       => 'payment_type',
-values => ['PayPal', 'Check'],
-default=> 'PayPal',
-linebreak  => 1,
-labels => \%payment_labels
);

$Q->autoEscape( $flag );
}





HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: need logic and one error help

2005-03-28 Thread Charles K. Clarkson
Steven Schubiger <mailto:[EMAIL PROTECTED]> wrote:

: On 28 Mar, T Raymond wrote:
: 
: : print header,
: 
: What is header supposed to act on?
: If it's the method declared in CGI.pm, which I'd assume,
: you need to create an object by saying my $q = new CGI and
: replace header with $q->header.

The OP is using the function oriented version of CGI.pm.
This is homework and perhaps his class hasn't gotten to
objects yet.


[snip]
: : die "cannot locate $filename\n";
: 
: Replace with "die "$filename: $!\n";
: $! contains the exception message emitted by many functions
: on failure.

Omit the "\n", it suppresses important information. I
prefer this idiom. The quotes around the filename have saved
me hours. :)

open FH, $file or die qq(Cannot open "$file": $!);


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: need logic and one error help

2005-03-28 Thread Charles K. Clarkson
T Raymond <mailto:[EMAIL PROTECTED]> wrote:
: Hi all,
: Please advise me about my logic/syntax errors. I can't seem to figure
: out how to write in a logical sequence this code.

What is in 'employee.dat'? It would be helpful if we could run the
example.


: I'm also getting an
: error  which I don't understand which states that m/^$first_name/ has
: an uninitialized variable.

Chances are there is a situation where $first_name is not set to
a value before it is used.

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328




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




RE: valid use of while expression

2005-03-30 Thread Charles K. Clarkson
T Raymond <mailto:[EMAIL PROTECTED]> wrote:

: If there is a word in $words[$n], is the following expression for
: while valid? --Teresa

Define "valid".

We can test the _syntax_: I get "a.pl syntax OK".

#!/usr/bin/perl -c
use strict;
use warnings;

my @words = split ' ', 'The quick brown fox';

my @letters;
my $n = 1;
while ( $words[$n] ) {
@letters=split//;
}

__END__


Do you want to know if the while loop is endless? Yes it is.
$words[$n] will always evaluate true until we do something to it
to make it evaluate to not true.

But these are things you could have tried yourself. So what
do you mean by "valid"?


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: Preventing CPU spikes / was switch confusion

2005-04-14 Thread Charles K. Clarkson
David Gilden <mailto:[EMAIL PROTECTED]> wrote:
 
: --- what I have now
: 
: use CGI qw/:standard/;
: use CGI;

Why use CGI.pm twice? You need to read the CGI.pm docs. There
is no reason to ever call the module more than once.


: use Fcntl qw( :DEFAULT :flock );
: use CGI::Carp qw(fatalsToBrowser);
: use strict;

Also need to turn on warnings.

use warnings;   # or use -w switch on older perl versions


: use switch;

CPAN has only Switch.pm, not switch.pm. Did you create your
own module or is this a typo?


: my $action = $q->param( "action" );

You have not yet defined $q as a CGI object. You should be
seeing this error in your browser.


: SWITCH: {

This does not follow the Switch.pm docs. It's basically a
named block which allows you to avoid writing 'else' clauses.


: if  ($action =~ /Upload/) {
: last SWITCH;
: };
:
: if  ($action =~ /Update/) {
: print redirect("./import_clean_csv.php");
: exit;
: last SWITCH;

Too late. You have already exit()ed the script.


: };
:
:
: if  ($action =~ /Clean/) {

Indent the same way throughout the whole script. The previous
'if' blocks were indented four spaces. Why not do the same here?


: my @filesToRemove;

Whenever possible, declare your variables as you first use
them.


: chdir UPLOAD_DIR or die "Couldn't chdir to _data directory: $!";

UPLOAD_DIR has not been defined in this script. You should be
seeing this error in your browser.


: opendir(DR,"./");

How do you know it opened?

opendir DR, './' or die qq(Cannot open "./": $!);



: @filesToRemove  =  grep  {$_ =~ /^(\w[\w.-]*)/} readdir DR;

my @filesToRemove = grep {$_ =~ /^(\w[\w.-]*)/} readdir DR;


: closedir DR;
:
:
: print $HTML_HEADER;

$HTML_HEADER is not defined in this script. You should be
seeing this error in your browser.


: print '';
:
:
: foreach my $fr (@filesToRemove) {
:
: print  "Deleted $fr\n";
: unlink($fr)  or die "Couldn't Delete $fr $!";
: }
:
:
:
: print <Your Done close this window!
: 
: 
: HTML_OUT
: print end_html;
:
: exit;
: last SWITCH;

Too late. You have already exit()ed the script.



: };
: }
:
:
: #more

   Other than typos and uninitialized variables, nothing above
seems to be hogging resources. The problem is likely in this
unseen part or in the switch.pm module (if that wasn't a typo.)


: __END__


How about skipping the Switch stuff and using something like this.

use CGI qw/:standard Button/;
.
.
.

if ( param() ) {
if ( param( 'action' ) =~ /Upload/ ) {
# call upload sub

} elsif ( param( 'action' ) =~ /Update/ ) {
print redirect("./import_clean_csv.php");

} elsif ( param( 'action' ) =~ /Clean/ ) {

print

header(),
start_html( -title => 'Clean Upload Directory' ),

div( { align => 'center' },

ul( { style => 'list-style-type: none;' },
li( clean_dir( 'upload_dir' ) ),
),

Button( { onclick => 'self.close()' },
'Close Window'
),
),
end_html();

}

} else {
# do other stuff
}

#more ...


sub clean_dir {
# Not Tested

# Don't output anything to the browser from this subroutine.
# Return an array reference containing the report. Allow the
# caller to decide how it will be marked up.

my $upload_dir = shift;
chdir $upload_dir or die qq(Couldn't chdir to "$upload_dir": $!);

opendir my $dir, './' or die qq(Cannot open "./": $!);
my @filesToRemove = grep {$_ =~ /^(\w[\w.-]*)/} readdir $dir;
closedir $dir;

my @report;
foreach my $file ( @filesToRemove ) {
if ( unlink $file ) {
push @report, qq(Deleted "$file");

} else {
push @report, qq(Could not delete "$file": $!);
}

}

return [EMAIL PROTECTED];
}

__END__


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328




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




RE: About unoffical HTTP headers

2005-04-26 Thread Charles K. Clarkson
Shu Cao <mailto:[EMAIL PROTECTED]> wrote:

: I am new to Perl CGI programming. And I encounter a difficult problem
: wish you guys can help me. Thank you! Here is the problem, how can
: Perl CGI program get the unofficial HTTP header value like "x: y". I
: examine the %ENV hash, and found nothing but some standard HTTP
: headers like "Accept", "User-Agent", etc..

This is the first I have heard there were unofficial HTTP headers
and you have me curious. Why would you want to see these? Are you
writing a low level server script?

TIA,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: [NOVICE] calling perl program within a cgi script with parameters from html form

2005-04-26 Thread Charles K. Clarkson
Sean Davis <mailto:[EMAIL PROTECTED]> wrote:

: suppose my form values are stored in variables
: $a = param('name')
: $b = param('age')
: 
: Now I need to call a perl function wth $a, $b as parameters.
: My $string = "perl test.pl $a $b"
: system($string)
: 
: This is wht I am using now. when I try  eg: perl test.pl john 12   
: It works. And the variables are bnided properly in cgi script. I
: cheked to make sure. Can anyone suggest how i should proceed.

First we need to cover some basics. You should refrain from
using $a and $b as variable names. They are used in sort() and it
can get confusing as you progress as a programmer. Use meaningful
variable names, even for small test scripts. It's a good habit.

Avoid naming a script test.pl. It is a common name for scripts
and you may find yourself running some other program than you
intended. Also investgate the use of the "strict" and "warnings"
modules at the beginning of all your scripts.

Do you have access to the test.pl script? Can you change it?
If you can, I would advise not using an external system command
to run another perl script. There are numerous internal perl
methods available.

Without looking at the script I can't tell much. Show us some
example code including the source of test.pl.

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: CGI form Caching problem

2005-05-03 Thread Charles K. Clarkson
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
wrote: 

: I thought this must be to do with browser caching... As, on
: submission, the browser seems to send the form back to the
: server with the old values in it. But surely, even If the
: browser has cached the page, when I alter the value in one of
: the input boxes it shouldn't send back the form with the old
: data!!! Thats crazy.
: 
: I have tried sending all sorts of headers to the browser to stop
: it caching the page but nothing has made a difference. So
: perhaps the problem is not in the browser, but in apache
: somewhere??

It's hard to say without seeing code or testing it from my own
browser, but the symptoms you describe seem an awful lot like a
browser caching problem. Which browser are you testing with?
If it's IE, I think you can get a fresh page by holding the shift
key down while clicking on reload. (I'm not certain, it's been a
while since I used IE.) If you are using a modern browser you
will need to read its manual.

HTH,


Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: CGI form Caching problem

2005-05-03 Thread Charles K. Clarkson
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
wrote: 

: : If you're using IE for development, ditch it.
: 
: I would never even thonk about using IE to develop with. I do use it
: for further testing, but thats about all. I am using Firefox (PC)
: mainly, although The problem still exists on IE (PC), Firefox (PX &
: Mac) and Safari (Mac) Safari Mac.
: 
: Please, try it yourself. The page is at
: http://www.virusbtn.com/subscribe.cgi

That came up "Forbidden" when I tried it at 11:27 AM (GMT -6:00)


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: How to save the state of a CGI script

2005-05-30 Thread Charles K. Clarkson
Ankur Gupta <mailto:[EMAIL PROTECTED]> wrote:

: Thanks a lot guys for the help. I guess I have to use hidden fields.

You could also use a session cookie.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328




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




RE: How to save the state of a CGI script

2005-05-30 Thread Charles K. Clarkson
Ankur Gupta <mailto:[EMAIL PROTECTED]> wrote:

: Hi Charles,

Hi.

: I am fairly new to use the CGI module. So I would like to know
: how a cookie would be different from a hidden field.

Take a look at this page. It is a general discussion about
shopping cart scripts. It gives a decent introduction to both
techniques.

 
http://ironbark.bendigo.latrobe.edu.au/subjects/CN/2004/lectures/l20.d/Lect2
0.html


: I mean that I can store all the parameters in the cookie but
: how can I pass the parameters to the CGI script.

HTTP cookies are covered near the end of the CGI.pm docs.
You may not want to hold *every* value in the cookie. Sometimes
you use the cookie to point to (sensitive) data on the server.

Take a look at CGI::Session. It has a tutorial with it,
CGI::Session::Tutorial.



HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: CGI.PM and IF statment....

2005-09-10 Thread Charles K. Clarkson
David Gilden <mailto:[EMAIL PROTECTED]> wrote:
: The if statement below does not seem to work as expected//
: 
: Given in the HTML:
: 

Don't use white space in form field names.




: and in the perl:
: 
: #!/usr/local/bin/perl
: use CGI qw/:standard/;
: use strict;
: 
: #and other stuff...
: 
: my $mt = param('message type');

my $mt = param('message_type');


I also don't use white space in option values.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: Use of uninitialized value

2005-09-13 Thread Charles K. Clarkson
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] wrote:

: I'd rather send the whole thing b/c I also would like a critique
: as well. Here she is!

First glaring item: you cannot nest subroutines. To perl, the
following are equivalent.


===
print "blah";
if ( $which_radio_button eq 'All-Clients' ) {
&viewall();

sub viewall {
# do something;
}

} elsif ( $which_radio_button eq 'Backup-Tapes' ) {
&viewbkups();
sub viewbkups {
# do something else;
}
}


===

print "blah";
if ( $which_radio_button eq 'All-Clients' ) {
viewall();

} elsif ( $which_radio_button eq 'Backup-Tapes' ) {
viewbkups();
}

sub viewall {
# do something;
}

sub viewbkups {
# do something else;
}

===

So there's no advantage to placing the subs in line and taking
them out makes your code more readable.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: Use of uninitialized value

2005-09-13 Thread Charles K. Clarkson

Which line is giving you the error? Line 246 is blank.


Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: Use of uninitialized value

2005-09-14 Thread Charles K. Clarkson
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> wrote:

: it is on line 207...thx!
: "Use of uninitialized value in string eq at line 207"

: (See attached file: ASM_monitor.pl)


Are you certain the version you sent is the version
on the server?


This does not produce an error. (It is from the version
you sent.)

#!/usr/bin/perl

use strict;
use warnings;

use CGI qw(:standard), (-unique_headers);

my $q = CGI->new();

my $which_import = $q->param('action') || '';

if ($which_import eq 'Import STKvol') {
print "foo\n";
}

__END__


This *does* produce an error.

#!/usr/bin/perl

use strict;
use warnings;

use CGI qw(:standard), (-unique_headers);

my $q = CGI->new();

my $which_import = $q->param('action');

if ($which_import eq 'Import STKvol') {
print "foo\n";
}

__END__


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328




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




RE: problems with CGI.pm upload feature

2005-09-19 Thread Charles K. Clarkson
Scott R. Godin <mailto:[EMAIL PROTECTED]> wrote:

: Regrettably this isn't getting me any closer to a resolution --
: what about the code? can anyone see anything I might have
: overlooked? done wrong? should it, in fact, be working right
: now?

   Did you test to be certain that @file actually holds the contents
of the uploaded file?

use CGI::Carp 'fatalsToBrowser;
my @file = <$fields{file_attached}>;
die @file;

Use a small file for the test.

 
: I had hoped this would be pretty straightforward, and tried my
: best to follow the examples in the docs and sample files, but
: I'm at a complete dead-end here. 
: 
: Anyone?


I haven't looked at the docs but shouldn't 'Data' be set to
an array reference, not an array?

$message->attach(
Type=> 'AUTO',
Data=> @file,
Disposition => 'attachment',
Filename=> param('file_attached'),
Encoding=> 'base64',
);

Use:

Data => [EMAIL PROTECTED],

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: "if" Question

2005-09-26 Thread Charles K. Clarkson
Vance M. Allen <mailto:[EMAIL PROTECTED]> wrote:

: I have several places in my code where I need to check if two
: string variables are empty, if one is empty and the other is
: not, and if they're both populated.
:
: Is there any simpler way to write the code than this?

No. At least there is no perl built-in way to rewrite it. You
could use a subroutine, but you haven't supplied enough details to
get detailed help. For example, if the response is always he same
then this may work.

compare( $var1, var2 );

# or

my @result = compare( $var1, var2 );

sub compare {
my @fields = @_;

if ( $fields[0] eq '' and $fields[1] eq '' ) {
# Neither are populated...
# ...

} elsif ( $fields[0] eq '' or $fields[1] eq '' ) {
# One is populated...
# ...

} else {
# Both are populated...
# ...
}
}

It's important, though, that the subroutine not work on
external variables. Variables not passed into the sub.

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: New Website for Perl Beginners: perlmeme.org

2005-10-03 Thread Charles K. Clarkson
Rob Bryant <mailto:[EMAIL PROTECTED]> wrote:

: On 10/2/05, Ovid <[EMAIL PROTECTED]> wrote:
: 
: : There's more and nitpicking seems petty 
:
: Yep, you're right on the money with that. It does indeed seem
: petty.

Perhaps that's why he left it out.

Are you are arguing that Ovid's critique of perlmeme.org was
petty? I think you miss the point of the web site. It is meant
to teach programmers better programming practices.


 This site is devoted to spreading the perl meme and to providing
 an easy place to find complete, working examples of good Perl
 code.


Having publicly proclaimed that their site provides "good
perl code" and "working examples", it is imperative that the
better programmers in the perl community test these examples for
those claims. Not doing this would be detrimental to the community
as we would have "approved" sites advancing poor code.

Ovid checked the code and found some of it didn't run while
other example were not well written. He then reported it here on
the relevant thread. There is nothing petty in this. He would be
irresponsible to the perl community had he not done this.


: So did Randal "I am Unhealthily Obsessed With The Flinstones"
: Schwartz's earlier post.

[yawn] Ad hominem attacks are not a replacement for sound
arguments.


: One would assume (apparently erroneously, however) that the
: "perl community" would generally be more enncouraging (sic) than
: discouraging the kind of effort the original poster put forth.

How was Randal discouraging the perlmeme.org contributors? He
said he would remove his complaint with the addition of just one
link. That link would *include* them into our community, not
exclude them.


: Anyway, this thread wasn't a complete waste. Now I remember why
: I always start to use Perl but then abandon it-- great tool,
: crappy community.

I find the perl community to be a fine one. I have found,
though, that I only get from any group what I add to it. If I
can only add pessimism . . .


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: implementing links on a system command output

2005-10-18 Thread Charles K. Clarkson
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> wrote:

: I do not understand what "/path/url.pl?H_String"; is.

It looks like a CGI GET request. Like this one for Google.

http://groups.google.com/groups?q=%22multi+column%22+css


: what is the ? before H_string for and why

It is used to separate the cgi script name from the list of
fields. I think RFC 2396 explains URIs.


: understand that the H_string will be generated from a system
: command for every $_ and it looks like
:
: sf.H02047 capacty: 189.1G space: 117.7G

Can you show more examples. (Is capacity really spelled wrong
in the code?). This one will fail in the code you gave. (Well,
everything will fail in the code given, but assuming a complete
code example was given, this example would fail.) How about five
that should fail to print and five that should succeed and print
a link.

Here's how I would write the code for a question to a list.
Note how I replaced the I/O with . I don't care how you get
the data, as long as you are sure the sample is an accurate
sample.

You can then just add the examples at the bottom of the script
below the __END__ tag. Then we can all cut and paste the script to
our editors and see your problem first hand.

Note that I deleted the "open' statement, the extra comments,
that $flag business, simplified the html, and added strict and
warnings. All the distractions are out of the way and we can find
what problem you are really having. As soon as we have some
sample data.



#!/usr/bin/perl

use strict;
use warnings;

viewhrtlab();

sub viewhrtlab {

foreach (  ) {

if ( /(?i)fs_heartlab\.1/ .. /(?i)fs_lanv1.1/ ) {
s<>;

if (/(?i)total space available:/) {
print "$_";

} else {
print qq(\n";
}
}
}
}

__END__
sf.H02047 capacity: 189.1G space: 117.7G
.
.
    .



    Can you supply us something like that?

HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328



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




RE: implementing links on a system command output

2005-10-20 Thread Charles K. Clarkson
[EMAIL PROTECTED]  wrote:

: ok here is what I am trying to do. In the atached doc it shows
: output from my perl cgi program ...

You sent this as a MS Word document. When I open it, Word
converts it to a word web view and when I view the code I get a
Word trashed html file listing. Can you send this as a raw text
file instead? The Word format is pretty useless.



 http://www.w3.org/TR/REC-html40";>

 
 
 
 
 
 
 
 
 

RE: implementing links on a system command output

2005-10-21 Thread Charles K. Clarkson
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> wrote:

: The difficulty is that $_ is an entire block of data that
: includes more than just H strings and therefore I cannot link
: all of $_ which is why I placed just the H strings from $_ in an
: array.  From this array, I was thinking of traversing
: through, running the command to get the capacity data.

Here's what I am gleaming from your words.

When you say $_ you are referring to this part of the script:

open (ARC, "archiver -v |") or error();
foreach ()
{

"archiver -v |" returns this.

fs_heartlab.1
 sort:path
 media: sg
 Volumes:
   H01192
   H01193
   H01195
   H01196
   H01197
 Total space available:  111.3G

fs_heartlab.2
 sort:path
 media: sf
 Volumes:
   H02047
   H02048
   H02051
   H02052
   H02000
   H02039
   H02040
   H02041
 Total space available:  527.8G

So, as a test case, we can use this script. DATA is the same
as ARC above, but now everyone on this list can play with the
code. I use 'while' instead of 'foreach' because it is the more
common idiom in this situation.

#!/usr/bin/perl

use strict;
use warnings;

while (  ) {
# do something
}

__END__

fs_heartlab.1
 sort:path
 media: sg
 Volumes:
   H01192
   H01193
   H01195
   H01196
   H01197
 Total space available:  111.3G

fs_heartlab.2
 sort:path
 media: sf
 Volumes:
   H02047
   H02048
   H02051
   H02052
   H02000
   H02039
   H02040
   H02041
 Total space available:  527.8G


Now, if I am not mistaken your task is to strip only the
"H strings" from this list and place it into an array. Since I am
mentally unable to name an array variable with a name containing
the word "array", I will be using the name @h_strings.

#!/usr/bin/perl

use strict;
use warnings;

my @h_strings;
while (  ) {
chomp;
push @h_strings, $1 if /\s*(H\d{5})/i;
}

print "$_\n" foreach @h_strings;

__END__

fs_heartlab.1
 sort:path
 media: sg
 Volumes:
   H01192
   H01193
   H01195
   H01196
   H01197
 Total space available:  111.3G

fs_heartlab.2
 sort:path
 media: sf
 Volumes:
   H02047
   H02048
   H02051
   H02052
   H02000
   H02039
   H02040
   H02041
 Total space available:  527.8G

Now @h_strings contains this. Which I believe provides you
with the array you needed to run your command.

H01192
H01193
H01195
H01196
H01197
H02047
H02048
H02051
H02052
H02000
H02039
H02040
H02041

To step through the array, you could use foreach.

foreach my $h_string ( @h_strings ) {
# Do something with $h_string.
}


If you want to do it all in one step, this would work.

#!/usr/bin/perl

use strict;
use warnings;

while (  ) {
chomp;
next unless /\s*(H\d{5})/i;

my $h_string = $1;
# Do something with $h_string.
}

__END__

To translate that back to your subroutine, we would do this.

sub viewhrtlab {

# Don't clobber ARC if it is already open somewhere else.
local *ARC;

open (ARC, "archiver -v |") or error();

while (  ) {
chomp;
next unless /\s*(H\d{5})/i;

        my $h_string = $1;

# Do something with $h_string.
}
}

HTH,


Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328





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




RE: implementing links on a system command output

2005-10-21 Thread Charles K. Clarkson
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> wrote:

: thx Charles, but your code is something I did knew (sic) already.
: I need to implement a link for each H string and I do not see
: this???

I assume by "implement a link" you mean that you want to
create an HTML ANCHOR tag for each H String. After re-reading your
original question on this thread I think you are looking for more
than just an anchor tag. You also need a method to retrieve
"capacity data sets" after a link has been followed.

Here is my solution.

my $url = 'capacity.pl?hstring';

my @links;
foreach my $h_string ( @h_strings ) {
push @links,
$q->a(
{ href=> "$url=$h_string" },
$h_string
);
}

print
$q->ul(
$q->li( [EMAIL PROTECTED] ),
);


# in capacity.pl

#!/usr/bin/perl

use strict;
use warnings;

use CGI;

my $q = CGI->new();

my $h_string = $q->param( 'hstring' );

print
$q->header(),
$q->start_html( "Capacity Data for $h_string" ),
$q->p( capcity_data( $h_string ) ),
$q->end_html;

sub capcity_data {
my $h_string = shift;

#
# Do that thing you do to get capacity data and
#   deposit the result in $capacity_data.
#

return $capacity_data;
}

__END__



: So in the FH reference local *ARC;
: once its open, I can just reuse the reference right?  Does the
: FH have to still be open in order to reuse it?

I don'tknow what you are asking. For more info on why I
added "local *ARC;" read this article.

http://perl.plover.com/local.html#2_Localized_Filehandles



HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




RE: Need help with making a Modules

2005-11-27 Thread Charles K. Clarkson
Lou Hernsen <mailto:[EMAIL PROTECTED]> wrote:

: I am studying modules.. I am seeking a mentor to help.

What do you mean by "module"? I ask because many people have very
different ideas about what one is.

For example, some people think about a library.

require 'my_perl_module.pl";


When I say "module", I am usually thinking of an object.

use TemplateVariables;

my $vars = TemplateVariables
-> new()
-> select_categories();


Others think of a library of subroutines and variables.

use CGI qw(:standard center);

print
header(),
start_html('foo'),
center(h1('foo')),
end_html();

In your own words, define "module."


: I have very simple questions like ...
: Do I need to pass vars into the mod?

That depends on what you are attempting to do. It also depends
on what you want the module to do. The CGI example above passed
variables into the module to tell it which subroutines should be
exported. An object may require variables to be added when it is
constructed.


: Do i need to declare vars in the mod?

It is often very difficult to write an entire module without
declaring a variable, but it is not impossible.


: What is "our"? something like "my" and "local"?

 Yes. Have you read perlfunc?


: Do I need to return vars?

Not usually. Most modules return values.

 
: The code I am writing creates part of a web page,
: so I can print it in the mod or in the main.
: (I wold prefer to print it in the mod.. if possible)
: 
: I have been reading for 2 weeks now and can't find a simple working
: model to disect that I can understand all the parts of.

Give us  a more detailed idea of what you are attempting and
perhaps we could write an example for you.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328

 . . . With Liberty and Justice for all (heterosexuals).


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




RE: Need help with making a Modules

2005-11-27 Thread Charles K. Clarkson
Lou Hernsen <mailto:[EMAIL PROTECTED]> wrote:

: I am trying to create a module that will print the Stats of the
: player of my on line game.
: all it should do is take the vars, do some calulations and print the
: HTML 
: since the Stats is used in every time i don't want to duplicate it in
: each program.

So there is just one subroutine.


: The main program has all your players vars loaded...
: the Stats subroutine (which I want to make into a mod)
: puts the HTML code in the  of the web page...
: from what I have read this should not be a hard things to do.

No. It is pretty easy.


: Module= a piece of code that is repeated in several programs.

That's what I thought you were after, but I wanted to be sure.


: Each location in the town is a separate program
: If I can't get this to work I'll just leave the sub Stats()  in
: each program and not worry about it.

Many people use copy and paste to reuse code. The problem is
you may need to make a change. Either you have to write a program
to make the changes in every file or you resign to not making the
change. A module is definitely the right solution for you.

package Stats;

# No need for BEGIN. Read the Exporter docs for details.
use Exporter 'import';

# Any element of this array will be imported into
# calling package namespace (probably main::).
@EXPORT = qw(Speed);

sub Speed
{
 $v0 = 1+$Army+$Hero+$Spy;
 $v1 = 1+$Army+$Hero+$Spy+$Wagon;
 if  ($Wagon < 1 && $Horse >= $v0
  && $Saddle >= $v0 && $Blanket >= $v0
  && $Load <= 100)
{$Speed = "1.5";}
 elsif ($Wagon == 0 && $Horse >= $v0 && $Load <= 100)
{$Speed = "2";}
 elsif ($Wagon > 0 && $Horse >= $v1 && $Load <= 100)
  {$Speed = "2.5";}
 elsif ($Wagon == 0 && $Load <= 100)
  {$Speed = "3";}
 elsif ($Load > 100)
  {$Speed = (int(.3 * $Load))/10;}
 else {$Speed=3;}

 # Do your HTML stuff
}

# This is more common than using "return 1;"
1;

In your program do this.

use lib '.';# Point to the directory where you placed
    # your module.

#use Stats; # This is fine, but
use Stats 'Speed';  # this tells you where Speed() come from.

.
.
.

Speed();



HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328

PS  Please, please, please, don't use global scoped variables in your
subroutines. Lou is stubborn, but the rest of you are not off the
hook. Pass all variables into the your subs and pass all variables
out of your subs. Do not operate (or depend) on variables which
are external a subroutine.


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




RE: our..... Lou's code ( was: Need help with making a Modules )

2005-11-28 Thread Charles K. Clarkson
Lou Hernsen <> wrote:

: Bob Showalter <> wrote:
: 
: : A variable declared with "my" is only accessible within the
: : enclosing file, block, or eval.
: 
: File is the entire program.

Yes.

: like a global var?

No. Globals are in the symbol table and can be accessed from
*outside* the file. File scoped lexicals can only be accessed
from *inside* the file.


: Block is the "if" or "while" or other {} framed code?

Yes.


: what is an eval?

A perl function. Read perlfunc or type "perldoc -f eval" from   
the command line (DOS box).


: : "our" is a declaration that allows you to use a global
: : (symbol-table) variable name without a package qualifier when
: : "use strict" is in effect. 
: 
: from what you say "our" is used in the main program

It can be used in any file. The main program or a module which
uses the "strict" module.


: so I don't have to declare them again in the mod?

No. You should be importing the module subroutines into the
"main" namespace. So your program will "think" the subroutine and
variables are from "main".

If you are not using "strict" you don't need "our".


: So if I run the mod as one big ad-in program to main
: and not calling subs in the mod, I don't have to pass vars in the
: ()'s? stats;
: and not
: stats::sub($var1, $var2, etc);

Yes. I showed an example in the "Need help with making a
Modules" thread.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328

 . . . With Liberty and Justice for all (heterosexuals).


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




RE: Lou's Code - need a little more help on mod questions.

2005-11-28 Thread Charles K. Clarkson
Lou Hernsen <mailto:[EMAIL PROTECTED]> wrote:

: Bareword "stats" not allowed while "strict subs" in use at
: C:\WWW\MYSTIC~1\CGI-BIN\TEST-N~1\MA.CGI line 4359. Execution of
: C:\WWW\MYSTIC~1\CGI-BIN\TEST-N~1\MA.CGI aborted due to compilation
: errors 

What's on the lines near line 4359?

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: Lou's Code - need a little more help on mod questions.

2005-11-29 Thread Charles K. Clarkson
Lou Hernsen <mailto:[EMAIL PROTECTED]> wrote:

: "Charles K. Clarkson" <[EMAIL PROTECTED]>
: 
: : Lou Hernsen <mailto:[EMAIL PROTECTED]> wrote:
: : 
: : : Bareword "stats" not allowed while "strict subs" in use at
: : : C:\WWW\MYSTIC~1\CGI-BIN\TEST-N~1\MA.CGI line 4359. Execution
: : : of C:\WWW\MYSTIC~1\CGI-BIN\TEST-N~1\MA.CGI aborted due to
: : : compilation errors
: : 
: : What's on the lines near line 4359?
: 
: stats;
: the command to call the module.

We don't "call" modules. We load them using "use", then we
use them according to how they were written. In the old thread you
wanted to import a subroutine named Speed(). To use that sub on
line 4359, you would call it like this. The error from perl
indicates that you did not export a sub named stats().

Speed();


The reason for this is because Stats.pm might have a hundreds
of subroutines in it. If we had to call all of them on each use of
any of them, we'd be up that smelly old creek. Remember how CGI.pm
works. We call it at the top of the script and then call its
imported subroutines as if we had written them in the "main" name
space.



HTH,


Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328

PS

The original name of the package was "Stats", not "stats".
"use" is case sensitive. The module should have a name which
matches the package name.


# In a file named "Stats.pm"
package Stats;

use Exporter 'import';

# Any element of this array will be imported into
# calling package namespace (probably main::).
@EXPORT = qw(Speed);

sub Speed
{
 $v0 = 1+$Army+$Hero+$Spy;
 $v1 = 1+$Army+$Hero+$Spy+$Wagon;
 if  ($Wagon < 1 && $Horse >= $v0
  && $Saddle >= $v0 && $Blanket >= $v0
  && $Load <= 100)
{$Speed = "1.5";}
 elsif ($Wagon == 0 && $Horse >= $v0 && $Load <= 100)
{$Speed = "2";}
 elsif ($Wagon > 0 && $Horse >= $v1 && $Load <= 100)
  {$Speed = "2.5";}
 elsif ($Wagon == 0 && $Load <= 100)
  {$Speed = "3";}
 elsif ($Load > 100)
  {$Speed = (int(.3 * $Load))/10;}
 else {$Speed=3;}

 # Do your HTML stuff
}

1;


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




RE: syntax error

2005-12-03 Thread Charles K. Clarkson
Thom Hehl <mailto:[EMAIL PROTECTED]> wrote:

: $SysIndex = 0;
: 
: if ($PageNo==1)
: {
: my @sysnamelist=split(/$SEPARATOR/,$config{$SYSNAME});
: my $sysnamelist[$SysIndex]=$input{$SYSNAME};

Remove the "my".

$sysnamelist[$SysIndex] = $input{$SYSNAME};


: $config{$SYSNAME}=join(/$SEPARATOR/,$sysnamelist);
: } elsif ($PageNo==2)

HTH,
Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: Backing Up Files to a Remote Server

2005-12-14 Thread Charles K. Clarkson
Adedayo Adeyeye <mailto:[EMAIL PROTECTED]> wrote:

: Thanks.
: 
: To get the statistics of a file on my windows box, I ran the
: following script: 
: 
: 
: open FILE1, "Perfect.xls" or die "Cannot open file: $!";
: 
: my @stuff = stat "FILE1";
: 
: print "@stuff";
: 
: Unfortunately, I don't know why this never returned any values into
: my @stuff variable.

Because stat() works on filenames, not file handles.

my @stuff = stat 'Perfect.xls';



: Next I tried this: 
: 
: open FILE1, "Perfect.xls" or die "Cannot open file: $!";
: 
: open FILE2, ">folder\Perfect.xls" or die "Cannot write to destination
: directory: $!"; 

In perl, directories are separated by "/" not "\". "\P" is an
escaped "P".


: system ("copy FILE1 FILE2");
: 
: close FILE1;
: close FILE2;

use File::Copy 'copy';

copy( 'Perfect.xls', 'folder/Perfect.xls') or die "Copy failed: $!";


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: Backing Up Files to a Remote Server

2005-12-14 Thread Charles K. Clarkson
Adedayo Adeyeye <mailto:[EMAIL PROTECTED]> wrote:

: Still didn't work. However, I removed use File::stat and everything
: works fine now.

IIRC, File::stat is an OO version of stat(). I believe it forces
stat() to return a hash or a blessed object, not an array.


: =>print "$atime";
: =>print "$mtime";

Why are $atime and $mtime in quotes? Read perlfaq4:
What's wrong with always quoting "$vars"?


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: Wildcards

2005-12-26 Thread Charles K. Clarkson
Bill Stephenson <mailto:[EMAIL PROTECTED]> wrote:

: I was playing around with it and found when I enter a "*" character
: it matches all records. That's kind of a cool feature for the users
: of this script. Are there any other special characters that will
: affect the results?

Yes. Many many. What you are matching above is a null string.
It is not a good practice. You'll get a warning if you turn on
warnings (which *is* a good thing). If the regex engine did not
specifically check for this condition the expression would create
an infinite loop. Run this script.


#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;

my @matches = grep /^*/i, qw(foo bar baz), '';

print scalar @matches;

__END__



It is usually better to eliminate as many special characters
in a search pattern as possible. Not doing so a is big security
risk. The 'quotemeta' function and the \Q operator are meant for
this purpose. Also check out the references to tainted data in
perlsec and in perlfaq7.

You're right, '*' is a handy way to match all the records in
your case. Just be aware of the pitfalls involved in relying on
special characters to do the work. There are many many people
out there who can wreak havoc on your server if you allow it.
Beware.

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328




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




RE: CGI - HTML::TEMPLATE - How do it ?

2006-02-02 Thread Charles K. Clarkson
Augusto Flavio wrote:
> Hi,
> 
> 
> I`m have a question. i want to do a table using the module
> HTML::Template. Well.. A simple table i can do but a table with
> differents rows i don`t made(sorry my english).. How i do a table
> like this:   
> 
> http://www.smartlinks.com.br/~aflavio/test.html
> 

That's not a very complicated table. Just 3 rows by six
columns. Why is it giving you problems?


Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: CGI - HTML::TEMPLATE - How do it ?

2006-02-02 Thread Charles K. Clarkson
Augusto Flavio wrote:

: The problem is my array... Look:
:
:
: @domains = (
:  { name => 'domain1.com'},
:  { name => 'domain2.com'},
:  { name => 'domain3.com'},
: );
:
: where i place the subdomain of the value domain2.com ?


@domains = (
 { name => 'domain1.com'},
 { name => 'domain2.com',
   subdomain => 'www.domain2.com',
 },
 { name => 'domain3.com'},
);

And in the template add a variable for sub domain in
the appropriate spot. You may need to turn off
"die_on_bad_params" when you initialize the template.






A more robust solution would allow for multiple sub domains.
Use this and an inner loop named "subdomains". The "if" part
may not be necessary. You'll need to test it.

@domains = (
 { name => 'domain1.com'},
 { name => 'domain2.com',
   subdomains => [
 { name => 'www.domain2.com' },
 { name => 'foo.domain2.com' },
     { name => 'bar.domain2.com' },
   ],
 },
 { name => 'domain3.com'},

);

And in the template something like this.








HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



















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




RE: Matching a string containing '+'

2006-02-08 Thread Charles K. Clarkson
Sara wrote:

[snip]
: my $sql = qq(
: SELECT CAT_TITLE,
: FROM categories
: WHERE CAT_TITLE REGEXP '^C_and_C\\+\\+/[a-zA-Z|_]+\$'
: );
[snip]

Why is there an escape character in front of the $ anchor?
There isn't one in any of the examples in the linked content.
Try this. It avoids the annoying escapes with character classes
and better highlights that stray escape '\'.

 '^C_and_C[+][+]/[a-zA-Z|_]+$'


Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: hi,how to get the correct statistic

2006-02-21 Thread Charles K. Clarkson
Joodhawk Lin wrote:
: hi all,
:
: i copy source from
:
http://www.planet-source-code.com/vb/scripts/ShowCodeAsText.asp?txtCodeId=48
1&lngWId=6,
: the piece source aims to  merges 2 or more text files into one more
: manageable file. and it also remove the duplicates and comments
: (start with #).   
[snip]
:
: it is the incorrect result. as we excepted, such as in the
: a.txt, we know 2 duplicates apparently.

Not necessarily. One of the duplicate words in a.txt is
the last line of the file. Does that line end with a new
line character? Many text files do not. If it doesn't, this
script will chop() the 'c' of the end of the word which
will not match the previous line with a 'c' because on that
line the line ending was chopped off. ('c' != '')

Also, we cannot tell from your example that there is no
stray white space in the files. The dated code you are using
does not check for line endings (it uses chop()) and it does
not strip for white space characters. The very fact that you
didn't mention white space characters in your message leads me
to believe they may be there.


: how to correct it ?

Rewrite it.

The script was probably written as a utility for a very
short term solution and was unlikely meant to be publicly
used or traded. The author does not verify I/O operations,
uses chop() where chomp() is more appropriate, has no error
checking, is not using lexical variables, and seems a little
unorganized.

My advice would be to check your data files first to be
certain your perceived errors are real errors and to stay
away from this script if you are planning to put this into a
production environment. Write your own script which follows
more modern perl standards and checks for stray white space
characters and missing last line line endings.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




RE: verify if e-mail is returned

2006-04-10 Thread Charles K. Clarkson
Cristi Ocolisan wrote:
: Hi all,
: 
: I'm trying to develop a system to send mass mailing.
: In order to do that I already developed the script, but I faced
: some problems when I ran it. (I'm using MySQL to store the e-mail
: addresses)
: 
: 1. It seems that I have to LIMIT the number of addresses (to max.
: 100) when I send a message.

Why do you have to do that? What happens when you use 101 email
addresses? Is this a limit of your mail server, MySQL, or of the
module you are using to send bulk mail?


: 2. I cannot verify if the message is received or it came back to me,
: unless I read the maillog on the server.

You need a module which reads the maillog on the server. Did you
search for a mail module like that at CPAN? Perhaps one that looks for
bounced email might do.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



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




  1   2   >