Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to read through form input line by line and categorize the information

by hdb (Monsignor)
on Jan 19, 2014 at 18:33 UTC ( [id://1071203]=note: print w/replies, xml ) Need Help??


in reply to How to read through form input line by line and categorize the information

The code snippet below demonstrates two techniques that you might use here. One, if you have data in a string ($user_input) you can open a file handle to that string by providing a reference to the string instead of a filename. Two, if you set $/ to the empty string, you can read from a file handle in paragraph mode, i.e. <$file_handle> reads chunks separated by blank lines.

use strict; use warnings; use Data::Dumper; my $user_input = <<EOI; first para some text second para more text EOI local $/ = ''; open my $string_handle, '<', \$user_input; my @para = <$string_handle>; close $string_handle; chomp @para; print Dumper \@para;

If you then read the file handle in list mode (my @para = <$string_handle>;) you get all you want in one go. What you need to be careful about is that your manipulation of $/ does not affect other code, so usually one would use local to avoid that problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1071203]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-19 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found