Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

reading from forn

Posted on 1998-11-14
7
Medium Priority
?
250 Views
Last Modified: 2010-03-04
how can i read a string from a form and process each character by character?

for example i enter: hi

i want to be able to edit "h" and "i" individualy
0
Comment
Question by:chongkong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1206215
what do you want to do with "h" and "i"?
0
 

Author Comment

by:chongkong
ID: 1206216
i wanted to add some prefix value for example "ab" to a string of number or character i enter and print if one on a new line

for "hi"

it would be abh and abi
0
 

Accepted Solution

by:
JFM earned 400 total points
ID: 1206217
Hi ozo,

You could try to add your prefixes by regular expression:

$line = "hi, this is JFM";
# put any character you want within the [ ]
$line =~ s/([hi])/ab$1\n/g;
print $line;

# shows:
abh
abi
, tabh
abi
s abi
s JFM

I don't know a possibility to read each character by character. For better effeciency it would be better to read line by line (or even the whole stream) and process the line afterwards.

Hope, that helps,
JFM.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Expert Comment

by:stepherd
ID: 1206218

Assuming your HTML form is using the post method, and (for argument) the name of the field is "text" use this:

#!/usr/local/bin/perl      

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

&parse_form;


@letters = split(//, $in{'text'});



sub parse_form {

   # Get the input
   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

   # Split the name-value pairs
   @pairs = split(/&/, $buffer);

   foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);

      # Un-Webify plus signs and %-encoding
      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      $value =~ s/<!--(.|\n)*-->//g;

      $in{$name} = $value;
   }

}


This will put all the letters in your the word into the array
@letters. So, if your form submitted the word "hi", then

@letters[0] = "h"
@letters[1] = "i"




0
 

Author Comment

by:chongkong
ID: 1206219
thanks stepherd,

its with i needed
0
 
LVL 84

Expert Comment

by:ozo
ID: 1206220
You're thanking stepherd, but accepted JFM's answer.
Which was really what you needed?

(also, substr($in{'text'},0,1) eq "h", substr($in{'text'},1,1) eq "i",
or vec, or while( m/(.)/sg ) or pack/unpack or some other technique may be appropriate depending on what kind of editing you wish to do)
0
 

Expert Comment

by:JFM
ID: 1206221
ok, sorry for that. I was a little bit too quick, thinking I understood the problem and had the right answer. Next time, it'll be a comment.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question