"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$..$/

In reply to Re^3: Merging/Rearranging Tables by liverpole
in thread Merging/Rearranging Tables by homeveg

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.