[24889] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7141 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 15 00:06:39 2004

Date: Tue, 14 Sep 2004 21:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 14 Sep 2004     Volume: 10 Number: 7141

Today's topics:
    Re: " (Tony)
    Re: $| (undocumented) magic? <spamtrap@dot-app.org>
    Re: $| (undocumented) magic? (Anno Siegel)
    Re: $| (undocumented) magic? <miknrene@drizzle.com>
        a splice question (justme)
    Re: Best place to learn perl? <emschwar@pobox.com>
    Re: Best place to learn perl? <zebee@zip.com.au>
        die question <nospam@nospam.com>
    Re: die question <noreply@gunnar.cc>
    Re: die question <spamtrap@dot-app.org>
        File::Tail Suggestions? (Michael)
    Re: Help with globbing <someone@example.com>
    Re: hv_iterinit has side effects - who cares about PL t (Ozgun Erdogan)
    Re: move 7500 files to various directories <abigail@abigail.nl>
    Re: move 7500 files to various directories <spamtrap@dot-app.org>
    Re: move 7500 files to various directories <abigail@abigail.nl>
    Re: preserving back references (ie $1, $2...) <someone@example.com>
        rand() question <nospam@nospam.com>
    Re: rand() question <sholden@flexal.cs.usyd.edu.au>
    Re: rand() question <mritty@gmail.com>
    Re: rand() question <mritty@gmail.com>
    Re: rand() question <usenet@MarcDashevsky.com>
    Re: rand() question <nospam@nospam.com>
    Re: rand() question <spamtrap@dot-app.org>
    Re: Running as a Service <lv@aol.com>
    Re: Running as a Service <ceo@nospam.on.net>
    Re: Xah Lee's Unixism <gregm-news@toadmail.com>
    Re: Xah Lee's Unixism <boutelbNOSPAM@acm.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 14 Sep 2004 20:12:38 -0700
From: aemee@hotmail.com (Tony)
Subject: Re: "
Message-Id: <8b060d80.0409141912.7c128334@posting.google.com>

"Tintin" <tintin@invalid.invalid> wrote in message news:<2ql693F10rn12U1@uni-berlin.de>...
> "Tony" <aemee@hotmail.com> wrote in message
> news:8b060d80.0409122320.1d36fc76@posting.google.com...
> [did your finger slip when writing the subject line?]
> 
> 
> > Whenever I run the system command in perl and try to make sure it runs
> > sucessfully otherwise do something else, even for the most basic
> > system commands, I get "Inappropriate ioctl for device"
> >
> > For example, the code:
> >
> > $testdate = system("date") or die "can't run /usr/bin/date: $!";
> > print "$testdate";
> >
> > returns:
> >
> > Mon Sep 13 17:01:38 UTC 2004
> > can't run /usr/bin/date: Inappropriate ioctl for device at test.pl
> > line 7, <STDIN> line 4.
> >
> > So it runs the command successfully, but dies anyway.  Yes I know
> > there's another way to do date, this is just an example of the problem
> > I have.  I need to use the system() command for other things, but no
> > matter what command I do I get the above.  I have tried
> > $varname=system(command) and then testing $varname, but that doesn't
> > return anything.
> >
> > Can anyone help?  I don't want to use another module, I'm sure I must
> > be missing something here.  Thanks in advance!
> 
> Seriously, where did you learn to use system?  Did you read the
> documentation for it, or did you see an example somewhere.  If you saw an
> example, it was obviously a bad example.

Sorry guys - finger did slip on the mouse and submitted without a
subject!  Thanks for your help, I worked it out after all, just by
testing the contents of a variable which I stored the outcome of the
system command.  I know there's probably heaps of other ways to do the
same thing!  It must just have been a bad example I was trying to use
from some website - I don't know too much about perl yet, I'm just
learning it really.  Got the o'reilly book on hand now tho.

Tony


------------------------------

Date: Tue, 14 Sep 2004 18:43:03 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: $| (undocumented) magic?
Message-Id: <wZqdnX08-qVl7trcRVn-tQ@adelphia.com>

Michele Dondi wrote:

> You may think what you want, but IMHO spending some time on JAPHs,
> golf et similia is an aid to improve one's programming skills also in
> "productive" code.

Yeah, but what you practice is what you do by habit later. Do you 
*really* want JAPH-style code to appear in production scripts?

