Samirx K Patel wrote: > > If I want to run a script on any file with a .vhd extension in the > directory, how do I pass *.vhd to the perl script? > > Easy one-line example (Note, I'm running on Windows): Say I want to find the > pattern "COMPONENT" in any file with a .vhd extension: > > perl -lane "if (/COMPONENT/) { printf \"$ARGV $. : $_\n\" }" *.vhd > > gives the error: > Can't open .*vhd: Invalid argument.
All items on the command line are accessible from your Perl program in the @ARGV array. The standard DOS/Windows command interpreters (command.com and cmd.exe) do NOT do wild card expansion, your program has to do it. You should use print instead of printf unless you really need the formatting that printf provides. perl -ne"BEGIN{@ARGV=map glob,@ARGV}/COMPONENT/&&print qq[$ARGV $.: $_];eof&&close ARGV" *.vhd > I need an answer that will work for full-blown scripts, as well as > one-liners. #!/usr/bin/perl -w use strict; @ARGV = map glob, @ARGV; while ( <> ) { print qq[$ARGV $.: $_] if /COMPONENT/; close ARGV if eof; # reset $. } __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]