Solved

reading from forn

Posted on 1998-11-14
7
218 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl - Mawk 2 95
delete query using perl dbi 3 100
Perl troubleshooting error. Base64 bootstrap parameter 5 69
what are these modules in perl script 4 98
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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.…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now