Also, JAPHs as sigs tend to give a bad impression of the language to 
those who've never seen any other Perl. They promote the idea of an 
insular community that delights in writing obscure code that's difficult 
for newbies and outsiders to grok.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


------------------------------

Date: 14 Sep 2004 23:10:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: $| (undocumented) magic?
Message-Id: <ci7tq1$qnu$1@mamenchi.zrz.TU-Berlin.DE>

Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMMXXXII
> September MCMXCIII in <URL:news:ci73es$b63$1@mamenchi.zrz.TU-Berlin.DE>:
> ..  J. Romano <jl_post@hotmail.com> wrote in comp.lang.perl.misc:
> .. > 
> .. >    Forgive me for bringing this up one more time, Michele.  I've been
> .. > thinking about this, and it seems to me that $| may have been
> .. > implemented to return 1 (if true) in order to behave like a boolean
> .. > variable.
> ..  
> ..  Well, it *is* a boolean variable.  The state of a filehandle is either
> ..  auto-flushing or not, so it wouldn't make much sense to have $| return
> ..  values other that 0 and 1.
> 
> 
> Well, $* is also a boolean variable - but you can assign (almost) anything
> to it. $^W acts more like $| though.

Yikes, I had blissfully forgotten about $*.  It even respects an overloaded
boolean -- not something I'd expect $| or $^W to do.  That's one more
inconsistency in Perl, though rarely noticed.

Anno


------------------------------

Date: Tue, 14 Sep 2004 16:32:12 -0700
From: Michael Slass <miknrene@drizzle.com>
Subject: Re: $| (undocumented) magic?
Message-Id: <m31xh48m0z.fsf@eric.rossnet.com>

Sherm Pendley <spamtrap@dot-app.org> writes:

>Also, JAPHs as sigs tend to give a bad impression of the language to those
>who've never seen any other Perl. They promote the idea of an insular
>community that delights in writing obscure code that's difficult for
>newbies and outsiders to grok.
>

Isn't that the whole point of a JAPH --- to show how clever the owner
is at writing obscure perl --- and for the puzzle-solving amusement
of the rest of us, figuring out how/why a particular JAPH works?
-- 
Mike Slass


------------------------------

Date: 14 Sep 2004 20:48:29 -0700
From: eight02645999@yahoo.com (justme)
Subject: a splice question
Message-Id: <c0837966.0409141948.204f57d2@posting.google.com>

hi

i found in the newsgroup something like this

open(FILE, "file.txt") or die "Cannot open file.txt";
print splice @{[<FILE>]}, -10;


supposed to be an implementation of "tail" in perl. The first arg of
splice is supposed to be an array, and i don't know how to interpret
@{[<FILE>]}. Can anyone help to interpret ? thanks


------------------------------

Date: Tue, 14 Sep 2004 18:44:31 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Best place to learn perl?
Message-Id: <etowtywgy34.fsf@wilson.emschwar>

none@anytime.net (ft4bredn) writes:
> WOW! I have the "Perl CBT?" thread, and that explanation is what I 
> was looking for. I actually understood the way you broke that 
> down... Do you know of any books or whatever that break things down 
> like that? Expert explanation man!!

Well, thanks, but please next time cite enough that I can figure out
it was me you were responding to.  Luckily, my prevous post was still
on the newwsspool, but that's not always going to happen.

No, I don't know of any books that break things down that way; I
deliberately took very small baby steps a book author is not likely to
be allowed the luxury to do.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


------------------------------

Date: Wed, 15 Sep 2004 01:15:35 GMT
From: Zebee Johnstone <zebee@zip.com.au>
Subject: Re: Best place to learn perl?
Message-Id: <slrnckf5id.eqd.zebee@zeus.zipworld.com.au>

In comp.lang.perl.misc on Tue, 14 Sep 2004 18:44:31 -0600
Eric Schwartz <emschwar@pobox.com> wrote:
> 
> No, I don't know of any books that break things down that way; I
> deliberately took very small baby steps a book author is not likely to
> be allowed the luxury to do.

And most books start at the other end - building up the expression, not
breaking it down.

I admit that a "how to parse the stuff you see on comp.lang.perl.misc"
would be a very nice thing to have!  I see many constructs here using
map and references that confuse me, but are clearly situation normal to
the poster.

Sometimes I take the time to break it down and fiddle to see what's
going on , but a lot of the time i've no idea what the poster is trying
to do, it's been way too compacted for me.  

