The hash structure is generated, so I can't change the structure of it, just extract it

Sometimes you just need to take out the chainsaw.

This assumes your file is just as you put it, parts always in quotes called hash1, hash2, hash3, there always are keys in quotes called paramA and paramB, and the values of those keys are always in quotes.

#!/usr/local/bin/perl use strict; use warnings; Generate(); sub Generate { Process_File('hash.pm'); } sub Process_File { my $filename = shift; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; my $file=''; while (my $line=<$fh>) { $file.=$line; } for my $n (1..3) { if ($file =~ m/\'hash$n\'.+?\{(.*?)\}/ms) { my $part=$1; my ($typ_s) = $part=~/\'paramA\'.*?\=\>.*?\'(.*?)\'/ms; my ($paramb)= $part=~/\'paramB\'.*?\=\>.*?\'(.*?)\'/ms; print "n $n typ_s $typ_s paramb $paramb\n"; } # part } # n }
Result
D:\goodies\pdhuck\down1\perl\monks>perl 1185438.pl n 1 typ_s 00 paramb FF n 2 typ_s 01 paramb 02 n 3 typ_s 00 paramb 03
Im sure others can improve on this too.


In reply to Re^3: Accessing the hash name in perl by huck
in thread Accessing the hash name in perl by Sonali

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.