Re: a way to make this more secured and better written?

2004-06-15 Thread Wiggins d'Anconia
Please bottom post and group reply so everyone can help and be helped, 
and you run less risk of being accidentally ignored...

Jason Gray wrote:
What do you exactly mean by passing $q as an argument?
In general you want to avoid the use of globals, and "encapsulate" your 
subroutines such that they only use information that has been 
specifically given to them, either through their argument list or 
because they are a method call (aka object/class, etc.).  In your code 
your subroutines access $q, which is not provided to the subroutine in 
one of these manners, it just happens to be available because the 
subroutines are in the same file as the initialization of $q, and 
because it is file scoped.  If you move the subroutines into their own 
library, or above the rest of the main body of the script they will no 
longer work and will complain about not knowing what $q is.  As your 
code gets more advanced you will want to be able to move large chunks of 
code without worrying about what may or may not break because of a 
particular scope or another. If for no other reason than it becomes 
difficult to test and debug.   This is a difficult case because $q acts 
like a singleton, which is the one time you might want to use this 
approach, but in that case you are better off making it a package 
variable and using its fully qualified name, so that moving the 
subroutines into a library will still have access to the variable, even 
as a singleton (though I don't really like this approach either).

So you end up with either the passing method, such that your calls look 
like:

check_field($q);
Then in the subroutine you would add something similar to
sub check_fields {
  my $query = shift;
  # use $query here instead of $q (name doesn't matter)
  ...
}
Or you could declare $q like,
our $q = new CGI;
Then in your subroutine,
sub check_fields {
   # use $main::q to access the variable here
}
If you feel that going through this when creating your subroutines is 
overkill or not beneficial, then I would do as the other poster 
mentioned and re-examine whether you really needed the code put into 
subroutines in the first place.

Does this help at all?  This is a pretty basic (though difficult) design 
philosophy, and I feel I haven't done a very good job explaining it.

http://danconia.org
- Original Message - 
From: "Wiggins d Anconia" <[EMAIL PROTECTED]>
To: "Jason Gray" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, June 15, 2004 10:18 AM
Subject: Re: a way to make this more secured and better written?


#!/usr/bin/perl -w
use strict;
use warnings;
You probably don't want both -w and 'use warnings'.  Personally I would
stick with the 'use warnings' unless you have to deal with older
versions of Perl which is not terribly likely. The -w turns on warnings
for the whole script, which will include those produced by CGI,
Mail::Mailer and any other CPAN modules used.  'use warnings' will be
for only this script (or any other file you add it too) which will allow
you to only hear about those things you can fix.

use CGI();
use Mail::Mailer;
my $q = CGI->new();
print $q->header();
#-
# * startup methods -> global variables.
check_fields();
#-
sub check_fields {
my $blanks;
my @fields = qw(name email city state message);
foreach my $field (@fields) {
 $blanks++ if !$q->param($field);
Using $q here has just broken encapsulation. If you move this subroutine
to the top of the file or into a library of its own it no longer works,
'strict' is not complaining because it is file scoped and sort of
"global".  You should be passing in $q as an argument or similar rather
than getting lucky that its scoped to the whole file.

}
if($blanks) {
 print qq(Error: There were some blank fields.);
 exit;
You might consider using 'die' here instead of a print followed by 'exit'. 

perldoc -f die
perldoc Carp

}
unless($q->param('email') =~ /[EMAIL PROTECTED]/) {
 print qq(Error: Please enter a valid email address.);
Before you exited on failure, why not here?  Also the above regex is not
sufficient for checking email addresses. If you really want to check for
a valid email address you should consider,
Email::Valid
From the CPAN.

}
send_email();
Why is calling send_email a part of checking the fields' validity?  This
is more likely better off being called from the main. Subroutines should
usually take parameters and return a value.  In this case you could
return nothing on success or an error message on failure, then your
error handling could be done outside of the routine.

}
sub send_email {
my $m = Mail::Mailer->new('sendmail');
$m->open({ From=> $q->param('email'),
   To  => 'perl <[EMAIL PROTECTED]>',
   Subject => '[INFO] Site Comment',
 }) or die $!;
Now your error handling has switched to using 'die'. You should use a
consistent approach, it is the consistency more than which approach that
you choose that 

Re: MIME::Entity fills my memory

2004-06-15 Thread Randy W. Sims
On 6/15/2004 6:34 PM, Papo Napolitano wrote:
Hi,
I just discovered this code:
[CODE SNIPPED]
makes my script eat all the available system memory (and swap!)
So my question is how do destroy $msg so the memory is freed?
'undef $msg' or '$msg = undef' inside the loop aren't working.
my variables are lexically scoped, meaning that they cease to exist 
after the enclosing scope ends. In this case the variable is created and 
destroy through each iteration of the loop. I.e. You don't need to do 
anything to recover resources; Your code should work as is.

I do not see the problem here. It may be a bug in the version of 
MIME::Entity or one of its dependents that you are using. Check 
 for any known problems with your version. Try 
upgrading to the latest version. If problem persists, report it to RT 
/AND/ the author. If the fix is long in coming, consider downgrading.

perl -MMIME::Entity -e 'print $MIME::Entity::VERSION'
=> 5.404
Regards,
Randy.

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



Re: Time

2004-06-15 Thread Wiggins d'Anconia
Your script appears to break every 4th year
http://danconia.org
Chris Welch wrote:
The attached text file is an example of a calendar I've used for CGI
purposes (I should point out this is not entirely my script, it's
modified by me but the original was by a friend of mine.)

-Original Message-
From: Mandar Rahurkar [mailto:[EMAIL PROTECTED]
Sent: 15 June 2004 23:22
Cc: [EMAIL PROTECTED]
Subject: Time
Hello All,
  I was wondering if there any module in perl which will let
me
add dates taking care of all the complications (i.e.,) if day is
greater
than 30 change month and so on.
Thanks,
Mandar

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


#! C:\web\perl\bin\perl.exe
require("../admin/mkttl.conf");
use CGI;
use Time::Local; ## from DMYHMS to epoch
$q = new CGI;
(my $true_sec, my $true_min, my $true_hour, my $true_mday, my $true_mon, my 
$true_year, my $true_wday, my $true_yday, my $true_isdst) = localtime(time);
$days_in_month[0] = 31;
$days_in_month[1] = 28;
$days_in_month[2] = 31;
$days_in_month[3] = 30;
$days_in_month[4] = 31;
$days_in_month[5] = 30;
$days_in_month[6] = 31;
$days_in_month[7] = 31;
$days_in_month[8] = 30;
$days_in_month[9] = 31;
$days_in_month[10] = 30;
$days_in_month[11] = 31;
$months[0] = 'January';
$months[1] = 'February';
$months[2] = 'March';
$months[3] = 'April';
$months[4] = 'May';
$months[5] = 'June';
$months[6] = 'July';
$months[7] = 'August';
$months[8] = 'September';
$months[9] = 'October';
$months[10] = 'November';
$months[11] = 'December';
$days[0] = 'Sunday';
$days[1] = 'Monday';
$days[2] = 'Tuesday';
$days[3] = 'Wednesday';
$days[4] = 'Thursday';
$days[5] = 'Friday';
$days[6] = 'Saturday';
# The calendar
$mon = ($q->param("month") - 1);
$year = ($q->param("year")) if ($q->param("year"));
$year = $true_year if ($year eq ""); # Use today's date if none are specified
$mon = $true_mon if ($mon == -1);
$todays_day_of_month = $true_mday if ($true_mon eq $mon && $true_year eq $year);
my $first_day_of_month_epoch = timelocal(1, 0, 0,1, $mon, $year);
(my $sec, my $min, my $hour, my $mday, my $mon, my $year, my $wday, my $yday, my $isdst) = localtime($first_day_of_month_epoch); 

$inset_month = $wday - 1;
$inset_month = 6 if ($inset_month < 0);
print "


«".$months[$mon]." ".($year + 
1900)."»



M
T
W
T
F
S
S
\n";

$day_position_counter = 0;
$day_number_counter = 1;
$final_day_number = $days_in_month[$mon];
## first create inset
$i = 0;
while ($i < $inset_month){
print "\n" if $day_position_counter == 0;
print " \n";
$day_position_counter++;
$i++;
}
## now create main section
while ($day_number_counter <= $final_day_number){
	## setup todays info
	$todays_epoch_date = timelocal(0, 0, 12, ($day_number_counter), $mon, $year);
		
	print "	\n" if $day_position_counter == 0;
			
	if ($todays_day_of_month eq $day_number_counter){
		print "		".$day_number_counter."\n";			
	} else {		
		print "		".$day_number_counter."\n";
	}			  	   		
			
	$day_position_counter++;
		   
	if ($day_position_counter == 7){
	   		$day_position_counter = 0;
			print "	\n";	
	}

$day_number_counter++;
}
## now finish off the row if necessary
while ($day_position_counter){
	print "		 \n";
	$day_position_counter++;
		   
	if ($day_position_counter == 7){
		$day_position_counter = 0;
		print "	\n";
	}
}

print "\n\n";
print "\n\n";
print "\n";
exit;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Time

2004-06-15 Thread Chris Welch
The attached text file is an example of a calendar I've used for CGI
purposes (I should point out this is not entirely my script, it's
modified by me but the original was by a friend of mine.)

> -Original Message-
> From: Mandar Rahurkar [mailto:[EMAIL PROTECTED]
> Sent: 15 June 2004 23:22
> Cc: [EMAIL PROTECTED]
> Subject: Time
> 
> Hello All,
>I was wondering if there any module in perl which will let
me
> add dates taking care of all the complications (i.e.,) if day is
greater
> than 30 change month and so on.
> 
> Thanks,
> Mandar
> 
> 
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  

#! C:\web\perl\bin\perl.exe

require("../admin/mkttl.conf");

use CGI;
use Time::Local; ## from DMYHMS to epoch

$q = new CGI;

(my $true_sec, my $true_min, my $true_hour, my $true_mday, my $true_mon, my 
$true_year, my $true_wday, my $true_yday, my $true_isdst) = localtime(time);

$days_in_month[0] = 31;
$days_in_month[1] = 28;
$days_in_month[2] = 31;
$days_in_month[3] = 30;
$days_in_month[4] = 31;
$days_in_month[5] = 30;
$days_in_month[6] = 31;
$days_in_month[7] = 31;
$days_in_month[8] = 30;
$days_in_month[9] = 31;
$days_in_month[10] = 30;
$days_in_month[11] = 31;

$months[0] = 'January';
$months[1] = 'February';
$months[2] = 'March';
$months[3] = 'April';
$months[4] = 'May';
$months[5] = 'June';
$months[6] = 'July';
$months[7] = 'August';
$months[8] = 'September';
$months[9] = 'October';
$months[10] = 'November';
$months[11] = 'December';

$days[0] = 'Sunday';
$days[1] = 'Monday';
$days[2] = 'Tuesday';
$days[3] = 'Wednesday';
$days[4] = 'Thursday';
$days[5] = 'Friday';
$days[6] = 'Saturday';

# The calendar
$mon = ($q->param("month") - 1);
$year = ($q->param("year")) if ($q->param("year"));
$year = $true_year if ($year eq ""); # Use today's date if none are specified
$mon = $true_mon if ($mon == -1);

$todays_day_of_month = $true_mday if ($true_mon eq $mon && $true_year eq $year);

my $first_day_of_month_epoch = timelocal(1, 0, 0,1, $mon, $year);
(my $sec, my $min, my $hour, my $mday, my $mon, my $year, my $wday, my $yday, my 
$isdst) = localtime($first_day_of_month_epoch); 

$inset_month = $wday - 1;
$inset_month = 6 if ($inset_month < 0);

print "


«".$months[$mon]." ".($year + 
1900)."»



M
T
W
T
F
S
S
\n";

$day_position_counter = 0;
$day_number_counter = 1;
$final_day_number = $days_in_month[$mon];

## first create inset
$i = 0;
while ($i < $inset_month){
print " \n" if $day_position_counter == 0;
print "  \n";
$day_position_counter++;
$i++;
}

## now create main section
while ($day_number_counter <= $final_day_number){
## setup todays info
$todays_epoch_date = timelocal(0, 0, 12, ($day_number_counter), $mon, $year);

print " \n" if $day_position_counter == 0;

if ($todays_day_of_month eq $day_number_counter){
print " ".$day_number_counter."\n"; 
 
} else {
print " ".$day_number_counter."\n";
}   

$day_position_counter++;
   
if ($day_position_counter == 7){
$day_position_counter = 0;
print " \n";   
}

$day_number_counter++;
}

## now finish off the row if necessary
while ($day_position_counter){
print "  \n";
$day_position_counter++;
   
if ($day_position_counter == 7){
$day_position_counter = 0;
print " \n";
}
}

print "\n\n";
print "\n\n";
print "\n";

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


MIME::Entity fills my memory

2004-06-15 Thread Papo Napolitano
Hi,

I just discovered this code:


#!/usr/bin/perl

use warnings;
use strict;
use MIME::Entity;

while (1) {
  my $msg = MIME::Entity->build(
From => 'TEST <[EMAIL PROTECTED]>',
Sender   => '[EMAIL PROTECTED]',
To   => '[EMAIL PROTECTED]',
Subject  => 'TEST',
Encoding => '-SUGGEST',
Type => 'text/plain',
Data => 'Hello world',
  );
}


makes my script eat all the available system memory (and swap!)
So my question is how do destroy $msg so the memory is freed?
'undef $msg' or '$msg = undef' inside the loop aren't working.

Thanks!

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




Re: Time

2004-06-15 Thread Randy W. Sims
On 6/15/2004 6:21 PM, Mandar Rahurkar wrote:
Hello All,
   I was wondering if there any module in perl which will let me 
add dates taking care of all the complications (i.e.,) if day is greater 
than 30 change month and so on.
The upcoming standard is the DateTime family of modules. However, many 
still seem to prefer Date::Calc or Date::Manip.

Randy.

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



Re: Time

2004-06-15 Thread Wiggins d Anconia
> Hello All,
>I was wondering if there any module in perl which will let me 
> add dates taking care of all the complications (i.e.,) if day is greater 
> than 30 change month and so on.
> 

Check CPAN for,

Date::Calc
Date::Manip

Depending on how fancy you need to get, you can also use the 'time' and
'localtime' built-ins along with some simple integer math performed in
seconds to get the same results.

http://danconia.org


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




Time

2004-06-15 Thread Mandar Rahurkar
Hello All,
   I was wondering if there any module in perl which will let me 
add dates taking care of all the complications (i.e.,) if day is greater 
than 30 change month and so on.

Thanks,
Mandar

 


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




RE: I can't build a sane perl (floating-point numbers go funny)

2004-06-15 Thread Deneb Meketa
Thanks for the perlnumber reference.  But the problem is more severe than
just inexact numbers.  I was writing about the inexact numbers because that
seemed like an easy thing to discuss :)

The more serious problems start whenever anything (including stuff in the
perl libraries) says something like:

  require 5.006;

In that case, I see:

  Perl v5.319.724 required--this is only v5.8.0

And that's, uh, a bit limiting.

I was wondering if the *degree* of inexactness hadn't somehow gotten a lot
worse than usual.  I've never seen perl have a problem storing something
like 1.1 exactly.  So I thought the "print 1.1" test was a simpler thing
that might have been indicative of the root problem.  I feel like,
somewhere, something is expecting one kind of floating-point representation
and getting another.

Anyway, I'll send this query to p5p, now that I have the suggestion that
it's a reasonable kind of thing to ask there.  I was originally wondering if
p5p limited itself to traffic about perl internals.

Thanks again
d.


-Original Message-
From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 15, 2004 7:58 AM
To: Deneb Meketa; [EMAIL PROTECTED]
Subject: Re: I can't build a sane perl (floating-point numbers go funny)

> I have some experience using perl, but I'm having a hard time finding or
> building a sane perl interpreter for my particular machine.  For example,
> perl -e "print 1.1" yields something like 1.10833.  This was true both
> of the 5.8.0 that came with my Red Hat 8.0 distro, and the 5.8.2 that I
> built from source using defaults.  The two builds give different
results for
> the "print 1.1" test, but they are both wrong.
>

Interesting that they provide different results, but the result provided
is not surprising, at least, if you are talking about the long decimal.

perldoc -q decimal
perldoc perlnumber

Should help explain.  
 

> I imagine it's quite possible that something is deeply broken in Red Hat
> 8.0, and I'm investigating other more recent distros.  In particular I
> wonder if something about my gcc or my glibc is screwy.  But if anyone has
> encountered this problem, and has ideas on how I might work around it, I'd
> greatly appreciate the help!
>

The differing results could be caused by different compiler switches,
slight differences in gcc versions, the orientation of the earth as it
sits on its axis, etc.
 
> Here is the output of myconfig for the 5.8.2 that I built (which did
compile
> successfully):
> 

If you are still concerned after reading the docs I posted above, you
should compare the perl -V output for *both* versions, see if and where
they differ.  After that if you are still concerned you should take a
look through the archives for the perl5-porters list to see if you can
find info on the differences with respect to this topic for versions
5.8.0-5.8.2. And if you are still concerned post a message there, I am
sure one of them can definitely provide info.

HTH,

http://danconia.org

> Summary of my perl5 (revision 5.0 version 8 subversion 2) configuration:
>   Platform:
> osname=linux, osvers=2.4.18-14, archname=i686-linux
> uname='linux swami 2.4.18-14 #1 wed sep 4 13:35:50 edt 2002 i686 i686
> i386 gnulinux '
> config_args='-de'
> hint=recommended, useposix=true, d_sigaction=define
> usethreads=undef use5005threads=undef useithreads=undef
> usemultiplicity=undef
> useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
> use64bitint=undef use64bitall=undef uselongdouble=undef
> usemymalloc=n, bincompat5005=undef
>   Compiler:
> cc='cc', ccflags
> ='-fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
> optimize='-O3',
> cppflags='-fno-strict-aliasing'
> ccversion='', gccversion='3.2 20020903 (Red Hat Linux 8.0 3.2-7)',
> gccosandvers=''
> intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
> d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
> ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
> lseeksize=8
> alignbytes=4, prototype=define
>   Linker and Libraries:
> ld='cc', ldflags =' -L/usr/local/lib'
> libpth=/usr/local/lib /lib /usr/lib
> libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc
> perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
> libc=/lib/libc-2.2.93.so, so=so, useshrplib=false, libperl=libperl.a
> gnulibc_version='2.2.93'
>   Dynamic Linking:
> dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
> cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
> 

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




how to sort certain pattern from a file

2004-06-15 Thread Naser Ali
Below is a sample report. I have been able to only capture lines between
"Intance Name" and "System totals", but here is my delima.
 
The menus on the report are repeated several times. For example, the line
starts with "Instance Name" appears twice.
I only want to capture the lines between first occurence of "Instance Name"
and upto "System Totals" , process it or copy in another temp file and then
delete it from the original file, so I can process the next one and so on
and so forth.
Also,
as you can see that each "Task" has three lines underneath it with related
data, how can I process it and associate it in arrays or lists.What is the
best of doing it?
For instance, for "Task 1", I would like to capture lines starting with
"Avg/Inst", "Avg/Occ.Inst", and " Total Count" be stored in an array or a
file, which ever is best to process later, but keep the association
maintained.

I ll truly appreciate any help and pointers.
Thanks 
 
 

===
 
 Instance Month  Last   Year   Last
  name  TodayYesterday   to Date Month to Date Year
     -  -  -  -  -
-
Task 1
Avg/Inst  0.03   0.00   0.00   0.04   0.03   0.03
Avg/Occ.Inst  0.03   0.00   0.00   0.04   0.03   0.03
 Total Count  8.08   0.00   8.08 303.001842.242512.88
Task 2
Avg/Inst  0.03   0.00   0.00   0.04   0.03   0.03
Avg/Occ.Inst  0.03   0.00   0.00   0.04   0.03   0.03
 Total Count  7.81   0.00   7.81 335.832147.752631.97
Task 3
Avg/Inst  0.00   0.03   0.03   0.01   0.02   0.03
Avg/Occ.Inst  0.00   0.03   0.03   0.01   0.02   0.03
 Total Count  0.00   7.56   7.56 109.62 965.792509.92
 
 
 

Insts   250250250   7500  62644  93496
   Occ. Insts   250250250   7500  62625  93496
 Avg/Inst  0.15   0.18   0.33   0.38   0.35   0.36
 Avg/Occ.Inst  0.15   0.18   0.33   0.38   0.35   0.36
System Totals 36.36  45.03  81.392877.72   21922.86   33578.77
 

Reports menu?r
 
 
 
 Instance Month  Last   Year   Last
  name  TodayYesterday   to Date Month to Date Year
  -  -  -  -  -  -
Task 1
Avg/Inst  0.00   0.02   0.02   0.01   0.01   0.02
Avg/Occ.Inst  0.00   0.02   0.02   0.01   0.01   0.02
 Total Count  0.00   4.85   4.85 101.85 902.101760.55
Task 2
Avg/Inst  0.00   0.02   0.02   0.03   0.03   0.02
Avg/Occ.Inst  0.00   0.02   0.02   0.03   0.03   0.02
 Total Count  0.00   6.00   6.00 228.002058.00 342.00
Task 3
Avg/Inst  0.03   0.00   0.00   0.04   0.03   0.03
 
.
.
.
.
.
.
.
.
 

===


Re: Link refresh

2004-06-15 Thread JupiterHost.Net

Werner Otto wrote:
Sorry this might be off the topic.
Is there anything that I can do in perl to: when I click on a link to 
refresh the page as I click on the hyperlink
Like imaitate the browser's refresh button with a link?
How about this:
#!/usr/bin/perl
use strict
use warnings;
use CGI;
print CGI::header();
...
print qq(Refresh\n);

...
see perldoc CGI for other, even better ways :)
HTH :)
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Is an Array

