On Wed, 30 May 2001, David Gilden wrote:

> The following seems to never break out of the loop,
> any comments?
> Thanks
>
> Dave
>
> #!/usr/bin/perl -w
>
>
> $data = 'some
> multi line
> string';
>
>
>     while($data){
>
>        push(@everyline, $_);
>
>     }

Yes, it's going to loop infinitely because $data is always true -- it has
a defined value it is holding, so the loop will never end.  You can't loop
through a multiline string that way.  You should use split to break the
string up into a list context and put that into your array:

#might want to use a here doc for complex strings
my $data = 'data
data
data
';

my @lines = split /\n/, $data;

foreach my $line (@lines) {

        print "$line : ";
}

my @everyline = split /\n/, $data;

-- Brett

Brett W. McCoy
Software Engineer
Broadsoft, Inc.
240-364-5225
[EMAIL PROTECTED]

Reply via email to