using variable in param

2006-02-21 Thread Adriano Allora

Hi all,

I need to obtain some values (passed with a form) without knowing their 
names (but I know these variable names correspond to names of some 
files.


So, I tried to write  something like this:

opendir(QUERY, 
/Users/adrianoallora/Sites/corpora/VALICO/indici_testa/) or $errtex = 
$!;

@interrogabili = readdir(QUERY);
foreach $elem (@interrogabili)
{
next if $elem =~ /^\..*/;
$elem = $home-param($elem);
}

Why the  $home-param($elem) line doesn't work? All the rest of the 
code works very well (It open effectively the directory, store all the 
entries in the array, read each array item...)


Any help is soo much appreciated.

alladr



|^|_|^|_|^|  |^|_|^|_|^|
 || ||
 || ||
 ||*\_/*\_/*\_/*\_/*\_/* ||
 |   |
 |   |
 |   |
 | http://www.e-allora.net|
 |   |
 |   |
**


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




hi,how to get the correct statistic

2006-02-21 Thread Joodhawk Lin
hi all,
 
i copy source from 
http://www.planet-source-code.com/vb/scripts/ShowCodeAsText.asp?txtCodeId=481lngWId=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 #).
 
i run it on the windows 2003 server dos console: 
---
C:\Inetpub\wwwroot\cgi-bin\testperl WorldListMerger.pl
Moth Merger 1.0 Wordlist Merger
Please specify an output file:test7
Please specify an input file:a.txt
5 added to test7
1 duplicates in a.txtAdd another file?(y/n):y
Please specify an input file:b.txt
7 added to test7
2 duplicates in b.txtAdd another file?(y/n):y
Please specify an input file:c.txt
1 added to test7
0 duplicates in c.txtAdd another file?(y/n):n
---
 
in a.txt:
a
b
c
#comments by joodhawk.
d
a
c
in b.txt
e
e
f
g
h
i
j
g
f
in c.txt
zzz
 
it is the incorrect result.
as we excepted,  such as in the a.txt, we know 2 duplicates apparently. 
how to correct it ?
 
thanks in advance.


How can I pass a file handle in a URL?

2006-02-21 Thread Mark Calleja

G'day,

I've got a CGI script that accepts a form, including a file handle, 
hence allowing users to upload files, but I'm having trouble passing the 
request in a URL request. The request is generated by a script using 
HTTP (no HTML is used in the process), and works with the LWP module by 
having something like the following in the client (showing only 
essential detail):


use LWP;
use HTTP::Request::Common;
my $ua = LWP::UserAgent-new;

my $res = $ua-request(
  POST $external_url,
  Content_Type = 'form-data',
  Content =
  [
   upload_file =  [ $filepath ],
   user = $userid,
   action = $action,
  ]
);

So the above client code works fine, but the following alternative fails:

my $req = HTTP::Request-new(POST = $external_url);
$req-content_type('application/x-www-form-urlencoded');
$req-content(upload_file=$filepathuser=$useridaction=$action);
my $res = $ua-request($req);

On the server side, the CGI scipt basically loads the uploaded file via 
(showing only essential detail):


use CGI qw(:standard);
my $q = new CGI;
my $fh_payload = $q-upload('upload_file');

Is there any reason why the second method (using the encoded URL) fails 
while the first method succeeds? More importantly, can anyone suggest a 
way of making the second method work?


Cheers,
Mark

--
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
1lngWId=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: Passing Perl parameters in a cgi-script

2006-02-21 Thread Ed Pigg


On Feb 21, 2006, at 1:08 AM, Mary Anderson wrote:



I have come to the conclusion that passing perl parameters from one  
perl
subroutine to another just doesn't work in CGI.  It looks like  
everything

is passed by value, and the language is not set up to take refs.  This
being the case, how best to handle the following piece of DBI code:

my$dbh = DBI:connect($connectionString);   # connect to the  
database

my$sth = $dbh-prepare($cmd);   # prepare a command



Using my declares the listed variables to be local (lexically) the  
variable to the enclosing block, file, or eval.

perldoc -f my

References can be passed.
perldoc perlref
perldoc perlreftut


What I think that I have found is that

my $dbh = DBI:connect($connectionString)  # dbh is a global  
variable set

in a global context


I am going to assume that you do this at the beginning of your cgi  
script. You would now have a database handle to use for the remainder  
of the script.




..

sub fubar{
  my $sth = $dbh-prepare($cmd);
}
seems to work, but it does not work to have the global variable set  
inside
a subroutine and accessed from another.  If it were a character  
string, I
would use hidden() to pass the values from one subroutine to  
another, but

the cgi macros are not set up to handle ref variables!


It sounds like you are trying to pass the handle to a separate  
request to the server. Since it is scoped to the first script you  
can't do that. You can transfer values in hidden fields of a form or  
in a session that can be accessed by the next process. There are ways  
to handle persistent database connections, although I have not worked  
with them at this point. If I know I will need a handle I grab it at  
the beginning of the script and then close it when I am done.




If I am right, that I can set $dbh globally and access it from some
subroutine, can I do this

if (something is true) {

my   $dbh = DBI:connect($connectionString);
}


That will get you a database handle that is valid inside the  
(something is true) block.


sub fubar{
my $sth = $dbh-prepare($cmd)



$dbh does not exist inside the fubar block.

Ed Pigg

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