user2256825 user2256825 - 4 months ago 9
Perl Question

Data Block in perl not being picked

Below code works fine, if i get the data from the file
But does'nt really work if i have same data in the data block
The motto of this script is to search for 780222306003 in array of it starts with a pattern My BEING REMOVED
and search 'up.v.000652',780222304203 if it starts with a pattern LINK BEING REMOVED

Any advises to change the code if any ?

use Switch;
use strict ;
use warnings;

use Data::Dumper;

my $chunk_separator=q();
local $/ = $chunk_separator;
getFirstIntervalReport('MY_W',780222306003,'up.v.000652',780222304203);


sub getFirstIntervalReport
{
my ($wssmInstType, $expLinkMy, $expStation,$expectedMyFailure) = @_;
my $scan = "on";
# Sort the report files basd on the date in the file name and process each file
my @fileData = <DATA>;
foreach my $input_line (@fileData)
{
print "$input_line \n";
my @my_fields = split /\n/, $input_line ;
my $info_containing_My = grep /My BEING REMOVED/ , $my_fields[0];
my $info_containing_link = grep /LINK BEING REMOVED/ , $my_fields[0];
if( $info_containing_My ) {
print Dumper @my_fields;
if( grep /$expectedMyFailure/ , $my_fields[1]){
print Dumper @my_fields;
}
else { print "Expected My not deleted \n "; }
}

elsif ( $info_containing_link && $scan eq "on" ){
if((grep /$expLinkMy/ , $my_fields[2]) && (grep /$expStation/ ,$my_fields[3])){
$scan = "off" ;
print Dumper @my_fields;
}
else {
$scan = "on" ;
next;
}
}
}
if($scan eq "on") { print " $expLinkMy, $expStation Not Found \n"}
}




__DATA__
<ALERT> ID=7 Link Straight info Loss with count of 10 for
My Identifier:780222304404
Station Address:up.v.000654
Time: 1468581106

<ALERT> ID=17 Link Straight info Loss with count of 10 for
My Identifier:780222304203
Station Address:up.v.000657
Time: 1468581994

<INFO> LINK BEING REMOVED: Link has had no communication for an extended period of time - being removed from monitoring
for
My Identifier:780222304404
Station Address:up.v.000654
Time: 1468582162

<INFO> LINK BEING REMOVED: Link has had no communication for an extended period of time - being removed from monitoring
for
My Identifier:780222306003
Station Address:up.v.000654
Time: 1468582562

<INFO> LINK BEING REMOVED: Link has had no communication for an extended period of time - being removed from monitoring
for
My Identifier:780222304203
Station Address:up.v.000301
Time: 1468583082

<INFO> LINK BEING REMOVED: Link has had no communication for an extended period of time - being removed from monitoring
for
My Identifier:780222304203
Station Address:up.v.000654
Time: 1468583082

<INFO> LINK BEING REMOVED: Link has had no communication for an extended period of time - being removed from monitoring
for
My Identifier:780222304203
Station Address:up.v.000656
Time: 1468583082

<INFO> LINK BEING REMOVED: Link has had no communication for an extended period of time - being removed from monitoring
for
My Identifier:780222304203
Station Address:up.v.000657
Time: 1468583082

<INFO> LINK BEING REMOVED: Link has had no communication for an extended period of time - being removed from monitoring
for
My Identifier:780222304203
Station Address:up.v.000656
Time: 1468583082

<INFO> LINK BEING REMOVED: Link has had no communication for an extended period of time - being removed from monitoring
for
My Identifier:780222304203
Station Address:up.v.000657
Time: 1468583082

<INFO> LINK BEING REMOVED: Link has had no communication for an extended period of time - being removed from monitoring
for
My Identifier:780222306003
Station Address:up.v.000652
Time: 1468583578

<INFO> My BEING REMOVED: Link has had no communication for an extended period of time - being removed from monitoring
My Identifier:780222304203
Time: 1468583082

<INFO> My BEING REMOVED: Link has had no communication for an extended period of time - being removed from monitoring
My Identifier:780222304454
Time: 1468583082


http://stackoverflow.com/a/38452025/6594367

Answer

There is a known problem with use Switch and the __DATA__ block. Remove the use Switch and it will work.

See a relevant perlmonks question exactly on this. Apprently it's related to how Switch module filters the source.

Comments