Cut short the code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karthik2423
    New Member
    • May 2007
    • 8

    Cut short the code

    Hi,
    Here's a code which I need to cut short using file handling... Please hv a look into it..

    [CODE=perl]
    #!/usr/bin/perl
    use strict;

    print "Enter 1 for device1\n";
    print "Enter 2 for device2\n";
    ...
    ....
    ...
    ..
    ..
    print "Enter n for device n \n";
    [/CODE]

    Depending on the user input, I need to run the command -
    nslookup $x where x is the number from 1 to n and $x is a unique value for each device n.

    Could you please tell me how I can implement this?


    Thanks in advance,
    Karthik
    Last edited by miller; Jun 4 '07, 04:48 PM. Reason: Code Tag and ReFormatting
  • jabirahmed
    New Member
    • Jun 2007
    • 5

    #2
    Try using a loop

    [CODE=perl]
    for (my $i = 0; $i < MAX; $i++){
    print "Enter 1 for device1\n";
    my $c = <STDIN>;
    chomp($c);
    &execCMD($c) ;
    }
    [/CODE]
    Last edited by miller; Jun 4 '07, 04:46 PM. Reason: Code Tag and ReFormatting

    Comment

    • miller
      Recognized Expert Top Contributor
      • Oct 2006
      • 1086

      #3
      Greetings Karthik,

      jabirahmed's code is exactly what you need. Or a little simplified.

      [CODE=perl]
      for my $i (1..$n) {
      print "Enter $i for device$i\n";
      }
      [/CODE]

      I suggest that you read a book on beginning perl:



      Chapter 4 covers Loops and Decisions, which would include a discussion of the for loop.

      - Miller

      Comment

      Working...