At 07:47 PM 5/22/01 -0400, David Gilden wrote:
>As an exercise here I want to play with this for a few minutes,
>and have a few basic questions
>
>#!/usr/bin/perl
>
># First question  do I use
># ( .... )  OR { ... }

In the below, either, they are just delimiters.  However, given what I am 
intuiting your level of expertise to be, I recommend you stick with () for 
qw everywhere for now.  And also that you make sure you know that

@lines = ("dave", "john", "mike", "drew");

does the same thing and that the thing on the right is a list.

>@lines = qq{dave john mike drew};
># First error, should be qw( ... )

Correct.

># qq is garbage, right?

No, it's like saying

@lines = "dave john mike drew";

which puts the one element in @lines.

># is the  ','  correct in my($a,$b) can you use a space my($a $b @c)

No.

>my (%sortKeys,$i);
>
>
>foreach ( @lines ) {
>     print"$_$i\n";
>
>     my $sortKey = $i++; # do something to create the sort key,
>                       # using %idToName to map the ID to the name
>     $sortKeys{$_} = $sortKey;

You have no variable $sortKey.

>    }
>
># Then create a sub to pass to sort:
>
>print "@lines $i\n";
>
># Could you elaborate on this
># $a $b are not passed any values -- don't understand
>
>sub bySortKey {
>     $sortKey{$a} cmp $sortKey{$b}
>}
>
>  print &bySortKey;

Nope, bySortKey is a comparison subroutine designed to be used for a sort 
operation, but there isn't one here.

>exit(0);  # If script executes successfully do you  exit(1)  OR  exit(0);

exit(0) for success, but it's not necessary; I only call exit if I want to 
supply a non-zero value.

You need to start with some more basic tutorials.  I recommend you get 
"Learning Perl," Second Edition, by Schwartz et al, from O'Reilly & Associates.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com

Reply via email to