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
Solved

reading from forn

Posted on 1998-11-14
7
227 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
  • 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 100 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

789 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