Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Have A Prob with a Global

Quote Reply
Have A Prob with a Global
Hi:

I have a global I use to shorten up one specific field for display on certian Detail pages. In essance, the object is to take a field longer than 75 characters (and some get into the 200-300's!) and bring it down to a "digest" size. Additionally, I use the one field for two fields of info, as you will see. For the "Digest", I remove the code to make it a seperate "apparent" field and just string it all together. The field is "Studio" which is the studio who makes a cartoon. As is sometimes the case (and in this specific example, it is Animaniacs), there is a Producing studio... and an animating studio. So, to make this two fields, I use this as an entry:

Warner Bros. Television Animation.<LI>Animation Studio</B>: Freelance Animators, Ltd.

When Incerted into my detail page, this will result in:

Warner Bros. Television Animation.
Animation Studio
: Freelance Animators, Ltd.

and when I "digest" this, it will result in:

Warner Bros. Television Animation, Freelance Animators, Ltd.

Here is the global to do that:

sub {

my $short1;

my $comma1;

my $cs1;

my ($rec) = @_;

my $stud = $rec->{'Studio'}; # Get the Info

$short1 =~ s/.<LI>Animation Studio<\/B>:/, /; # Remove the Animation Studio header, subsitute comma

$short1 =~ s/,<LI>Animation Studio<\/B>:/, /; # Same, and a test

if (length $stud < 45) { # If Studio is less than 45, do NOTHING

$short1 = $stud;

}

else { # If Studio is more than 45 characters...

$short1 = substr ($stud, 0, 75); #Cut it to 75 Characters

$short1 =~ s/\s\S+?$//;

$short1 =~ s/.<BR>/, /; #Remove a <BR> if there is one

$cs1 = chop($short1);

until ($comma1 eq ",") { ### Loop until we find a comma

$comma1 = chop($short1); # Cut it off AT the comma

}

$short1 .= "..."; # Add a "..." so we know it is chopped

}

return $short1;

}



OK, this has been working well and good for me for a while... But it is crashing me on one SPECIFIC entry.... and I cannot figure out why. When Studio = Warner Bros. Television Animation.<LI>Animation Studio</B>: StarToons.

This goes into a death spiral... I have been all over the code (as best I can!) and I cannot figure out why this just does not return:

Warner Bros. Television Animation....

Any Ideas?

Thanks!

dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Have A Prob with a Global In reply to
When you say death spiral do you mean it hangs and hangs in an eternal loop?
Quote Reply
Re: [Paul] Have A Prob with a Global In reply to
Paul:

Yes.... When I try to open any page with

Warner Bros. Television Animation.<LI>Animation Studio</B>: StarToons.

On it ("digest") version, so running the global...

TOP shows a couple of processes opened, and chewing up a TON of Resources. Here,, let me do one!

OK, on the "Full Return page, I get exactly what I expect:
  • Warner Bros. Television Animation.
  • Animation Studio: StarToons.[/b]


  • When I go to the digest page, it LOOKS like nothing happens on the web page itself- it stays white, but this is from TOP:

    PID USERNAME PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND
    87062 nobody 64 0 33740K 31812K RUN 0:09 41.91% 27.98% httpd
    87074 nobody 63 0 33740K 31812K RUN 0:06 30.79% 20.56% httpd

    Note the PRI value... takes over the computer!!!! Also, State is RUN, which is not usual...

    Now, when I take the Studio value to Warner Bros. Television Animation, this page displays fine.... so it has to be something with StarToons... Also, there are 5-6 "Animation" studios for Animaniacs, and all of thoise dispaly fine.

    My gut tells me it has something to do with "StarToons" being a short number of letters.... but when I tried "StarToons Animation Studios" (which is NOT the proper title, but added a lot more letters) it still death spiraled...

    Here are some that work FINE:

    Warner Bros. Television Animation.<LI>Animation Studio</B>: Freelance Animators, Ltd.

    Nope- I checked... that one seems to not work now...

    OK, I moved a line (well, two) in the above global... I am back to the original, which is like this (All I did was move where the "Animation Studio substitution is made. THIS global works for all BUT Startoons!)

    sub {
    no strict;

    my $short1;
    my $comma1;
    my $cs1;
    my ($rec) = @_;

    my $stud = $rec->{'Studio'};
    if (length $stud < 45) {
    $short1 = $stud;
    }
    else {
    $short1 = substr ($stud, 0, 75);
    $short1 =~ s/\s\S+?$//;
    $short1 =~ s/.<BR>/, /;
    $short1 =~ s/.<LI>Animation Studio<\/B>:/, /;
    $short1 =~ s/,<LI>Animation Studio<\/B>:/, /;

    $cs1 = chop($short1);

    until ($comma1 eq ",") {
    $comma1 = chop($short1);
    }
    $short1 .= "...";
    }
    return $short1;
    }

    OK, NOW Nevermind.... it seems to have fixed itself somehow....

    Blush
    dave

    Big Cartoon DataBase
    Big Comic Book DataBase
    Quote Reply
    Re: [carfac] Have A Prob with a Global In reply to
    The only part of your global that would cause the hang is this:

    >>
    until ($comma1 eq ",") {
    $comma1 = chop($short1);
    }
    <<

    The until() will probably just kepp going and going if $short1 doesn't contain a comma.
    Quote Reply
    Re: [Paul] Have A Prob with a Global In reply to
    Paul:

    Yeah, and I have had that problem before.... I was thinking the subsitution was the problem, not getting the comma in or something...

    Doi not know why, but it seems to be fine right now with the same code I started with. I did that move thinking to do the sub early might be better...
    dave

    Big Cartoon DataBase
    Big Comic Book DataBase
    Quote Reply
    Re: [Paul] Have A Prob with a Global In reply to
    What do you want that until() loop to do?

    It would be better changing it.
    Quote Reply
    Re: [Paul] Have A Prob with a Global In reply to
    Paul:

    I am showing the limits of my programing ability. As it is written, it is supposed to back space, a character at a time, from the 75th character until it finds a comma. Then it chops it at the comma, and adds an ellipese (...) .

    I guess the problem is when there is NOT a comma in the first 75 characters, and that is when it spirals to death! I have only had this problem a couple of times, and usually I can find and fix it easily (I have learned to spot the symptoms. Plus, when Links rebuilds, the category it hands at is most likely the one with the problem!)

    If you have a better way to do this, I would be MOST gratefull to know it and impliment it! I am sure there is a better way, even if it just counts the number of loops, and ends at 75!

    dave
    dave

    Big Cartoon DataBase
    Big Comic Book DataBase