in reply to Scalar size limits

1. Show us your code to point you precisely.
2. To put hyphen at 50th character for more than 50 characters:
$_ = 'x' x 80; $_ .= 'y' x 100; s/((.){49})/$1-/g; print;
3. To seperate the big word by a space
s/((.){49})/$1 /g;
substr($_,0,49) =~ s/$/-/ if length($_) > 50;

Updated as per hardburn's comments

artist

Replies are listed 'Best First'.
Re: Re: Scalar size limits
by fglock (Vicar) on Jun 26, 2003 at 16:32 UTC

    To write a
    + in next line:

    substr($_,0,49) =~ s/$/<br><font color=red>+<\/font>/ if length($_) > 50;

    Now seriously: see Text::Wrap

      Ok, I have the same question for you as I do artist. You are s/// a $, where do I set my variable to this?
      substr($_,0,49) =~ s/$/<br><font color=red>+<\/font>/ if length($_) > +50;

        $ is the end of the substr'ed $_ !

        But ignore this and see my update on Text::Wrap.

      I still don't have the foggiest idea on how I would use that to do anything. How would I assign $description to that?

      Also, I checked out Text::Wrap and it's not going to work. "It formats a single paragraph at a time by breaking lines at word boundries", it sounds like this will only work if they person uses real words and spaces, my problem is someone can screw everything up by typing

      "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz +zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz +zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz +zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz +zzzzzzzzzzzzzzzzzzzzzzz"
      and I need to find a way to break it up so it doesn't scroll the page (like it does here).

      update (broquaint): added <code> tags around the problem string

        use Text::Wrap qw( wrap $columns ); $_ = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz +zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz +zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz +zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz +zzzzzzzzzzzzzzzzzzzzzzzzzzzz"; $columns = 50; print wrap( '', '', $_ );

        output:

        zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzz
Re: Re: Scalar size limits
by hardburn (Abbot) on Jun 26, 2003 at 16:25 UTC

    What if the word isn't 51 characters long, but 101? Or 300? or 314159? Your code would break it into a word 50 chars long, then a hyphen, then the rest of the long string.

    When I first looked at this problem, I though inserting the hyphen would be the easiest solution. After I started working it out, I think its actually the hardest.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

      That's true...that could be a problem. I need it setup so no word can be larger than a specified limit and if it is, break it up into two words by a space or a hyphen. Whether it be 51 or a million, I have to get them broken up.

      Artist, I want to try your code but I don't quite understand how to implement it. Let's say I have $description, how would I use that with your example? Sorry, I'm just a little confused.