Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-26 Thread Marcello
JupiterHost.Net ha scritto:
In benchmarking some code I've come across something I did not expect:
slice:
use strict;
use warnings;
my @k=qw(1 2 3 4 5 6);
my %n;@[EMAIL PROTECTED] = @k;
print "hi" if exists $n{1};
print "hi" if exists $n{3};
print "hi" if exists $n{5};
print "hi" if exists $n{7};
print "hi" if exists $n{9};
print "hi" if exists $n{11};
grep:
use strict;
use warnings;
my @k=qw(1 2 3 4 5 6);
print "hi" if grep /^1$/, @k;
print "hi" if grep /^3$/, @k;
print "hi" if grep /^5$/, @k;
print "hi" if grep /^7$/, @k;
print "hi" if grep /^9$/, @k;
print "hi" if grep /^11$/, @k;

Benchmark: timing 500 iterations of grep, slice...
  grep: 3.65945 wallclock secs ( 2.33 usr +  0.04 sys =  2.37 CPU) @ 
2109704.64/s (n=500)
 slice: 2.37966 wallclock secs ( 2.52 usr + -0.01 sys =  2.51 CPU) @ 
1992031.87/s (n=500)
   Rate slice  grep
slice 1992032/s--   -6%
grep  2109705/s6%--

I would've thought the "slice and then use exists" would have been 
faster then "greping the entire array each time and using regexes" when 
you check it. but its consistently faster by an average 6-10%

Any ideas why that might be?
Just for curiosity, I ran a slightly different version of your benchmarks:

use strict;
use warnings;
use diagnostics;
my @k=qw(1 2 3 4 5 6);
my %n;
@[EMAIL PROTECTED] = @k;
my $times = 500;
my $dummy;
while($times--) {
$dummy=1 if exists $n{1};
$dummy=1 if exists $n{3};
$dummy=1 if exists $n{5};
$dummy=1 if exists $n{7};
$dummy=1 if exists $n{9};
$dummy=1 if exists $n{11};
}


use strict;
use warnings;
use diagnostics;
my @k=qw(1 2 3 4 5 6);
my $times = 500;
my $dummy;
while($times--) {
$dummy=1 if grep /^1$/, @k;
$dummy=1 if grep /^3$/, @k;
$dummy=1 if grep /^5$/, @k;
$dummy=1 if grep /^7$/, @k;
$dummy=1 if grep /^9$/, @k;
$dummy=1 if grep /^11$/, @k;
}

The results were:

[EMAIL PROTECTED] time perl slice-bench.pl
9.15user 0.01system 0:09.89elapsed 92%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+1015minor)pagefaults 0swaps
[EMAIL PROTECTED] time perl grep-bench.pl
67.52user 0.01system 1:12.97elapsed 92%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+1015minor)pagefaults 0swaps

The slice version took about 10 seconds, the grep one took more than 1 
minute.

Marcello
--
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 read this array?

2005-01-26 Thread Marcello
Jerry Preston ha scritto:
I have this array and I am trying to figure out how to read $id  in it.  Any
ideas?
@history = (
  {
program => 'racer',
version => '0.45',
input => {
  '/home/' => undef,
},
input_contents => '
  $name= \'Jerry\';
  $id  = \'035\';
  1;
',
perl => {
  location => '/home/',
  version => 5.00502
}
  }
);
Thanks,
Jerry
Hi, the value associated with key "input_contents" seems to be perl 
code. Thus you can "eval()" it:


use strict;
use warnings;
use diagnostics;
# the data:
my @history = (
{
program => 'racer',
version => '0.45',
input => { '/home/' => undef, },
input_contents => '$name= \'Jerry\';$id  = \'035\';1;',
perl => {
location => '/home/',
version => 5.00502
}
}
);
# the problem: read $id "value"
my $input_contents = $history[0]->{input_contents};
# predeclare variables in eval()ed code to satisfy use strict pragma
my $id;
my $name;
# see perldoc -f eval (eval EXPR)
eval $input_contents;
print "Code to be eval()ed:\n";
print "$dummy1\n\n";
print "After eval():\n";
print "\$name=$name\n";
print "\$id=$id\n";

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



