How to use Text-Format0.52 module

I have this :

<TEXTAREA NAME = "Content" ROWS = "8" COLS = "52" wrap = "off"></TEXTAREA>

and how to use Text-Format to justify whatever user type in the textarea

LVL 1
tanc02Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guadalupeCommented:
#!/usr/local/bin/perl


&parseInput;

$text->columns(10);
$text->bodyIndent(8);
$formatted_text = $text->format($fields{'content'});



#---------------------------------Parse Input---------------------------------------#
#                  Arguments:      NONE                                                                                    #
#                  Purpose            Standard Form/Query String Parsing                                          #
#                  Calls:            NONE                                                                                    #
#-----------------------------------------------------------------------------------#

sub parseInput()
{
      #Parse form variables
      if ($ENV{'REQUEST_METHOD'} eq "POST")
      {
            read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});
      }

      elsif ($ENV{'REQUEST_METHOD'} eq "GET" )
      {
            $temp = $ENV{'QUERY_STRING'};
      }

      @pairs=split(/&/,$temp);
      
      foreach $item(@pairs)
      {
            ($key,$content)=split (/=/,$item,2);
            $content=~tr/+/ /;
            $content=~ s/%(..)/pack("c",hex($1))/ge;
            $fields{$key}=$content;
      }

}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
guadalupeCommented:
OOPPPSSS!!

Sorry change top to:

#!/usr/local/bin/perl


&parseInput;
use Text::Format 0.43;
$text = new Text::Format;
0
tanc02Author Commented:
how to make the content justfy ?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

tanc02Author Commented:
this is what I have :

#!/usr/bin/perl

&parseInput;
use Text::Format;
$text = new Text::Format;

print "Content-type: text/html\n\n";
$text->columns(10);
$text->bodyIndent(8);
print $text->format($fields{'Content'});

sub parseInput()
{  
    if ($ENV{'REQUEST_METHOD'} eq "POST")
    {
      read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});
    }
    elsif ($ENV{'REQUEST_METHOD'} eq "GET" )
    {
      $temp = $ENV{'QUERY_STRING'};
    }
    @pairs=split(/&/,$temp);
    foreach $item(@pairs)
    {
      ($key,$content)=split (/=/,$item,2);
      $content=~tr/+/ /;
      $content=~ s/%(..)/pack("c",hex($1))/ge;
      $fields{$key}=$content;
    }



and in the textarea box, I typed a very long line without hit enter. After I hit submit, I saw a long
striing of line printed in the screen. It wasn't justify. But

$text->columns(10);

above statement will break the long line into
10 characters per line, right ?


0
guadalupeCommented:
Yes this will do 10 char lines...

What do you mean by justify... left right or full justified...
0
ozoCommented:
$text = new Text::Format({justify => 1});
print "Content-type: text/html\n\n";
print "<pre>";
print $text->format($fields{'Content'});
print "</pre>";
0
guadalupeCommented:
Centered would be:

$text->center("hello world","cool");

or else justify would be:

#Set justify to true
$text->config ({ justify => 1});

$text->format("hello world","cool");

0
tanc02Author Commented:
I set $text->bodyIndent(0);
it still give some indented apsce. Why ?
0
guadalupeCommented:
You can force a null first indent like so:

$text->config ({ justify => 1, firstIndent => 0});
0
tanc02Author Commented:
I have this :

#!/usr/bin/perl

print "Content-type: text/html\n\n";
&parseInput;
use Text::Format;
$text = new Text::Format();
$text->config ({justify => 1, firstIndent => 0});
$text->columns(60);
print "<pre>";
print $text->format($fields{'Content'});
print "</pre>";
........


if I type :

 1
 2   5
 3

and why it display :

 1253


how to the change the code, so it will detect the ENTER and SPEACE and still jusify the content ?
Then it should display :

 1
 2   5
 3


please go to http://24.17.48.48/d.html for a look
0
guadalupeCommented:
Aahhhh, yes because what you pass as a single varaible Text::Format understands to be a single paragraph.  It therefore ignores the newlines which are there and will place new ones in oder to comply with the columns setting.  You can force each line to be taken as a new paragraph by first splitting the text box at the new lines and then passing them one by one to format like this:


#!/usr/bin/perl

print "Content-type: text/html\n\n";

&parseInput;

#$fields{'Content'} = "TExt1\nText2 jjj\ntext3";


@paragraphs = split(/\n/, $fields{'Content'});

use Text::Format;
$text = new Text::Format();
$text->config ({justify => 1, firstIndent => 0});
$text->columns(60);
print "<pre>";
foreach $line (@paragraphs)
{
print $text->format($line);
}


print "</pre>";  
0
tanc02Author Commented:
You have solved my ENTER problem, how about SPACES.

I typed :

 1      5
    f



and it gave me :

15
f


but I would like :

1     5
   f

to be displayed. How ?
0
guadalupeCommented:
I seems to me like you dont want the Text::Format package at all.  Why don't you try this: simply output the text of the textbox back out but between the <pre>  tags.

Like this:

print "<pre>\n";

print "$fields{'Content'}\n";

print "</pre>\n";

The pre tags make html pay attention to returns and multiple spaces which normally it ignores.  Let me know if that does it...
0
tanc02Author Commented:
what if someone type some very very long lines without hit ENTER and short lines, and I still want the content to be justify. Then How ?
0
guadalupeCommented:
Try this though I'm not sure.  Change the code with Text::Format to

text->config ({justify => 1, firstIndent => 0, extraSpace => 1});
0
tanc02Author Commented:
No, it isn't
0
guadalupeCommented:
No it isn't what?  Do you mean it did't work or what...?
0
tanc02Author Commented:
It isn't work. For example :

1       2


3

I will get  :

12


3
0
guadalupeCommented:
Sorry for the delay, try this:

#!/usr/bin/perl

print "Content-type: text/html\n\n";

&parseInput;

#$fields{'Content'} = "TExt1\nText2 jjj\ntext3";


@paragraphs = split(/\n/, $fields{'Content'});

use Text::Format;
$text = new Text::Format();
$text->config ({justify => 1, firstIndent => 0});
$text->columns(60);
print "<pre>";
foreach $line (@paragraphs)
{
    if (length($line) > 60)
    {
         print $text->format($line);
    }
    else
    {
         print $line;
    }
}


print "</pre>";
0
tanc02Author Commented:
Give me a day, i will get back to you
0
tanc02Author Commented:
Adjusted points to 70
0
tanc02Author Commented:
100% correct, it is what I am expected. Thanks
I am increasing another 20 points.

Do you know how to write  perl script in
Inthersho environment ?
0
guadalupeCommented:
About the Inthersho environment, I don't even know what it is sorry.  But in general perl runs anywhere it has been ported...meaning if you can find a version of perl for this system(?) then you should be able to run scripts that you have writtenm and run with sucess elsewhere.  There are of course some exceptions but most are obvious.  If you try to use system("") then the system command must be compatible with the shell (same with backtics ``).  And of course other very system specific things like trying to acces windows APIs in unix/linux or trying to do a chmod in windows.  Let me know if it helps.  Oh and (forgive me, but) are you accepting the answer...?
0
tanc02Author Commented:
yes, I forget to select accept .
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.