Deb wrote:
> Hi Guys,
>
> I have an array in which each element is a line commandline data. It looks
> something like this -
>
> @Array contains lines:
>
> post1: -r [EMAIL PROTECTED] -x cat-100 -h post1
> post2: -x tel -h post2
> post3: -h post3 -x hifi
The getRelationships sub here has a few less typos, and the test stub runs well.
#!/usr/bin/perl -w
use strict;
use warnings;
sub getRelationship($$);
testGetRelationships();
sub testGetRelationships {
my $string = "post1: -r [EMAIL PROTECTED] -x cat-100 -h post1";
my %relationships;
getRelationship($string, \%relationships);
foreach my $key (keys %relationships) {
print "$key:=$relationships{$key}\n";
}
}
sub getRelationship ($$) {
my ($commandline, $relationships) = @_;
# print "$commandline\n"; #debug
my @commands = split /\s+-/, $commandline;
my $key = shift(@commands);
foreach (@commands) {
if (s/^x\s+//) {$$relationships{$key} = $_;}
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]