Re: tie DB_File flags

2005-01-26 Thread Marcello
Ken Gillett ha scritto:
Information about these has proved hard to come by, but having 
ascertained what I need to use I find another problem. I want to 
calculate the flags to use beforehand, but if I try

tie %$dbm, "DB_File", $dbf, $dbflags, $mode, $DB_HASH;
even though $dbflags contains O_RDONLY I get the following error:=
Argument "O_RDONLY" isn't numeric in subroutine entry at 
/usr/lib/perl5/5.8.6/i686-linux/DB_File.pm
You are passing the string "O_RDONLY" to the subroutine, no the value of 
O_RDONLY.

Maybe this works (untested):

$dbflags = O_RDONLY;
tie %$dbm, "DB_File", $dbf, $dbflags, $mode, $DB_HASH;

Marcello
This is caused by using the variable for the flags and if I replace that 
with the actual string (no quotes) it works fine, so it's happy with 
$dbf and $mode.

I'm using 5.8.6, but the problem also exists with 5.8.5 at least.
Can anyone suggest how I can get around this and use a variable for the 
flags?


Ken  G i l l e t t
_/_/_/_/_/_/_/_/_/


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

2005-01-27 Thread Marcello
Ramprasad A Padmanabhan ha scritto:
Hi Manav,
 But still import does not work across multiple files.
for eg, 
main.pl-
#!/usr/bin/perl
#
use Some::Module qw(someFunction1);
require MyLibModule;

# This function will now work
someFunction1();

MyLibModule::someOtherFunction();
---END

--MyLibModule.pm--
#
#
#
use Some::Module qw(someFunction1);
sub someOtherFunction { 
   someFunction1() ; 
# WILL NOT WORK HERE 
# I have to write Some::Module::someFunction1()
}

1;
-END

Thanks
Ram

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



Re: Safety of storing pricing information in a CGI::Session

