"Thank you a lot!"
You're welcome a lot!
"Will the following code work for me?"
Well, I'm tempted to ask -- "what happens when you try?". The best way to learn is, after all, by trying.
I do see that you're trying to initialize @files from a list reference ['tab1.txt','tab2.txt']; which likely won't do what you're expecting (you'll get a single item in @files, which itself is a reference to the 2-item list).
Better to declare it like this:
my @files = ('tab1.txt','tab2.txt');
# Or, using the "quote-word" function "qw",
# which lets you omit the quotes and the comma:
my @files = qw( tab1.txt tab2.txt );
Furthermore, you're creating a variable $hash_key which you're never assigning to, but rather trying to perform a regex substitution on with:
my $hash_key =~ s/\.txt//; # generate hash key
That's why, when I run it with use strict; and use warnings; I get the error:
Use of uninitialized value in substitution (s///) at merge.pl line 16.
So I'm assuming what you want instead is to assign to the filename $file, and then perform the substitution to get the resulting hash key:
(my $hash_key = $file) =~ s/\.txt//; # generate hash key
A final thought: make liberal use of Data::Dumper to see what data a given data structure contains at any time. For example, to see the entire contents of $ptables after making each assignment:
$ptables{$hash_key} = [ @string_array ]; # save all strings to the has
+h
print Dumper(\%ptables); # use "\" to pass reference o
+f hash
Update: fixed typo (thanks johngg).
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
|