[25698] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7939 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 4 00:06:30 2005

Date: Sun, 3 Apr 2005 21:05:08 -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           Sun, 3 Apr 2005     Volume: 10 Number: 7939

Today's topics:
    Re: #!perl ?? <jkrugman345@yahbitoo.com>
    Re: #!perl ?? (Anno Siegel)
    Re: #!perl ?? <jkrugman345@yahbitoo.com>
    Re: Can perl do this? <pilsl@goldfisch.at>
    Re: difference between two files axel@white-eagle.invalid.uk
        Generate random arrays? <bcc@abcz.com>
    Re: Generate random arrays? <1usa@llenroc.ude.invalid>
    Re: Generate random arrays? <bcc@abcz.com>
    Re: Generate random arrays? xhoster@gmail.com
        Golf Q: \$h{X} ? <jkrugman345@yahbitoo.com>
        Help with a script.. clearguy02@yahoo.com
    Re: Help with a script.. <1usa@llenroc.ude.invalid>
    Re: Help with a script.. axel@white-eagle.invalid.uk
    Re: Newbie. Use of uninitialized value in print?? axel@white-eagle.invalid.uk
    Re: Subroutine paramater question <perl@my-header.org>
    Re: Subroutine paramater question <nobull@mail.com>
    Re: Subroutine paramater question <perl@my-header.org>
    Re: To change the time stamp format... <jwkenne@attglobal.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 3 Apr 2005 19:49:01 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Re: #!perl ??
Message-Id: <d2phbc$kl6$1@reader1.panix.com>

In <slrnd4t8hb.54c.tadmc@magna.augustmail.com> Tad McClellan <tadmc@augustmail.com> writes:

>J Krugman <jkrugman345@yahbitoo.com> wrote:
>> What do I have to do to use #!perl (instead of
>> a fully qualified path) as my shebang line?

>Why do you think you want to use #!perl (instead of a fully 
>qualified path) as your shebang line?

It's just laziness on my part :) .  I want be able to download Perl
scripts and run them as is (after changing permissions):

% wget -q -O perl_script.pl http://url.to.some/perl_script.txt && \
> chmod +x perl_script.pl && \ 
> perl_script.pl

without having to fuss with firing up vi and fixing the first line.
(Of course, the above is something I'd do only with a script that
I was confident was safe.)  Arguably I could just use

% perl perl_script.pl

but this solution is suboptimal because often a Perl script will
have switches on the first line that are critical to its operation,
so I'd have to first inspect that first line and replicate the
switches in my own invocation.  This is a minor pain with simple
switches like '-l', but it because increasingly more of a pain as
the complexity of the switches increases.

As I said, just another case of programmerly laziness...

jill

-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



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

Date: 3 Apr 2005 21:25:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: #!perl ??
Message-Id: <d2pn0h$bth$1@mamenchi.zrz.TU-Berlin.DE>

J Krugman  <jkrugman345@yahbitoo.com> wrote in comp.lang.perl.misc:
> In <slrnd4t8hb.54c.tadmc@magna.augustmail.com> Tad McClellan
> <tadmc@augustmail.com> writes:
> >J Krugman <jkrugman345@yahbitoo.com> wrote:
> >> What do I have to do to use #!perl (instead of
> >> a fully qualified path) as my shebang line?

[...]

>  Arguably I could just use
> 
> % perl perl_script.pl
> 
> but this solution is suboptimal because often a Perl script will
> have switches on the first line that are critical to its operation,

Perl is friendly enough to parse those switches, even when invoked
explicitly, so don't worry about that.

> As I said, just another case of programmerly laziness...

 ...supported by Perl, so just go along with your intuition.

Anno


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

Date: Mon, 4 Apr 2005 01:07:02 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Re: #!perl ??
Message-Id: <d2q3vm$7e0$1@reader1.panix.com>

In <d2pn0h$bth$1@mamenchi.zrz.TU-Berlin.DE> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:

>J Krugman  <jkrugman345@yahbitoo.com> wrote in comp.lang.perl.misc:
>> In <slrnd4t8hb.54c.tadmc@magna.augustmail.com> Tad McClellan
>> <tadmc@augustmail.com> writes:
>> >J Krugman <jkrugman345@yahbitoo.com> wrote:
>> >> What do I have to do to use #!perl (instead of
>> >> a fully qualified path) as my shebang line?

