Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

moritz's scratchpad

by moritz (Cardinal)
on Aug 15, 2007 at 18:07 UTC ( #632816=scratchpad: print w/replies, xml ) Need Help??

For jairly

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @lines; while (<DATA>) { chomp; if (/^>/) { push @lines, $_; } else { $lines[-1] .= $_; } } print Dumper \@lines; __DATA__ >bob 123456789012345678901234567 8901234567890123 >squeaka TTTGGACCCACAACGTACCACAGGTAT SAJFIJEIFIRVNUTR >trumpet TTTTGAGACCCCCACAAAAGGATTTTT ANDANOTHERLINERT >nautilus AGTCAGTCGATCGTACGTATATAACAC CSADJOIASJNEEESA

Allowing a callback to return more than one level

I want to write some kind of text-only menu system, and that defines callbacks which are called for specific input.

Now the default behavior is to simply ignore the return value (trust me, it makes sense in my $work context), and exit the menu when the input is empty. However I want to give some callbacks the possibility to exit the menu too.

How? A normal return() doesn't accomplish that, so here is my hack:

use strict; use warnings; use 5.010; my $return_args; sub RETURN { $return_args = [@_]; no warnings 'exiting'; last 'UNIQUELABEL'; } sub menu { UNIQUELABEL: for (@_) { $_->(); } return @{$return_args} if $return_args; }; say menu sub { say 'go on' }, sub { RETURN 'ended' }, sub { 'never called' },
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[Eily]: hu, don't tell the other French people I never tried it, I might get kicked out :P
choroba . o O ( The Czech at-sign is also edible )
[Eily]: the French @ is a mouthful I guess...
[Eily]: choroba Wikipedia gives me Zavináč which doesn't seem to translate to something edible?
[Eily]: (yes I'm very good at using question marks, thank you)
[Discipulus]: O_O frexit for you! even me i tried. it was in the arabic quarter in Granada; they offered as 'tapas' in bars. I eataly somewhere they eat ;=P Sardinia a Pulia iirc
[choroba]: Zavináč
[Eily]: choroba oh, that makes sense :)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2017-11-21 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (297 votes). Check out past polls.

    Notices?