Hi,

I occasionally have to write Perl scripts that should behave the same on
Unix- and DOS-like Systems. One little problem I encounter there is:

For quick hacks, the "while(<>)" mechanism is very handy, because it
saves a lot of typing. On Unix, I can call a script as a filter, with
filenames or with glob-Patterns without having to worry about the
details - in any case I can just use <> to read the data. On DOS (and
its descendants), this used to be the same - I still have an old binary
of Perl 5.005 lying around, where Perl silently takes over the glob
expansion that on Unix would be done by the shell. Unfortunately, this
obviously is not the case anymore: With more recent Perl versions, when
a script is called with '*.xyz' it will just try to open '*.xyz' and
fail.

The only workaround I know is to do something like:

@ARGV=map { /[\*\?]/ ? glob($_) : $_} @ARGV;
unshift(@ARGV, '-') unless @ARGV;
while (my $fname = shift @ARGV) {
    open(F, $fname)) or die;
    while (defined(my $f=<F>)) {
    ...
    }
}

Is all this really necessary, or is there a better / more elegant way?

Regards,
                            Peter


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to