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

Re: Dynamically parse BibTeX and create hash of hash

by pvaldes (Chaplain)
on Dec 07, 2012 at 15:40 UTC ( #1007762=note: print w/ replies, xml ) Need Help??


in reply to Dynamically parse BibTeX and create hash of hash

(mmmh... I wonder why are you using this form)

my (my $hkey, my $hvalue); # my (my ???


Comment on Re: Dynamically parse BibTeX and create hash of hash
Download Code
Re^2: Dynamically parse BibTeX and create hash of hash
by Anonymous Monk on Dec 07, 2012 at 17:47 UTC
    my(my ??) was just a typo, thank you both you helped a lot. Can you please also suggest how can I firstly sort this structure according "outer - %bibliography" hash keys (Forrest1996, Lee2000a) and then according "inner/nested - %article" hash keys (author, abstract, title, year e.g.) I know that if I am printing hash it first prints key and then value and the order cannot be guaranteed, therfore my idea was to iterate over hashes, bud did not work as expected. Code I have so far
    for $i (sort keys(%bibliography)){ print "$i", "\n"; #print "$i ", Dumper ($bibliography{"$i"}); for $j (sort keys ($i)){ print "$j\n"; } }
    Desired output (during iteration)
    $VAR1 = { 'Forrest1996' => { 'abstract' => 'Abstract goes here', 'author' => 'Forrest, Stephanie and Hofme +yr, Steven A. and Anil, Somayaji', 'title' => '{Computer immunology}', 'year' => '1996' }, 'Lee2000a' => { 'abstract' => 'Abstract goes here', 'author' => 'Lee, Wenke and Stolfo, Salvator +e J', 'title' => '{Data mining approaches for intr +usion detection}', 'year' => '2000' }, };
    Or is there any better way (structure) to strong this ? Thank you

      Something like this? (untested)

      for my $bibkey (sort keys %bibliography) { my $entry = $bibliography{$bibkey}; print "$bibkey:\n"; for my $key (sort keys %$entry) { print "\t$key => ", $entry->{$key}, "\n"; } }

      Alternatively, $Data::Dumper::Sortkeys = 1;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2014-09-16 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (46 votes), past polls