Wierd "if" behavior. 
Author Message
 Wierd "if" behavior.

Whenever the value in the if statement evaluates to true none of the
print statements are executed.  I for the life of me can't figure out
why.


        {
        if (/<font face=/)
                {
                dataHash{"title"}=$_;
                }
        print $_;
        }
print "Title = ";
print $dataHash{"title"};
print "end";

Mark Healey
marknews(the 'at' thing)healeyonline.com



Thu, 23 Sep 2004 11:37:47 GMT  
 Wierd "if" behavior.

Quote:

> Whenever the value in the if statement evaluates to true none of the
> print statements are executed.  I for the life of me can't figure out
> why.


>         {
>         if (/<font face=/)
>                 {
>                 dataHash{"title"}=$_;
>                 }
>         print $_;
>         }
> print "Title = ";
> print $dataHash{"title"};
> print "end";

Never mind.  I'm going blind.

Mark Healey
marknews(the 'at' thing)healeyonline.com



Thu, 23 Sep 2004 16:12:34 GMT  
 Wierd "if" behavior.

Quote:
> Never mind.  I'm going blind.

Ugly brace formatting and indenting will do that.
Quote:
> > Whenever the value in the if statement evaluates to true none of the
> > print statements are executed.  I for the life of me can't figure out
> > why.


> >         {
> >         if (/<font face=/)
> >                 {
> >                 dataHash{"title"}=$_;
> >                 }
> >         print $_;
> >         }
> > print "Title = ";
> > print $dataHash{"title"};
> > print "end";

> Never mind.  I'm going blind.

> Mark Healey
> marknews(the 'at' thing)healeyonline.com



Thu, 23 Sep 2004 16:52:30 GMT  
 Wierd "if" behavior.

Quote:

>Whenever the value in the if statement evaluates to true none of the
>print statements are executed.  I for the life of me can't figure out
>why.


>        {
>        if (/<font face=/)
>                {
>                dataHash{"title"}=$_;
>                }
>        print $_;
>        }
>print "Title = ";
>print $dataHash{"title"};
>print "end";

>Mark Healey
>marknews(the 'at' thing)healeyonline.com

Try

/<font\s+face=/ instead of /<font face=/

If you are using a single space between 'font' and 'face' and the actual data uses another variation, such as two or more spaces or a tab, then there will be no match. The metacharacters '\s+' cover all bases. The saying goes, "Assumption is the mother of all *uckups."

Herb is correct about your choice of brace locations. They suck since they take more effort to read than the standard brace positions. If you need to be individualistic then write a cool algorithm instead :)

Vic



Sat, 25 Sep 2004 20:01:47 GMT  
 Wierd "if" behavior.

Quote:


> >Whenever the value in the if statement evaluates to true none of the
> >print statements are executed.  I for the life of me can't figure out
> >why.


> >        {
> >        if (/<font face=/)
> >                {
> >                dataHash{"title"}=$_;
> >                }
> >        print $_;
> >        }
> >print "Title = ";
> >print $dataHash{"title"};
> >print "end";

> >Mark Healey
> >marknews(the 'at' thing)healeyonline.com

> Try

> /<font\s+face=/ instead of /<font face=/

> If you are using a single space between 'font' and 'face' and the actual data uses another variation, such as two or more spaces or a tab, then there will be no match. The metacharacters '\s+' cover all bases. The saying goes, "Assumption is the mother of all *uckups."

> Herb is correct about your choice of brace locations. They suck
>since they take more effort to read than the standard brace
>positions. If you need to be individualistic then write a cool
>algorithm instead :)

People have told me this before but I find it easier.  My way keeps
them on the same verticle line when one uses a monofaced font which
makes it easier to find a braces mate when they are more than one
screen height apart.

Mark Healey
marknews(the 'at' thing)healeyonline.com



Sun, 26 Sep 2004 12:13:24 GMT  
 Wierd "if" behavior.

Quote:



>>>Whenever the value in the if statement evaluates to true none of the
>>>print statements are executed.  I for the life of me can't figure out
>>>why.


>>>       {
>>>       if (/<font face=/)
>>>               {
>>>               dataHash{"title"}=$_;
>>>               }
>>>       print $_;
>>>       }
>>>print "Title = ";
>>>print $dataHash{"title"};
>>>print "end";

>>>Mark Healey
>>>marknews(the 'at' thing)healeyonline.com

>>Try

>>/<font\s+face=/ instead of /<font face=/

>>If you are using a single space between 'font' and 'face' and the actual data uses another variation, such as two or more spaces or a tab, then there will be no match. The metacharacters '\s+' cover all bases. The saying goes, "Assumption is the mother of all *uckups."

>>Herb is correct about your choice of brace locations. They suck
>>since they take more effort to read than the standard brace
>>positions. If you need to be individualistic then write a cool
>>algorithm instead :)