>[...]

>>  Arguably I could just use
>> 
>> % perl perl_script.pl
>> 
>> but this solution is suboptimal because often a Perl script will
>> have switches on the first line that are critical to its operation,

>Perl is friendly enough to parse those switches, even when invoked
>explicitly, so don't worry about that.

>> As I said, just another case of programmerly laziness...

>...supported by Perl, so just go along with your intuition.

Thanks!!!

jill

-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



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

Date: Sun, 03 Apr 2005 20:32:07 +0200
From: peter pilsl <pilsl@goldfisch.at>
Subject: Re: Can perl do this?
Message-Id: <4250371d$0$1947$79720d31@newsreader.inode.at>

A. Sinan Unur wrote:
> 
>>while (1) {              # run forever (until ctrl-c breaks)
>>   $dir_new=`ls -l $folder`;       # get the content of the folder
> 
> 
> Polling like this, i.e. writing a busy loop is probably not a good idea.
>

It would, if there werent a sleep-statement inside this loop which 
controls the check-intervals.

at least in my experience a busy-loop like this does not need any 
resources, cause the sleep is for free :)


best,
peter

-- 
http://www.goldfisch.at/know_list


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

Date: Sun, 03 Apr 2005 17:04:52 -0500
From: axel@white-eagle.invalid.uk
Subject: Re: difference between two files
Message-Id: <KKidnbeLKYUZ9c3fRVn-jw@adelphia.com>

xhoster@gmail.com wrote:
> peter pilsl <pilsl@goldfisch.at> wrote:
>> oneliners are fast-written and often-written, cause I never save them to
>> disk and when I need em again I've to think them over again.
>> So on the longer term fourliners are maybe better ;)
 
> On the other hand, if every one-liner I have ever written was saved to
> disk as a four-liner, there would be so stinking many of them I would never
> be able to find the one I wanted when I wanted it again.

The simple solution is to quickly save them with a quick comment
in a single file -  along with other snippets of code such as
longwinded regular expressions which can be cut and pasted when
required.

Axel



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

Date: Mon, 04 Apr 2005 01:14:08 GMT
From: BCC <bcc@abcz.com>
Subject: Generate random arrays?
Message-Id: <Ax04e.1155$qD2.113@newssvr14.news.prodigy.com>

Hi,  I have a matrix that is 100x100x100, and wish to generate a list of 
  1000 randomly chosen non-repeating x,y,z coordinates within the space.

I can generate a list of non-repeating single digits using rand(), but 
Im not sure how to take it to the next level...

Thanks,
B


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

Date: Mon, 04 Apr 2005 01:35:55 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Generate random arrays?
Message-Id: <Xns962DDBB7ABCC5asu1cornelledu@127.0.0.1>

BCC <bcc@abcz.com> wrote in
news:Ax04e.1155$qD2.113@newssvr14.news.prodigy.com: 

> Hi,  I have a matrix that is 100x100x100, and wish to generate a list
> of 
>   1000 randomly chosen non-repeating x,y,z coordinates within the
>   space. 
> 
> I can generate a list of non-repeating single digits using rand(), but
> Im not sure how to take it to the next level...

I am not exactly sure what you mean by 'non-repeating'. Now, the best
way to get help here is to first make an attempt, then ask specific
questions. Please do read the posting guidelines for this group. 

Here is some code (untested) that may or may not do what you want.

#! /usr/bin/perl

use strict;
use warnings;

my @points;

gen_coord(\@points) for (1 .. 3);

use Data::Dumper;
print Dumper \@points;

sub gen_coord {
    my $points = shift;
    my %args = (
        num => 100,
        min => 0,
        max => 100,
        @_,
    );

    for my $i (0 .. $args{num} - 1) {
        push @{ ${ @{$points} }[$i] }, 
            $args{min} + rand($args{max}-$args{min} + 1);
    }
}
__END__


-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Mon, 04 Apr 2005 01:50:30 GMT
From: BCC <bcc@abcz.com>
Subject: Re: Generate random arrays?
Message-Id: <G314e.1205$qD2.1077@newssvr14.news.prodigy.com>

A. Sinan Unur wrote:

> I am not exactly sure what you mean by 'non-repeating'. Now, the best
> way to get help here is to first make an attempt, then ask specific
> questions. Please do read the posting guidelines for this group. 

