On 9/22/2007, Marconi said:
Can anyone offer advice on how to do this?
Paste the following into a new perl script, change the local
variable "$dir" near the top of the file to specify the
directory where you want the files written, then run it from the
command line like this:
perl path/to/your/perl/script < mylist.txt
Here's the script. I think it does everything you requested.
(Note that it includes an extra bit on the end of every file's
base name. Protects from overwrites if you have 2 files that
both start with 'a', for example.)
---------
#!/usr/bin/perl -w
my $holdTerminator = $/;
undef $/;
my $buf = <>;
$/ = $holdTerminator;
my $basefilename = "mylist";
my $dir = "/Users/seth/Desktop/listfiles";
if (-e $dir) {
if ( ! -d $dir ) {
die( "$dir already exists, but is not a directory." );
}
}
else {
mkdir $dir;
}
while ( $buf =~ /([\w\W]{1,4095}(?:\n|\z))/gsm ) {
my $s = $1;
my $fchar = substr( $s, 0, 1 );
my $ext = '-0';
while ( -e "$dir/$basefilename-$fchar$ext.txt" ) {
$ext = substr( $ext, 1 ) + 1;
$ext = "-$ext";
}
open( MYOUTFILE, ">$dir/$basefilename-$fchar$ext.txt" )
or die( "Couldn't open file because $!" );
print MYOUTFILE $s, "\n";
close( MYOUTFILE );
}
--
------------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_script.shtml>
List archives: <http://www.listsearch.com/bbeditscripting.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>