[EMAIL PROTECTED] <> wrote:
>>> my $cgi = CGI->new();
>>> if ( $cgi->param('select_dir') ) {
>>> my $sessionids = List_Sessions($server);
>>> # here $sessionids is filled, it's a hashref } elsif (
>>> $cgi->param('select_files') ) {
>>> Kill_Sessions($sessionids);
>>> # this $sessionids is empty though...
>>> } else {
>>> List_Dirs($rootpath);
>>> }
>>
>> The above code should not compile. If it does, as you imply, then it
>> means that either you do not have "use strict;" at the start of your
>> code which is bad news, or that $sessionids is also defined at an
>> outer scope which is also bad news (it increases the likely hood of
>> confusion and bugs).
>
> ok, sorry, I didn't provide enough information... I have this above
> (and it doesn't compile yet because of the use strict):
>
> use warnings;
> use Win32::LanMan qw(NetFileEnum);
> use CGI;
> use CGI::Carp qw(fatalsToBrowser);
> use strict;
> use Data::Dumper;
> $Data::Dumper::Indent=1;
> $Data::Dumper::Sortkeys=1;
> use constant DEBUG => 1;
>
> my $cgi=new CGI;
> my $rootpath="W:\\";
> my $server='servername.domain';
>
>>> I get the hashref back fine from List_Sessions($server), but how do
>>> I get it into the next elsif where I need it?
>>
>> Your question suggests to me that you have not sufficiently worked
>> out the logic of your program yet, and you haven't provided enough
>> information for us (well me anyway) to try to work it out to make any
>> useful suggestion. All I can think of are questions, like:
>
> basically the above part is the main logic. At the first call,
> directories are listed with
>
> sub List_Dirs {
> my $cgi = CGI->new();
> my $rootpath=shift;
> my @directories='';
> opendir MYDIR, $rootpath;
> my @dircontents = sort(readdir MYDIR);
> foreach my $content(@dircontents) {
> if (-d "$rootpath$content") {
> push(@directories,"$rootpath$content");
> }
> }
> closedir MYDIR;
> print $cgi->header();
> print $cgi->start_html('Kill Sessions');
> print $cgi->start_form();
> print $cgi->h1('Select directory');
> print
> $cgi->radio_group(-name=>'dirs',-values=>[EMAIL PROTECTED],-columns=>1);
> print $cgi->submit('select_dir','Submit');
> print $cgi->end_form();
> print $cgi->end_html();
> }
>
> which works fine. Then a directory is selected, and used to enter the
> next step ($cgi->param('select_dir') is true)
>
> sub List_Sessions {
>
> #this part also works and does a
>
> return \%sessionids;
> }
>
> here %sessionids is filled fine, and I can print (or dump) it from the
> (above) main part:
>
> if ( $cgi->param('select_dir') ) {
> my $sessionids = List_Sessions($server);
> print $sessionids;
> }
>
> but in the last part
>
> sub Kill_Sessions {
> my $sessionids=shift;
> print $sessionids;
> my $cgi = CGI->new();
> print $cgi->pre ( Data::Dumper->Dump([\%sessionids])) if DEBUG;
> print $cgi->header();
> print $cgi->start_html('Kill Sessions');
> my @files = $cgi->param('file');
> foreach my $file (@files) {
> print @{$sessionids->$file};
> }
> print @files;
> print $cgi->end_html();
> }
>
> I don't get $sessionids.
>
> in short:
>
> 1. List directories and select one <- works fine 2. List sessions in
> directory and select based on files <- works fine 3. Kill the
> sessions to those files
>
> between 2. and 3. I lose the $sessionids it seems. I think I know it
> is because in the main if-elsif construction above each part runs
> independantly from each other, and although I return the $sessionids
> it doesn't get into the next elsif because in the one before it's
> declared with "my"...
I think I see your problem a bit clearer now and it seems to be based on
a misunderstanding of how CGI works. It might be a good idea to do some
more research in that area.
What you seem to have are 3 distinct functions, which could be written
as 3 separate scripts. The first script (list directories, say)
generates the form which when "submitted" executes the second script
(list sessions, say) which generates the form for the third script (kill
sessions, say). You wouldn't expect a variable in script 2 to be visible
to the code in script 3, which is effectively what you are trying to do
because each time you click "Submit" you are executing your script in a
completely separate process.
In fact it might be a good idea to rewrite your application as 3
separate scripts. It may help you understand your problem a bit better.
You may need to investigate methods of transfering information from one
CGI program to another, e.g. sessions, cookies and hidden form
variables.
HTH
--
Brian Raven
=================================
Atos Euronext Market Solutions Disclaimer
=================================
The information contained in this e-mail is confidential and solely for the
intended addressee(s). Unauthorised reproduction, disclosure, modification,
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately
and delete it from your system. The views expressed in this message do not
necessarily reflect those of Atos Euronext Market Solutions.
L'information contenue dans cet e-mail est confidentielle et uniquement
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee.
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail
vous parvient par erreur, nous vous prions de bien vouloir prevenir
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre
systeme. Le contenu de ce message electronique ne represente pas necessairement
la position ou le point de vue d'Atos Euronext Market Solutions.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs