Thanks Arun and Rob,

For example if this is the url then ,
https://localhost/Iv2/cbox/cbox-gui.pl?action=status

my ($myself) = split(/\?/,$q->self_url);
#$myself = https://localhost/Iv2/cbox-gui.pl

my @base_url = split(/\//, $myself);
# @base_url = {localhost, Iv2, cbox-gui.pl}

my $base_url = $base_url[0]."//".$base_url[2]."/";
# $base_url = localhost//cbox-gui.pl/

my $cbox_url = $base_url."Iv2/";
#$cbox_url = localhost//cbox-gui.pl/Iv2/

Please correct me if i made a mistake some where,

if(!(my $action = $q->param('action'))) {

    my $dsn = "DBI:$driver:database=$db;host=$hostname";
    my $dbh = DBI->connect($dsn,$user,$password, { RaiseError => 1 });

    undef($nav); undef(@nav); undef(%nav);
    my $nav, @nav, %nav;

    $nav = "CBox Management";
    $nav["0"] = "Home";          #what is the difference between these two
lines.
    $nav{"0"} = $cbox_url;

1-My question is what happen with https://
2- IS there any tool by which i can run these lines to check the output.





On Thu, Oct 15, 2009 at 4:26 PM, Rob Coops <rco...@gmail.com> wrote:

>
>
> On Thu, Oct 15, 2009 at 2:55 PM, Raheel Hassan <raheel.has...@gmail.com>wrote:
>
>> Hi,
>>
>> I will be very thankful if someone explains under given code.
>>
>> #----- CGI Module ------------------------------
>> use CGI;
>>
>> $q = CGI->new();
>>
>> my ($myself) = split(/\?/,$q->self_url);     #from where it will call the
>> url?
>> my @base_url = split(/\//, $myself);         #what is \ /
>> my $base_url = $base_url[0]."//".$base_url[2]."/";
>> my $validate_url = $q->self_url."&validate=1";
>> my $id = $q->param("id");                                #what is the role
>> of param here?
>> my $hub = $q->param("HUB");
>>
>> Regards,
>> Raheel.
>>
>
> Lets have a go at this then :-)
>
> my ($myself) = split(/\?/,$q->self_url);     #from where it will call
> the url?
> my @base_url = split(/\//, $myself);         #what is \ /
> my $id = $q->param("id");                                #what is the
> role of param here?
>
> To understand the first line you have to understand what the line before
> that does...
> $q = CGI->new();
> This creates a new CGI object. As most objects a CGI object has various
> attributes one of them being the URL used to start the CGI script. So
> $q->self_url returns the value of this attribute.
>
> The next line is a lot easier: in a regular expression or a split where you
> use the default delimiters for the expression / and / means you cannot just
> tell perl to split on / as that would for perl indicate the end of the
> expression. So you escape the / part of the expression with a \ resulting in
> the following /\// meaning split the string on the character /.
>
> As we determined before $q contains a CGI object this object has attributes
> one of them is the URL used to start the script another one is a hash with
> parameters found behind the URL. Think of a URL like this:
> http://mysite.com/cgi-bin/script.cgi?id=1&start=hello
> The attribute self_url in this case is: mysite.com/cgi-bin/script.cgi
> The parameters are: start with the value hello and id with the value 1
> *(Note, you might want to have a look at the difference between GET and
> POST variables. In the HTML 4.1 specification as understanding the
> difference can save you a lot of trouble when working with CGI)*
>
> Figuring out what these parameters are is done by calling CGI
> Object->param("<parameter name>").
> Since the script stored the CGI Object in the variable $q making the
> following call $q->param("id") will return the value of the parameter with
> the name: id.
>
> Hope that helped a bit.
>
> Rob
>

Reply via email to