perl script


Results 1 to 7 of 7

Thread: perl script

  1. #1
    Join Date
    Mar 2005
    Posts
    125

    perl script

    To whom it may concern,

    One of my friends made a perl script for me and I need to know what it does. I would translate it myself but right now one of my other friends is borrowing my o'reilly perl script book. Can someone help me out?

    Here is the script:

    #include<iostream.h>
    #include<stdio.h>
    void main ( )
    {
    int i=0;
    int n;
    int a[10];
    int j;

    cout << "enter number", << i+1 <<" 10 to end ";
    cin >> n;
    }
    for (j =i; j>0; j--)
    cout << a[j] << "\n";

  2. #2
    Join Date
    Jan 2003
    Location
    Oregon
    Posts
    114
    umm sorry to burst your bubble... but it's not perl

    it looks like c/c++, really bad c/c++

    its hard to follow, since it does nothing with the value j, which is never initalized or even set before accessing the array which is a guarantee for out of bounds array accessing

    BUT

    if it was set it looks like it would display one line at a time the top x elements of array a where x is the value that one would input to at the prompt

    EDIT:
    ahh i notice that j is actually set at the beginning of the for loop, but still, the values of the array a[] are not set, which would give you different values each time you ran it
    Last edited by eyceguy; 12-14-2007 at 01:28 PM.
    Laptop: Pentium4 2.8Ghz ; 512Mb Ram ; SimplyMepis 6.0

    AppleGeeks | 8-Bit Theatre

  3. #3
    Join Date
    Nov 2002
    Location
    new jersey
    Posts
    757
    It is C++. Best I can figure, it tries to do this

    #include <iostream.h>
    #include <stdio.h>

    int main ( )
    {
    int i=0;
    int j;

    cout << "enter number: " << 1 <<" 10 to end ";
    cin >> i;

    for (j =i; j>0; j--) cout << "Value " << j << endl;
    }

    Although, I haven`t got a clue, why?

  4. #4
    Join Date
    Feb 2003
    Posts
    11
    You could have copied and pasted the first line on Google or Yahoo and found out what it is (C++). Then peruse each line and figured it out. You know "what is a loop?" etc ...

    addendum
    well you need to type it on a utility (e.g. vi, kate oe nano)
    compile it and test the lines
    use the command line to make and display results
    you can do it
    Last edited by whk; 12-14-2007 at 07:29 PM.

  5. #5
    Join Date
    May 2003
    Location
    San Diego, CA
    Posts
    140
    What were you or your friend trying to do with the code?

    Code:
    #include<iostream.h>
    #include<stdio.h>
    
    void main ( ){
    \\ Declares some integers
    int i=0;
    int n;
    int a[10];
    int j;
    
    \\ Prompts user for a number (1 in this case)
    cout << "enter number", << i+1 <<" 10 to end ";
    \\ Takes a number as input
    cin >> n;
    }
    
    \\ Notice this part is outside of main()
    \\ I'm not even sure this part will run
    \\ If it does, notice that j starts at 0 and proceeds to count down
    \\ As far as I can tell, it'll cycle through all of the negative integers
    \\ and then stop when it cycles through to the largest int
    for (j =i; j>0; j--)
    cout << a[j] << "\n";

  6. #6
    Join Date
    Mar 2005
    Location
    asdhsadgas
    Posts
    197
    your program does not make very much sense to me,but
    here it is translated in perl.
    Code:
    my i,n,j; my @a;
    n=<>;
    print "value $j\n" for $j(reverse 0..$i);
    i'm stupid

  7. #7
    Join Date
    Dec 2007
    Location
    San Marcos, TX
    Posts
    48
    Quote Originally Posted by Polanski
    To whom it may concern,

    One of my friends made a perl script for me and I need to know what it does. I would translate it myself but right now one of my other friends is borrowing my o'reilly perl script book. Can someone help me out?

    Here is the script:

    #include<iostream.h>
    #include<stdio.h>
    void main ( )
    {
    int i=0;
    int n;
    int a[10];
    int j;

    cout << "enter number", << i+1 <<" 10 to end ";
    cin >> n;
    }
    for (j =i; j>0; j--)
    cout << a[j] << "\n";
    OK so this is c++. What this does is it has a user input one number into an array. then outputs the whole array. But this is terrible code. First you need to input all 10 values, or else the program may seg fault when it tries to output the other nine values that weren't inputed. So you would need for the input:

    add:
    for (int k=0; k<10; k++)
    before:
    cin >> n;

    Also outside of main you have the output:

    for (j =i; j>0; j--)
    cout << a[j] << "\n";

    You want to move that before the last } and change j-- to j++

    Also take out the #include <studio.h>

    you are adding an extra header file you do not need.

    I believe someone had the perl script listed above...

    Use that instead... Maybe your friend should not be programming if he believes the above code is perl
    Last edited by whitewater3505; 12-26-2007 at 11:56 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •