Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Two files from one.

by buckaduck (Chaplain)
on May 22, 2002 at 16:38 UTC ( #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? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2022-12-10 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?