2004-06-15 Thread James Edward Gray II
On Jun 15, 2004, at 2:24 PM, Angie Ahl wrote:
Hi
Howdy.
Scouring the books to try and find this, but it's evading me.
How can I test whether something is an array.
For some definition of "something" that includes references, use ref(). 
 :)

ie I have a hash and some values are anon arrays and some are strings. 
I want to test to see whether one is an array and then traverse it.
if ( ref($some_hash{might_be_array_ref}) eq 'ARRAY' ) {
# ...
}
Hope that helps.
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Is an Array

2004-06-15 Thread Jeff 'japhy' Pinyan
On Jun 15, Angie Ahl said:

>ie I have a hash and some values are anon arrays and some are strings.
>I want to test to see whether one is an array and then traverse it.

  if (ref $hash{$key}) {
# do something with @{ $hash{$key} }
  }

perldoc -f ref

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN[Need a programmer?  If you like my work, let me know.]
 what does y/// stand for?   why, yansliterate of course.


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




Is an Array

2004-06-15 Thread Angie Ahl
Hi
Scouring the books to try and find this, but it's evading me.
How can I test whether something is an array.
ie I have a hash and some values are anon arrays and some are strings. 
I want to test to see whether one is an array and then traverse it.

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



Re: Parsing binary file.

