On 22/05/2010 15:22, Akhthar Parvez K wrote:
On Saturday 22 May 2010, Jim Gibson wrote:
On 5/21/10 Fri May 21, 2010 12:13 PM, "Akhthar Parvez K"
<akht...@sysadminguide.com> scribbled:
Jim, thanks for your continued help.
Jim, forget everything that I "scribbled" upto now, how would you
tell Perl to pick 'cd' of 'abcd' and 'abcd' itself and 'pq' of 'pqrs'
and 'pqrs' itself, and nothing else, from an array ( = 'abcdpqrsxyz')
by asingle statement.
my @data = 'abcdpqrsxyz';
my %matches =<your statement>;
foreach my $cut (keys %matches)
{ print "$cut => $matches{$cut}\n"; }
and the output should be:
abcd => cd
pqrs => pq
Your answer would be much appreciated.
I think you may have simplified the problem you are facing a little too
much, but the code below does what you ask for. If, as I suspect, this
solution is not applicable to your real data, then please try to
describe the problem rather than coding up bits of Perl and leavng us to
guess what the data is like.
HTH,
Rob
use strict;
use warnings;
my $data = 'abcdpqrsxyz';
my %matches = $data =~ /(ab(cd))((pq)rs)/;
foreach my $key (keys %matches) {
print "$key => $matches{$key}\n";
}
__END__
*OUTPUT*
pqrs => pq
abcd => cd
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/