Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Handling lines and saving them into variables

by jeffa (Chancellor)
on Feb 15, 2011 at 20:50 UTC ( #888378=note: print w/ replies, xml ) Need Help??


in reply to Handling lines and saving them into variables

If your HTML is not terribly complex, you could use something like YAML

use strict; use warnings; use Data::Dumper; use YAML; # Load a YAML stream of 3 YAML documents into Perl data structures. my $data = do {local $/ = <DATA> }; my @yaml = Load( $data ); for my $hash (@yaml) { my $question = $hash->{question}; my $answer = $hash->{answer}; print "q: $question\na: $answer\n"; } __DATA__ --- question: <b>What... is your name?</b> answer: <p>My name is Sir Lancelot of Camelot.</p> --- question: <b>What... is your quest?</b> answer: <p>To seek the Holy Grail.</p> --- question: <b>What... is your favourite colour?</b> answer: <p>Blue.</p>


jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)


Comment on Re: Handling lines and saving them into variables
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2014-12-18 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (61 votes), past polls