The data in the text file is the same as before. Nothing different. The error i get is.
bad data </home/vlr/archive/temp.txt> at ./vlr-cdma-test.pl line 32, <$fh> line 1.
These are my codes.
#vlr-cdma-parse.pl
#!/usr/bin/perl -w
use strict;
use warnings;
use Text::ParseWords;
my $dir = "/home/vlr/archive/";
my $date = "20211201";
chomp($date);
# Check directory for relevant files
opendir(DIR, $dir) or die "Could not open ".$dir."\n";
my @dir = grep(/^USRINF.*.$date.*.1700.txt$/, readdir DIR);
closedir DIR;
my $file = $dir."temp.txt";
open my $FH, '>', $file;
foreach $_(sort @dir){
my $DFile = $dir.$_;
print "Processing: ".$DFile."\n";
# Open Data File and parse each line
open my $DF, '<', $DFile or die "Can't open $DFile $!";
foreach $_ (<$DF>){
chomp( $_ );
if((length $_ > 0)&&($_ =~ /^\d{15}/)){
$_ =~ s/\s+/;/g;
my($imsi,$mdn,$sec) = (quotewords('[\t;]+|,\s', 0, $_))[0,
+1,3];
if((($imsi =~ /^\d{15}/)&&($imsi =~ /^(702|310)/))&&(($mdn
+ =~ /^\d{10}/)&&($mdn =~ /^(501)/))){
print $FH $imsi.",".$mdn.",".$sec."\n";
}
}
}
close $DF;
}
close $FH;
Then I would like to call the text file with your code.
#vlr-cdma-test.pl
#!/usr/bin/perl -w
use strict; # https://perlmonks.org/?node_id=11140267
use warnings;
use Data::Dumper qw(Dumper);
my $dir = "/home/vlr/archive/";
my $file = $dir."temp.txt";
open my $fh, '<', \$file or die; # FIXME change for your file
my $thirty = 1; # FIXME 1 for testing, should be 30
my (%answer, %lines);
$lines{ /,(.+)/ ? $1 : die "bad data <$_>" }++ while <$fh>;
for ( keys %lines )
{
my ($value, $key) = split ',';
$lines{$_} > $thirty and push @{ $answer{$key} }, $value;
}
open my $FH, '>', 'output.txt';
print $FH Dumper(\%answer);
close $FH;