Complete.Org: Mailing Lists: Archives: linux-help: July 2000:
[linux-help] Re: Perl confusion
Home

[linux-help] Re: Perl confusion

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: <linux-help@xxxxxxxxx>
Subject: [linux-help] Re: Perl confusion
From: "Jeremy King" <jmking@xxxxxxxxxxxxxx>
Date: Wed, 19 Jul 2000 13:32:09 -0500
Reply-to: linux-help@xxxxxxxxx

While it would help to see the datafile and the actual error messages, I
was able to (i think) replicate your problem with my own datafile.
Essentially, the code works on my datafile until it reads the last line,
which is blank.

while ($first = <JDATA>) evaluates to true
('\n' != false) as far as perl is concerned, so the loop body tries to
execute one more time.  With no more lines in the datafile, perl gripes
every time you try to chomp() $word and $cheap.
Try something like:

while (($first = <JDATA>) && ($first ne '\n'))

But I'm not seeing any problem with the  way that the subroutine
arguments are gettting passed--if the initial loop exits at the right
time, valid values should be passed using the code below.

Jeremy King

----- Original Message -----
From: Lrs v.d.Ast <mrprenzl@xxxxxxxxxx>
To: <linux-help@xxxxxxxxx>
Sent: Monday, July 17, 2000 11:58 PM
Subject: [linux-help] Perl confusion


> Please take a look at this Perl code:
>
> --------------------
> ....
> open(JDATA, "junk.data") || die "can't open junk.data : $!";
> while ($first = <JDATA>) {
>     chomp($first);
>     $word = <JDATA>;
>     chomp($word);
>     $cheap = <JDATA>;
>     chomp($cheap);
>     test_word($first, $word, $cheap);
> }
> close (JDATA) || die "can't close junk.data: $!";
>
> sub test_word {
>     my($firstname, $lastname, $cheapgift);
>     ($firstname, $lastname, $cheapgift) = @_;
>     open(JUNKMAIL, "junkmail") || die "can't open junkmail : $!";
> ...
> --------------------
>
> For some reason the variables are not getting passed to the
> subroutine; they're claiming to not be initialized. I haven't touched
> Perl in over a year and am a bit rusty....
>
> -- This is the linux-help@xxxxxxxxx list.  To unsubscribe,
> visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi
>
>


-- This is the linux-help@xxxxxxxxx list.  To unsubscribe,
visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi


[Prev in Thread] Current Thread [Next in Thread]