manan.patel has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, How i can use getopt in my logic??
#!/usr/bin/perl use strict; use warning; $abc = $ARGV[0] ; $def = $ARGV[1] ; open (abc,"$abc") ; open (def, "$def"); while (<abc>){ if ($flag eq 1 ) { push (@abc ,$_); $flag =0; } if (/123/ ) { #$_ =~ s/^\s+// ; push (@abc ,$_); if (/\\/){ $flag = 1; } } } while (<def>){ if ($flag eq 1 ) { push (@def ,$_); $flag =0; } if (/123/ ) { push (@def ,$_); if (/\\/){ $flag = 1; } } } foreach $abc (@abc ) { foreach $def (@def) { if ($abc eq $def) { $flag1 =1; break } } if ($flag1 eq 0){ print $abc; } $flag1 =0; }
please help me for these how i use these module? Thanks !

Replies are listed 'Best First'.
Re: How i can use getopt in my script?
by kcott (Archbishop) on Apr 25, 2014 at 07:38 UTC

    G'day manan.patel,

    Welcome to the monastery.

    I can see at a glance that the code you've posted won't compile. This means I don't know what real code you're running. I won't be commenting further on what you have here.

    "Hello all, How i can use getopt in my logic??"

    There's well-documented, builtin modules to do this. I prefer Getopt::Long. There's also Getopt::Std.

    -- Ken

Re: How i can use getopt in my script?
by choroba (Cardinal) on Apr 25, 2014 at 07:43 UTC
    What is your logic? The script doesn't even compile.

    Some hints:

    • It's warnings, not warning.
    • Using strict is a good practice. It means more than just putting use strict at the top of your code. Where do you declare your variables?
    • break is used to leave a given block. You need last to leave a for loop.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: How i can use getopt in my script?
by karlgoethebier (Abbot) on Apr 25, 2014 at 09:12 UTC

    Take a look at Getopt::Long and Pod::Usage.

    I do it like this:

    Update: Bad copy & paste. Added handling of help option...

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Re: How i can use getopt in my script?
by Anonymous Monk on Apr 25, 2014 at 07:39 UTC

    Hello all, How i can use getopt in my logic??

    That is the part you're supposed to figure out on your own ... what do you want out of getopt?