2005-02-02 Thread Marcello
Michael Kraus ha scritto:
G'day all...
I'm currently using CGI::Session as part of an online ordering system.
I've been passing database primary keys back and forth between the
client and server, with all values double checked upon being received at
the server.
The only problem is that I need to present the total price to the client
at more than one point of operation, and I have been recalculating the
price each time.
How safe is it to store the pricing information on the session object
itself - are their any security flaws or issues of which I should be
aware? (I'm figuring it's pretty safe - but I'd rather be ultra-sure.)
Thanks heaps!
Regards,

http://www.stonehenge.com/merlyn/WebTechniques/col61.html
 

Michael S. E. Kraus
B. Info. Tech. (CQU), Dip. Business (Computing)
Software Developer
Wild Technology Pty Ltd
--- Anything below this line is attached via a mail server ---

Wild Technology Pty Ltd , ABN 98 091 470 692
Sales - Ground Floor, 265/8 Lachlan Street, Waterloo NSW 2017
Admin - Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017
Telephone 1300-13-9453 |  Facsimile 1300-88-9453
http://www.wildtechnology.net
DISCLAIMER & CONFIDENTIALITY NOTICE:  The information contained in this email 
message and any attachments may be confidential information and may also be the 
subject of client legal - legal professional privilege. If you are not the intended 
recipient, any use, interference with, disclosure or copying of this material is 
unauthorised and prohibited.   This email and any attachments are also subject to 
copyright.  No part of them may be reproduced, adapted or transmitted without the 
written permission of the copyright owner.  If you have received this email in 
error, please immediately advise the sender by return email and delete the message 
from your system.


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



Re: Problem in reading cookies

2005-02-02 Thread Marcello
Mallik ha scritto:
Hi All,
I have an perl script that reads cookies. In one system it is able to
read the cookies properly. But the same is not working in another
system. Browsers and their versions are same in both systems. I even set
the browser properties same in both the systems.
You mean "accept cookies" and such ?
Then I printed the environment variables in that script. The variable
HTTP_COOKIE is printed in first system but not in the other system
(where it is not able to read the cookies).
What could be the reason for this? Any help in this is greatly
appreciated.
Thanks & Regards,
Mallik.
You should supply more information to help somebody help you.
Marcello
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: while(1){print "a"; sleep 1;}

2005-02-09 Thread Marcello
TapasranjanMohapatra ha scritto:
Hi All,
Why I dont get a's printed with the code below?
+++
while(1)
{
 print "a";
 sleep 1;
}
+++
It works well if I print a newline with a, i.e
while(1)
{
 print "a\n"; # newline with a
 sleep 1;
}
Please help if you know the cause.
TIA
Tapas

I think the "problem" is output buffering.
The buffer doesn't get flushed (i.e. its content printed to screen) 
until it's full.
I guess the newline character causes the buffer to be flushed.
To force buffer flushing after each print, you can se $| to a non-zero 
value.
I attached a sample script to show this.

Marcello
use strict;
use warnings;

$|++;

while(1) {
print "a";  # with this line we don't get any output unless 
we put a $|++ beforehand
#print "a\n";   # with this line every "a" gets printed 
regardless of $| value (0 or 1)
sleep 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: strange if-else problem

2005-02-28 Thread Marcello
Graeme McLaren ha scritto:
Morning all.  I have a strange problem with an if-else statement.  Both 
parts of the statement are being executed and I have no idea why, the 
offending code is this:
Try to add two warnings to see if handle_error is called from the "else" 
branch if this statement or from one of the routines in the "if" branch.

if($password =~ /\S\S\d\d\S\S/){
 warn "Inside IF part";
   #if there is a password user then exists in ldap, update the username
   $error = ChangeUsername($old_username, $new_username, 'suppliers', 'select', 
'dci');
   # make sure user has "approved" status
   record_username_success([EMAIL PROTECTED], $count);
   print "username changed from \"$old_username\" to \"$new_username\" using password 
\"$password\" \n";
} else {
 warn "Inside ELSE part";
   handle_error($error, [EMAIL PROTECTED], $count);
}
It prints off the username that has been changed and its password.  Then 
the handle_error function is called.

Anyone got any ideas?
Cheers in advance,
Graeme :)

Just my two cents.
Marcello
--
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 Code Issue

2005-03-02 Thread Marcello
Wilson, Josh --- Systems Analyst --- GO ha scritto:
All,
 
I'm trying to determine what is wrong with this script.   Here is what
I'm trying to do:
 
1.)  Export the output of the following command to a file located at
c:\perl\bin\log\accessreport.log
   Global "Domain Admins" ARFW > c:\perl\bin\accessreport.log
 
2.)  For each line of information that is returned, execute the
following command (Ex. 1st line of output is jlw5038)
  Cscript "c:\program files\resource kit\useraccount.vbs"  /N
jlw5038 |grep FullName
 
3.)  I want the information that is grepped to be thrown into a separate
file called accessreport2.log
 
For whatever reason, I never make it to my first print statement within
the foreach code shown below.  This is a perl script created in a
Windows Environment for a windows environment and I'm running ActivePerl
5.8 on my system.
 
Any help is appreciated!
 
 
 
 
 
BEGIN:
 
# Exporting Windows 2000 Resource Kit command output to file
system("global \"Domain Admins\" ARFW >
c:\\perl\\bin\\log\\accessreport.log");
 
# Creating a foreach statement for each line of accessreport.log which
in this case is a userid.
open(IDS, "type c:\\perl\\bin\\log\\accessreport.log |");
Just a question: why do you "type" the file instead of just opening it 
from perl ?

@IDLIST=;
foreach $USERID (@IDLIST)
{
if ($USERID != "")
{
 
chomp($USERID);
 
print("Processing UserID: $USERID\n");
 
open(FULLNAME, "cscript \"C:\\program files\\resource
kit\\useraccount.vbs\" /N $USERID |grep FullName |");
 
chomp($NAME=);
 
close(FULLNAME);
 
open(REPORT, ">c:\\perl\\bin\\logs\\accessreport2.log");
print
REPORT ("$USERID - $NAME\n");
 
close(REPORT);
}
}
 
EOF:
 
 

***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


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



Re: parsing columns

2005-08-18 Thread Marcello

Manav Mathur ha scritto:

Hi all,
I have a text file with columns, where the columns may not be aligned,
and not all lines may have data in all columns:

header1 header2 header3header4

l1dat1l1dat2l1dat3  l1dat4
l2dat1l2dat4
l3veryveryveryverylongdat1 l3dat2

As you can see, line1 has all data, line2 is missing clomuns 2 and 3,
line 3 is a mess :)