2004-06-15 Thread Jeff 'japhy' Pinyan
On Jun 15, Rod Za said:

>I am trying to read a binary file (HP-PCL file
>(windows printer)) to count  the number of pages and
>copies.

You probably want to look at the unpack() function, which allows you to
convert binary data into the stuff it represents.  For instance, if you
have read a string from a file that contains two signed longs and an
unsigned short, you can get those numeric values like so:

  ($long_1, $long_2, $short) = unpack "llS", $string;

>I got a C code that works good - but i want to do that
>in Perl to learn.

If you showed us relevant portions of the C code, we could help you in the
translation process.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN[Need a programmer?  If you like my work, let me know.]
 what does y/// stand for?   why, yansliterate of course.


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




Parsing binary file.

2004-06-15 Thread Rod Za
Hello all,

I am trying to read a binary file (HP-PCL file
(windows printer)) to count  the number of pages and
copies.

Can someone help me?

I got a C code that works good - but i want to do that
in Perl to learn.

thank you very much.

Rod Za



__
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail 

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




Link refresh

2004-06-15 Thread Werner Otto
Sorry this might be off the topic.
Is there anything that I can do in perl to: when I click on a link to 
refresh the page as I click on the hyperlink

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



Re: How to open a file for read as well as write

2004-06-15 Thread James Edward Gray II
On Jun 15, 2004, at 10:02 AM, Ramprasad A Padmanabhan wrote:
No that is not what I wanted
I found that out anyways thanks
Want to bet?  Guess how the code you posted works, behind the scenes.  
;)

Seriously, I'm glad you found your answer.
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: How to open a file for read as well as write

2004-06-15 Thread Ramprasad A Padmanabhan
No that is not what I wanted
I found that out anyways thanks
{
 local(@ARGV)=($filename);
 local($^I)=".BAK";
 while(<>){
if(){  
   s/$oldvar/$newvar/;
}
print;
}
}
  

On Tue, 2004-06-15 at 19:02, Stephan Hochhaus wrote:
> Am 15.06.2004 um 12:48 schrieb Ramprasad A Padmanabhan:
> 
> > I want to open a file using a perl script and change a particular
> > variable in it.
> I would use the method James described. But if you absolutely have to 
> open a file in read & write mode you can use this:
> 
> open (FILE, "+ 
> this will open your file for writing and reading
> 
> You could also use
> open (FILE, "+>filename.ext");
> but this will erase the contents of a file.
> 
> Stephan
> 



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




Re: I can't build a sane perl (floating-point numbers go funny)

2004-06-15 Thread Wiggins d Anconia
> I have some experience using perl, but I'm having a hard time finding or
> building a sane perl interpreter for my particular machine.  For example,
> perl -e "print 1.1" yields something like 1.10833.  This was true both
> of the 5.8.0 that came with my Red Hat 8.0 distro, and the 5.8.2 that I
> built from source using defaults.  The two builds give different
results for
> the "print 1.1" test, but they are both wrong.
>

Interesting that they provide different results, but the result provided
is not surprising, at least, if you are talking about the long decimal.

perldoc -q decimal
perldoc perlnumber

Should help explain.  
 

> I imagine it's quite possible that something is deeply broken in Red Hat
> 8.0, and I'm investigating other more recent distros.  In particular I
> wonder if something about my gcc or my glibc is screwy.  But if anyone has
> encountered this problem, and has ideas on how I might work around it, I'd
> greatly appreciate the help!
>

The differing results could be caused by different compiler switches,
slight differences in gcc versions, the orientation of the earth as it
sits on its axis, etc.
 
> Here is the output of myconfig for the 5.8.2 that I built (which did
compile
> successfully):
> 

If you are still concerned after reading the docs I posted above, you
should compare the perl -V output for *both* versions, see if and where
they differ.  After that if you are still concerned you should take a
look through the archives for the perl5-porters list to see if you can
find info on the differences with respect to this topic for versions
5.8.0-5.8.2. And if you are still concerned post a message there, I am
sure one of them can definitely provide info.

HTH,

http://danconia.org

> Summary of my perl5 (revision 5.0 version 8 subversion 2) configuration:
>   Platform:
> osname=linux, osvers=2.4.18-14, archname=i686-linux
> uname='linux swami 2.4.18-14 #1 wed sep 4 13:35:50 edt 2002 i686 i686
> i386 gnulinux '
> config_args='-de'
> hint=recommended, useposix=true, d_sigaction=define
> usethreads=undef use5005threads=undef useithreads=undef
> usemultiplicity=undef
> useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
> use64bitint=undef use64bitall=undef uselongdouble=undef
> usemymalloc=n, bincompat5005=undef
>   Compiler:
> cc='cc', ccflags
> ='-fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
> optimize='-O3',
> cppflags='-fno-strict-aliasing'
> ccversion='', gccversion='3.2 20020903 (Red Hat Linux 8.0 3.2-7)',
> gccosandvers=''
> intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
> d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
> ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
> lseeksize=8
> alignbytes=4, prototype=define
>   Linker and Libraries:
> ld='cc', ldflags =' -L/usr/local/lib'
> libpth=/usr/local/lib /lib /usr/lib
> libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc
> perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
> libc=/lib/libc-2.2.93.so, so=so, useshrplib=false, libperl=libperl.a
> gnulibc_version='2.2.93'
>   Dynamic Linking:
> dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
> cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
> 


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




Re: a way to make this more secured and better written?

2004-06-15 Thread Wiggins d Anconia
 
> 
> >  my @fields = qw(name email city state message);
> >  foreach my $field (@fields) {
> >   $blanks++ if !$q->param($field);
> >  }
> for(@fields) { $blanks ++ if $q->param($_) eq ''; }
> 

IMO, I disagree that removing whitespace and switching a named variable
such as $field to $_ is an improvement.  You have also significantly
changed the functionality from the original, while this may represent an
improvement if it better matches the spec (given the variable name it
probably does), it does break the original spec.

Of course the OP should also realize that if a person enters the value
of '0' his check will fail since it is false, but in this case could be
valid (aka non-blank).  It is important to understand the difference
between a boolean true/false, and what you consider valid/invalid.

$.02...

http://danconia.org

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




Re: a way to make this more secured and better written?

2004-06-15 Thread Wiggins d Anconia
> #!/usr/bin/perl -w
> 
> use strict;
> use warnings;

You probably don't want both -w and 'use warnings'.  Personally I would
stick with the 'use warnings' unless you have to deal with older
versions of Perl which is not terribly likely. The -w turns on warnings
for the whole script, which will include those produced by CGI,
Mail::Mailer and any other CPAN modules used.  'use warnings' will be
for only this script (or any other file you add it too) which will allow
you to only hear about those things you can fix.

> 
> use CGI();
> use Mail::Mailer;
> 
> my $q = CGI->new();
> 
> print $q->header();
> 
> #-
> # * startup methods -> global variables.
> 
> check_fields();
> 
> #-
> 
> sub check_fields {
>  my $blanks;
>  my @fields = qw(name email city state message);
>  foreach my $field (@fields) {
>   $blanks++ if !$q->param($field);

Using $q here has just broken encapsulation. If you move this subroutine
to the top of the file or into a library of its own it no longer works,
'strict' is not complaining because it is file scoped and sort of
"global".  You should be passing in $q as an argument or similar rather
than getting lucky that its scoped to the whole file.

>  }
>  if($blanks) {
>   print qq(Error: There were some blank fields.);
>   exit;

You might consider using 'die' here instead of a print followed by 'exit'. 

perldoc -f die
perldoc Carp

>  }
>  unless($q->param('email') =~ /[EMAIL PROTECTED]/) {
>   print qq(Error: Please enter a valid email address.);

Before you exited on failure, why not here?  Also the above regex is not
sufficient for checking email addresses. If you really want to check for
a valid email address you should consider,

Email::Valid

>From the CPAN.


>  }
>  send_email();

Why is calling send_email a part of checking the fields' validity?  This
is more likely better off being called from the main. Subroutines should
usually take parameters and return a value.  In this case you could
return nothing on success or an error message on failure, then your
error handling could be done outside of the routine.

> }
> 
> 
> sub send_email {
>  my $m = Mail::Mailer->new('sendmail');
>  $m->open({ From=> $q->param('email'),
> To  => 'perl <[EMAIL PROTECTED]>',
> Subject => '[INFO] Site Comment',
>   }) or die $!;

Now your error handling has switched to using 'die'. You should use a
consistent approach, it is the consistency more than which approach that
you choose that will provide the most return in the long run.  Again,
using $q here has broken the encapsulation.

>  print $m "Name: " . ucfirst($q->param('name')) . "\n";
>  print $m "Location: " . ucfirst($q->param('city')) . ", " .
> $q->param('state') . "\n\n";
>  print $m $q->param('message');
>  $m->close();
>   print qq(Thank you for emailing us. We will contact you in the next 24
> hours.);

Printing the success is similarly misplaced to calling 'send_email' was
above. The subroutine should provide a single functionality, in this
case sending email. Again, let it return a value, if that value is
success then the handling of the content sent back to the user is done
in the main, otherwise handle the error.  Keep similar functionality at
similar levels.

> }
> 

As for security, it is often (always?) a good idea to turn on taint
checking.  

perldoc perlsec

HTH,

http://danconia.org


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




Re: loop jumping

2004-06-15 Thread Jeff 'japhy' Pinyan
On Jun 15, [EMAIL PROTECTED] said:

>I am trying to make subroutine which asks (via a regular expr) where some
>files are and then list them - but I would like it to jump back to the
>start of the loop if it does not find any files.
>
>The jumping part works if there are only files in the folder, as soon as
>there are files and folders it does not jump out of the loop. Can any
>body give me an idea how to break this one??

If you change the logic of your loop, you should have no problems:

  sub filecheck {
my @files;

# loops until the size of @files is not zero
# (that is, loop until there's something in @files)
until (@files) {
  print "Enter file glob: ";
  chomp(my $file_pattern = );

  # use grep(-e, files) to weed out false positives
  # for example, glob("foo") will return "foo",
  # whether or not it exists
  @files = grep -e, glob $file_pattern;
}

print "Results:\n";
print "  $_\n" for @files;
  }

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN[Need a programmer?  If you like my work, let me know.]
 what does y/// stand for?   why, yansliterate of course.


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




Re: weird

2004-06-15 Thread Jeff 'japhy' Pinyan
On Jun 14, Randy W. Sims said:

>I've always thought that behaviour kinda weird myself (though now it's
>become second nature). I like the way Ruby has two versions for chop/chomp:
>
>newstring = str.chomp; # leave original untouched
>str.chomp!;# update original inplace
>
>Of course, method names with punctuation take a little getting used to.

