?
Solved

reading from forn

Posted on 1998-11-14
7
Medium Priority
?
247 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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

764 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