$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]', }

I am very new at this so help would be appreciated I have a file containing text like the one above, I have called it dumpparse.txt, that I created parsing a bigger file using Data::Dumper module. I want to very siimply change the lead text from $VAR1 to my %hash. Then I can read the file back in and do a hash search. so far I have read in the file as an array and the idea is to just use a simple substitution useing the code like the following. The trouble is the regex and the substitution look like variables and the programme compalins, help would be apreciated. Thanks

# #!/usr/bin/perl; use strict; use warnings; my $hashfile = 'dumpparse.txt'; unless ( open(DUMPPARSE, $hashfile) ) { print "Could not open file $hashfile!\n"; exit; } my @hashfile = <DUMPPARSE>; foreach my $line (@hashfile){ if ($line = ~s/ $VAR1/ my %hash /) } # Close the file. close DUMPPARSE; exit;

In reply to 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.