Total Utter Just Delivered Perl Newbie with a Pignant Question 
Author Message
 Total Utter Just Delivered Perl Newbie with a Pignant Question

Hi

I'm new with Perl, wet behind the ears even,

Can you just call Perl as you would with a a shell script with arguments, if
so how (?) as all the examples I've seen make it far more complicated than a
shell script for accepting command line arguments, dealing with STDIN as you
would with C using ARGV, ARGC. If it's so great why all the overhead as you
don't need in a bash script ??

eg in Bash . . .

#!/bin/sh
# change to home directory
cd $HOME
case $# in
     0) echo " no arguments" ;;
     1) echo "one argument $1";;
     2) echo "two arguments $2";;
     *) echo "{*filter*}!";;
esac



Tue, 25 Oct 2005 01:12:07 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question

Quote:

> Hi

> I'm new with Perl, wet behind the ears even,

> Can you just call Perl as you would with a a shell script with arguments, if
> so how (?) as all the examples I've seen make it far more complicated than a
> shell script for accepting command line arguments, dealing with STDIN as you
> would with C using ARGV, ARGC. If it's so great why all the overhead as you
> don't need in a bash script ??

> eg in Bash . . .

> #!/bin/sh
> # change to home directory
> cd $HOME
> case $# in
>      0) echo " no arguments" ;;
>      1) echo "one argument $1";;
>      2) echo "two arguments $2";;
>      *) echo "{*filter*}!";;
> esac


In contrast to e.g. C-programs, there is no predefined $ARGC, so your
example could (TMTOWTDI) be written as

#! /usr/bin/perl -w
chdir $ENV{HOME};
if ($#ARGV == -1) {
    print "no arguments\n";

Quote:
} elsif ($#ARGV == 0) {

    print "one argument $ARGV[0]\n";
Quote:
} elsif ($#ARGV == 1) {

    print "two arguments $ARGV[1]\n";
Quote:
} else {

    print "{*filter*}!\n";

Quote:
}

(untested!)

Josef
--
Josef M?llers (Pinguinpfleger bei FSC)
        If failure had no penalty success would not be a prize
                                                -- T.  Pratchett



Tue, 25 Oct 2005 13:21:12 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question

Quote:
> Hi

> I'm new with Perl, wet behind the ears even,

> Can you just call Perl as you would with a a shell script with arguments, if
> so how (?) as all the examples I've seen make it far more complicated than a
> shell script for accepting command line arguments, dealing with STDIN as you
> would with C using ARGV, ARGC. If it's so great why all the overhead as you
> don't need in a bash script ??

So?  Perl programming gives you a lot more control over details than
shell scripting does, so there are more details to take care of.

If your problem is better solved with a shell script, use the shell script.

Quote:
> eg in Bash . . .

> #!/bin/sh
> # change to home directory
> cd $HOME
> case $# in
>      0) echo " no arguments" ;;
>      1) echo "one argument $1";;
>      2) echo "two arguments $2";;
>      *) echo "{*filter*}!";;
> esac

Are you asking how to do that in Perl?  Here is one way:

    #!/usr/local/bin/perl
    use strict; use warnings; $| = 1;

    chdir ( $ENV{ HOME});
    my $num =


Anno



Tue, 25 Oct 2005 13:35:27 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question



: > Hi
: >
: > I'm new with Perl, wet behind the ears even,
: >
: > Can you just call Perl as you would with a a shell script with
arguments, if
: > so how (?) as all the examples I've seen make it far more complicated
than a
: > shell script for accepting command line arguments, dealing with STDIN as
you
: > would with C using ARGV, ARGC. If it's so great why all the overhead as
you
: > don't need in a bash script ??
:
: So?  Perl programming gives you a lot more control over details than
: shell scripting does, so there are more details to take care of.
:
: If your problem is better solved with a shell script, use the shell
script.
:
: > eg in Bash . . .
: >
: > #!/bin/sh
: > # change to home directory
: > cd $HOME
: > case $# in
: >      0) echo " no arguments" ;;
: >      1) echo "one argument $1";;
: >      2) echo "two arguments $2";;
: >      *) echo "{*filter*}!";;
: > esac
:
: Are you asking how to do that in Perl?  Here is one way:
:
:     #!/usr/local/bin/perl
:     use strict; use warnings; $| = 1;
:
:     chdir ( $ENV{ HOME});
:     my $num =


