Simple Perl problem

Discussion in 'Programming' started by Pureseller, Aug 9, 2007.

  1. #1
    Hello,

    While learning perl., i had a example to do with getopt :

    my sample program is :

    http://rapidshare.com/files/47947512/getopt.pl

    i have came across with the below error :
    Kindly, someone help me to get thru this error if you know !


     
    Pureseller, Aug 9, 2007 IP
  2. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm no perl expert but i would imagine you need a space between the print and the quotes on line 10 of your perl script.
     
    ecentricNick, Aug 9, 2007 IP
  3. Pureseller

    Pureseller Banned

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i tried to give a space before itself.
    but no luck !
    any perl expert here ?
    please help me !
     
    Pureseller, Aug 9, 2007 IP
  4. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It might help if you posted the perl script - the page you post to is just an html page?
     
    ecentricNick, Aug 10, 2007 IP
  5. Pureseller

    Pureseller Banned

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I have uploaded here.
    Once you download it, change the extension to .pl from .txt !

    hope that will help you as well as me !

    Regards !
     

    Attached Files:

    Pureseller, Aug 10, 2007 IP
  6. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ok, i made two changes to make it work on my server...

    I changed the mixed case "If" to "if" on line 9

    and added curly brackets after the condition.

    try this instead...

    
    se Getopt::Std;
    getopts (":S:n:",\%args);
    if (defined $args{s}){
    $string = $args{s};
    }
    if (defined $args{n}) {
    $number = $args{n};
    }
    if (!defined $args{s} or !defined $args{n}){
    print "Usage: Perl $0 -s String -n Number/n";
    exit;
    }
    print "this is a string = $string this is a Number = $number/n";
    
    Code (markup):
    Now, I still get an error which says...

    Can't locate object method "se" via package "Getopt::Std" (perhaps you forgot to load "Getopt::Std"?) at ./getopt.pl line 1.

    But I'm assuming you've got something configured I haven't.
     
    ecentricNick, Aug 10, 2007 IP
  7. Drag Racer

    Drag Racer Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    it should be 'use' not 'se'

    use Getopt::Std;
     
    Drag Racer, Aug 10, 2007 IP
  8. Drag Racer

    Drag Racer Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    of course if you want to use less memory by eliminating the variables and speed it up by eliminating the extra conditionals (if)

    use Getopt::Std;
    getopts (":S:n:",\%args);
    if (defined $args{s} && defined $args{n}){
     print "this is a string = $args{s} this is a Number = $args{n}/n";
    }
    else {
     print "Usage: Perl $0 -s String -n Number/n";
     exit;
    }
    Code (markup):
     
    Drag Racer, Aug 10, 2007 IP
  9. Pureseller

    Pureseller Banned

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    that was easy DRAG RACER, Thanks a lot
    Thanks to you too Ecentrix ! :)
     
    Pureseller, Aug 10, 2007 IP
  10. bscdesign.com

    bscdesign.com Active Member

    Messages:
    681
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #10
    lol. This is an easy fix. at the end of the print statements you have /n";

    You need to replace it with \n";

    Notice the difference in the slashes. If you don't know how to type the correct slash it is SHIFT+BUTTON ABOVE ENTER
     
    bscdesign.com, Aug 11, 2007 IP