Any thoughts on parsing such a "table"?
Please don't offer solutions suggesting to change the way the text
file is written, I have no control over that...

Regards,
--
Offer Kaye



How do you logically determine that "l2dat4" in line 2 is column 4 and not
column 2??

Manav





Just a thought: because l2dat4 starting column is greater than column 4 
header starting column ?


Marcello

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




Re: mysql through dbi problem

2005-10-05 Thread Marcello

linc ha scritto:

Howdy,
I'm having some serious trouble.  I'm running a query and getting the
data, but having problems using that data in the next query.  Thus:
#first query

$sth = $dbh->prepare
( "select distinct hmac, hport, hsid from netdata_history" );

$sth->execute(  );
$sth->bind_columns
( undef, \$hmac, \$hport, \$hsid );
while ( ( $hmac, $hport, $hsid ) = $sth->fetchrow_array )
{
push @hsid, $hsid;
push @hport, $hport;
push @hmac, $hmac;

 }


You are using bind_columns and fetchrow_array together.
I bet this is causing you trouble.
DBI.pm documentation (bind_columns section) suggests something like:

my ( $hmac, $hport, $hsid );
$sth->bind_columns( \$hmac, \$hport, \$hsid );
while($sth->fetch) {
push(@hsid, $hsid);
push(@hport, $hport);
push(@hmac, $hmac);
}

Otherwise, leave out the bind_columns part:

my ( $hmac, $hport, $hsid );
while ( ( $hmac, $hport, $hsid ) = $sth->fetchrow_array ) {
push(@hsid, $hsid);
push(@hport, $hport);
push(@hmac, $hmac);
}




$sth->finish();
#now cycle through result set in next query
foreach $myhsid (@hsid)
{
$myhport = pop(@hport);
$myhmac = pop(@hmac);
print "trying $myhsid $myhport $myhmac\n";
$sth = $dbh->prepare
( "select * from netdata_history
where hsid=" . $dbh->quote( $myhsid ) . "
and hport=" . $dbh->quote( $myhport ) . "
and hmac=" . $dbh->quote( $myhmac ) . "
order by hdate limit 1" )
or die "Can't execute SQL statement: $DBI::errstr\n";
$sth->execute(  );
$sth->bind_columns
( undef, \$hdateoldest, \$hsidoldest, \$hportoldest, \
$hmacoldest, \$hipoldest )
or die "Can't execute SQL statement: $DBI::errstr\n";
while ( ( $hdateoldest, $hsidoldest, $hportoldest, $hmacoldest,
$hipoldest ) = $sth->fetchrow_array )
{
warn "Data fetching terminated early by error: $DBI::errstr\n"
if $DBI::err;
print "oldest for this combination $hdateoldest\n";
}
$sth->finish();

So, my first query gets the distinct list of unique sets for those three
fields.

My next query seems to get empty sets returned!  In other words, "oldest
for this combination" never prints.  Is there something about using
@hsid as the iterator in the foreach?  Is it making the data I send to
the query in $myhsid out of sequence or reverse order from the data in
the other two arrays?

I also wonder if any of the fields I'm returning are null, does that
affect things?

Anyways, I've rewritten this several times.  I don't know why my queries
are coming back with empty sets.  Shouldn't it be impossible to get an
empty set since the data is coming from the database in the first query?

Any pointers appreciated.

Thanks,

Linc




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




Re: datetime odd problem

2005-10-06 Thread Marcello

John ha scritto:

THe following code

my $cur_datetime=DateTime->new(year=>$fields[2], month=>$fields[1], day=>$fields[0], 
hour=>$fields[3], minute=>$fields[4], second=>$fields[5]);

is working properly on a 32-bit Suse Linux

but not in a 64-bit Suse Linux

giving the error below

The 'hour' parameter (undef) to DateTime::new was an 'undef', which is not one 
of the allowed types: scalar

The module DateTime is the exaclty the same.

Any idea on what might be going wrong?





I think you should show us where those $fields come from.

--
Marcello Romani
Developer
Spin s.r.l.
Reggio Emilia
http://www.spinsoft.it


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




Re: mysql through dbi problem

2005-10-10 Thread Marcello

rutledge.50 ha scritto:



Hi, thanks Marcello :)
I finally figured it out by painfully following 10 sets of data through 
the process.

First, this was causing two problems:


#now cycle through result set in next query
foreach $myhsid (@hsid)
{
$myhport = pop(@hport);
$myhmac = pop(@hmac);
print "trying $myhsid $myhport $myhmac\n";


Foreach was only iterating through UNIQUE instances of $myhsid.  So the 
whole dataset was not used.  Also I was pop'ing two values from the set, 
while foreach was iterating through the other array TOP DOWN, where pop 
goes BOTTOM UP.  D'oh!


So I ended up with something like:
for ([EMAIL PROTECTED]; $count !=0; $count--) {
$myhsid=pop(@hsid);

So now I get the count from @hsid, and then pop all arrays so the 
datasets stay matched :)
Unfortunately the database is huge.  When I left work Friday my script 
was still running after about 30 hours.  It looks like 'order by hdate 
desc limit 1' is a LOT SLOWER than 'order by hdate limit 1' for some 
reason.  Must be internal MySQL stuff...


Just some thoughts as I read this:
1) it seems to me you are reading the whole dataset into @hsid, @hport, 
etc. arrays. If the database is huge, maybe the machine is swapping 
heavily, thus increasing the processing time of the script...

2) maybe you have an index on hdate but not on the hdate, desc couple.




