iLTC Home
Bookmark iLTC!

Categories

Perl
  • Perl Tutorials Beginners

  • Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

  • HTML
  • HTML Tutorials

  • Command Line
  • Command Line Tutorials

  • How Tos
  • Other Tips and Tricks



  • I love the code... dot com
    2210847

    iLoveTheCode.com

    Create or Put Items into an Array in Perl

    To create or put items into an array in Perl:

    @jiji=("Hi","Hello","Hiya");

    print @jiji;

    Which prints:
    HiHelloHiya

    -We named our array jiji because it's fun to type jiji. (Arrays start with @ unlike scalars which start with $)
    -We stored our three items, separated by commas with each enclosed in quotation marks.
    -We printed our array.


    NOTES: Even though we created this array in a very formal manner. Almost anything can be converted into an array and pieced out using Perl's built-in split function. Just slap an @ in front of something!

    Imagine you have a scalar variable $ko...

    $ko="England wins World Cup.";

    @jiji=split(/ /, $ko);

    print $jiji[1];


    Which Prints:
    wins


    -We created a variable named ko and stored some words there.
    -We used Perl's split function on our variable $ko and stored the pieces into our new array jiji. (We split at the spaces / /)
    -We printed the second piece of @jiji. (Index numbers start at 0, so $jiji[0] would equal England.)


    Copy and Paste Perl Code:

    #!/usr/bin/perl

    print "Content-type:text/html\n\n";

    @jiji=("Hi<br>","Hello<br>","Hiya<br>");

    print @jiji;

    $ko="England wins World Cup.";

    @jiji=split(/ /, $ko);

    print $jiji[1];

    exit;



    Resources:
    Perl:
    Use the Perl PRINT FUNCTION
    Splitting an ARRAY in Perl
    Undefine an Array in Perl
    What's in an Array, Index Numbers
    Finding the Length (Index Numbers) of an Array in Perl

    Javascript:
    Splitting an Array using Javascript





    Previous Article: Undefine an Array in Perl
    Next Article: Add to End of an Array with Push in Perl






    Search iLTC w/ Google




    Recent Articles

  • HTML Font Code
  • Javascript and CSS - Easy Pop Up Help Balloons
  • Use OnMouseOver in Javascript
  • Use onMouseOut in Javascript
  • Use innerHTML to Change Text on a Page
  • Renaming a File with Perl's RENAME Function
  • PRINT to Browser with document.write Command in Javascript
  • Passing an Argument or Variable to a Javascript
  • Opening an Alert Box in Javascript
  • Opening a REMOTE WINDOW in Javascript
  • OPEN and WRITE a Data File in Perl
  • OPEN and READ a Data File in Perl
  • Mimic Typing from a Textfield in a Textarea with Javascript
  • Javascript Reset Form








  • Perl Programming - Javascript Programming - HTML Code - Mac Unix Command Line - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006-2009 iLoveTheCode.com


    Contact Chris | About this Site


    2210059
    Counter by iLoveTheCode.com


    Last Modified: Saturday, 10-Jan-2009 05:40:24 EST



    Hosted as well :)
    Home-brewed logo - 1997