Solved

reading from forn

Posted on 1998-11-14
7
193 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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 …
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

16 Experts available now in Live!

Get 1:1 Help Now