Thanks,

Lincoln


Prego

Marcello

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




Re: fork + objects + logging

2005-10-12 Thread Marcello

Tom Allison ha scritto:

[snip other question]



Logging:

I am using a package Log::Dispatch to do my logging.
Is there any penalty to loading the same modules for Log::Dispatch into 
multiple Packages (Main plus all my custom package/modules)?  IIRC this 
should share the memory but allow each package space to see the 
Log::Dispatch methods with no penalty memory or speed.


True?



Under apache/mod_perl, you maximize memory sharing by loading modules 
before children are spawn.

One way to achieve this is to put

  PerlModule 

directives in httpd.conf for every module that you use.

In addition, you need to

  use ;

in every module or script where you use that 's exported 
functions or class medthods. If you don't include the 'use' directive 
you should get compilation errors.


--
Marcello Romani
Developer
Spin s.r.l.
Reggio Emilia
http://www.spinsoft.it


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




Re: Space problem

2005-10-14 Thread Marcello

Martha kavishe ha scritto:

Hi All,
I received some response to my problem but unfortunately my problem 
isn't solved, I'm still struggling..


Thank you all for your contribution

Here is a better short code for the program which gives a clear picture 
of what I'm trying to ask help for.


use DBI;

$dsn= "dbi:mysql:db_martha:localhost";

my $user= "mysql";

my $password = "mysql123";

$dbh = DBI->connect($dsn,$user,$password);

##GET ARGS #

$msg = $ARGV[1];

$source = $ARGV[0];

$msg =~ s/\"/' /igx;

$time = localtime();

open (OUTFILE ,">>C:\\logs\\martha.txt");

print OUTFILE "$time\t$source\t$msg\n";

close(OUTFILE);

$found = 0;

## GU #

if (($msg =~ /gu1/i) && ($msg !~ /gu1[0123456789]+/i))

{

$vote = 'gu1';

$found = 1;

}

elsif (($msg =~ /gu2/i) && ($msg !~ /gu2[0123456789]+/i))

{

$vote = 'gu2';

$found = 1;

}

.

.some more elseif statements here

.

elsif (($msg =~ /gu10/i)&& ($msg !~ /gu10[0123456789]+/i))

{

$vote = 'gu10';

$found = 1;

}

elsif (($msg =~ /gu11/i)&& ($msg !~ /gu11[0123456789]+/i))

