On 12/20/07, banker123 <[EMAIL PROTECTED]> wrote:

> I have two started the first is my attempt to read the file into an
> array, the second is processing each variable.  I am unsure how to
> identify the last variable in a variable length line of data.
>
> open (input, 'c:\organization.txt') or die "Cannot open file: $!";

It's generally good practice to use all caps for filehandle names, or
to use lexical variables. Also, for a number of reasons, it's better
to use forward slashes instead of backslashes in literal filenames. So
I'd probably re-write that code something like this, and change the
rest of the code accordingly:

  open my $input, "c:/organization.txt" or die "Can't open file: $!";

> open ('input', 'c:\organization.txt') or die "Cannot open file: $!";
> open ('output', '>C:/out.txt') or die "Cannot open file: $!";

I'm not sure what you're trying to do here; didn't you already open
your input filehandle? But using strings as filehandle names like that
is discouraged.

>       my
> ($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10,$v11,$v12,$v13,$v14,$v15,$v16,$v17,$v18,$v19,$v20,$v21,$v22,$v23,$v24)
> = split (/,/);

Ouch! Using many numbered variables is a warning sign that a data
structure is needed. In this case, an array could make your life much
simpler. After using split() into an array, the problem of identifying
the last element's index is easy; it's the last valid index of the
array.

    my @v = split /,/, $_;
    my $last_elem_index = $#v;

Does that get you closer to a solution? Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

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


Reply via email to