In Perl, these are spelled:

  chomp($newstring = $str);
  chomp($str);

In Perl 6, chomp() will probably be a string method, which means you might
be able to write

  ($newstring = $str).chomp;

But this is speculation.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN[Need a programmer?  If you like my work, let me know.]
 what does y/// stand for?   why, yansliterate of course.


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




Re: How to open a file for read as well as write

2004-06-15 Thread James Edward Gray II
On Jun 15, 2004, at 5:48 AM, Ramprasad A Padmanabhan wrote:
I want to open a file using a perl script and change a particular
variable in it.
I think by setting the $^I variable I can open a file for read and
write, But I am not getting any examples anywhere
You CAN open a file for read and write, but don't do that here.
Open the file for reading and an output file.  Copy your original over, 
making the change you need in passing.  Then rename the file the same 
as the original (warning:  Data Loss Step!).

Hope that helps.
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: a way to make this more secured and better written?

2004-06-15 Thread JupiterHost.Net

Jason Gray wrote:
#!/usr/bin/perl -w
use strict;
use warnings;
use CGI();
use Mail::Mailer;
my $q = CGI->new();
print $q->header();
#-
# * startup methods -> global variables.
check_fields();
#-
sub check_fields {
 my $blanks;
   my $blanks = 0; # so you avoid uninitialized warnings if no params 
are given.

 my @fields = qw(name email city state message);
 foreach my $field (@fields) {
  $blanks++ if !$q->param($field);
 }
   for(@fields) { $blanks ++ if $q->param($_) eq ''; }
 if($blanks) {
  print qq(Error: There were some blank fields.);
  exit;
 }
 unless($q->param('email') =~ /[EMAIL PROTECTED]/) {
  print qq(Error: Please enter a valid email address.);
 }
 send_email();
   if($blanks) {
 print 'Error: There were some blank fields.';
   elsif($q->param('email') ~~ /[EMAIL PROTECTED]/) {
 print 'Error: Please enter a valid email address.';
   } else {
 send_mail();
   }
Single quotes mean no interpolation which is a bir faster, aslo not exit 
call.

}
sub send_email {
 my $m = Mail::Mailer->new('sendmail');
 $m->open({ From=> $q->param('email'),
To  => 'perl <[EMAIL PROTECTED]>',
Subject => '[INFO] Site Comment',
  }) or die $!;
 print $m "Name: " . ucfirst($q->param('name')) . "\n";
 print $m "Location: " . ucfirst($q->param('city')) . ", " .
$q->param('state') . "\n\n";
 print $m $q->param('message');
 $m->close();
  print qq(Thank you for emailing us. We will contact you in the next 24
hours.);
I'd switch any double quotes (" and qq) to singel if there are no vars 
to be interpolated.

}
Also, why are these in funtions? You're not reusing them. Why not:
#!/usr/bin/perl
use warnings;
use strict
use CGI();
use Mail::Mailer;
my $q = CGI->new();
print $q->header();
my $blanks = 0;
for(@fields) { $blanks ++ if $q->param($_) eq ''; }
if($blanks) {
   print 'Error: There were some blank fields.';
} elsif($q->param('email') ~~ /[EMAIL PROTECTED]/) {
   print 'Error: Please enter a valid email address.';
} else {
  my $m = Mail::Mailer->new('sendmail');
  $m->open({ From=> $q->param('email'),
  To  => 'perl <[EMAIL PROTECTED]>',
  Subject => '[INFO] Site Comment',
}) or die $!;
  print $m 'Name: ' . ucfirst($q->param('name')) . "\n";
  print $m 'Location: ' . ucfirst($q->param('city')) . ', ' .
  $q->param('state') . "\n\n";
  print $m $q->param('message');
  $m->close();
  print 'Thank you for emailing us. We will contact you in the next 24 
hours.';

}
HTH
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



How to open a file for read as well as write

2004-06-15 Thread Ramprasad A Padmanabhan
I want to open a file using a perl script and change a particular
variable in it. 
I think by setting the $^I variable I can open a file for read and
write, But I am not getting any examples anywhere

Thanks
Ram



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




RE: loop jumping

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

: I am trying to make subroutine which asks (via a regular
: expr) where some files are and then list them - but I
: would like it to jump back to the start of the loop if
: it does not find any files.
: 
: The jumping part works if there are only files in the
: folder, as soon as there are files and folders it does
: not jump out of the loop. Can any body give me an idea
: how to break this one??

Sounds like a glob() problem. Show us a few examples.
Show us your inputted paths and your results. If the
results differ from what you expect, tell us. Show us
exactly what you are typing at the prompt for each
example.

What version of perl are you using (print $];)?


