Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Handling lines and saving them into variables

by jeffa (Bishop)
on Feb 15, 2011 at 20:50 UTC ( [id://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)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2025-06-14 04:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.