iLTC Home
Bookmark iLTC!
iLTC Google Boards

Google Groups
Receive The Code in Email!



Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • Perl with cheese...
    123,700

    iLoveTheCode.com
    Perl > Perl Tutorials How To Easy > INCREMENT and DECREMENT a Variable in Perl

    INCREMENT and DECREMENT a Variable in Perl



    You create a variable and name it $i because you hate typing long variable names.

    $i=0;

    We are glossing over where $huhu and @gy come from because this is about INCREMENTING.

    $huhu="London-Paris-Tokyo-";
    @gy=split(/-/, $huhu);

    foreach $gy(@gy) {
    $i++;
    print "$i $gy<br>";
    }

    Which prints:

    1 London
    2 Paris
    3 France


    In plain English:

    $i equals zero to start.
    Each time through the foreach loop $i gets one added to it.

    If we'd have said $i-- we'd have gotten negative numbers printed:

    -1 London
    -2 Paris
    -3 Tokyo


    Start Copy and Paste Perl Code:

    #!/usr/bin/perl

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

    $i=0;

    $huhu="London-Paris-Tokyo-";
    @gy=split(/-/, $huhu);

    foreach $gy(@gy) {
    $i++;
    print "$i $gy<br>";
    }

    exit;


    Perl Increment Code - See in Action (new window)


    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: Write a WHILE LOOP in Perl, Carefully
    Next Article: Use the Perl PRINT FUNCTION





    DojoDojo

    Matthew A. Russell...

    New $26.39

    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.85

    Information Architecture...Information Architecture for the Wor...

    Louis Rosenfeld, P...

    New $26.39

    Learning Web DesignLearning Web Design

    Jennifer Niederst ...

    New $26.99

    Head First HTML with CSS...Head First HTML with CSS & XHTML

    Eric Freeman, Elis...

    New $23.99

    HTML & XHTMLHTML & XHTML

    Chuck Musciano, Bi...

    New $29.99

    HTML, XHTML, and CSS, Si...HTML, XHTML, and CSS, Sixth Edition ...

    Elizabeth Castro

    New $23.09

    Bulletproof Web DesignBulletproof Web Design

    Dan Cederholm

    New $23.99

    CSSCSS

    Eric Meyer

    New $29.69


    Of Interest:
  • What Environmental Variables are Available
  • Check for Existing File in Perl
  • Write a FOR LOOP in Perl
  • To Reverse an Array in Perl
  • Create a Function in Javascript
  • Javascript Status Bar
  • Use onLoad in Body Tag with Javascript
  • Environmental Variables Available in Javascript using Navigator Object
  • HTML Frames
  • Make a New Paragraph Using HTML
  • HTML Codes
  • HTML Status

  • More Articles:
  • Matching at the Beginning and End 2
  • Getting What is Matched in Perl
  • Write a FOR LOOP in Perl
  • Get the Length of a Word or String in Perl
  • onClick Javascript
  • Use onLoad in Body Tag with Javascript
  • Getting Epoch Time in Javascript
  • Reading Cookies using Javascript
  • Environmental Variables Available in Javascript using Navigator Object
  • HTML Superscript Text
  • HTML Underline Text
  • HTML Center
  • HTML Background

  • Search iLTC w/ Google





    Recent Articles

  • Javascript Focus Form Field
  • Javascript Lowercase Text
  • Javascript Uppercase Text
  • Javascript Superscript Text
  • Javascript Subscript Text
  • Make Text Blink Using Javascript
  • Make a String into a Link in Javascript
  • Javascript Italics Text
  • Javascript Bold Text
  • Javascript Redirect
  • HTML Frames
  • HTML Color Chart
  • HTML Link
  • Javascript Status Bar








  • Perl Programming - Javascript Programming - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006 iLoveTheCode.com


    Contact Chris | About this Site


    420,461
    Counter by iLoveTheCode.com


    Last Modified: Friday, 23-Jun-2006 07:23:14 EDT