For slightly less overhead, you can take advantage of sprintf's error checking.
(shamelessly adapted from a Perl Cookbook recipe)
sub fmt_num2 {
use warnings FATAL => "numeric";
$rv = eval { sprintf("%0.9f",$_[0]) };
return $@ ? $_[0] : $rv;
}
the 'use warnings' elevates the non-numeric...
A different approach, without the regex overhead, is to just index for the necessary character positions.
my $word = 'WORD';
my $len = length($word);
foreach (@mylist) {
print "$_\n" if index($_,'(') < index($_,$word)
and index($_,')') > (index($_,$word) + $len-1);
}
jaa
If it's only a 'once in a while' thing, then I'd say start by checking your cookie generation. That's the most obvious part of the code that had any randomness to it. Sounds like user A is getting assigned user B's cookie.
jaa
The problem with your code is that you are trying to do a string comparison with the numeric operator (==). Your code will work if you change the '==' to 'eq'. See 'Equality Operators' in the perlop perldoc.
if ($file =~ /^\./ or $file eq '') {
next;
}
That said, you shouldn't have...
> Maybe we should setup a school of excellence where we needlessly tune everything to the nth degree!
What I find interesting is that rarely do people posting here complain that their code runs too slow or seems to take forever, only that it doesn't work. when I was weaned on Perl, almost every...
I think the idiosyncratic tips-n-tricks of a programming language are the first to go. Especially if you switch between languages often.
BTW, the algorithmic efficiency of the sort in my previous post should have been Nlog(N) rather than N. (Oh, if only it were log(N) .. Sorting faster than...
This type of sorting is well suited for the Schwartzian transform. In this way, the regex is only run once for each item in the array rather that once for each comparison (N vs log(N))
my @sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1]
or $a->[2] <=> $b->[2] }...
use Mail::Sendmail;
my %mail = (
To => 'webmaster@server.com',
From => 'inquiringmind@host.com',
Message => 'What is the expiry date of your certificate?',
);
sendmail(%mail) or die $Mail::Sendmail::error;
:-)
(But seriously, what kind of certificate via which protocal?)...
It doesn't matter whether the request is done being read, if all you need if the first line then your code is fine. Although, the first line of an HTTP response is usually the official response code, something like 'HTTP/1.1 200 OK'. This all assumes you have a proper http server listening on...
The main problem is that:
'http://www.bright-shadows.net/challenges/programming/get_started/tryout.php'
is not a valid PeerAddr (i.e. a hostname or ip address), even though it may be a valid URL. There's a difference.
You need to connect to the host first, then request the page you want from...
You are free to choose your own poison. But, fair warning to you, the "non-regex" version will bugger any number that has a decimal in it-- 1000.01, 1.101, etc. The regex implementation is also about 2-4 times more effecient (benchmarked).
jaa
It probably has something to do with the way you are defining the check_name sub. My guess is that you have the sub defined something like:
sub check_name () {
# ....
}
# Rather than:
sub check_name {
# ....
}
or have an equivalent sub declaration, which imposes argument prototypes...
It's possible to use require for a dynamically called module, but it requires a modification in the way the module is referred to.
two different ways:
without importing, needs symbolic (soft) references
my $test = "Trig";
require "Math/$test.pm";
print "Math::${test}::tan"->(1);
or...
There's no need to pre-create a file suffix cache. You can use Perl's string increment to create them on the fly. This also removes the extension number limit imposed by the array cache. Additionally, the current line number for a file handle is stored in '$.' so no need to track it manually...
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.