I need help figuring out how to incorporate/get sum total of strings, while inside a foreach block. any help will be appreciated.
Here's the code:
_________________________________________
#!usr/bin/perl
use strict;
use File::stat;
our $dir_path = 'C:\path_name';
open DIR, $dir_path or die "Can't locate $dir_path: $!";
our @xml_files = glob '*.xml';
foreach my $xml_file_name (@xml_files) {
open FILE, $xml_file_name or die "Can't open $xml_file_name: $!";
my $xml_file_size = stat($xml_file_name)->size;
print "$xml_file_name is $xml_file_size BYTES ";
foreach my $line (<FILE>) {
if ($line =~ /^<product>/i) {
my @count = shift;
print "and contains ", scalar(@count), " record.\n";
}
}
}
close FILE;
close DIR;
=========================================
Here's what i'm getting right now:
Books_10292006_onix21.xml is 36670 BYTES and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
STER_10292006_bn_onix21.xml is 17393 BYTES and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
==============================================
Here's the output i need from it:
Books_10292006_onix21.xml is 36670 BYTES and contains 13 record.
STER_10292006_bn_onix21.xml is 17393 BYTES and contains 6 record.
Here's the code:
_________________________________________
#!usr/bin/perl
use strict;
use File::stat;
our $dir_path = 'C:\path_name';
open DIR, $dir_path or die "Can't locate $dir_path: $!";
our @xml_files = glob '*.xml';
foreach my $xml_file_name (@xml_files) {
open FILE, $xml_file_name or die "Can't open $xml_file_name: $!";
my $xml_file_size = stat($xml_file_name)->size;
print "$xml_file_name is $xml_file_size BYTES ";
foreach my $line (<FILE>) {
if ($line =~ /^<product>/i) {
my @count = shift;
print "and contains ", scalar(@count), " record.\n";
}
}
}
close FILE;
close DIR;
=========================================
Here's what i'm getting right now:
Books_10292006_onix21.xml is 36670 BYTES and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
STER_10292006_bn_onix21.xml is 17393 BYTES and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
and contains 1 record.
==============================================
Here's the output i need from it:
Books_10292006_onix21.xml is 36670 BYTES and contains 13 record.
STER_10292006_bn_onix21.xml is 17393 BYTES and contains 6 record.