Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > debugging and flow control

Reply
Thread Tools

debugging and flow control

 
 
alexxx.magni@gmail.com
Guest
Posts: n/a
 
      09-07-2007
Hi all, I need some advice:

in the past, when writing programs I often used, to help me in
debugging, the following style:

my $debuglevel=1;
.....
print("var value is $a\n") if ($debuglevel>0);
.....
print(LOGFILE "array values are @x\n") if ($debuglevel>2);
....

you get the idea.
Now I'm working on a project very computational-intensive, and I'm
worried about the many lines "if ($debuglevel...)" to be evaluated.

I was wandering: if $debuglevel was a constant, not a variable, it is
possible that the program, when launched, evaluates those lines from
the beginning? In this case I should not worry about later evaluation.

Any other suggestion for flow control?

thanks!

Alessandro Magni

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      09-07-2007
On Sep 7, 7:33 am, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> my $debuglevel=1;
> ....
> print("var value is $a\n") if ($debuglevel>0);
> ....
> print(LOGFILE "array values are @x\n") if ($debuglevel>2);
> ...
>
> you get the idea.
> Now I'm working on a project very computational-intensive, and I'm
> worried about the many lines "if ($debuglevel...)" to be evaluated.
>
> I was wandering: if $debuglevel was a constant, not a variable,
> it is possible that the program, when launched, evaluates those
> lines from the beginning? In this case I should not worry about
> later evaluation.


That would appear to be accurate....

$ perl -MO=Deparse -e'
my $x = 1;
print "Hello " if $x;
print "World\n" if $x;
'
my $x = 1;
print 'Hello ' if $x;
print "World\n" if $x;
-e syntax OK


$ perl -MO=Deparse -e'
use constant x => 1;
print "Hello " if x;
print "World\n" if x;
'
use constant ('x', 1);
print 'Hello ';
print "World\n";
-e syntax OK


However, I'm not even a little bit convinced that the savings you'll
see from this will be noticeable. I'd try a Benchmark if I were you,
to see if it's worth your time to go through and change your code...

Paul Lalli

 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      09-07-2007
On 2007-09-07 13:33:05 +0200, "(E-Mail Removed)"
<(E-Mail Removed)> said:

> Hi all, I need some advice:
>
> in the past, when writing programs I often used, to help me in
> debugging, the following style:
>
> my $debuglevel=1;
> ....
> print("var value is $a\n") if ($debuglevel>0);
> ....
> print(LOGFILE "array values are @x\n") if ($debuglevel>2);
> ...
>
> you get the idea.
> Now I'm working on a project very computational-intensive, and I'm
> worried about the many lines "if ($debuglevel...)" to be evaluated.


Especially if the program is computational-intensive, it is unlikely
that skipping debug statements is going to make a noticeable difference.

> I was wandering: if $debuglevel was a constant, not a variable, it is
> possible that the program, when launched, evaluates those lines from
> the beginning? In this case I should not worry about later evaluation.


If needed, that can be done using the constant pragma. The technique
is described in "perldoc constant", so I don't have to repeat it here.

Anno

 
Reply With Quote
 
alexxx.magni@gmail.com
Guest
Posts: n/a
 
      09-10-2007
On 8 Set, 00:36, Anno Siegel <(E-Mail Removed)-berlin.de> wrote:
> On 2007-09-07 13:33:05 +0200, "(E-Mail Removed)"
> <(E-Mail Removed)> said:
>
> > Hi all, I need some advice:

>
> > in the past, when writing programs I often used, to help me in
> > debugging, the following style:

>
> > my $debuglevel=1;
> > ....
> > print("var value is $a\n") if ($debuglevel>0);
> > ....
> > print(LOGFILE "array values are @x\n") if ($debuglevel>2);
> > ...

>
> > you get the idea.
> > Now I'm working on a project very computational-intensive, and I'm
> > worried about the many lines "if ($debuglevel...)" to be evaluated.

