Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Handling lines and saving them into variables

by jeffa (Bishop)
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>


(the triplet paradiddle with high-hat)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://888378]
[karlgoethebier]: Cojones! We need cojones!
[karlgoethebier]: Ouch! Permissions! We need permissions!
[BarApp]: I can not use modules. I gain temporary access and still can not use modules.
[Cosmic37]: ta erix - this szabo geezer is pretty cool methinks and he writes about undef but I cannot see instructions for redefining the record separator after having undefined it
[Corion]: $/ = "wahtever";
[Corion]: (it's a magic variable)
[karlgoethebier]: BarApp: whoami
[Cosmic37]: ok fankyou - I was wondering about that but thought there might be a redefine command or something; peachy

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-06-29 16:45 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (672 votes). Check out past polls.