$attach_name =~ s/[^\w\s\-\.]/_/; $safe_attach_name = $1;
However, this isn't populating $safe_attach_name with anything. What am I doing wrong?
This is an age old mistake - trying to ban unsafe characters.
Try to think in reverse:
$attach_name = s/[^a-z0-9]/\_/gi;
This changes anything NOT A-Z or 0-9 into _
For example, changing your sed statement -
$_ = '/[^\w\s\-\.]/_/';
s/[^a-z0-9]/\_/gi;
print "$_\n";
__END__
Outputs -
____w_s________
I make NO warranties about filename safeness with regard to existing files...
There are CPAN modules you should research - in the meantime; play with this -
#! /usr/local/bin/perl -w
use strict; use warnings;
# Variables to set - my $path = '/usr/local/apache2/htdocs/blackhole/'; my $ext = '.txt'; # WARNING: Do Not Use HTML! # End of user configurable items...
my ( $sec,
$min,
$hour,
$mday,
$mon,
$year,
$wday) = localtime;my $lt = sprintf("%02d%02d%02d%02d%02d%4d%d",
$sec, $min, $hour, $mday,
++$mon, ($year + 1900), $wday);$lt .= $ext; $path .= $lt; my $slt = scalar localtime;
use 5.004;
use Fcntl qw(:DEFAULT :flock);
sysopen(BLACKHOLE, "$path", O_WRONLY | O_CREAT)
or die "can't create $path: $!";
flock(BLACKHOLE, LOCK_EX)
or die "can't lock $path: $!";
truncate(BLACKHOLE, 0)
or die "can't truncate $path: $!";
print BLACKHOLE <<_EndOfHeaders_; $path
... whatever file contents ...
_EndOfHeaders_
exit;
__END__
-- _Sx_ http://youve-reached-the.endoftheinternet.org/ _____ http://jaxpm.insecurity.org/ http://cis4dl.insecurity.org/
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