HTH,

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


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




I can't build a sane perl (floating-point numbers go funny)

2004-06-15 Thread Deneb Meketa
I have some experience using perl, but I'm having a hard time finding or
building a sane perl interpreter for my particular machine.  For example,
perl -e "print 1.1" yields something like 1.10833.  This was true both
of the 5.8.0 that came with my Red Hat 8.0 distro, and the 5.8.2 that I
built from source using defaults.  The two builds give different results for
the "print 1.1" test, but they are both wrong.

I imagine it's quite possible that something is deeply broken in Red Hat
8.0, and I'm investigating other more recent distros.  In particular I
wonder if something about my gcc or my glibc is screwy.  But if anyone has
encountered this problem, and has ideas on how I might work around it, I'd
greatly appreciate the help!

Here is the output of myconfig for the 5.8.2 that I built (which did compile
successfully):

Summary of my perl5 (revision 5.0 version 8 subversion 2) configuration:
  Platform:
osname=linux, osvers=2.4.18-14, archname=i686-linux
uname='linux swami 2.4.18-14 #1 wed sep 4 13:35:50 edt 2002 i686 i686
i386 gnulinux '
config_args='-de'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
  Compiler:
cc='cc', ccflags
='-fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O3',
cppflags='-fno-strict-aliasing'
ccversion='', gccversion='3.2 20020903 (Red Hat Linux 8.0 3.2-7)',
gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=4, prototype=define
  Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=/lib/libc-2.2.93.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.2.93'
  Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

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




I can't build a sane perl (floating-point numbers go funny)

2004-06-15 Thread Deneb Meketa
I have some experience using perl, but I'm having a hard time finding or
building a sane perl interpreter on my particular machine.  For example,
perl -e "print 1.1" yields something like 1.10833.  This was true both
of the 5.8.0 that came with my Red Hat 8.0 distro, and the 5.8.2 that I
built from source using defaults.  The two builds give different results for
the "print 1.1" test, but they are both wrong.

I imagine it's quite possible that something is deeply broken in Red Hat
8.0, and I'm investigating other more recent distros.  In particular I
wonder if something about my gcc or my glibc is screwy.  But if anyone has
encountered this problem, and has ideas on how I might work around it, I'd
greatly appreciate the help!

Here is the output of myconfig for the 5.8.2 that I built (which did compile
successfully):

Summary of my perl5 (revision 5.0 version 8 subversion 2) configuration:
  Platform:
osname=linux, osvers=2.4.18-14, archname=i686-linux
uname='linux swami 2.4.18-14 #1 wed sep 4 13:35:50 edt 2002 i686 i686
i386 gnulinux '
config_args='-de'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
  Compiler:
cc='cc', ccflags
='-fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O3',
cppflags='-fno-strict-aliasing'
ccversion='', gccversion='3.2 20020903 (Red Hat Linux 8.0 3.2-7)',
gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=4, prototype=define
  Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=/lib/libc-2.2.93.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.2.93'
  Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'



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




a way to make this more secured and better written?

2004-06-15 Thread Jason Gray
#!/usr/bin/perl -w

use strict;
use warnings;

use CGI();
use Mail::Mailer;

my $q = CGI->new();

print $q->header();

#-
# * startup methods -> global variables.

check_fields();

#-

sub check_fields {
 my $blanks;
 my @fields = qw(name email city state message);
 foreach my $field (@fields) {
  $blanks++ if !$q->param($field);
 }
 if($blanks) {
  print qq(Error: There were some blank fields.);
  exit;
 }
 unless($q->param('email') =~ /[EMAIL PROTECTED]/) {
  print qq(Error: Please enter a valid email address.);
 }
 send_email();
}


sub send_email {
 my $m = Mail::Mailer->new('sendmail');
 $m->open({ From=> $q->param('email'),
To  => 'perl <[EMAIL PROTECTED]>',
Subject => '[INFO] Site Comment',
  }) or die $!;
 print $m "Name: " . ucfirst($q->param('name')) . "\n";
 print $m "Location: " . ucfirst($q->param('city')) . ", " .
$q->param('state') . "\n\n";
 print $m $q->param('message');
 $m->close();
  print qq(Thank you for emailing us. We will contact you in the next 24
hours.);
}



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




Re: loop jumping

2004-06-15 Thread Edward Wijaya

On Tue, 15 Jun 2004 09:39:31 +0200, <[EMAIL PROTECTED]> wrote:
The jumping part works if there are only files in the folder, as soon as 
there are files and folders it does not jump out of the loop. Can any 
body give me an idea how to break this one??

Use "last" function.
perldoc -f last
Regards
Edward WIJAYA
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



loop jumping

2004-06-15 Thread kof
Hi All,

I am trying to make subroutine which asks (via a regular expr) where some files are 
and then list them - but I would like it to jump back to the start of the loop if it 
does not find any files.

The jumping part works if there are only files in the folder, as soon as there are 
files and folders it does not jump out of the loop. Can any body give me an idea how 
to break this one??

Thanks

#!/usr/local/bin/perl -w
use strict;
sub filecheck {
LINE: while (1 == 1) {   #--- > I know this type of loop is not the best 
approach, but could not think of another way to do it.
print "\nWhere are you file places (e.g /home/rfn/data/*.dat) ? 
...\n\n";
chomp(my $files = );
my @fil = glob("$files"); 
print "\nResult of your query:\n\n";
foreach my $check(@fil) {
if ( not -e $check ) {
print "\nno files\n";
redo LINE;
} else {
print "$check\n";
}
}
last;
}
print "\nYou did it!!\n";
}
filecheck ();

Cheers,
Jakob

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