in reply to Re^3: perl regular expressions
in thread perl regular expressions

First of all,Thank you so much for explaining in detail.Appreciate it.

Is there a way to combine these two scripts into one single script

#!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); 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! +");
I tried to do it ,but looks likes the 2nd part didn't work. Any suggestions please ?

Replies are listed 'Best First'.
Re^5: perl regular expressions
by AppleFritter (Vicar) on Jun 24, 2014 at 19:00 UTC

    You're welcome!

    Yes, there is a way to combine them into one. Add a use Data::Undump, and then change the the part between say Dumper($hash) and $data = <> so that you're not printing to STDOUT and reading from STDIN anymore:

    #!usr/bin/perl use feature qw/say/; use Data::Dumper; use Data::Undump; $Data::Dumper::Terse = 1; $hash = { 'testing' => { 'link' => "http://www.espn.com", 'bandwidth' => "100", 'r' => "2", }, }; $data = Dumper($hash); $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! +");

    But of course now you're dumping and undumping your data in the same script, which is basically a no-op. So you could further simplify this to the following:

    #!usr/bin/perl use feature qw/say/; $hash = { 'testing' => { 'link' => "http://www.espn.com", 'bandwidth' => "100", 'r' => "2", }, }; die "'testing' not found!" unless($hash->{'testing'}); say $hash->{'testing'}->{'link'} // (die "'link' not found!"); say $hash->{'testing'}->{'bandwidth'} // (die "'bandwidth not found!") +;

    But that's got little to do with you original question anymore.