You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Kaare Rasmussen <ka...@kakidata.dk> on 2003/12/03 18:41:16 UTC

execute problems

If I do this

  Execute ({inputfile => 'findList.sub', import => 1});

Then this line in findList.sub will not be executed if it's outside the subs 
in findList.sub:

[- $req = shift -]

But I'm using the $req object, so I'll try this:

  Execute ('findList.sub');

OK except that the subs are not imported now.

Will I have to do this to get what I want - which is both the req object AND 
the sub routines ?

  Execute ({inputfile => 'findList.sub', import => 1});
  Execute ('findList.sub');

-- 
Kaare Rasmussen            --Linux, spil,--        Tlf:        3816 2582
Kaki Data                tshirts, merchandize      Fax:        3816 2501
Howitzvej 75               Åben 12.00-18.00        Email: kar@kakidata.dk
2000 Frederiksberg        Lørdag 12.00-16.00       Web:      www.suse.dk


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: execute problems

Posted by Kaare Rasmussen <ka...@kakidata.dk>.
Luiz, Gerald

Thanks for your feedback.

If I just execute the file it seems that the "global" (for that file) value 
sticks - but that it will be purged after some time. At least I get erratic 
behaviour trying to do that.

Maybe I'll make it as object. Suits me better, I think.

> You can make it even more smart if you are using EmbperlObject. If you
> execute your files with the "isa" syntax in the "base template" file you
> can call your subs as methods of the $req object.

Not quite sure what the isa syntax is here.

-- 
Kaare Rasmussen            --Linux, spil,--        Tlf:        3816 2582
Kaki Data                tshirts, merchandize      Fax:        3816 2501
Howitzvej 75               Åben 12.00-18.00        Email: kar@kakidata.dk
2000 Frederiksberg        Lørdag 12.00-16.00       Web:      www.suse.dk


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: execute problems

Posted by "Luiz Fernando B. Ribeiro" <lu...@engenhosolucoes.com.br>.
On Wed, 3 Dec 2003 18:41:16 +0100, Kaare Rasmussen <ka...@kakidata.dk> wrote:

> If I do this
>
>   Execute ({inputfile => 'findList.sub', import => 1});
>
> Then this line in findList.sub will not be executed if it's outside the 
> subs
> in findList.sub:
>
> [- $req = shift -]
>
> But I'm using the $req object, so I'll try this:
>
>   Execute ('findList.sub');
>
> OK except that the subs are not imported now.
>
> Will I have to do this to get what I want - which is both the req object 
> AND
> the sub routines ?
>
>   Execute ({inputfile => 'findList.sub', import => 1});
>   Execute ('findList.sub');
>

If you need just the subs in a file you can import or use the "objet" 
syntax:
$obj = Execute({object => 'findList.sub'});

and then use a pseudo-constructor passing the $req object and store the 
$req inside the object:
$obj->initialize($req);

After this you call your subs as methods:
$obj->do_something

But with this technique you have to change your subs to receive the $obj 
(or $self if you like) as the first parameter in @_.

You can make it even more smart if you are using EmbperlObject. If you 
execute your files with the "isa" syntax in the "base template" file you 
can call your subs as methods of the $req object.

This is just one of the alternatives.

Other solution is to pass the $req to every sub you call in the file 
imported.

-- 
Luiz Fernando B. Ribeiro
Engenho Soluções para a Internet

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Writing to a file

Posted by Gerald Richter <ri...@ecos.de>.
Pete Moran wrote:
> Since I have upgraded from 1.3 to 2.0, I dont seem to be able to write
> to a file
>
> [-
> open(TMP, "> /tmp/test");
> print TMP "THIS IS A TEST";
> close TMP;
>
>
> -]
>
> Results in 0 byte file being created any ideas why ?
>

The code looks ok, this should work with 2.0 without problems.

Maybe there is a permission problem. It's always a good idea to check return
values e.g.

open(TMP, "> /tmp/test") or die "cannot open ($!)" ;

Gerald




--------------------------------------------------------------
Gerald Richter     ecos electronic communication services gmbh
IT-Securitylösungen * dynamische Webapplikationen * Consulting

Post:       Tulpenstrasse 5          D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de          Voice:   +49 6133 939-122
WWW:        http://www.ecos.de/      Fax:     +49 6133 939-333
--------------------------------------------------------------
|
|   ECOS BB-5000 Firewall- und IT-Security Appliance: www.bb-5000.info
|
+-------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Writing to a file

Posted by Pete Moran <pe...@forloop.co.uk>.
Since I have upgraded from 1.3 to 2.0, I dont seem to be able to write
to a file

[-
open(TMP, "> /tmp/test");
	print TMP "THIS IS A TEST";
close TMP;


-]

Results in 0 byte file being created any ideas why ?


Thanks


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: execute problems

Posted by Gerald Richter <ri...@ecos.de>.
Kaare Rasmussen wrote:
> If I do this
>
>   Execute ({inputfile => 'findList.sub', import => 1});
>
> Then this line in findList.sub will not be executed if it's outside
> the subs in findList.sub:
>

When you say inport => 1 only code inside [! !] is executed, because you
want to import and not to execute.

> [- $req = shift -]
>

I guess you need this in your subs, so it doesn't make sense to execute it
when you import the file anyway (because this is done only once and not for
every request).

You need to pass $req to your subs or use the way Luiz has described

Gerald

P.S. In 2.0 you could also access $Embperl::req

--------------------------------------------------------------
Gerald Richter     ecos electronic communication services gmbh
IT-Securitylösungen * dynamische Webapplikationen * Consulting

Post:       Tulpenstrasse 5          D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de          Voice:   +49 6133 939-122
WWW:        http://www.ecos.de/      Fax:     +49 6133 939-333
--------------------------------------------------------------
|
|   ECOS BB-5000 Firewall- und IT-Security Appliance: www.bb-5000.info
|
+-------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org