What I meant was that you'd have to read the data and then process it. Consider the following snippets. The first produces a data file:

#!usr/bin/perl use feature qw/say/; use Data::Dumper; $Data::Dumper::Terse = 1; $hash = { 'testing' => { 'link' => "http://www.espn.com", 'bandwidth' => "100", 'r' => "2", }, }; say Dumper($hash);

You'll want to invoke this as perl script.pl >data.txt or so, BTW. Here's what the resulting data file will look like:

{ 'testing' => { 'link' => 'http://www.espn.com', 'bandwidth' => '100', 'r' => '2' } }

This in turn can be fed to another script again, perhaps something along the following lines:

#!/usr/bin/perl use feature qw(say); use Data::Undump; undef $/; $data = <>; $undump = undump($data); die "'testing' not found!" unless($undump->{'testing'}); say $undump->{'testing'}->{'link'} // (die "'link' not found!"); say $undump->{'testing'}->{'bandwidth'} // (die "'bandwidth not found! +");

This should be invoked as perl script.pl <data.txt; it'll read in the data in one big chunk, undump it, verify that the testing key exists (and raise an error otherwise), and print the link and bandwidth values associated with it, again raising an error if they don't exist (by abusing the // defined-or operator, which I'm not convinced is considered good style).

Playing around with this, I've found that Data::Undump can be fairly fussy about exactly what the data you feed it should look like (which is perhaps what the author meant when they aluded to it being an "early release"), so depending on how much control you have over the processes creating these data files, it may not be suitable for you. Certainly it does not seem like a very robust module (in the Postelian sense), and the cleanest solution might be to write a proper parse using Parse::RecDescent or so. Whether that's worth the effort is perhaps another question.


In reply to Re^5: perl regular expressions by AppleFritter
in thread perl regular expressions by iamsachin

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.