Doug Essinger-Hileman wrote:
I am just learning Perl, and am having a problem with something which seems like it should be so easy. Still . . . . I have read through a couple of books, including _Beginning Perl_ and _Picking Up Perl_, to no avail.

I am trying to read a file, then assign some information within a script. The problem comes in assigning. My file has three lines. The first line contains a list of names seperated by spaces; the next two lines contain numbers:

Doug Sandy Lois
0
1

In order to isolate the problem, I have created a simplified script:

# always always always do these, they will tell you about errors for you :) use strict; use warnings;


#read from file

open (CONTROL1, "<test.cont");

always always test to see if it opened or not: (and don't use double quotes when nothgin is beinf interpolated so Perl doesn't have to check it to see if somethign needs interpolated)


 open CONTROL1, '<test.cont' or die "Could not open test.cont: $!";

@constants = <CONTROL1>;

my @constants = <CONTROL1>;

close (CONTROL1);

You don;t need parens necessarily here:

close CONTROL1;

easier to read IMHO

#parse

$names = @constants[0];

my $names = $constants[0];

IE $ instead of @, strict and warnings would've told you about that I imagine

@group = qw($names);

you;'re adding the literl string $names to @group

my @group = ($names);

or do you mean:

 my @group = split /\s+/, $names;

#print

open (CONTROL2, ">test2.cont");

open CONTROL2, '>test2.cont' or die "Could not open test2.cont: $!";

print CONTROL2 "Names: $names";
print CONTROL2 "Group: @group";

print CONTROL2 "Group: $_\n" for @group;

close (CONTROL2);

close CONTROL2;

HTH :)

Lee.M - JupiterHost.Net

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