in reply to Re: Context of "if" statements?
in thread Context of "if" statements?

You are correct, $infile is a typo.

Is still do not understand why
(my $server, my $dir, my $type) = split if !/^#/
does not work (that is, it splits every line), and
print if !/^#/
does work (it only prints lines not starting with #).

What's the difference?

<-> In general, we find that those who disparage a given operating system, language, or philosophy have never had to use it in practice. <->

Replies are listed 'Best First'.
Re^3: Context of "if" statements?
by tadman (Prior) on Nov 24, 2002 at 04:25 UTC
    Having my in the same context as a trailing if is usually bad form. As far as I can tell, the variables are declared regardless of the outcome of the if and are scoped to the block.

    In plain english, this means that the split is not occuring, but the variables are there, and you are still printing because there is no conditional on the print.

    That's why I suggested using a next call to skip to the next line. If it is a comment, there's no point in calling either split or print, is there?

    Update:
    For additional clarity, here's an example of what's happening:
    while (<INFILE>) { my ($infile, $dir, $type); if (!/^#/) { ($infile, $dir, $type) = split; } print "$infile $dir $type\n"; }