I’m glad it’s got you thinking. Here’s a little more to play with. The only part it answers directly is the delete function. I think you will start to understand more the more you play around with the code. Part of what makes Perl so easy/fun is how easy it is to test ideas, adjust and run. Remember, you have great built-in documentation. Just run perldoc -f delete for functions for example. Or perldoc perltoc or perldoc Data::Dumper, etc… :P

use strict; use warnings; use Data::Dumper; $Data::Dumper::Terse = 1; # Raw structures, no $VAR1 style names. # One hash, with a (hash) reference taken to it– my %stuff = ( somekey => "someval", o => "hai" ); my $stuff_ref = \%stuff; # reference literally *references* original. print "Same hash, two ways to access: $stuff{o} eq $stuff_ref->{o}\n"; # See the hash right now. print "Original hash: ", Dumper( $stuff_ref ); my $value = delete $stuff_ref->{o}; print "Hash after deleting key o: ", Dumper( $stuff_ref ); print "Print it directly (uninitialized now): o => ", $stuff_ref->{o}, + $/; # Add a new dimension to the data– $stuff_ref->{new_key}{sub_key} = "new value"; # Give it a friend, old key/value, new position– $stuff_ref->{new_key}{o} = $value; print "Hash after moving stuff around: ", Dumper( $stuff_ref ); $stuff_ref->{as}{deep}{as}{you} = "please"; $stuff_ref->{as}{deep}{as}{array_ref} = [ "one", "two" ]; $stuff_ref->{subroutine} = sub { print "OHAI!\n" }; $stuff_ref->{fancy_data} = [ "one", { two => "is a hash(ref)" }, ["ano +ther","array"], "last" ]; print "Perl data structures are *flexible* ", Dumper( $stuff_ref ); print "Excecuting code ref through data..."; $stuff_ref->{subroutine}->();
Same hash, two ways to access: hai eq hai Original hash: { 'somekey' => 'someval', 'o' => 'hai' } Hash deleting key o: { 'somekey' => 'someval' } Use of uninitialized value in print at /Users/moo/Desktop/pm.pl line 1 +7. Print it directly (unintialized now): o => Hash after moving stuff around: { 'new_key' => { 'o' => 'hai', 'sub_key' => 'new value' }, 'somekey' => 'someval' } Perl data structures are *flexible* { 'subroutine' => sub { "DUMMY" }, 'fancy_data' => [ 'one', { 'two' => 'is a hash(ref)' }, [ 'another', 'array' ], 'last' ], 'somekey' => 'someval', 'as' => { 'deep' => { 'as' => { 'array_ref' => [ 'one', 'two' ], 'you' => 'please' } } }, 'new_key' => { 'o' => 'hai', 'sub_key' => 'new value' } } Excecuting code ref through data...OHAI!
(Update: I'm not missing <ins>you</ins> at all… now.)

In reply to Re^5: Find a Position and Insert Text by Your Mother
in thread Find a Position and Insert Text by jlb333333

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.