Just that there should be no duplicate coordinates generated... and to 
retroactivly correct my post, here was the first attempt, extracted and 
modified from a web site:

use strict;
use warnings;

my @shuffle = &getCoords;
sub getCoords {
    my @nums = (1..100);
    my %random = ();
    my $num = 0;
    until ($num == 1000) {
       my $i = int($nums[rand(@nums)]);
       $random{$i}=1;
       $num = keys %random;
    }
    return(keys %random);
}

Thanks for the help,
B


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

Date: 04 Apr 2005 02:59:57 GMT
From: xhoster@gmail.com
Subject: Re: Generate random arrays?
Message-Id: <20050403225957.562$5o@newsreader.com>

BCC <bcc@abcz.com> wrote:
> A. Sinan Unur wrote:
>
> > I am not exactly sure what you mean by 'non-repeating'. Now, the best
> > way to get help here is to first make an attempt, then ask specific
> > questions. Please do read the posting guidelines for this group.
>
> Just that there should be no duplicate coordinates generated... and to
> retroactivly correct my post, here was the first attempt, extracted and
> modified from a web site:
>
> use strict;
> use warnings;
>
> my @shuffle = &getCoords;

Don't call subs with & for no good reason.

> sub getCoords {
>     my @nums = (1..100);

this variable serves no good purpose.  Only it's size is used in a
meaningful way, so just use that size directly (or a scalar holding the
size).

>     my %random = ();
>     my $num = 0;

This variable serves no good purpose. It only stores the size of the hash,
which is easy enough to just use directly.  (Of course, if you need a
multi level hash for the "real" solution, then $num may come in handy yet.)

>     until ($num == 1000) {
      until (1000 == keys %random) {

>        my $i = int($nums[rand(@nums)]);
         my $i = int(rand 100)+1;

>        $random{$i}=1;
I'd prefer to set it to () rather than 1, but no big deal.

>        $num = keys %random;
no longer necessary.

>     }
>     return(keys %random);
> }


Ok, so now that you showed it to us, why doesn't it do what you want
it to do?  Is it because you want it be nonrepeating among
all three dimensions simultaneously, but possible to repeat within any
single dimenstion considered alone?  If that is the case, I'd just change
the one line to:

     my $i=join"\t",int(rand 100)+1,int(rand 100)+1,int(rand 100)+1;

And then use map and split to munge the keys into the desired format at
the end:

      return map [split /\t/], keys %random;

You could use multi-level hash instead, but I wouldn't bother in this
case.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Mon, 4 Apr 2005 01:05:05 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Golf Q: \$h{X} ?
Message-Id: <d2q3s1$s9l$1@reader1.panix.com>




In an old FWP post I found online, there is a golfing construct I
can't figure out; this is all the post says

  \$h{X} is one less than ++$h{X}

If it weren't for the leading backslash, the interpretation of "one
less" would be obvious and hardly worth remarking upon in such a
post.  But given the leading backslash, I figure that the "one
less" is referring to "one fewer characters".  Still, I can't figure
out what the whole thing means.  Any help would be much appreciated.

TIA!

jill


-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



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

Date: 3 Apr 2005 17:58:41 -0700
From: clearguy02@yahoo.com
Subject: Help with a script..
Message-Id: <1112576321.475302.71500@z14g2000cwz.googlegroups.com>

Hi all,

I have the below script ready to change a time stamp from
15-Sep-04.01:03 to 2004-09-15 01:03:00.

===================================
$date = '15-Sep-04.01:03';
%months = qw(January 1 February 2 March 3 April 4 May 5 June 6 July 7
August 8 September 9 October 10 November 11 December 12);

$month_lookup = join '|', keys %months;
if ( $date =~ /(\d+)-($month_lookup)-(\d+)\.(\d+):(\d+)/ )
 {
  $finalDate = sprintf ("20%02d-%02d-%02d %02d:%02d:00\n", $3,
$months{$2}, $1, $4, $5);
 }
print "$finalDate";
====================================

Now my problem is that the $date variable might have 15-Sep-04.01:03 or
15-Sept-04.01:03 or 15-September-04.01:03 (month will have a range from
minumum first three chanracters to the whole month name).

then how can I make sure that I can translate either Sep or Sept or
September in to 09 in the final output?

Thanks in advance,
John.



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

Date: Mon, 04 Apr 2005 01:39:30 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Help with a script..
Message-Id: <Xns962DDC533B2ECasu1cornelledu@127.0.0.1>

clearguy02@yahoo.com wrote in news:1112576321.475302.71500
@z14g2000cwz.googlegroups.com:

>   $finalDate = sprintf ("20%02d-%02d-%02d %02d:%02d:00\n", $3,
> $months{$2}, $1, $4, $5);

As I noted before, there is a Y2.1K bug in there. When doing the right 
thing is just as easy as doing the wrong thing, why not do the right 
thing?

> then how can I make sure that I can translate either Sep or Sept or
> September in to 09 in the final output?

What have you tried?

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Sun, 03 Apr 2005 23:01:02 -0500
From: axel@white-eagle.invalid.uk
Subject: Re: Help with a script..
Message-Id: <BLCdnQeI_9xjJs3fRVn-2g@adelphia.com>

clearguy02@yahoo.com wrote:
> I have the below script ready to change a time stamp from
> 15-Sep-04.01:03 to 2004-09-15 01:03:00.
 
> ===================================
> $date = '15-Sep-04.01:03';
> %months = qw(January 1 February 2 March 3 April 4 May 5 June 6 July 7
> August 8 September 9 October 10 November 11 December 12);
> 
> $month_lookup = join '|', keys %months;
> if ( $date =~ /(\d+)-($month_lookup)-(\d+)\.(\d+):(\d+)/ )
> {
>  $finalDate = sprintf ("20%02d-%02d-%02d %02d:%02d:00\n", $3,
> $months{$2}, $1, $4, $5);
> }
> print "$finalDate";
> ====================================
 
> Now my problem is that the $date variable might have 15-Sep-04.01:03 or
> 15-Sept-04.01:03 or 15-September-04.01:03 (month will have a range from
> minumum first three chanracters to the whole month name).
 
> then how can I make sure that I can translate either Sep or Sept or
> September in to 09 in the final output?

Well, you could just expand the hash %months...

	$date = '15-Sep-04.01:03';
	%months = qw(Jan 1 January 1 enero 1 Feb 02 Mar 03 Apr 04
	    May 05 Jun 06 Jul 07 Aug 8 Sep 9 Sept 9 September 9
	    Oct 10 Nov 11 Dec 12);

	if ($date =~ /(\d+)-(\w+)-(\d+)\.(\d+):(\d+)/
		&& (my $mon = $months{$2})) {
	    $finalDate = sprintf ("20%02d-%02d-%02d %02d:%02d:00\n",
		$3, $mon, $1, $4, $5);
	}
	print "$finalDate";

Or without changing the hash, use the first three characters of the
month supplied and reply on your data to be correct and not have,
e.g. 'Sepulchre' present where the name of a month should occur,
use something like...

	if ($date =~ /(\d+)-(\w+)-(\d+)\.(\d+):(\d+)/
		&& (my $mon = $months{substr($2, 0, 3)})) {
 
Axel




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

Date: Sun, 03 Apr 2005 17:23:22 -0500
From: axel@white-eagle.invalid.uk
Subject: Re: Newbie. Use of uninitialized value in print??
Message-Id: <laadnSijwvpH8c3fRVn-qg@adelphia.com>

A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
>> $prices2 = @raw_data;
 
> As others have pointed out, assigning the number of lines in the 
> original file to $prices2
 
>> @prices1to5 = split (/:/, $prices2);
 
> and splitting that causes the warning to be emitted.
 
No, not that split and assignment, both of which are valid
Perl code and will raise no warning.

The warning comes afterwards from trying to use an element of
@proces1to5 which has not been assigned.

Just making a note in case the OP is confused.

Axel



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

Date: Sun, 03 Apr 2005 20:57:16 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: Subroutine paramater question
Message-Id: <51f051pqpi1m0vncj7e3hchg3t0a0c632b@4ax.com>

X-Ftn-To: Brian McCauley 

Brian McCauley <nobull@mail.com> wrote:
>For reasons I've explained numerous times before you should actually 
>local(*_), never local($_).

Strange, I can't find your article at Google; can you take a look at your
outbox? :)



-- 
Matija


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

Date: Sun, 03 Apr 2005 20:32:33 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Subroutine paramater question
Message-Id: <d2pg1k$noq$1@sun3.bham.ac.uk>



Matija Papec wrote:

> Brian McCauley <nobull@mail.com> wrote:
> 
>>For reasons I've explained numerous times before you should actually 
>>local(*_), never local($_).
> 
> Strange, I can't find your article at Google;

Very strange. How did you look?  I just tried "author:nobull@mail.com 
local" and looked at the first 100 (out of 375) hits.

The first place I found an explaination was the second hit.  ("Bug: 
local($_), for() and tied scalars").

That is by chance the first one where I started a thread specifically to 
  describe this in July 2002.

The next one I found was hit number 31 in thread "eval function" from 
October 2004.

And like buses 2 came along at once... hit 32 was also on this subject 
in the unhelpfully entitled thread "New to Perl: Need help with a 
script" from June 2004.

Hit 41 was in thread "perl CGI.pm upload file questions" as recently as 
February 2005 but here I only mention it but don't explain.

Hit 51 (hmmm... a pattern 31,41,51...) again I mention it but don't explain.

Hit 55 yet again I mention it but don't explain (but that time I said it 
was already being discussed in another active thread).

I think that was the thread "No Question - Just Posting some Code I'm 
Proud of" found in hit 58.

Didn't find it again until hit 83 and that was the last one I found in 
the first 100 hits.

Interestingly in hit 202 a thread "Reversable loop" from last May I 
actually got it wrong and said local(*_) was unsafe. D'oh.

> can you take a look at your outbox? :)