Zebee


------------------------------

Date: Tue, 14 Sep 2004 18:27:49 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: die question
Message-Id: <1095200905.276966@nntp.acecape.com>

i want to turn this line

open MAIL, "| /usr/sbin/sendmail -t" || die "Could not open sendmail: $!";


into something that goes like

some variable = open MAIL, "| /usr/sbin/sendmail -t";
if (!some variable)

how do i?  am too new at perl




------------------------------

Date: Tue, 14 Sep 2004 22:42:45 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: die question
Message-Id: <FtK1d.3221$d5.24788@newsb.telia.net>

daniel kaplan wrote:
> i want to turn this line
> 
> open MAIL, "| /usr/sbin/sendmail -t" || die "Could not open sendmail: $!";
> 
> into something that goes like
> 
> some variable = open MAIL, "| /usr/sbin/sendmail -t";
> if (!some variable)
> 
> how do i?

You do just that. To get a better understanding of what it means, you 
can for instance find out what the open() function returns by looking 
it up in the docs.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Tue, 14 Sep 2004 18:54:27 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: die question
Message-Id: <eOGdnci82fs569rcRVn-hA@adelphia.com>

daniel kaplan wrote:

> i want to turn this line
> 
> open MAIL, "| /usr/sbin/sendmail -t" || die "Could not open sendmail: $!";
> 
> 
> into something that goes like
> 
> some variable = open MAIL, "| /usr/sbin/sendmail -t";
> if (!some variable)
> 
> how do i?  am too new at perl

What have you tried? As documented, open() returns undef on failure and 
a non-zero value on success, so it should work just about how you've 
written it:

my $some_variable = open MAIL, '| /usr/sbin/sendmail -t';
if (!$some_variable) {
	...
}

That's if you *really* want to store the result of the open() for later. 
If all you want is to execute a block of code when it fails, instead of 
just a die(), you could do this:

unless (open MAIL, '| /usr/sbin/sendmail -t') {
	...
}

By the way, you shouldn't be piping directly to sendmail - there are 
CPAN modules that are simpler, and don't rely on the presence of a 
specific mailer.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


------------------------------

Date: 14 Sep 2004 15:28:36 -0700
From: michaeln@twentyten.org (Michael)
Subject: File::Tail Suggestions?
Message-Id: <6e072929.0409141428.66699bf@posting.google.com>

I'm analyzing a set of log files, but the files are rotated once they
reach a certain size:

Name format:
access_log_YYYYMMDDHHMM.log

e.g.
access_log_200409120143.log

So what I want the script to do is to read the log, but once it stops
getting data, to re-scan for the newest file.  Is there a
value/trigger in
File::Tail that I can look for?  If not, what would be a good way to
do this?


Michael


------------------------------

Date: Tue, 14 Sep 2004 23:55:40 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help with globbing
Message-Id: <0yL1d.20346$KU5.9553@edtnps89>

Mr. Land wrote:
> 
> Actually, I have read the docs you've mentioned.  Right now I have
> something that looks like:
> 
> $baseString = "Something with spaces in it";
> opendir(DIR, ".");
> @fileList = grep { /$baseString.*[gG].*4$/ } readdir(DIR);
> closedir(DIR);
> 
> ($baseString isn't hard-coded like this, it's being loaded with unique
> basenames.)
> 
> ...this seems to work OK, until my $baseString variable gets filled
> with something like:
>                    "It's a beautiful day"
> 
> Then things go awry.  Could it be the single apostrophe?  Should I be
> quoting $baseString when I use it in grep's regular expression?

Yes you should.

my @fileList = grep /\Q$baseString\E.*[gG].*4$/, readdir DIR;


John
-- 
use Perl;
program
fulfillment


------------------------------

Date: 14 Sep 2004 18:58:05 -0700
From: ozgune@gmail.com (Ozgun Erdogan)
Subject: Re: hv_iterinit has side effects - who cares about PL theory
Message-Id: <48b43181.0409141758.63b388c9@posting.google.com>

> > 
> > It may be well known by folks who tried to write OS or DB code in
> > Perl. I don't think other users of Perl are really aware of the
> > implications of this 'feature'.
> 
> It's reasonably clearly laid out in the perldocs on 'each':
> 
> I would at least expect people to read it when they encounter problems
> with iterations over hashes.

I'm sure this property is very well documented. I didn't say otherwise
in this forum. However, the subject says, "who cares about PL
theory?". This feature, from my perspective, is not a good design
choice. For two reasons:
 i ) Perl is a very widely used programming language.
 ii ) Hash is a primitive data structure in Perl.
The fact that it's documented doesn't change the design decision. On
the other hand, I must admit that I was wrong in stating that this is
a bug (as it's documented). I'm going to state it's a "gotcha".

Besides, neither did I say that people don't know/read about this
'feature'. I said,

> I don't think other users of Perl are really aware of the
> implications of this 'feature'.

At the beginning of this post, you knew that a Perl hash structure
contains its iterator in it. But you didn't know that Perl has to lock
down the whole data structure (with a write lock of some sort), even
if you are doing a hash read/lookup (two prev. posts). Which means,
you weren't really aware of the implications of this 'feature'.


------------------------------

Date: 14 Sep 2004 22:12:31 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: move 7500 files to various directories
Message-Id: <slrncker6f.qm8.abigail@alexandra.abigail.nl>

Greg DePasse (greg.depasse@gmail.com) wrote on MMMMXXXII September
MCMXCIII in <URL:news:a7927fe3.0409140723.3d6f8a6@posting.google.com>:
:}  Let me say up front that this is my first software writing experience.
:}   As of a week ago, I had no knowledge of perl or any other language. 
:}  Over the past weekend, I've done a ton of searching and reading.  I
:}  believe my problem is simple, but the solution isn't quite as easy for
:}  me to write.
:}  
:}  My problem:
:}  
:}  I have 7500 pictures in a directory that need to move to roughly 40
:}  different directories.  I have a text file that lists the names of
:}  7500 files (digital pictures) and the corresponding directory they
:}  need to be moved to.  All the files are currently in a single
:}  directory, c:\photos. The filenames do not contain spaces, but the
:}  directory names do.  I'm also working in windows XP with activestate
:}  installed. If needed I could transfer everything to a linux machine.
:}  
:}  Sample from album.txt:
:}  picture1.jpg c:\album\2002-12 christmas at home
:}  picture2.jpg c:\album\2002-07 july 4th in DC


Why bother with Perl when you can do it in a shell one-liner?

   $ while read $from $dir $to; do mv $from $dir\\$to.jpg; done < album.txt



Abigail
-- 
END   {print "Hacker\n"}
BEGIN {print "Just "   }
CHECK {print "another "}
INIT  {print "Perl "   }


------------------------------

Date: Tue, 14 Sep 2004 18:44:39 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: move 7500 files to various directories
Message-Id: <wZqdnXw8-qXK6drcRVn-tQ@adelphia.com>

Abigail wrote:

> Greg DePasse (greg.depasse@gmail.com) wrote on MMMMXXXII September
> MCMXCIII in <URL:news:a7927fe3.0409140723.3d6f8a6@posting.google.com>:
> :}  Sample from album.txt:
> :}  picture1.jpg c:\album\2002-12 christmas at home
> :}  picture2.jpg c:\album\2002-07 july 4th in DC
> 
> 
> Why bother with Perl when you can do it in a shell one-liner?

Did you see the "C:\"? He's probably using a dain bramaged shell.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


------------------------------

Date: 14 Sep 2004 23:37:12 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: move 7500 files to various directories
Message-Id: <slrnckf058.qm8.abigail@alexandra.abigail.nl>

Sherm Pendley (spamtrap@dot-app.org) wrote on MMMMXXXII September
MCMXCIII in <URL:news:wZqdnXw8-qXK6drcRVn-tQ@adelphia.com>:
~~  Abigail wrote:
~~  
~~ > Greg DePasse (greg.depasse@gmail.com) wrote on MMMMXXXII September
~~ > MCMXCIII in <URL:news:a7927fe3.0409140723.3d6f8a6@posting.google.com>:
~~ > :}  Sample from album.txt:
~~ > :}  picture1.jpg c:\album\2002-12 christmas at home
~~ > :}  picture2.jpg c:\album\2002-07 july 4th in DC
~~ > 
~~ > 
~~ > Why bother with Perl when you can do it in a shell one-liner?
~~  
~~  Did you see the "C:\"? He's probably using a dain bramaged shell.


Bash runs fine on a Windows platform. Running Windows is no excuse
for lacking the standard Unix tools. Besides, he was saying he do 
the work from Linux as well.