>People have told me this before but I find it easier.  My way keeps
>them on the same vertical line when one uses a monofaced font which
>makes it easier to find a braces mate when they are more than one
>screen height apart.

>Mark Healey
>marknews(the 'at' thing)healeyonline.com

Yes, I understand your reasoning now. Another way to keep braces on the
vertical is:


{
        if /<font face=/)
        {
                dataHash{"title"}=$_;
        }
        print $_;

Quote:
}

Since most perl programs look like


        if /<font face=/) {
                dataHash{"title"}=$_;
        }
        print $_;

Quote:
}

I decided to go with the flow and use that format. But, if I inherited
your code for maintenance, I would continue to use your bracing method
in that code. When I was a youngn' I would have done something stupid
like moving the braces around to suit me and therefore create new bugs.

Vic



Sun, 26 Sep 2004 20:26:08 GMT  
 Wierd "if" behavior.

Quote:




>>>> Whenever the value in the if statement evaluates to true none of the
>>>> print statements are executed.  I for the life of me can't figure out
>>>> why.


>>>>       {
>>>>       if (/<font face=/)
>>>>               {
>>>>               dataHash{"title"}=$_;
>>>>               }
>>>>       print $_;
>>>>       }
>>>> print "Title = ";
>>>> print $dataHash{"title"};
>>>> print "end";

>>>> Mark Healey
>>>> marknews(the 'at' thing)healeyonline.com

>>> Try

>>> /<font\s+face=/ instead of /<font face=/

>>> If you are using a single space between 'font' and 'face' and the
>>> actual data uses another variation, such as two or more spaces or a
>>> tab, then there will be no match. The metacharacters '\s+' cover all
>>> bases. The saying goes, "Assumption is the mother of all *uckups."

>>> Herb is correct about your choice of brace locations. They suck
>>> since they take more effort to read than the standard brace
>>> positions. If you need to be individualistic then write a cool
>>> algorithm instead :)

>> People have told me this before but I find it easier.  My way keeps
>> them on the same vertical line when one uses a monofaced font which
>> makes it easier to find a braces mate when they are more than one
>> screen height apart.

>> Mark Healey
>> marknews(the 'at' thing)healeyonline.com

> Yes, I understand your reasoning now. Another way to keep braces on
> the vertical is:


>     if /<font face=/)
>     {
>         dataHash{"title"}=$_;
>     }     print $_; }

> Since most perl programs look like


>     if /<font face=/) {
>         dataHash{"title"}=$_;
>     }     print $_; }

> I decided to go with the flow and use that format. But, if I inherited
> your code for maintenance, I would continue to use your bracing method
> in that code. When I was a youngn' I would have done something stupid
> like moving the braces around to suit me and therefore create new bugs.

> Vic

Note: the bracing I gave got scrrewed up in the transmission. I give up.

- Show quoted text -



Sun, 26 Sep 2004 20:44:40 GMT  
 Wierd "if" behavior.

 a question about ...

Quote:

> >>>>       {
> >>>>       if (/<font face=/)
> >>>>               {
> >>>>               dataHash{"title"}=$_;
> >>>>               }
> >>>>       print $_;
> >>>>       }
> >>> Herb is correct about your choice of brace locations. They suck
> >>> since they take more effort to read than the standard brace
> >>> positions. If you need to be individualistic then write a cool
> >>> algorithm instead :)

> >> People have told me this before but I find it easier.  My way keeps
> >> them on the same vertical line when one uses a monofaced font which
> >> makes it easier to find a braces mate when they are more than one
> >> screen height apart.

Solution 1 - find an editor which allows you to jump back and forth between matching delimiters. I like emacs, or vi when emacs isn't available. They are available for
DOS as well as most other OSes.

Solution 2 - a subroutine should ideally fit on one page, in which case it doesn't involve too much scrolling up and down on the monitor. If your subroutines are too long
for a page, consider moving some of the code into routines of their own. While the subroutine may be called only once, it will embody some action, so the code where
the routine is caled becomes easier to understand.

Of course, it isn't always possible to achieve the one page per routine guidline. I take length simply as a hint that I should examine the code carefully. Sometimes it is a
sign that I should break up my code, sometimes it indicates a poor design, sometimes a long routine simply can't be helped.

Tom Legrady



Sun, 10 Oct 2004 11:54:18 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Expected behavior of running "make test"

2. odd behavior of eval "/^\xNN/"

3. Strange behavior with "local"

4. Help on "while" behavior sought

5. counterintuitive behavior of "shift"

6. behavior of open "+>>"

7. Strange Behavior Of "gethostbyaddr"

8. Behavior of -scrollbars in "Tiler"

9. "character class ""bug""

10. system(("cp", "-Rf", "/tmp/a/*", "/tmp/b")); doesnt wrk

11. how to parse a "this", "that", "and the ", "other" file

12. Odd behavior for variables "a" and "b"

 

 
Powered by phpBB® Forum Software