>
> Especially if the program is computational-intensive, it is unlikely
> that skipping debug statements is going to make a noticeable difference.
>
> > I was wandering: if $debuglevel was a constant, not a variable, it is
> > possible that the program, when launched, evaluates those lines from
> > the beginning? In this case I should not worry about later evaluation.

>
> If needed, that can be done using the constant pragma. The technique
> is described in "perldoc constant", so I don't have to repeat it here.
>
> Anno



Maybe I could be clearer: yes, I was talking about "use constant...".
Do you know if this:

use constant DEBUGON=>1;
if (DEBUGON>0) {...}

is evaluated, the if eliminated and the block {...} accepted, prior to
the global run?


thanks!

Alessandro

 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      09-10-2007
On 2007-09-10 09:54:04 +0200, "(E-Mail Removed)"
<(E-Mail Removed)> said:

> On 8 Set, 00:36, Anno Siegel <(E-Mail Removed)-berlin.de> wrote:
>> On 2007-09-07 13:33:05 +0200, "(E-Mail Removed)"
>> <(E-Mail Removed)> said:
>>
>>> Hi all, I need some advice:

>>
>>> in the past, when writing programs I often used, to help me in
>>> debugging, the following style:

>>
>>> my $debuglevel=1;
>>> ....
>>> print("var value is $a\n") if ($debuglevel>0);
>>> ....
>>> print(LOGFILE "array values are @x\n") if ($debuglevel>2);
>>> ...

>>
>>> you get the idea.
>>> Now I'm working on a project very computational-intensive, and I'm
>>> worried about the many lines "if ($debuglevel...)" to be evaluated.

>>
>> Especially if the program is computational-intensive, it is unlikely
>> that skipping debug statements is going to make a noticeable difference.
>>
>>> I was wandering: if $debuglevel was a constant, not a variable, it is
>>> possible that the program, when launched, evaluates those lines from
>>> the beginning? In this case I should not worry about later evaluation.

>>
>> If needed, that can be done using the constant pragma. The technique

^^^^^^^^^^^^^
>> is described in "perldoc constant", so I don't have to repeat it here.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> Maybe I could be clearer: yes, I was talking about "use constant...".
> Do you know if this:
>
> use constant DEBUGON=>1;
> if (DEBUGON>0) {...}
>
> is evaluated, the if eliminated and the block {...} accepted, prior to
> the global run?


There are at least two ways you could find out yourself. Take a look at
"perldoc constant" as recommended in my last reply. Or use the O:eparse
function to see directly what the compiler makes of your statement.

Anno

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      09-10-2007
On Sep 10, 7:28 am, Anno Siegel <(E-Mail Removed)-berlin.de>
wrote:
> On 2007-09-10 09:54:04 +0200, "(E-Mail Removed)"
> <(E-Mail Removed)> said:
>
> > Do you know if this:

>
> > use constant DEBUGON=>1;
> > if (DEBUGON>0) {...}

>
> > is evaluated, the if eliminated and the block {...} accepted,
> > prior to the global run?

>
> There are at least two ways you could find out yourself. Take a
> look at "perldoc constant" as recommended in my last reply. Or
> use the O:eparse function to see directly what the compiler
> makes of your statement.


Which is, of course, exactly what I did for the OP in the first reply
to this thread three days ago. . .

Paul Lalli

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query:difference between node flow and filter flow in java's I/O,system? Jack Dowson Java 0 05-07-2007 03:35 PM
Control page flow in ASP.Net 1.0 and 2.0 Coleen ASP .Net 2 08-31-2006 06:41 PM
Flow control and multicast or broadcast traffic Rahan Cisco 0 08-07-2006 04:14 PM
Flow Control and traffic optimization Rahan Cisco 0 08-04-2006 04:04 PM
os.system and flow control Lad Python 3 10-15-2004 09:48 PM



Advertisments