:
so 'my' is similar in that it is like arguments to main in C ???

: Anno
:
:



Tue, 25 Oct 2005 01:55:29 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question
Dear Rod -

Quote:

> Can you just call Perl as you would with a a shell script with
> arguments, if so how (?) as all the examples I've seen make it far
> more complicated than a shell script for accepting command line
> arguments, dealing with STDIN as you would with C using ARGV, ARGC

> #!/bin/sh
> # change to home directory
> cd $HOME
> case $# in
>      0) echo " no arguments" ;;
>      1) echo "one argument $1";;
>      2) echo "two arguments $2";;
>      *) echo "{*filter*}!";;
> esac

I don't see that it's "far more complicated".  As with any language it
takes some time to become familiar with the syntax and idioms.

#!/usr/local/bin/perl
# change to home directory
cd $ENV{'HOME'};
if    ( $#ARGV < 0 )  { print " no arguments" ; }
elsif ( $#ARGV == 0 ) { print "one arguments $ARGV[0]\n" ; }
elsif ( $#ARGV == 1 ) { print "two arguments $ARGV[1]\n" ; }
else                  { print "{*filter*}!" ; }

Quote:
> If it's so great why all the overhead as you don't need in a bash
> script ??

Because you it allows you to do more.

     Yours -      Billy

============================================================

                          http://www.*-*-*.com/ :8080      
============================================================

          Lest we forget:

Conversation: A series of digressions.

                - Kevin Montuori



Tue, 25 Oct 2005 14:19:43 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question

Quote:

> I'm new with Perl, wet behind the ears even,

Please check out the Posting Guidelines that are posted here frequently.

Quote:
> Can you just call Perl as you would with a a shell script with arguments,

Yes.

Quote:
> if
> so how (?)

as you would with a a shell script with arguments:

   my_perl_script arg1 arg2

Quote:
> #!/bin/sh
> # change to home directory
> cd $HOME
> case $# in
>      0) echo " no arguments" ;;
>      1) echo "one argument $1";;
>      2) echo "two arguments $2";;
>      *) echo "{*filter*}!";;
> esac

(untested!)

#!/usr/bin/perl
use warnings;
use strict;

chdir;

   { print "no arguments\n" }

   { print "one argument $ARGV[0]\n" }

   { print "one argument $ARGV[1]\n" }
else
   { print "{*filter*}!\n" }

--
    Tad McClellan                          SGML consulting

    Fort Worth, Texas



Tue, 25 Oct 2005 14:18:54 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question

Quote:


> (untested!)

>    { print "one argument $ARGV[1]\n" }

Two.

Pignant; pregnant pig.

Purl Gurl
--
http://www.purlgurl.net



Tue, 25 Oct 2005 15:13:57 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question


: Dear Rod -
:
:
: > Can you just call Perl as you would with a a shell script with
: > arguments, if so how (?) as all the examples I've seen make it far
: > more complicated than a shell script for accepting command line
: > arguments, dealing with STDIN as you would with C using ARGV, ARGC
: >
: > #!/bin/sh
: > # change to home directory
: > cd $HOME
: > case $# in
: >      0) echo " no arguments" ;;
: >      1) echo "one argument $1";;
: >      2) echo "two arguments $2";;
: >      *) echo "{*filter*}!";;
: > esac
:
: I don't see that it's "far more complicated".  As with any language it
: takes some time to become familiar with the syntax and idioms.
:
: #!/usr/local/bin/perl
: # change to home directory
: cd $ENV{'HOME'};
: if    ( $#ARGV < 0 )  { print " no arguments" ; }
: elsif ( $#ARGV == 0 ) { print "one arguments $ARGV[0]\n" ; }
: elsif ( $#ARGV == 1 ) { print "two arguments $ARGV[1]\n" ; }
: else                  { print "{*filter*}!" ; }
:
: > If it's so great why all the overhead as you don't need in a bash
: > script ??
:
: Because you it allows you to do more.
:
very helpful, all the examples I have seen have been STDIN or filehandles.



Tue, 25 Oct 2005 03:24:14 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question

(snipped)

Quote:
> Can you just call Perl as you would with a a shell script with arguments
> case $# in
>      0) echo " no arguments" ;;
>      1) echo "one argument $1";;
>      2) echo "two arguments $2";;
>      *) echo "{*filter*}!";;

