On Feb 2, Support said:

>foreach $lines(@database_array) {
>  @edit_array = split(/\:/,$lines);
>  push(@member_array,[EMAIL PROTECTED]);
>  $x++;
>}   #loop

First, it doesn't look like you're using 'strict', which means you're not
declaring your variables.  This is probably going to lead to trouble down
the line.

Second, colons don't need backslashing in regexes.

Third, why are you using a counter variable, $x?  I don't think you're
going to need it (even though you use $count and $x later).

Fourth, WHY do your array names end in "_array"?  I think that's a waste
of space and typing.

I'd write your code as:

  for my $line (@database) {
    my @edit = split /:/, $line;
    push @members, [EMAIL PROTECTED];
  }

But I'd probably use [EMAIL PROTECTED] instead of [EMAIL PROTECTED]  This won't work 
in YOUR
code, because in your code, @edit_array isn't lexically scoped, so every
entry in @member_array would be the same array reference.

  for my $line (@database) {
    my @edit = split /:/, $line;
    push @members, [EMAIL PROTECTED];
  }

But I'd go even further, by using the default variable for the loop and
for split():

  for (@database) {
    my @edit = split /:/;
    push @members, [EMAIL PROTECTED];
  }

But I don't even NEED @edit:

  for (@database) {
    push @members, [ split /:/ ];
  }

And by this point, I'd probably just use map() which is like a for loop
with a return value:

  my @members = map [ split /:/ ], @database;

>while($count<$x){
>  $newline = join("\:",$member_array[$count],[EMAIL PROTECTED]);

I don't know WHAT'S going on here.

>  chomp($newline);
>  print DAT "$newline\n";
>  $count++;
>}

I think your join() line should be

  $line = join ":", @{ $members[$count] };

Since $members[$count] is an array reference, we need to DE-reference it
(with the @{ ... } syntax) to get the array out of it.  Also, colons don't
need to be backslashed in strings.

But again, I'd do things differently.  First, instead of a while loop with
a counter, I'd use another for loop.

  for (@members) {
    my $line = join ":", @$_;
    chomp $line;
    print DAT "$line\n";
  }

Notice that instead of @{ $members[$x] }, I'm doing @$_.  This is because
$_ is each element of the array in turn (first it's $members[0], then it's
$members[1], etc.).

And I'm curious why you're chomp()ing the line... just to add a newline at
the end.  I have a feeling you're creating @database like this:

  open FILE, ...;
  @database = <FILE>;
  close FILE;

If so, I'll ignore the whole "why are you slurping a file into an array?"
talk and just tell you that you can chomp the lines there:

  chomp(@database = <FILE>);

And then you don't need to chomp() them later:

  for (@members) {
    my $line = join ":", @$_;
    print DAT "$line\n";
  }

I might even do without $line:

  for (@members) {
    print DAT join(":", @$_), "\n";
  }

Then, since it looks like that, I might use an inverted for loop:

  print DAT join(":", @$_), "\n" for @members;

I request that, when you get your program working, you submit it to this
list for a critique.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
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