Abigail
-- 
:$:=~s:$":Just$&another$&:;$:=~s:
:Perl$"Hacker$&:;chop$:;print$:#:


------------------------------

Date: Wed, 15 Sep 2004 00:34:57 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: preserving back references (ie $1, $2...)
Message-Id: <R6M1d.20360$KU5.17067@edtnps89>

rob wrote:
> When you perform regular expressions with capturing Perl creates back
> references into the original string such that you can access parts of
> the string using $1, $2, etc. My testing shows that using the back
> reference directly is MUCH faster than copying it to a variable and
> then using it.
> 
> For example, these two pieces of code have identical output, but the
> first on will be faster than the second.
> 
> my $string='a,b;c,d;e,f';
> if ( $string=~/([a-z,]+);([a-z,]+);([a-z,]+)/ ){
>   print "START_1\n";
>   print "[",$1,"]\n";
>   print "[",$2,"]\n";
>   print "[",$3,"]\n";
>   print "END_1\n";
> }
> 
> my( $one, $two, $three)= $string=~/([a-z,]+);([a-z,]+);([a-z,]+)/;
> print "START_2\n";
> print "[",$one,"]\n";
> print "[",$two,"]\n";
> print "[",$three,"]\n";
> print "END_2\n";
> 
> Output:
> 
> START_1
> [a,b]
> [c,d]
> [e,f]
> END_1
> START_2
> [a,b]
> [c,d]
> [e,f]
> END_2
> 
> Note, I chose a simple example for this post; my testing was on a
> larger volume of data and I ruled out i/o being a factor. I just
> wanted to show that the code is equivalent.
> 
> Since using back references is much faster than accessing the data
> though named scalar vars, I would like to use them in my application.
> The problem with back references is that they get overwritten each
> time you do a regular expression. For example:
> 
> my $string='a,b;c,d;e,f';
> if ( $string=~/([a-z,]+);([a-z,]+);([a-z,]+)/ ){
>   print "START_3\n";
>   print $1,"\n";
>   if($1=~/(\w+),(\w+)/){
>     print "START_3_inner\n";
>     print "[",$1,"]\n";
>     print "[",$2,"]\n";
>     print "END_3_inner\n";
>   }
>   print "[",$2,"]\n";
>   print "[",$3,"]\n";
>   print "END_3\n";
> }
> 
> The output is:
> START_3
> a,b
> START_3_inner
> [a]
> [b]
> END_3_inner
> [b]
> []
> END_3
> 
> Notice that $2 has been overwritten and that $3 is now undefined. 
> 
> Does anyone know of a way to preserve that back reference so you can
> continue to access parts of a sting with out having to parse them out
> into separate scalar variables?

You mean something like this.  :-)

my $string = 'a,b;c,d;e,f';
if ( $string =~ /([a-z,]+);([a-z,]+);([a-z,]+)/ ) {
   print "START_3\n";
   print "$1\n";
   { local $_ = $1;
     local ( $1, $2, $3 );
     if ( /(\w+),(\w+)/ ) {
       print "START_3_inner\n";
       print "[$1]\n";
       print "[$2]\n";
       print "END_3_inner\n";
     }
   }
   print "[$2]\n";
   print "[$3]\n";
   print "END_3\n";
}



John
-- 
use Perl;
program
fulfillment


------------------------------

Date: Tue, 14 Sep 2004 20:58:25 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: rand() question
Message-Id: <1095209944.109086@nntp.acecape.com>

so i generate a serial number with the exact code below (three lines):

$number1 = 10000 + int(rand(99999));
$number2 = 10000 + int(rand(99999));
$shrwsn = "$number1-$number2";

the point is i want TWO five digit numbers separated by a dash "-"
and all is cool, but i just noticed, that for the three entries i have made
test wise:

79109-72626
106421-1023        these last two are six and four digits.....
108629-3542

WHY?  these were all made with the SAME script...............




------------------------------

Date: 15 Sep 2004 01:10:36 GMT
From: Sam Holden <sholden@flexal.cs.usyd.edu.au>
Subject: Re: rand() question
Message-Id: <slrnckf5kc.q4u.sholden@flexal.cs.usyd.edu.au>