#!perl


Purl Gurl
--
"...behind all those DoS attacks, the release of Kevin Mitnick, and Purl Gurl."
   - Chris Nandor, Perl News



Tue, 25 Oct 2005 15:29:21 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question


:
:
:
: > (untested!)
:

: >    { print "one argument $ARGV[1]\n" }
:
: Two.
:
: Pignant; pregnant pig.

my what lovely manners you lack.
:
:
: Purl Gurl
: --
: http://www.purlgurl.net



Tue, 25 Oct 2005 03:44:37 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question


:
: (snipped)
:
: > Can you just call Perl as you would with a a shell script with arguments
:
: > case $# in
: >      0) echo " no arguments" ;;
: >      1) echo "one argument $1";;
: >      2) echo "two arguments $2";;
: >      *) echo "{*filter*}!";;
:
:
: #!perl
:

:
Thanks Troll, but you are the only obnoxious person in this group. A legend
in your own mind perhaps, big fish in a small sea ?
so um . . .
 taa-taa !
Plonk.



Tue, 25 Oct 2005 03:54:38 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question

Quote:


> : Rod wrote three troll articles:

(snipped)

Quote:
> Thanks Troll, but you are the only obnoxious person in this group. A legend
> in your own mind perhaps, big fish in a small sea ?
> so um . . .
>  taa-taa !
> Plonk.

Your deflating masculine ego sounds much like a squealing stuck pig.

Purl Gurl
--
"The name Purl Gurl comes to mind."
 - Takshaka, Perl Monks



Tue, 25 Oct 2005 16:09:15 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question

Quote:



[big snip]

Quote:
> :     my $num =
> :         ( 'no arguments',  'one argument', 'two arguments')[ scalar


> :
> so 'my' is similar in that it is like arguments to main in C ???

Similar to what?  No, my() doesn't declare arguments to the main program.

You'd better start at the beginning.  Get a good tutorial and start reading
instead of jumping in in the middle.

Anno



Tue, 25 Oct 2005 19:16:40 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Quote:
> In contrast to e.g. C-programs, there is no predefined $ARGC, so
your
> example could (TMTOWTDI) be written as

> #! /usr/bin/perl -w
> chdir $ENV{HOME};
> if ($#ARGV == -1) {
>     print "no arguments\n";
> } elsif ($#ARGV == 0) {
>     print "one argument $ARGV[0]\n";
> } elsif ($#ARGV == 1) {
>     print "two arguments $ARGV[1]\n";
> } else {
>     print "{*filter*}!\n";
> }


gives you the number of arguments.  No off-by-one nonsense:


        print "no arguments\n";

        print "one argument\n";

        print "two arguments\n";
    }

- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13

iD8DBQE+vDzIY96i4h5M0egRAoM+AKD99MW8g6Xj+4bK/9V/l8eDMSxDhgCg44hh
vJA4gW9LkAQrS/4k1uk9bHQ=
=ULQ6
-----END PGP SIGNATURE-----



Wed, 26 Oct 2005 00:41:57 GMT  
 Total Utter Just Delivered Perl Newbie with a Pignant Question


:

:
: > : Rod wrote three troll articles:
:
: (snipped)
:
: > Thanks Troll, but you are the only obnoxious person in this group. A
legend
: > in your own mind perhaps, big fish in a small sea ?
: > so um . . .
: >  taa-taa !
: > Plonk.
:
:
: Your deflating masculine ego sounds much like a squealing stuck pig.
:

ho hum, sefl-adulating-lame-flamer bot now on ..
enjoy  the fruit of your labour :-).
:
: Purl Gurl
: --
: "The name Purl Gurl comes to mind."
:  - Takshaka, Perl Monks



Wed, 26 Oct 2005 05:25:56 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. Piping HTML tags (total newbie question)

2. Total Newbie Question

3. Total Newbie Question

4. Utter newbie

5. Newish to perl and a total TK newbie

6. Total Newbie Here!, I need help with system call

7. total newbie

8. Sorry - TOTAL newbie

9. Total Newbie: Forms and accented characters

10. total newbie

11. Perl delivered with HP-UX ??

 

 
Powered by phpBB® Forum Software