(tye)Re: unix to windows?
by tye (Sage) on May 31, 2001 at 19:30 UTC
|
Add:
@ARGV= map { glob($_) } @ARGV if $^O =~ /MsWin/i;
near the top of your script for a simple work-around.
You can also recompile Perl such that it does this for you.
-
tye
(but my friends call me "Tye")
| [reply] [d/l] |
Re: unix to windows?
by azatoth (Curate) on May 31, 2001 at 17:40 UTC
|
| [reply] |
|
|
Also look at U/WIN. Available at: http://www.research.att.com/sw/tools/uwin/
Have fun,
Carl Forde
| [reply] |
Re: unix to windows?
by petdance (Parson) on May 31, 2001 at 18:07 UTC
|
Short version: in Unix the shell takes care of the
filename globbing for you. In Windows, your program has
to take care of it manually.
xoxo,
Andy
%_=split/;/,".;;n;u;e;ot;t;her;c; ". # Andy Lester
'Perl ;@; a;a;j;m;er;y;t;p;n;d;s;o;'. # http://petdance.com
"hack";print map delete$_{$_},split//,q< andy@petdance.com >
| [reply] |
Re: unix to windows?
by mpolo (Chaplain) on May 31, 2001 at 18:08 UTC
|
The ActiveState Perl distribution for Windows NT (and 2000) permits you to make a batch file out of a perl script. (pl2bat scriptname). For the wildcards, you'll need to look at the glob function. | [reply] |
Globbing in Windows
by John M. Dlugosz (Monsignor) on Jun 01, 2001 at 18:37 UTC
|
I updated tcgrep with a similar feature. It will expand wildcards into the ARGV array, in a way that works right under the platform, if it detects the need.
do_glob is passed the options hash, so it can check flags for overrides and globbing mode argument switch. Note the DOS-style quoting rules wrapper around the built-in glob abilities. This worked fine when I wrote it, but has a little problem now with the latest ActiveState build (concerning directories, I think) but I could override the rule on the command line so I've not gotten to the bottom of it yet.
—John
our $default_optG= 'none';
###################################
# This function added 19-Feb-2001 by John M. Dlugosz.
# When should this script expand globs (wildcard characters) in the fi
+le name arguments?
# First idea is when the OS (via $^OS) is Windows or other non-Unix sy
+stems. But, what
# if you're running a globbing shell anyway? I need to know the shell
+ that invoked Perl (if any),
# not the OS.
# I abstracted out the logic into this function, so it may easily be u
+pdated or customized.
sub shall_I_glob (%) {
my $opt= shift;
if (exists $opt->{G}) {
return $opt->{G} ne "none";
}
my $shell= $ENV{COMSPEC};
if (defined $shell && $^O =~ /^MS/i) {
$default_optG= 'qDOS';
# if this exists, assume an OS with a DOS lineage.
# List those I know about. Others will add to this list as the
+ need arises.
return 1 if $shell =~ /4nt.exe$/i; # return true for shells
+that don't glob arguments.
return 1 if $shell =~ /4dos.exe$/i;
return 1 if $shell =~ /cmd.exe$/i;
return 1 if $shell =~ /command.com$/i;
return undef if $shell =~ /bash.exe$/i; # return false for
+shells that glob before running program
}
# ... try other ways to get $shell here. ...
return undef; # don't do anything (the behavior we always had).
}
###################################
# This function added 19-Feb-2001 by John M. Dlugosz.
# This will 'glob' the filename arguments, which at the time this is c
+alled, is what
# remains in @ARGV.
# This is abstracted into its own function in case it gets more comple
+x, such as
# special quoting rules.
sub do_glob (%) {
my $opt= shift;
my $globsub= undef;
my $optG= $opt->{G} || $default_optG;
my $quoteflag= ($optG =~ /^q/);
if ($optG =~ /DOS$/) { # Use DosGlob, not core glob
require File::DosGlob;
$globsub= \&File::DosGlob::glob;
}
# could have others (e.g. regex glob, 4DOS-style glob) added HERE.
my @result;
foreach my $fname (@ARGV) {
if ($quoteflag) { # glob() doesn't like the stuff a DOS/Windo
+ws/NT user puts on
# the command line, especially if using command-completion
+ or other tools which
# will always use backslash not giving you the oppertunity
+ to type the forward slash instead.
# This was found to work on both glob() forms and give the
+ expected results.
$fname =~ s/\\/\//g; # changes backslashes to forward sl
+ashes
$fname= qq("$fname"); # put whole thing in quotes
}
push @result, $globsub ? $globsub->($fname) : glob($fname);
}
if ($quoteflag) {
# restore canonical path separator
foreach (@result) { s[/][\\]g };
}
@ARGV= @result;
}
| [reply] [d/l] [select] |
Re: unix to windows?
by Desdinova (Friar) on Jun 01, 2001 at 20:49 UTC
|
Gotta throw in the ob link to the Perl Power Tools page. This is a project to reimplement a lot of the common unix commands as perl.
The Home Page for the project
The unix2dos command
Hope this Helps you out with this and other tools you might need. | [reply] |
Re: unix to windows?
by snafu (Chaplain) on Jun 01, 2001 at 18:22 UTC
|
Flog your management...switch back to Unix. That will solve your problem =P
----------
- Jim | [reply] |
Re: unix to windows?
by Anonymous Monk on Jun 03, 2001 at 03:11 UTC
|
isn't the bash shell available for windows? let them use that. | [reply] |
|
|
package GlobArgv;
use strict;
my $file = ();
my $line = ();
@ARGV = map { glob } @ARGV;
1;
foreach $file(@ARGV) {
my $string;
$/ = "";
foreach ($file) {
open (FILE, $_);
$string = <FILE>;
close FILE;
$string =~ s/\r\n/\n/sig;
$string =~ s/\r/\n/sig;
open (FILE, ">$_");
print FILE $string;
close FILE;
}
rename ($file, "$file.txt") or die "can't rename $file: $!";
print "process completed for: $file \n";
2;
| [reply] [d/l] |
Re: unix to windows?
by dl748 (Initiate) on Jun 02, 2001 at 06:03 UTC
|
if you associate .pl files with perl... you can do that from the command prompt in win2k... | [reply] |
|
|
I don't know about NT5, but in NT4 associating .pl files to perl does not get the arg list passed to perl. I think there is some syntax you can use when you set up the association.
In DOS, IIRC, the numbered variables $1 $2 and so on are the command line args. Note that $0 is the name of the command.
The batch wrappers use this to work. They generally call perl and have it read in and execute $0 with $1 etc as args. Look inside them for help, there may be a general arg list DOS variable, but I don't know what it is..
You may just want to buy/get a unix shell for windows. I use MKS toolkit at work. The main thing I like about it (I almost never use its shell) is that I get many of the unix command I know and love while I am in dos-hell. Just the addition of a decent more is a wonderful thing...
UPDATE: PiEquals3 is quite right about the variables. Use %1, etc. for batch files. I just discovered that %* is all the args. Which language am I using?
REM foo.bat
echo %*
REM End of foo.bat
c:\foo bar baz
bar baz
So, I just tried switching my .pl association to 'c:\perl\bin\perl.exe %0 %*'. It seems fine so far.
TGI says moo
| [reply] [d/l] |
|
|
Hey thanks for the info!! MKS is EXACTLY what I was looking
for! Now I all I have to do is check with managment! So
far it seems the only aspect I need is the korn shell feature
| [reply] |
|
|
|
|
"In DOS, IIRC, the numbered variables $1 $2 and so on are the command line args. Note that $0 is the name of the command."
<NITPICK>
Eh.. The prefix is '%'.
i.e.: %0 %1 %2 etc.
</NITPICK>
...at least in a batch file, which is what we're talking about, right?
--
PiEquals3
"Et tu, obfuscation?"
| [reply] |