Hi GotSilk

It is not clear to me what you are asking for. From the code it looks like you are collecting all the digits from any character stream beginning with /SRS[_\s\]?/ out of some files ending in .ctl or .log

# Create some files $touch {1..3}{a..c}.{ctl,log} $ls 1a.ctl 1a.log 1b.ctl 1b.log 1c.ctl 1c.log 2a.ctl 2a.log 2b.ctl + 2b.log 2c.ctl 2c.log 3a.ctl 3a.log 3b.ctl 3b.log 3c.ctl 3c. +log junk.pl $echo "SRS_222" >> 1c.ctl $echo "SRS_333" >> 1c.log $echo 'SRS_111SRS_2222SRS_3333' > 1a.log
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; opendir(my $dh, '.') or die $!; my @files = map { /(.*)\.ctl$/ }readdir $dh; my %srss; for (@files) { # $_ is set to each element in @files for my $extension(qw(ctl log)) { my $file = "$_.$extension"; open (my $fh, $file) or die $!; while (my $line = <$fh>) { while ($line =~ /SRS[_\s]?(\d+)/g) { $srss{$1} = 1; } } } } print join '|', sort {$a <=> $b} keys %srss; # 111|222|333|2222|3333
But maybe later you want to store more information such as what file the line was found in. A more complex data structure is needed.
#!/usr/bin/env perl use strict; use warnings; use Data::Dump; opendir(my $dh, '.') or die $!; my @files = map { /(.*)\.ctl$/ }readdir $dh; my %hashSlice; @hashSlice{@files} = undef; my $srss; $srss->{files} = { %hashSlice } ; for (@files) { # $_ is set to each element in @files for my $extension(qw(ctl log)) { my $file = "$_.$extension"; open (my $fh, $file) or die $!; while (my $line = <$fh>) { while($line =~ /SRS[_\s]?(\d+)/g) { $srss->{files}{$_}{$extension}{$1} = ' +Found'; } } } } dd $srss; { files => { "1a" => { log => { 111 => 1, 2222 => 1, 3333 => 1 } }, "1b" => undef, "1c" => { ctl => { 222 => 1 }, log => { 333 => 1 } }, "2a" => undef, "2b" => undef, "2c" => undef, "3a" => undef, "3b" => undef, "3c" => undef, }, }
While more complicated this has the advantage of showing which files did not have matches, which ones did, and what file extension they were found in. You can see all of the perl documentation with the perldoc commands. 'perldoc perl' will give you tons of material to read on the command line. There is a ton of references out there to learn from. There is a really concise tutorial at Learn Perl in 2.5 hours. Hope this helps.

In reply to Re^3: adding another file type to a hash table by trippledubs
in thread adding another file type to a hash table by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.