On Tue, 14 Sep 2004 20:58:25 -0400, daniel kaplan <nospam@nospam.com> wrote:
> so i generate a serial number with the exact code below (three lines):
>
> $number1 = 10000 + int(rand(99999));
> $number2 = 10000 + int(rand(99999));
> $shrwsn = "$number1-$number2";
>
> the point is i want TWO five digit numbers separated by a dash "-"
> and all is cool, but i just noticed, that for the three entries i have made
> test wise:
>
> 79109-72626
> 106421-1023        these last two are six and four digits.....
> 108629-3542
>
> WHY?  these were all made with the SAME script...............

int(rand(99999)) can generate the integers greater than 90000 which
when added to 10000 will give numbers greater than 100000 which have
six digits.

As for the four digit part I can only assume you are only printing
(or keeping) the first 11 characters in the string and hence
truncating the last digit (or two) of the second number.

-- 
Sam Holden


------------------------------

Date: Tue, 14 Sep 2004 21:17:21 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: rand() question
Message-Id: <ci857a$m5b$1@misc-cct.server.rpi.edu>

[crosspost to defunct group comp.lang.perl removed]

daniel kaplan wrote:

> so i generate a serial number with the exact code below (three lines):
> 
> $number1 = 10000 + int(rand(99999));
> $number2 = 10000 + int(rand(99999));
> $shrwsn = "$number1-$number2";
> 
> the point is i want TWO five digit numbers separated by a dash "-"
> and all is cool, but i just noticed, that for the three entries i have made
> test wise:
> 
> 79109-72626
> 106421-1023        these last two are six and four digits.....
> 108629-3542
> 
> WHY?  these were all made with the SAME script...............

The last time I checked, 90,000 + 10,000 = 100,000 and that's a 6 digit 
number.  Please check the perl FAQ:
perldoc random
(2nd question returned)

As for the four digit number, you'll have to show us how you're printing 
it out.  Where is this string being stored, and how is it being 
retrieved for your viewing?  (My initial guess is that you're storing it 
in a varchar database field that has a length of 10, but that's just a 
guess).

Paul Lalli


------------------------------

Date: Tue, 14 Sep 2004 21:18:28 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: rand() question
Message-Id: <ci859c$m5b$2@misc-cct.server.rpi.edu>

Paul Lalli wrote:

> Please check the perl FAQ:
> perldoc random
> (2nd question returned)

That should, of course, be:
perldoc -q random

Paul Lalli


------------------------------

Date: Wed, 15 Sep 2004 01:25:32 GMT
From: Marc Dashevsky <usenet@MarcDashevsky.com>
Subject: Re: rand() question
Message-Id: <MPG.1bb16412521bd22b989a52@netnews.comcast.net>

In article <1095209944.109086@nntp.acecape.com>, nospam@nospam.com says...
> so i generate a serial number with the exact code below (three lines):
> 
> $number1 = 10000 + int(rand(99999));
> $number2 = 10000 + int(rand(99999));
> $shrwsn = "$number1-$number2";
> 
> the point is i want TWO five digit numbers separated by a dash "-"

So why don't you do:

$shrwsn = sprintf("%05d-%05d", rand(100000), rand(100000));

> and all is cool, but i just noticed, that for the three entries i have made
> test wise:
> 
> 79109-72626
> 106421-1023        these last two are six and four digits.....
> 108629-3542
> 
> WHY?  these were all made with the SAME script...............

-- 
  Go to http://MarcDashevsky.com to send me e-mail.


------------------------------

Date: Tue, 14 Sep 2004 21:31:45 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: rand() question
Message-Id: <1095211944.504949@nntp.acecape.com>

i'll do that, but somehow the two OFF results don't ake sense to me
"Marc Dashevsky" <usenet@MarcDashevsky.com> wrote in message
news:MPG.1bb16412521bd22b989a52@netnews.comcast.net...
> In article <1095209944.109086@nntp.acecape.com>, nospam@nospam.com says...
> > so i generate a serial number with the exact code below (three lines):
> >
> > $number1 = 10000 + int(rand(99999));
> > $number2 = 10000 + int(rand(99999));
> > $shrwsn = "$number1-$number2";
> >
> > the point is i want TWO five digit numbers separated by a dash "-"
>
> So why don't you do:
>
> $shrwsn = sprintf("%05d-%05d", rand(100000), rand(100000));
>
> > and all is cool, but i just noticed, that for the three entries i have
made
> > test wise:
> >
> > 79109-72626
> > 106421-1023        these last two are six and four digits.....
> > 108629-3542
> >
> > WHY?  these were all made with the SAME script...............
>
> -- 
>   Go to http://MarcDashevsky.com to send me e-mail.




------------------------------

Date: Tue, 14 Sep 2004 22:16:31 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: rand() question
Message-Id: <W4adnWMhM4SdO9rcRVn-vA@adelphia.com>

daniel kaplan wrote:

> so i generate a serial number with the exact code below (three lines):
> 
> $number1 = 10000 + int(rand(99999));
> $number2 = 10000 + int(rand(99999));
> $shrwsn = "$number1-$number2";
> 
> the point is i want TWO five digit numbers separated by a dash "-"

That's not what you're asking for with this code. You're asking for two 
numbers from 10000 to 109999, inclusive.

What you want to do is as another poster suggested, use rand(100000) to 
get a number from 0 to 99999, inclusive, and then use sprintf() to pad 
that with zeroes as needed to get five digits.

> and all is cool, but i just noticed, that for the three entries i have made
> test wise:
> 
> 79109-72626
> 106421-1023        these last two are six and four digits.....
> 108629-3542
> 
> WHY?  these were all made with the SAME script...............

The code you've given cannot produce either 1023 or 3542, so the problem 
lies elsewhere, when $shrwsn is stored and/or output.

Are you truncating these somewhere, using code that assumes that both 
parts are five digits? Storing them in a fixed-length database column 
perhaps?

By the way, comp.lang.perl is an ex-group. It's gone, defunct, pining 
for the fjords. It's only standing up because your provider nailed it to 
the server. It's *dead*. Followups set.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


------------------------------

Date: Tue, 14 Sep 2004 20:48:13 -0500
From: l v <lv@aol.com>
Subject: Re: Running as a Service
Message-Id: <41479f5c_3@corp.newsgroups.com>

Barry_Alder wrote:
> I have a PERL script that I want to run as a service in Windows NT4 and
> 2000, but it stops whenever I log off the server. While I'm logged on, it
> works fine. I am using SRVANY.exe to run it. In the SRVANY documentation,
> it mentions that I must be set up to ignore the CTRL_LOGOFF_EVENT.
> Unfortunately, I haven't been able to find any documentation on how to do
> this. Can someone point me in the right direction?
> 
> Thanks,
> 
> Barry
> 

I have had good results using the windows task scheduler both at 
computer startup and at repeating intervals.

Execute perl.exe script.pl arg1 arg2 arg<n>

Len


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 100,000 Newsgroups - 19 Different Servers! =-----


------------------------------

Date: Wed, 15 Sep 2004 03:46:00 GMT
From: ChrisO <ceo@nospam.on.net>
Subject: Re: Running as a Service
Message-Id: <YVO1d.2680$ab4.792@newssvr15.news.prodigy.com>

Barry_Alder wrote:
> I have a PERL script that I want to run as a service in Windows NT4 and
> 2000, but it stops whenever I log off the server. While I'm logged on, it
> works fine. I am using SRVANY.exe to run it. In the SRVANY documentation,
> it mentions that I must be set up to ignore the CTRL_LOGOFF_EVENT.
> Unfortunately, I haven't been able to find any documentation on how to do
> this. Can someone point me in the right direction?
> 

I've built perhaps 5-6 production daemons/services using the SRVANY.EXE 
method at two different companies and I don't recall *ever* having to 
train it to ignore the CTRL_LOGOFF_EVENT.  I don't recall that mentioned 
in the Microsoft documentation I've used either.  Not saying you are 
seeing things; simply that I personally have never come across this. 
All are "Perl script services."  Basically some Reg pokes and you are 
done.  The meat of the syntax would be easy enough to post here if you 
are at all interested.

There are, as someone else pointed out, now better ways of doing this. 
I saw some code from David Roth somewhere that demonstrated straight 
Perl code that responded to service START, STOP, RESTART, etc. events. 
You may trying Googling for "David Roth" and "Perl NT Service"???

-ceo


------------------------------

Date: 14 Sep 2004 18:40:14 -0400
From: Greg Menke <gregm-news@toadmail.com>
Subject: Re: Xah Lee's Unixism
Message-Id: <m3ekl4wk35.fsf@europa.pienet>

Chuck Dillon <spam@nimblegen.com> writes:
> Greg Menke wrote:
> > Chuck Dillon <spam@nimblegen.com> writes:
> >
> >>Antony Sequeira wrote:
> >>
> >>
> >>>Chuck Dillon wrote:
> >>>How is that related to Saqqddam Hussqqqqqain being a jackass and us
> >>>spending 100 or whatever billions on removing him and having 1000+
> >>>of Americans + unknown number of Iraqqqqqis getting killed. How does
> >>>that help avoid
> >>>9 qqqq  11 or are you confused between Iraqqqqqis and Saudqqqqis ?
> >>
> >>If you reread the post that you responded to you will see it has
> >>nothing to do with Iraq.
> >>
> >>However, to answer your question: How does regime change in Iraq help
> >>avoid another 9/11...
> >>	1) It removes one of the states that might consider sponsing
> >>such a future attach.
> > Wouldn't it have made more sense to invade Saudi Arabia?  Thats where
> > the terrorist money and terrorist leadership is from.  Iraq is chump
> > change on that account- heck, even Iran or Syria would've made a much
> > better target on this basis.  Or are we such bullies that we'll pick
> > the weakest kid to beat up to show how strong we are?
> 
> Please try and follow the trend of the thread you respond to.  I did
> not address whether or not regime change in Iraq was an optimal
> move. I'm responding to the question posed, see above for what it was.
> 
> Regardless of how we got where we are there are arguably benefits to
> the "war on terror".  That doesn't mean you should miopically focus on
> them as the sole rationale for regime change in Iraq.  See the various
> U.N Security Counsil resolutions for the primary rationale.  Also, see
> the reports from Blix et.al. that point out the lack of cooperation on
> the part of the Iraqi government.

I still fail to see why invading Iraq has anything to do with "war on
terror".  If the goal is to fight terror (laudable), then why are we
not invading the countries that actually sponsor it?  Afganistan was
the right step- but who the hell cares if Iraq "obeyed" the
resolutions?  Saddam's regime was wasting away on its own.  At some
point, someone was going to get lucky and off him- and then the
Islamic fundamentalist state that Iraq seems to want to become would
start up with the west as investors, not invaders.

 
> >>	6) It underscores that 9/11 should go into the "bad idea"
> >>category for future planners of Islamic extremist operations.
> > Afganistan taught that.
> 
> Hence my use of the qualifier "underscores".
> 

But you keep proposing that Iraq is also underscoring the same point.
What it means to me is that the US will attack the weakest, easiest
opponent- but not really take over.  Instead we'll fool around trying
to be civilized- not much deterrent value there.

If the goal is really to change regimes, then you go in heavy, crack
skulls & massacre as required and then occupy for decades like the
Soviets had to do in the Balkans.  THAT would make the impression you
seem to want.  If we're unwilling to be the butchers we appropriately
condemn others for being, then we shouldn't be playing games invading
and occupying other countries.

Iraq is a frigging joke- the most powerful military in the world has
every spare soldier both regular and reserves, occupying essentially a
3rd world country, yet is subject to "no go zones" and is forced to
allow organized resistance to simply walk home & start fighting again?
This is a textbook case of how to take on a superpower and win, taught
directly to the people we're trying to fight.


> > Iraq teaches the Islamic world that we're
> > crazy.
> 
> By "we" you are referring to the some 40 nations who have contributed
> to the effort right?
> 

Each nation with their couple hundred or fewer people?  Don't make me
laugh.  This one is the US and the UK and whatever bits & pieces we
could muscle out of all the countries that owe favors.  Last time
around we had an actual coalition this one is pretty much only PR.

Gregm


------------------------------

Date: Wed, 15 Sep 2004 15:42:48 +1200
From: Brian Boutel <boutelbNOSPAM@acm.org>
Subject: Re: Xah Lee's Unixism
Message-Id: <KSO1d.3578$mZ2.328256@news02.tsnz.net>

Greg Menke wrote:


> 
>>>Iraq teaches the Islamic world that we're
>>>crazy.
>>
>>By "we" you are referring to the some 40 nations who have contributed
>>to the effort right?
>>
> 
> 
> Each nation with their couple hundred or fewer people?  Don't make me
> laugh.  This one is the US and the UK and whatever bits & pieces we
> could muscle out of all the countries that owe favors.  Last time
> around we had an actual coalition this one is pretty much only PR.
> 

And, of course, very few countries sent troops to be part of the 
invasion force. Many others, like ours, are there in 
non-combatant roles to help repair the damage the invaders caused.


--brian


-- 
Brian Boutel
Wellington New Zealand


Note the NOSPAM


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 7141
***************************************


home help back first fref pref prev next nref lref last post