1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

problems with "for" loop in perl

Discussion in 'Perl' started by newbie_10, Aug 22, 2011.

  1. newbie_10

    newbie_10 New Member

    Joined:
    Jun 6, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    if ($string =~ /(.*?)u(.*)/s)
    {

    my $pre = $1;
    my $post = $2;

    for my $index(0..4)
    {
    print "$pre$index$post\n";
    push(@register_list, "$pre$index$post");
    }

    }

    is there a way to make it print like 0,1,2,3,4 and not just 1,2,3,4??
     
  2. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    Try to change 0 with -1. But Im not 100% suree.
     
  3. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Code:
    [pradeep@dev tmp]# perl -e ' for my $i(0..4) { print "$i\n"; }'
    0
    1
    2
    3
    4
    
     

Share This Page