Uri Guttman wrote:
>>>>>> "t" == trapd00r  <trapd...@trapd00r.se> writes:
> 
>   t> I would like to have someone looking over my script, which is a
>   t> basic frontend for playing radio with mplayer. In particular, I'm
>   t> wondering how I could get rid of all those elsif's when parsing the
>   t> arguments; as you can see, there's lots of them, and I suspect that
>   t> there's a better way of doing things.
> 
>   t> Any criticism on anything is highly appreciated, since I want to learn.
>   t> Cheers.
> 
> i see an error on line 42.

I knew you were good, but now I know you are great!

To the OP, without code, it makes it difficult to tell what you are
after. Here's a portion of a utility script that I use for a Conversion
module I wrote:

#!/usr/bin/perl

use warnings;
use strict;

#...use() calls here

my %arg_table = (

        '--plans'           => \&plans,
        '--uledger'         => \&uledger,
        '--gledger'         => \&gledger,
        '--balance'         => \&balance,
        '--clients'         => \&clients,
        '--plan_passwords'  => \&plan_passwords,
    );

my $convert = \%arg_table;

my @allowed_args = keys %arg_table;

if ( ! defined $ARGV[0] || $#ARGV > 1 ) {

    print "\n" .
          "You must supply one of:\n\n" .
          "${\( join \"\n\", @allowed_args ) }" .
          "\n\n";
    exit;
}

my $item_to_translate = $ARGV[0];

# call the requested conversion function

$convert->{$item_to_translate}();

# ironically, vim folds nicely, so you can see how I have
# my subs defined via copy/paste...

# define the functions

+--  4 lines: sub plans
{-------------------------------------------------------------------------------------------------------------------------------
+--  4 lines: sub clients {
----------------------------------------------------------------------------------------------------------------------------
+--  4 lines: sub gledger
{-----------------------------------------------------------------------------------------------------------------------------
+--  4 lines: sub uledger
{-----------------------------------------------------------------------------------------------------------------------------
+--  4 lines: sub balance
{-----------------------------------------------------------------------------------------------------------------------------
+--  4 lines: sub plan_passwords
{----------------------------------------------------------------------------------------------------------------------
~


~

Steve

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to