in reply to Copying files from one file to another file

Hello harishnv,

What have you got so far? Can you show us some code that you have tried and failed?

Looking forward to your update. BR / Thanos

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: Copying files from one file to another file
by harishnv (Sexton) on Feb 19, 2018 at 16:45 UTC
    i'm trying to split the function : and then trying to read the preceeding term of it but i'm not able to do.
Re^2: Copying files from one file to another file
by harishnv (Sexton) on Feb 20, 2018 at 07:15 UTC
    I have tried doing so much. I have saved the path address into a key and the rest of the line to the value using split (:) function. Now, if the key is same how can I append the values to the same key?

      Try something like:

      c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @lines = ( 'foo: 12 : //comment twelve ', 'bar: 13 : //comment thirteen', 'foo: 5 : //comment five', ); ;; my %hash; for my $line (@lines) { my ($k, $v) = split qr{ : \s+ }xms, $line, 2; push @{ $hash{$k} }, $v; } dd \%hash; " { bar => ["13 : //comment thirteen"], foo => ["12 : //comment twelve ", "5 : //comment five"], }
      push-ing to an  @{ ... } array referenced by a hash key  $hash{$k} autovivifies an array reference if it did not already exist. See "autovivification" in perlglossary and here.


      Give a man a fish:  <%-{-{-{-<

        I didn't understand from here, Dd\%hash; And next line meaning? Can I know more about it?

        the path is written in terminal/ command window right? " code " should I put those apostrophe? Data::Dump::dd() is enough in the first line of the code?

        Can you write comments for the code? Didn't understand dd \%hash; from there

        Can someone help me out asap.

        not able to get the output

      $hash{$key} = $hash{$key}  . $line;

      or simply

      $hash{$key} .= $line;

      poj

Re^2: Copying files from one file to another file
by harishnv (Sexton) on Feb 19, 2018 at 17:21 UTC
    is it good by creating a hash table?

      One can well imagine that split-ing each line read from the input file and creating some sort of hash table might be involved in the solution of the problem presented in the OP. Unfortunately, I, for one, do not now understand the basic problem well enough to want to make the effort to attempt a solution. (Update: davido, a more patient man than I (at least today), has made a determined effort to provide a helpful solution in the face of a vague specification. ++davido.) Please see this and thanos1983's reply.


      Give a man a fish:  <%-{-{-{-<

      Only if you need one. What do you intend to use it for?


      Dave