{

$vote = 'gu11';

$found = 1;

}

if ($found == 1)

{

$statement = "insert into t_count (time_in, sender, code) values 
(now(),'$source','$msg')"; #insert into a database


$sth= $dbh->prepare("$statement");

$sth->execute;

print "You entered $vote .\n"; }

else

{

print "Error message or anythingfor testing";

}

$dbh->disconnect;

exit;

###EndHere##

from the above code, the program accepts GU1 to GU11 but not GU 1(space 
before no), when i send GU 1, it jumps to the else statement. I want the 
program to ignore the space..


Are you sure you are calling the script using "GU 1" ? If you don't use 
quotes your program will see GU and 1 as separate arguments.

This is because the shell treats space as argument separator.



I thought  by putting x on the line   ($msg =~ s/\"/' /igx;) will ignore 
the space but it doesn't


Your suggestion/help are highly appreciated...

Help me please




--
Marcello Romani
Developer
Spin s.r.l.
Reggio Emilia
http://www.spinsoft.it


--
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 is better?

2005-10-18 Thread Marcello

M. Lewis ha scritto:

Thanks Thomas. Appreciated.

Thomas Bätzler wrote:


Hi,
M. Lewis <[EMAIL PROTECTED]> asked:

Charles K. Clarkson recently replied to Sreedhar Reddy in which one 
of the corrections he made was:


open my $fh, '<', $input_file or die qq(Cannot open "$input_file": $!);



[...]


When I have opened a file, I have always done:

open (FILE, $file) || die "Cannot open $file :$!";

A couple of things different.
- I use a FILEHANDLE, where Charles used a variable.




Passing a filehandle to a subroutine is possible, but if
you use IO::Handle objects like Charles, it's much easier.


- Charles explicitly said the file was being opened for reading. My 
understanding is that is the default. I assume that Charles did this 
for clarity.




Security, too. In Charles' case, all the open ever does is
try to open a file. In your case, it could be used to do
almost anything. That's fine as long as your code runs on
your box only, probably with a fixed "my $file = ..."
right above it - but just imagine your code if part of a
CGI program and $file is a CGI parameter, and somebody
set it to '/bin/rm -rf /|'.



I rarely do CGI stuff so this really isn't really in my realm, although 
I can see how via your example, it would be a good idea to make that a 
habit.




- Charles opted to use qq() which cause him to have to enclose the 
$input_file in "".




Dead wrong. He used qq() so that he did not have to quote
the "" inside a string which he wanted to be interpolated.

Delimiting arguments in an error message by quotes is a very good idea 
because it lets you see leading or trailing

whitespace which you'd otherwise miss.




You've lost me here Thomas. Again, his code was:

open my $fh, '<', $input_file or die qq(Cannot open "$input_file": $!);

What am I missing here?


I hope this 3-lines script will clarify the issue:

my $var = "world";
print qq(Hallo "$var"\n);
print qq(Hallo $var \n);

HTH

[snip]

--
Marcello Romani
Developer
Spin s.r.l.
Reggio Emilia
http://www.spinsoft.it


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




Re: input validation and persistency module for (mod_perl) web apps?

2005-11-03 Thread Marcello

John Doe ha scritto:

Dear list members

Maybe the perl-module-authors would be the more appropriate list for my 
question(s), but here are people confronted with the same tasks to solve when 
programming web applications, so...


Some of the tasks always to be solved in an interactive webapp:

a) validate/sanitize user input


Data::FormValidator can be a little daunting at first, but it's very 
powerful and flexible. After some use it becomes your best friend ;-)



b) differentiate between persistent parameter values and "volatile" ones (the
latter meaning a value only used along one request/answer)


You're talking about session values and request values.
I think you should a search for 'Session' on search.cpan.org and try out 
some modules, especially those in the Apache:: namespace.
Also, read the documentation of some of them even if you don't try them 
out: you'll learn a lot about the problem(s) you are trying to solve.


[snip rest of message]

HTH

--
Marcello Romani
Developer
Spin s.r.l.
Reggio Emilia
http://www.spinsoft.it


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