in reply to Warning counter

You almost had it... You just can't increment inside quotes like that. But, warn takes a list just like print does.

open ( F, $filename ) or warn "Cannot open $filename (", $counter++, " +): $!\n";

If you want, you can use a do block to do more complex things if the open fails.

open ( F, $filename ) or do { $counter++; warn "Cannot open $filename ($counter): $!\n"; # And whatever else you want... };
-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Warning counter
by Thelonius (Priest) on Jul 01, 2003 at 18:08 UTC
    Warn takes a list! Heck, die takes a list, too! Has this always been so? All this time I've been using . to concat.

    Where did I get the idea that it had to be one string?

    Not that it matters a whole lot, but it's just slightly nicer to use commas.

      Has this always been so?
      Indeed it has. If you look at the top of the warn and die docs you'll see the prototype func LIST meaning it takes a list. Although this isn't terrifically relevant to the output as the list is concatenated into a single string and the same behaviour goes for the arguments to the __WARN__ and __DIE__ signal handlers. So it's really just for your convenience, such is perl's way :)
      HTH

      _________
      broquaint

Re: Re: Warning counter
by Anonymous Monk on Jul 01, 2003 at 17:36 UTC
    thank you to both of you.