in reply to Re^2: Find the array element as per the pattern.
in thread Find the array element as per the pattern.

Sure. But so could you, if you just read what Modern::Perl does, and by inference, what it does for this script.

Remove the line "use Modern::Perl;". Add the following three lines:

use 5.010_001; use strict; use warnings;

If you're using an older version of Perl, remove the say, add print, and put a newline at the end. Or change that first line to use feature qw/say/;, again assuming at least Perl 5.10.


Dave

Replies are listed 'Best First'.
Re^4: Find the array element as per the pattern.
by senthil_v (Sexton) on Jun 07, 2011 at 10:13 UTC

    Great Thanks dave it works here. actually in my script i having that all array elements in single "@all_metrics". So how can i use instead of while(<DATA>).

      All the array elements are in a single array:).

      Here's your original code. I cleaned it up a little, but davido showed you the best way to do it. Run this, and you'll see why.

      #!/usr/bin/perl use strict; my @all_metrics = <DATA>; foreach my $each_metrics_grp (@all_metrics) { $each_metrics_grp =~ s/RTRV(.*)//gi; my (@sub_metrics) = split( /'\n'/, $each_metrics_grp, 0 ); my ($matched_true) = grep( /"(([A-Z0-9]+)\-(\d+)),/sig, @sub_metri +cs ); print "$1\n"; print "@sub_metrics"; if ( $each_metrics_grp =~ m/\"(([A-Z0-9]+)\-(\d+)),/gis ) { push my @all_head, $1; print "matched:[$1]\n"; } else { print "not matched\n"; } } __DATA__ 'RTRV-PM-ALL:ADEL-OM3500-1:ALL:1898::,0-UP,NEND,,1-DAY,02-11,,;| ADEL- +OM3500-1 09-02-12 03:46:54 M 1898 COMPLD "OC192-11,OC192:CVS,0,COMPL,NEND,RCV,1-DAY,02-1 +1,00-00,1" "OC192-11,OC192:ESS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11,OC192:PSCW,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11,OC192:PSCP,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11,OC192:PSD,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-12,OC192:CVS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-12,OC192:PSCW,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" >'; 'RTRV-PM-ALL:ADEL-OM3500-1:ALL:1898::,0-UP,NEND,,1-DAY,02-11,,;| ADEL- +OM3500-1 09-02-12 03:46:56 M 1898 COMPLD "OC192-12,OC192:PSCP,0,COMPL,NEND,RCV, +1- DAY,02-11,00-00,1" "OC192-12,OC192:PSD,0,COMPL,NEND,RCV,1-DAY,02-11,00 +-00,1" "OC192-11-28,STS3C:CVP,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11-28,STS3C:UASP,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11-28,STS3C:FCP,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11-145,STS3C:CVP,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11-145,STS3C:ESP,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" "OC192-11-145,STS3C:SESP,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1" ;';
    A reply falls below the community's threshold of quality. You may see it by logging in.