Perl
  Home arrow Perl arrow Page 4 - Perl: Another Round with Hashes
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

Perl: Another Round with Hashes
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-05-05

    Table of Contents:
  • Perl: Another Round with Hashes
  • Adding More Than One Record
  • Using the Delete Function
  • Storing a Deleted Value in a Variable

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    Perl: Another Round with Hashes - Storing a Deleted Value in a Variable
    (Page 4 of 4 )

    We don't have to simply do away with our deleted value. In the following code, we will store it in a variable and append it to a sentence:


    #!/usr/bin/perl

    %Wrestlers=(Champ=> ' CM Punk ', Chump => ' Chavo Guerrero ',

    OldSkool=> ' Big John Stud ', Boof=> ' Brutus Beefcake ');

    print values(%Wrestlers);

    print "\n\n";

    $Dead=delete(@Wrestlers{Champ});

    print values(%Wrestlers);

    print "\n\n";

    print "This guy is dead: " . $Dead;

    Here we have:

      Brutus Beefcake Big John Stud CM Punk Chavo Guerrero

      Brutus Beefcake Big John Stud Chavo Guerrero

      This guy is dead: CM Punk

    And finally, we come back to our scenario where both Chavo and CM Punk die. Now we would like to add them to a growing list of dying wrestlers. Since seeing is believing, here is the eye-catching code:


    #!/usr/bin/perl

    %Wrestlers=(Champ=> ' CM Punk ', Chump => ' Chavo Guerrero ',

    OldSkool=> ' Big John Stud ', Boof=> ' Brutus Beefcake ');

    print values(%Wrestlers);

    print "\n\n";

    @Dead=delete(@Wrestlers{Champ,Chump});

    print values(%Wrestlers);

    print "\n\n";

    print "These guys are dead: " . @Dead[0] . @Dead[1];

    This will delete the records for 'Champ' and 'Chump' and store them in the list @Dead. When we run this program we get the following printout:

      Brutus Beefcake Big John Stud CM Punk Chavo Guerrero

     

      Brutus Beefcake Big John Stud

      These guys are dead: CM Punk Chavo Guerrero

    One final note. Had you tried to write out both values in the @Dead list like so:


    print "These guys are dead: " . @Dead;

    You would have been given the sentence:

      These guys are dead: 2

    Instead of printing the values, it would have printed the number of elements. Why that is, I am not certain.

    Well that's all the time we have for this one. Be sure to stop by next time as we continue talking about hashes and go into those multidimensional lists you've been hearing so much about.

    Till then...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Thanks for stopping by to read another article in my series on Perl Lists and...
     

       

    PERL ARTICLES

    - Perl: A Continuing Look at Hashes and Multid...
    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util
    - Perl Lists: Utilizing List::Util
    - Perl Lists: The Split() Function
    - SQL and CGI with Perl and DBI
    - Perl Lists: More Functions and Operators
    - SELECT Queries and Perl
    - Perl Lists: More on Manipulation
    - Creating a Database with Perl and DBI
    - Perl: Sailing the List(less) Seas
    - Perl and DBI
    - Perl: Concatenating Text and More
    - Perl Text: Quoting Without Quote Marks

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway