Interzona has asked for the wisdom of the Perl Monks concerning the following question:
$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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: trouble with substitution
by ww (Archbishop) on Jan 19, 2012 at 03:27 UTC | |
by Interzona (Initiate) on Jan 20, 2012 at 00:31 UTC | |
Re: trouble with substitution
by kejohm (Hermit) on Jan 19, 2012 at 02:45 UTC | |
Re: trouble with substitution
by CountZero (Bishop) on Jan 19, 2012 at 07:28 UTC | |
by remiah (Hermit) on Jan 19, 2012 at 12:43 UTC | |
by CountZero (Bishop) on Jan 19, 2012 at 19:25 UTC | |
Re: trouble with substitution
by InfiniteSilence (Curate) on Jan 19, 2012 at 04:04 UTC |