"the programme compalins" (sic)
. Yes, it certainly does. Did you try to understand the complaints?
C:\>perl -c F:\_Perl_\pl_test\verbatim.pl Global symbol "$VAR1" requires explicit package name at verbatim.pl li +ne 24. syntax error at verbatim.pl line 25, near ") }" verbatim.pl had compilation errors.

Did you read even the very first section of the posting guidelines (How do I post a question effectively?, inter alia) which tell you'll we'll be better able to help if you tell us (inside code tags) the wording (verbatim!) of what the program says when it "compalins?"

In any case, the first message says you failed to declare $VAR1 before using it.

The second points to the fact that you've written an if clause (a "conditional") without a block of code telling the program what to do when the if returns 'true' (and preferably, also, when it returns 'false'). See "Conditionals" in perldoc perlintro (at your CLI) or perlintro (in your browser).

What you seem to be looking for is something like this:

#!/usr/bin/perl; use strict; use warnings; use 5.012; my ($line, @newarr); my @hashfile = <DATA>; for my $line (@hashfile){ $line =~ tr/\$//; if ( $line =~ /VAR1/ ) { $line =~ s/VAR1/my \%hash/; push @newarr, $line; } else { push @newarr, $line; } } for $_( @newarr) { say $_; } __DATA__ $VAR1 = { '' => '', '362520' => 'Fktn and Name: fukutin[Rattus norvegicus]', '375790' => 'AGRN and Name: agrin[Homo sapiens]', '3339' => 'HSPG2 and Name: heparan sulfate proteoglycan 2[Ho +mo sapiens]', '1428' => 'CRYM and Name: crystallin, mu[Homo sapiens]', }

which produces this output:

$my %hash = { '' => '', '362520' => 'Fktn and Name: fukutin[Rattus norvegicus]', '375790' => 'AGRN and Name: agrin[Homo sapiens]', '3339' => 'HSPG2 and Name: heparan sulfate proteoglycan 2[Ho +mo sapiens]', '1428' => 'CRYM and Name: crystallin, mu[Homo sapiens]', }

Adding the necessary code to write a new file from @newarr (or, to write the new file without resort to that extra varaible/data structure) is left as an exercise.

HOWEVER, the job sequence of which this is a part would probably be less subject to error and easier to maintain, were you to process whatever the source data that's fed into your dumpparse.txt into an appropriate data structure (which may or may not be a hash; more likely, not, from the looks of it, but you haven't told us enough to put much credence in that interpretation) and perform the remaining processing in a single script.

Updated: minor edits for brevity/clarity.


In reply to Re: trouble with substitution by ww
in thread trouble with substitution by Interzona

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.