# Assumptions:
# Each 'fielda' value appears at most ONCE in the master
# file and ONCE in the log file. You may want to add
# checks to this program to ensure that these assumptions
# are true.
#
# The ordering of the master file will be mixed up
# by the hash. This is assumed to be...
I think your code nesting is a bit goofed up.
By the time you get to your if statement $username
has the first line of the last stats.cgi file in it.
You need something like this I think...
opendir(DIR, "$basedir");
@members = readdir (DIR);
closedir(DIR);
$result =...
Another way to do this is to use embedded pattern-match operators (see man perlre). These work by adding a string with the pattern match parameters before the regular expression. For example (building on your code):
# $case will contain embedded pattern-match operator
$case = "(?i)"...
I think your routine will work and in a time acceptable to you.
However using a hash would be more efficient.
Your program is executing grep on your songlist array once for each playlist entry.
Try this algorithm:
- Initialize hash using .mp3 filenames as keys
foreach $songname (@mp3s) {...
print file "blah\n";
foreach (@file) { print file "@file\n"; }
If @file is an array of 10,000 elements, your code will write out the entire array 10,000 times.
I think your second line should be either
foreach (@file) {print file "$_\n"; }
or
print file @file...
I've done some testing and it looks like like I was completely wrong about returning hashes. My 'solution' would work, but only as well as your original code. I think the first problem pointed out in hmerrill's post is probably your problem. If you want to call a sub that is declared later in...
You can't return a hash from a function like that. You need to use references or return the hash as an array. The returned array is assigned into the hash with the even numbered elements (0, 2, 4, ...) being the keys and the odd elements as the values (element 1 is the value for the key in...
hmerrill's '\' escape works with a double-quoted string.
You don't need to escape a '$' inside a single-quoted string.
print '$1,000';
print "\n";
print "\$1,000";
print "\n";
When a browser renders HTML it ignores things like newlines. What you need is some <BR> to tell the browser to start a new line.
print "$FORM_DATA{'personname'}<BR>\n";
print "$FORM_DATA{'address'}<BR>\n";
print "$FORM_DATA{'phone1'}<BR>\n";
print...
You'd need to use cmp instead of <=> for the parts of the split that you want sorted alphabetically:
{(my $a1, $a2) = split(/~/, $a); (my $b1, $b2) = split(/~/, $b); $a1 <=> $b1 || $a2 cmp $b2}
That code is pretty cool. <=> and cmp evaluate to 0 when the values are equal, so the second...
You just need to split the key and do a numeric sort on the first part:
%h = (
"2~afga~X" => "b",
"12~ands~L" => "l",
"1~ijdf~N" => "a",
"3~FDSAF~V" => "c",
"7~Udsd~U" => "g"...
You could use map or grep, but I'm not sure that would be any faster:
my $total_size = 0;
map {$total_size += $_} @array;
or
my $total_size = 0;
grep {$total_size += $_} @array;
If you have samples if the .EXE files you are looking for then you could try these ideas:
User has renamed file, but it is still an .exe:
- Look for .exe files of the same size.
- Run a checksum or MD5 digest on the .exe files and look for matches.
User may transform the file to hide it...
Either of these would do it. $string is the string you are testing...
$string =~ /^a/ # regular expression
substr($string, 0, 1) eq 'a' # substring containing first character
The first idea that came to mind and is probably
really inefficient:
sub permute_and_print {
my $pre = shift;
my @p = @_;
if ($#p >= 0) {
foreach $i (0..$#p) {
my @newp = @p;
my $newpre = $pre . " " . splice(@newp, $i, 1);
permute_and_print($newpre, @newp);
}
}
else...
It looks like find is making up a complete list of directories before it starts executing your sub. I can't really see a way around that. On the other hand, you don't really need to use find to get the desired result:
sub dir_dash_to_underscore {
my $dir = shift;
# find subdirectories of...
Now we are in trouble. I'm the forum's 'Top Expert' and I've never even written anything in Ruby. Maybe your post on the newsgroup will attract some more knowledgable posters?
8-)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.