Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: trouble with substitution

by CountZero (Bishop)
on Jan 19, 2012 at 07:28 UTC ( #948709=note: print w/ replies, xml ) Need Help??


in reply to trouble with substitution

Assuming your dumpparse.txt file contains a straight copy of the output of Data::Dumper), you can simply eval the contents of that file.

use Modern::Perl; my $data; my $VAR1; my %hash; { local $/; $data = <DATA>; } eval $data; %hash = %$VAR1; __DATA__ $VAR1 = { '' => '', '362520' => 'Fktn and Name: fukutin[Rattus norvegicus]', '375790' => 'AGRN and Name: agrin[Homo sapiens]', '3339' => 'HSPG2 and Name: heparan sulfate proteoglycan 2[Homo sap +iens]', '1428' => 'CRYM and Name: crystallin, mu[Homo sapiens]', }
Update: Silly me. I totally forgot about the do function!
use Modern::Perl; my %hash = %{do 'dumpparse.txt'}; say map {"$_ : $hash{$_}\n"} keys %hash;

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James


Comment on Re: trouble with substitution
Select or Download Code
Re^2: trouble with substitution
by remiah (Hermit) on Jan 19, 2012 at 12:43 UTC

    I usually use 'require' to thaw dumped text.

    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $dat = require "dump.txt";

    It has been very handy for me.

      Yes, that will work as well, provided your file lives somewhere @INC points to.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://948709]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2014-09-20 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (152 votes), past polls