[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] regex to lift Crypt::Tea strings out of XML



On Tue, Mar 18, 2008 at 9:46 AM, Jay Hannah <jhannah@omnihotels.com> wrote:

reverse() is neat. I didn't know/remember that Perl function.  :)

And for those of you wondering (like I was), here's what happens when you run it with multiple values on the right side of the => sign...

Code:
use Data::Dumper;
use strict;
use warnings;
my %a2b = ( A=>000, B=>001, C=>001, D=>002 );
printf ("Original:\n");
printf Dumper(\%a2b);

my %b2a = reverse %a2b;
printf ("\n======================\nReversed:\n");
printf Dumper(\%b2a);

printf ("Done!\n");


Output:
Original:
$VAR1 = {
          'A' => 0,
          'D' => 2,
          'C' => 1,
          'B' => 1
        };

======================
Reversed:
$VAR1 = {
          '1' => 'C',
          '0' => 'A',
          '2' => 'D'
        };
Done!

RESULT:
"There can be only one" (to be expected with a hash variable), but there aren't any warnings that appear when there are multiple values.  I'm not certain if it is 'last one wins' (last being last one defined in original hash), or 'first one wins' (first being the first as stored in memory and shown in the Dumper output)...

Dan
 
--
"Quis custodiet ipsos custodes?" (Who can watch the watchmen?) -- from the Satires of Juvenal
"I do not fear computers, I fear the lack of them." -- Isaac Asimov (Author)
** *** ***** ******* *********** *************