All pastes #801108 Raw Edit

arg parser

public text v1 · immutable
#801108 ·published 2007-11-29 00:10 UTC
rendered paste body
use strict;
#chdir( 'C:/Documents and Settings/' .
#       $ENV{USERNAME} .
#       '/My Documents/My Music' ) or die 'CHD';

my %data = parse_toks();
print "$_ -> $data{$_}\n" foreach keys %data;

sub get_data {
  die 'ARG';
}

sub parse_toks {
  my ($ckey,$nkey,@args);
  my @toks = @ARGV or get_data();
  foreach my $tok (@toks,'!END') {
    ($ckey,$nkey) = ($nkey,0);
    $nkey = $1 if $tok =~ /^!(\w+.*)/;

    push(@args,$ckey,1) if $ckey and $nkey;
    push(@args,$ckey,$tok) if $ckey and !$nkey;
  }
  return @args;
}