Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Two files from one.

by buckaduck (Chaplain)
on May 22, 2002 at 16:38 UTC ( [id://168509]=note: print w/replies, xml ) Need Help??


in reply to Two files from one.

(Untested) If the questions in the input are separated by blank lines:
# Read input a paragraph at a time # and put carriage returns on output lines local $/ = "\n\n"; local $\ = "\n"; # Read input, one question at a time while (<>) { chomp; # Grab the question number my $number = /^(\d+\.)/; # Split the question into lines my @question = split /\n/; # The answer is the last line my $answer = pop @question; # Send the results to different output streams print OUT1 join("\n", @question); print OUT2 "$number $answer"; }

buckaduck

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-18 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found