D. Bolliger wrote:
> John W. Krahn am Sonntag, 14. Mai 2006 00.11:
>>
>>Or you could "cheat" and let Getopt::Long parse it for you:
>>
>>$ perl -MGetopt::Long -MData::Dumper -e'
>>$_ = q[iptables -A INPUT -p tcp -s 123.45.678.90 --dport 22 -j ACCEPT];
>>my %h;
>>{ local @ARGV = split;
>> GetOptions( \%h, "A=s", "p=s", "s=s", "dport=i", "j=s" );
>> }
>>print Dumper \%h;
>>'
>>$VAR1 = {
>> 'A' => 'INPUT',
>> 'p' => 'tcp',
>> 's' => '123.45.678.90',
>> 'j' => 'ACCEPT',
>> 'dport' => 22
>> };
>
> The disadvantage may be that it accepts wrong syntax like -ptcp (see remark
> above), but the idea is great!
$ perl -MGetopt::Long -MData::Dumper -e'
$_ = q[iptables -A INPUT -ptcp -s 123.45.678.90 --dport 22 -j ACCEPT];
my %h;
Getopt::Long::Configure( "bundling_override" );
{ local @ARGV = split;
GetOptions( \%h, "A=s", "p=s", "s=s", "dport=i", "j=s" );
}
print Dumper \%h;
'
$VAR1 = {
'A' => 'INPUT',
'p' => 'tcp',
's' => '123.45.678.90',
'j' => 'ACCEPT',
'dport' => 22
};
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>