[sword-devel] Using Perl script usfm2osos.pl in Windows?
DM Smith
dmsmith at crosswire.org
Mon Apr 11 12:11:29 MST 2011
On 04/11/2011 02:11 PM, David Haslam wrote:
> My expectations are simple enough...
>
> I'd like to be able to use usfm2osis.pl with Windows filespec wildcards.
> e.g. *.SFM, as the last command line parameter ("like it says on the tin").
<snip>
>
> Is that not something that a good Perl programmer can add fairly simply?
The request is that the file globbing be done within the program rather
than at the command line. Or to allow for both.
There are various perl modules that allow for this. These probably are
not part of every distribution, so the program would need to
conditionally include them if the platform is windows and if not there,
complain (i.e. tell the user which module to use) and fall back to the
current behavior.
This would be something like:
(from: http://www.perlmonks.org/?node_id=781801 )
# This BEGIN block avoids including File::DosGlob::Param for non-windows
systems BEGIN { if ( $^O =~ /win/i ) { require File::DosGlob::Param;
import File::DosGlob::Param qw( dosglob ); } }
# convert filename wildcards to actual filenames if ( $^O =~ /win/i ) #
only if DOS { if ( exists( $INC{'File/DosGlob/Param.pm'} ) ) # only if
loaded { dosglob( "Array_Ref" => \@ARGV, "Remove_Empty_Matches" => 1,
"Warn_On_Empty_Matches" => 1 ); } END { if ( ( $^O =~ /win/i ) and not
exists( $INC{'File/DosGlob/Param.pm'} ) ) { warn "Consider installing
module File::DosGlob::Param...\n"; } } }
Alternatively, one could modify the program to take a directory argument
instead of a file list.
So if the argument is a directory it would look for all sfm files in there.
if (-d $ARGV[i]) {
$dir = $ARGV[i];
| @files =<$dir/*.sfm>;
|| foreach $file (@files) {
print $file . "\n";
}
}
|
It might be reasonable to take a look at argv and do the following:
if ($ARGV[$i] ~= m/\*/) {
@files = <$ARGV[$i]>;
}
Hopefully this is helpful to one that has time to actually work on it.
In a Un*x environment one can test this last approaches by putting
single quotes around the argument as in:
prog.pl 'Bibles/*.sfm'
In Him,
DM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.crosswire.org/pipermail/sword-devel/attachments/20110411/728ec9b9/attachment.html>
More information about the sword-devel
mailing list