Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. justice41

    printing small numbers

    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...
  2. justice41

    regular expressions again

    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
  3. justice41

    mod_perl variable sharing problem

    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
  4. justice41

    help with readdir

    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...
  5. justice41

    sorting in perl

    > 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...
  6. justice41

    sorting in perl

    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...
  7. justice41

    sorting in perl

    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] }...
  8. justice41

    Perl certificate validity check

    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?)...
  9. justice41

    IO::Socket problem

    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...
  10. justice41

    IO::Socket problem

    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...
  11. justice41

    Thousands...

    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
  12. justice41

    User's IP address and location

    a CPAN module does it: http://search.cpan.org/~location/Geo-IP2Location-1.00/lib/Geo/IP2Location.pm jaa
  13. justice41

    eval error: Undefined subroutine &main:: called at eval_test.pl line 5

    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...
  14. justice41

    how to use the value of a scalar as a name for another scalar

    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...
  15. justice41

    Split Large Files in to Several Small Files

    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...
  16. justice41

    Simple substitution

    try using a character class in the substitution instead of '|': s#[/\\]#\\\\#g; jaa
  17. justice41

    SHIFT @ARRAY

    i think you will have to post more of the code, but it sounds like the statement is in a boolean test (either a while() or an if()). If that is the case then you should evaluate whether the expression is defined, as in: while ( defined($prm = shift @parms) ) { Another alternative is to use a...
  18. justice41

    Syntax in perl script to run as unix user

    You need to set the setuid bit of the file permissions of the script. The script must be owned by the user chown user1 myscript.pl and then you set the bit using chmod chmod u+s myscript.pl A user other than the owner of the file must have permission to execute the script chmod a+x...
  19. justice41

    Permissions to commands

    You will probably have to have the script run as suid root or as a uid or gid with enough permission to execute the command you want. This can be a big security hole. jaa
  20. justice41

    problem reading file in while loop

    How are you calling the subroutine? Is $file the name of a file or a filehandle? If its the name of a file then you have to open the file first and loop over the filehandle. jaa

Part and Inventory Search

Back
Top