William Paoli <[EMAIL PROTECTED]> wrote:

: What is this doing?

    Very little. See below.

: sub data_file {
:     open FILE, "colon-delimted.txt";

    Always verify I/O operations.

my $file = 'colon-delimted.txt';
open FH, $file or die qq(Cannot open "$file": $!);


:  while ( my $line = <FILE> ) {

    Here we set $line = to each successive line in the file.


:    $line

    Here we assign something else to $line. Clobbering what
was already there.


:  = ($driver,$sponsor,$owner,$chief,$car,$bio,$team)

    This part indicates that you either are not using
'strict' and 'warnings' or that you are deliberately
affecting variables outside this sub's scope.


:   = split /:/, @_;

    Here you are splitting the number of elements
passed to the subroutine. Since the integer does not
have any colons in it, it only populates the first
field ($driver).

:     }
: }

: am I on the right track?

    Probably not. What is the right track?

    The sub is equivalent to this.

sub data_file {

    $driver  = @_;
    $sponsor = undef;
    $owner   = undef;
    $chief   = undef;
    $car     = undef;
    $bio     = undef;
    $team    = undef;

    return 1;
}

    A well-written sub should generally not affect the
external environment. This sub may be affecting the
external variables $driver, $sponsor, $owner, $chief,
$car, $bio, and $team.


: I want to populate this into a hash after splitting it:

    What is "this"?
    Which field is the hash key?
    What is the name of the hash you are trying to
create?
    How is data_file() being called?


    You cannot describe your problem in two questions
and a short sentence. We need more information.

    When debugging a subroutine, we need to know how
you are calling it. What data is going in, what data
is coming out, and how you would like to have any
incoming data processed.

    We are not clairvoyant. You have to tell us (in
words) each detail of your problem for us to help you
find a solution.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to