I post from several different computers.



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

Date: Sun, 03 Apr 2005 22:47:27 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: Subroutine paramater question
Message-Id: <eik051t4udbcl5e1kgj0skn2gt97nkbj1f@4ax.com>

X-Ftn-To: Brian McCauley 

Brian McCauley <nobull@mail.com> wrote:
>>>For reasons I've explained numerous times before you should actually 
>>>local(*_), never local($_).
>> 
>> Strange, I can't find your article at Google;
>
>Very strange. How did you look?  I just tried "author:nobull@mail.com 
>local" and looked at the first 100 (out of 375) hits.
>
>The first place I found an explaination was the second hit.  ("Bug: 
>local($_), for() and tied scalars").

Tnx, I wasn't careful enough.



-- 
Matija


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

Date: Sun, 03 Apr 2005 18:20:32 -0400
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: To change the time stamp format...
Message-Id: <c_Z3e.6315$oo5.4776@fe11.lga>

Brian McCauley wrote:
> 
> 
> A. Sinan Unur wrote:
> 
>> "John W. Krahn" <someone@example.com> wrote in 
>> news:EEG3e.127836$ZO2.94802
>> @edtnps84:
>>
>>> A. Sinan Unur wrote:
>>>
>>>> Ooops! How about that Y2.1K bug?!
>>>
>>>
>>> Is that thing still around?  :-)
>>
>>
>> Yeah, it seems like a new version is released every century :)
> 
> 
> Indeed, I always wondered why people insisted on calling the centuary 
> bug 'the millenium bug' or the 'Y2K bug'.
> 
> But it's really more often than that.  There are all sort of ways that 
> various software encodes dates internally.  Each of these can introduce 
> its own problems.
> 
> There was one on 9th September 2001.  (10**9 seconds since 1970).
> 
> Of course there's the famous 'Unix' one on 19th January 2038 (2**31 
> seconds since 1970).
> 
> There's a lesser known one one a couple of years earlier (2**32 seconds 
> since 1900).
> 
> There's even one in 2010 that some users of systems written in the MUMPS 
> programing language may hit.

IBM mainframes started to have "keep forever" files deleted on August 
16th, 1972, which was 9999 days before 2000-01-01.

(There was also a beta version of OS/VS1 that crashed every 24 hours at 
exactly midnight, GMT, with a zero-divide error in the nucleus, because 
one of the programmers who wrote the date/time code was aware that 1900 
was not a leap year, and another one wasn't.)

-- 
John W. Kennedy
"The pathetic hope that the White House will turn a Caligula into a 
Marcus Aurelius is as naïve as the fear that ultimate power inevitably 
corrupts."
   -- James D. Barber (1930-2004)


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

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 7939
***************************************


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