[30550] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1793 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 14 14:09:44 2008

Date: Thu, 14 Aug 2008 11:09:07 -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           Thu, 14 Aug 2008     Volume: 11 Number: 1793

Today's topics:
    Re: CLPM - a help group? <mjcarman@mchsi.com>
    Re: CLPM - a help group? <justin.0805@purestblue.com>
    Re: CLPM - a help group? <justin.0805@purestblue.com>
    Re: double slash operator syntax question <ced@blv-sam-01.ca.boeing.com>
    Re: empty "if" statement - it doesn't look nice, does i <jurgenex@hotmail.com>
        En/Decrypt Mismatch: Command-Line Tool vs. Crypt::OpenS <jerry@ieee.org>
    Re: How to check for filetype existence quickly <jurgenex@hotmail.com>
    Re: modifying the haystack string inside while($haystac <jl_post@hotmail.com>
        new CPAN modules on Thu Aug 14 2008 (Randal Schwartz)
        perlish way for ( 0 .. $n) , but downcounting <blabla@dungeon.de>
    Re: perlish way for ( 0 .. $n) , but downcounting <justin.0805@purestblue.com>
    Re: perlish way for ( 0 .. $n) , but downcounting <willem@stack.nl>
    Re: perlish way for ( 0 .. $n) , but downcounting <jimsgibson@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 14 Aug 2008 01:54:15 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: CLPM - a help group?
Message-Id: <bfMok.242178$TT4.143431@attbi_s22>

Adam Worrall wrote:
> No, not all help desk work that way.

Why the ^%*!& are you still arguing this? It's obvious that no one else
agrees with you (no one who's willing to post, at least). It's also
obvious that your not going to sway anyone, nor beat them into submission.

-mjc


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

Date: Thu, 14 Aug 2008 14:20:42 -0000
From: Justin C <justin.0805@purestblue.com>
Subject: Re: CLPM - a help group?
Message-Id: <408f.48a43f3a.e7a23@zem>

On 2008-08-13, Adam Worrall <worrall+unet@remove.cs.bris.ac.uk> wrote:
> Stop assuming everyone agrees with the "popular" views.

Stop assuming that everyone accept you doesn't.

	Justin.

-- 
Justin C, by the sea.


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

Date: Thu, 14 Aug 2008 14:34:31 -0000
From: Justin C <justin.0805@purestblue.com>
Subject: Re: CLPM - a help group?
Message-Id: <4140.48a44277.8717b@zem>

On 2008-08-13, Adam Worrall <worrall-unet@cs.bris.ac.uk> wrote:
> John Bokma wrote:
>> 
>> Something that /appears/ to function as, in this case, a voluntary help 
>> desk, doesn't make it one.
>
> It also doesn't not make it one. Why is it you can dictate what it is or 
> isn't yet any other person who gets buried for it?

Al Qaeda, selling cookies door-to-door, dressed as boy scouts,
apparently raising money for Georgian orphans doesn't make Al Qaeda a
charitable organisation either. They're still terrorists. 

Even if they raised billions for orphans around the world would you
disregard 9/11 and not call them terrorists?

This group is for discussion of Perl. That many people request, and get,
help here changes nothing.

Did you come for a five minute argument or the full half-hour?

Most normal people would have just given up by now and either gone away
or shut up, chalking one up to experience. You seem intent on making as
many enemies as possible, and ending up in a record number of
kill-files. Whatever your intention, if you request help here in the
future you may well find yourself short of respondents through
persevering with this stupid argument.

Right or wrong, who cares when it's this tedious? Please, give it up.

	Justin.

-- 
Justin C, by the sea.


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

Date: Wed, 13 Aug 2008 16:51:32 -0700 (PDT)
From: "comp.lang.c++" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: double slash operator syntax question
Message-Id: <ae235a56-d545-4a99-ba8c-f0222d38d58e@v26g2000prm.googlegroups.com>

On Aug 10, 6:35 pm, Lars Eighner <use...@larseighner.com> wrote:
> I may have asked this in another form recently, but I'm senile, so indulge
> me.
>
> What I want to do:  if $lb_lang is undefined, I want to set it.
>
> What I wrote:
>
> $lb_lang // {$lb_lang = 'en'};
>
> What perl -w yelled:
>
> Useless use of single ref constructor in void context at etc.
> But it seems to work in spite of the yelling.

If you're able to upgrade, you'll get even more
yelling :)

# /opt/perl-5.10.0/bin/perl  -w
$lb_lang // {$lb_lang = "en"}
^D
Useless use of anonymous hash ({}) in void context at -e line 1.
Odd number of elements in anonymous hash at -e line 1.
en
>
> If I omit the braces, it dies with:
> Can't modify defined or (//) at etc.
>

Hm, with 5.8.8, I see a different yell:

# /opt/perl-5.8.8/bin/perl  -w
$lb_lang // $lb_lang = "en"
^D
Search pattern not terminated at - line 1

--
Charles DeRykus



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

Date: Thu, 14 Aug 2008 14:23:43 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <aif8a4hioe2qajj9t1b342a1c99fkk10h7@4ax.com>

Tomasz Chmielewski <tch@nospam.wpkg.org> wrote:
>Peter Makholm schrieb:

>> The negated condition would be 2!( $a == 1 && $b == 2)"
>
>if !( $a == 1 && $b == 2)
>
>Doesn't look correct to me?

Right, it's a syntax error. You need to write
	
	if (!($a == 1 && $b == 2))

>> or by applying
>> De Morgans Law: "$a != 1 || $b != 2"
>
>No, it wouldn't work in a desired way.

Nonsense, of couse it does.. Have you ever had even basic teaching in
Boolean logic?

>What I meant: negating the "if ($a == 1 && $b == 2)" wouldn't make what 
>I want.

Obviously you have no clue whatsoever. Negating the condition of an
if-statement will swap the 'then' and 'else' parts without causing any
semantic difference. 
Maybe that is not what you want, but then maybe you should restate your
goal because by all sensible interpretations of you question that is
exactly what you were asking for.

jue


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

Date: Wed, 13 Aug 2008 22:25:19 -0700 (PDT)
From: Jerry Krinock <jerry@ieee.org>
Subject: En/Decrypt Mismatch: Command-Line Tool vs. Crypt::OpenSSL::RSA
Message-Id: <f3ac2e56-2958-4066-9b1c-733b166fe13d@v57g2000hse.googlegroups.com>

I posted this to openssl-users-at-openssl.org a couple days ago but no
one seems to know the answer.

I cannot get RSA-encrypted messages which I generate using
Crypt::OpenSSL::RSA to decrypt using the openssl command-line tool.
It may be something easy/stupid since I am a new openssl user.

Attempting to cut the problem in half, I then did another experiment
to see if they would generate the same signature.  They don't.  So I
conclude that the problem is in the ENcrypting.  I gave both
encryptors (Crypt::OpenSSL::RSA and openssl command) the...

  Same message
  Same private key
  Same padding (PKCS1)
  Same digest (SHA1)
  Both running on same Macintosh, presumably using the same
     OpenSSL version 0.9.7l library in Mac OS X 10.5.4.

Here are my commands/code and results, starting with the command-line:

###############################################################
# Create a private key
Jerrys-Mac-Mini: jk$ openssl genrsa -out Test248.private.pem
Generating RSA private key, 512 bit long modulus
 .........++++++++++++
 .............++++++++++++
e is 65537 (0x10001)

# Create signature of message "Bonehead" using the key in file
# Test248.private.pem, SHA1 digest and PKCS padding [1]:

Jerrys-Mac-Mini: jk$ echo -n "Bonehead" \
| openssl dgst -sha1 -binary\
| openssl rsautl -pkcs -sign -inkey Test248.private.pem -hexdump
0000 - 8a c6 56 19 97 f5 e7 16-20 30 f2 2f 0e af 7c 28
0010 - df 9d cd 5a 0e b0 11 c1-cc bb f2 3b 03 87 f0 96
0020 - 0d ce b4 55 dc 69 81 bc-30 40 75 9d 74 b8 b7 bd
0030 - 3b 15 a0 5d c2 db ab 9a-8d d3 f2 4b 77 e1 e9 a1
##############################################################

Now I try to create the same signature using a perl script:

##############################################################
#!/usr/local/bin/perl -w

use strict ;
use warnings ;

use Crypt::OpenSSL::Random ;
use Crypt::OpenSSL::RSA ;

# Read in the key file just created
my $private_key_string = "" ;
my $key_path = "/Users/jk/Documents/SheepSystems/Keys/
Test248.private.pem" ;
open (KEY_FILE, $key_path) ;
   while (my $line = <KEY_FILE>) {
       $private_key_string .= $line ;
   }
close(KEY_FILE);

print "Read key from file:\n$private_key_string\n" ;

my $rsa_priv = Crypt::OpenSSL::RSA-
>new_private_key($private_key_string);

# Use same message, padding and digest as in the command-line test
my $msg = "Bonehead" ;
$rsa_priv->use_pkcs1_padding();
$rsa_priv->use_sha1_hash() ;

my $signature = $rsa_priv->sign($msg);
my $showHexSig = showHex($signature) ;
print "signature of 'Bonehead':\n$showHexSig\n" ;

# sub showHex is shown at the bottom of this message
##############################################################

Running the above script, I get this:

##############################################################
Read key from file:
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBALE2d5DpKbYxfIqv+6jYnW6DDvDyJFCdQt+s432GQsy8+ymL9DOR
mPcRQfk1jas1pqtsy+GGUlYd4R1kxbBZb4UCAwEAAQJANqtw83ma7qQRoc9sucgp
uUAhSd/JqDz7tnllrQHQdcyLMRSCBxvZ/i72YVixRRTHb1GVZ79iJWBmzh8ATLvj
uQIhAOuYWu6Vkve+zQ4Cd5EGWpytY/Or/6ZXvQf3L9ELIB07AiEAwI+miVT8t22w
Ge1IX+Q3L7lK2uBm97Pkwix9Wf7K2j8CIFUrQtQ1ZmgBpgeGhMr8zQ0O8a9JYqYz
2bZjefnMV9O5AiEAqSrKLKYcKm1To0NhLNUKYoPPLkCsVPqWgruhGDoOLfMCIE1E
kpJF13Dtq3KQOsaCoXbL4vo350vkBUrSovu45/6p
-----END RSA PRIVATE KEY-----

signature of 'Bonehead':
64 bytes:
78 b3 43 22 4b 4b 86 7f 47 25 00 f1 62 a2 66 70
e6 7e 82 f2 7a b6 cf ff ab dd f1 8a ff 0d cf a1
b5 3d 60 dc ac 9f 6f 0c 83 b9 51 c9 ac fa 7d 15
0b cc 97 cf 99 e5 6b ee 41 f0 d1 35 a1 a0 c1 09
##############################################################

As you can see the two signatures are both 64 bytes long but do not
match.

What might I be missing?

Thanks very much,

Jerry Krinock

[1] The reason I used PKCS padding (-pkcs) is because if I change it
to -oaep in the command-line test, I get an error message:
RSA operation error
  error:04066076:rsa routines:RSA_EAY_PRIVATE_ENCRYPT:unknown padding
type:rsa_eay.c:360:
which does not make sense because my version is:
Jerrys-Mac-Mini:Keys jk$ openssl
OpenSSL> version
OpenSSL 0.9.7l 28 Sep 2006
and "RSA_padding_add_PKCS1_OAEP() and RSA_padding_check_PKCS1_OAEP()
were added in OpenSSL 0.9.2b" according to documentation:
http://openssl.org/docs/crypto/RSA_padding_add_PKCS1_type_1.html#

[2]
sub showHex {
   my $data = shift ;
   use bytes ;
   my $len = length($data) ;
   my $i ;
   my $show = "" ;
   for ($i=0; $i<$len; $i++) {
       my $value = ord(substr($data, $i, 1)) ;
       $show .= " " ;
       $show .= sprintf("%02x", $value) ;
       if ((($i+1) % 16) == 0) {
           $show .= "\n" ;
       }
   }

   return "$len bytes:\n$show" ;
}


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

Date: Thu, 14 Aug 2008 14:37:08 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How to check for filetype existence quickly
Message-Id: <4bg8a45h2g6p0hhen5kq6s3csiovmrmpgv@4ax.com>

fidokomik <fidokomik@gmail.com> wrote:
>I have directory, say "c:\documents" on Windows or "/home/petr/
>documents" on Linux. In this directory many files are stored with many
>filetypes (extensions), say *.doc, *.txt, *.zip. I need to find fastes
>way how to check if some filetype exist. 

I would simply use a glob and check if it returns any results:

	if (<*.doc>) {
		print ".doc file(s) found\n";
	}

Only downside: it will read the directory in full even if the first file
is a match already.
Only way I know to avoid that is to do what you are doing already: loop
through the directory using readdir() and abort as soon as the first
match is found. 
Which one of these is faster for your environment you will have to
benchmark.

jue


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

Date: Thu, 14 Aug 2008 09:21:54 -0700 (PDT)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: modifying the haystack string inside while($haystack =~  /needle/g) { ... }
Message-Id: <4a75583c-6f51-49d8-802a-4e4579d6e7dd@34g2000hsh.googlegroups.com>

On Aug 10, 1:25=A0am, Yakov <iler...@gmail.com> wrote:
> What exactly happens if I modify the $haystack =A0inside such while (see
> subject) ?

   You're referring to:  while($haystack =3D~ /needle/g) { ... }

   This actually happened to me once.  I had to traverse a set of
messages in a string and modify one byte (character) in each message.
However, I discovered that whenever I modified the variable ($haystack
in your case), its pos() would reset to zero and the regular
expression would start matching from the beginning.

   To work around that behavior, once I located the byte/character to
change I saved off the pos() value, changed the byte of the message,
and then restored the pos() value of the string, like this:

   while ( $haystack =3D~ m/ ... /g )
   {
      .
      .
      .

      if ( byte_needs_changing )
      {
          # Modifying $haystack resets the pos(),
          # so save it off and then restore it
          # after modifying it:
         my $savedPos =3D pos();
         substr($haystack, $offset, 1) =3D $newByte;
         pos() =3D $savedPos;
      }
   }

   If you use this approach, I recommend leaving the comments in
explaining this, as it's not intuitive for all Perl programmers, and
some will appreciate the explanation.


> I see two-three possibilities
> (1) matching position is reset to 0

   Yes, that is it.  That's what I discovered on my own, and I
eventually found it documented in the perldocs, but now I can't
remember where.

   I hope this helps, Yakov.

   -- Jean-Luc


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

Date: Thu, 14 Aug 2008 04:42:21 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Aug 14 2008
Message-Id: <K5KqEL.1Aw6@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

App-ZofCMS-Plugin-BreadCrumbs-0.0101
http://search.cpan.org/~zoffix/App-ZofCMS-Plugin-BreadCrumbs-0.0101/
add "breadcrumbs" navigation to your sites 
----
CatalystX-ListFramework-Builder-0.21
http://search.cpan.org/~oliver/CatalystX-ListFramework-Builder-0.21/
Instant AJAX web front-end for DBIx::Class, using Catalyst 
----
Class-Load-0.01
http://search.cpan.org/~sartak/Class-Load-0.01/
a working `require "Class::Name"` and more 
----
Class-MethodCache-0.01
http://search.cpan.org/~nuffin/Class-MethodCache-0.01/
Manipulate Perl's method resolution cache 
----
Class-MethodCache-0.02
http://search.cpan.org/~nuffin/Class-MethodCache-0.02/
Manipulate Perl's method resolution cache 
----
Class-MethodCache-0.03
http://search.cpan.org/~nuffin/Class-MethodCache-0.03/
Manipulate Perl's method resolution cache 
----
ClearPress-249
http://search.cpan.org/~rpettett/ClearPress-249/
Simple, fresh & fruity MVC framework 
----
ClearPress-250
http://search.cpan.org/~rpettett/ClearPress-250/
Simple, fresh & fruity MVC framework 
----
Crypt-PBC-0.852
http://search.cpan.org/~jettero/Crypt-PBC-0.852/
OO interface for the Stanford PBC library 
----
DSlib-2.13
http://search.cpan.org/~madz/DSlib-2.13/
----
Data-AMF-0.02002
http://search.cpan.org/~typester/Data-AMF-0.02002/
serialize / deserialize AMF data 
----
Data-ParseBinary-0.04
http://search.cpan.org/~semuelf/Data-ParseBinary-0.04/
Yet Another parser for binary structures 
----
Finance-Quote-Hollywood-1
http://search.cpan.org/~kryde/Finance-Quote-Hollywood-1/
download Hollywood Stock Exchange quotes 
----
Gaim-Log-Parser-0.14
http://search.cpan.org/~mschilli/Gaim-Log-Parser-0.14/
Parse Gaim's Log Files 
----
Google-Chart-0.05003
http://search.cpan.org/~dmaki/Google-Chart-0.05003/
Interface to Google Charts API 
----
Graphics-Primitive-0.15
http://search.cpan.org/~gphat/Graphics-Primitive-0.15/
Device and library agnostic graphic primitives 
----
Graphics-Primitive-0.16
http://search.cpan.org/~gphat/Graphics-Primitive-0.16/
Device and library agnostic graphic primitives 
----
HTML-BBCode-2.04
http://search.cpan.org/~blom/HTML-BBCode-2.04/
Perl extension for converting BBcode to HTML. 
----
HTTP-Engine-0.0.13
http://search.cpan.org/~yappo/HTTP-Engine-0.0.13/
Web Server Gateway Interface and HTTP Server Engine Drivers (Yet Another Catalyst::Engine) 
----
HTTP-Engine-Compat-0.01
http://search.cpan.org/~yappo/HTTP-Engine-Compat-0.01/
version 0.0.12 Compatibility layer of HTTP::Engine 
----
HTTPEx-Declare-0.02
http://search.cpan.org/~yappo/HTTPEx-Declare-0.02/
Declarative HTTP::Engine 
----
JSON-DWIW-0.27
http://search.cpan.org/~dowens/JSON-DWIW-0.27/
JSON converter that Does What I Want 
----
Layout-Manager-0.12
http://search.cpan.org/~gphat/Layout-Manager-0.12/
2D Layout Management 
----
Log-Log4perl-CommandLine-0.03
http://search.cpan.org/~ctilmes/Log-Log4perl-CommandLine-0.03/
Simple Command Line Interface for Log4perl 
----
Math-GSL-0.08
http://search.cpan.org/~leto/Math-GSL-0.08/
Perl interface to the GNU Scientific Library (GSL) 
----
Method-Specialize-0.01
http://search.cpan.org/~nuffin/Method-Specialize-0.01/
Generate per-subclass variants for your methods. 
----
MySQL-Slurp-0.24
http://search.cpan.org/~ctbrown/MySQL-Slurp-0.24/
Use PIPEs to import a file into MySQL table. 
----
MySQL-Slurp-0.25
http://search.cpan.org/~ctbrown/MySQL-Slurp-0.25/
Use PIPEs to import a file into MySQL table. 
----
MySQL-Slurp-0.251
http://search.cpan.org/~ctbrown/MySQL-Slurp-0.251/
Use PIPEs to import a file into MySQL table. 
----
Net-Domain-ExpireDate-0.92
http://search.cpan.org/~despair/Net-Domain-ExpireDate-0.92/
obtain expiration date of domain names 
----
Net-FireEagle-1.2
http://search.cpan.org/~simonw/Net-FireEagle-1.2/
access Yahoo's new FireEagle location service 
----
Net-Pcap-Easy-1.31
http://search.cpan.org/~jettero/Net-Pcap-Easy-1.31/
Net::Pcap is awesome, but it's difficult to bootstrap 
----
Net-Pcap-Easy-1.32
http://search.cpan.org/~jettero/Net-Pcap-Easy-1.32/
Net::Pcap is awesome, but it's difficult to bootstrap 
----
Net-Plazes-0.01
http://search.cpan.org/~rpettett/Net-Plazes-0.01/
----
Net-Squid-Auth-Plugin-SimpleLDAP-0.01.02
http://search.cpan.org/~russoz/Net-Squid-Auth-Plugin-SimpleLDAP-0.01.02/
A simple LDAP-based credentials validation plugin for Net::Squid::Auth::Engine 
----
Net-Zemanta-0.3
http://search.cpan.org/~avian/Net-Zemanta-0.3/
----
PDF-Burst-1.05
http://search.cpan.org/~leocharre/PDF-Burst-1.05/
create one pdf doc for each page in existing pdf document 
----
POE-Component-Client-MPD-0.9.0
http://search.cpan.org/~jquelin/POE-Component-Client-MPD-0.9.0/
a full-blown mpd client library 
----
Parse-Marpa-0.211_012
http://search.cpan.org/~jkegl/Parse-Marpa-0.211_012/
Earley's algorithm with LR(0) precomputation 
----
Parse-Marpa-0.212000
http://search.cpan.org/~jkegl/Parse-Marpa-0.212000/
Earley's algorithm with LR(0) precomputation 
----
Queue-Q4M-0.00012
http://search.cpan.org/~dmaki/Queue-Q4M-0.00012/
Simple Interface To q4m 
----
Reaction-0.001001
http://search.cpan.org/~mstrout/Reaction-0.001001/
----
Rose-DBx-Object-Renderer-0.26
http://search.cpan.org/~danny/Rose-DBx-Object-Renderer-0.26/
Web UI Rendering for Rose::DB::Object 
----
String-Comments-Extract-0.01
http://search.cpan.org/~rkrimen/String-Comments-Extract-0.01/
Extract comments from C, C++, and JavaScript 
----
String-Comments-Extract-0.02
http://search.cpan.org/~rkrimen/String-Comments-Extract-0.02/
Extract comments from C/C++/JavaScript/Java source 
----
TAP-Formatter-HTML-0.05
http://search.cpan.org/~spurkis/TAP-Formatter-HTML-0.05/
TAP Test Harness output delegate for html output 
----
Template-Toolkit-2.20
http://search.cpan.org/~abw/Template-Toolkit-2.20/
Template Processing System 
----
Tree-RB-0.4
http://search.cpan.org/~arunbear/Tree-RB-0.4/
Perl implementation of the Red/Black tree, a type of balanced binary search tree. 
----
WWW-WhitePages-2008.0813
http://search.cpan.org/~ermeyers/WWW-WhitePages-2008.0813/
WhitePages Development Interface (WPDI) 
----
Web-oEmbed-0.01
http://search.cpan.org/~miyagawa/Web-oEmbed-0.01/
oEmbed consumer 
----
XML-Parser-Lite-Tree-XPath-0.20
http://search.cpan.org/~iamcal/XML-Parser-Lite-Tree-XPath-0.20/
----
XML-RelaxNG-Compact-PXB-0.10
http://search.cpan.org/~mpg/XML-RelaxNG-Compact-PXB-0.10/
create perl XML (RelaxNG Compact) data binding API 
----
XUL-App-0.09
http://search.cpan.org/~agent/XUL-App-0.09/
Nifty XUL apps in a XUL::App 
----
Zscore-0.00001
http://search.cpan.org/~miki/Zscore-0.00001/
Simple scoring module that uses statistics STANDARD SCORE. 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


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

Date: Thu, 14 Aug 2008 06:21:31 -0700 (PDT)
From: hofer <blabla@dungeon.de>
Subject: perlish way for ( 0 .. $n) , but downcounting
Message-Id: <3652dbb9-817f-4275-8714-825024e47658@b30g2000prf.googlegroups.com>

Hi,

I know I can live without it or with a self written iterator
or . . . , but would still like to know
other perlish ways


creating an array with numbers from 0 to 9 i would use
@a = (0...9);
for the reverse
@a = reverse(0..9);

cycling trough 0 to n (n verly large)
I'd do
$n=100000;
foreach $v (0..$n){ dowith($v) }
# If I understood well the (0..$n) would NOT create a list, but act as
iterator

for the reverse I'd hesitate to use reverse() as it creates probably
the entire list first
so I'd do either
foreach $v_up (0..$n) { $v_down = $n-$v; dowith($v); }

or foreach( $v=$n;$v>=0;$v--){ dowith($v); }



Does anybody have a 'nicer' way ?







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

Date: Thu, 14 Aug 2008 14:55:34 -0000
From: Justin C <justin.0805@purestblue.com>
Subject: Re: perlish way for ( 0 .. $n) , but downcounting
Message-Id: <4272.48a44766.38687@zem>

On 2008-08-14, hofer <blabla@dungeon.de> wrote:
> Hi,
>
> I know I can live without it or with a self written iterator
> or . . . , but would still like to know
> other perlish ways
>
>
> creating an array with numbers from 0 to 9 i would use
> @a = (0...9);
> for the reverse
> @a = reverse(0..9);
>
> cycling trough 0 to n (n verly large)
> I'd do
> $n=100000;
> foreach $v (0..$n){ dowith($v) }
> # If I understood well the (0..$n) would NOT create a list, but act as
> iterator

[snip]

Not pretty, but works without warnings:

my $i = 1000

for ( -$i .. 0 ) {
    print "$i\n";
    $i--;
}

	Justin.

-- 
Justin C, by the sea.


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

Date: Thu, 14 Aug 2008 15:35:58 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Re: perlish way for ( 0 .. $n) , but downcounting
Message-Id: <slrnga8k6u.f9l.willem@snail.stack.nl>

Justin C wrote:
) Not pretty, but works without warnings:
)
) my $i = 1000
)
) for ( -$i .. 0 ) {
)     print "$i\n";
)     $i--;
) }

Why not go all the way then:

  for (-1000 .. 0) { dowith(-$_) }


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


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

Date: Thu, 14 Aug 2008 10:24:15 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: perlish way for ( 0 .. $n) , but downcounting
Message-Id: <140820081024154643%jimsgibson@gmail.com>

In article
<3652dbb9-817f-4275-8714-825024e47658@b30g2000prf.googlegroups.com>,
hofer <blabla@dungeon.de> wrote:

> Hi,
> 
> I know I can live without it or with a self written iterator
> or . . . , but would still like to know
> other perlish ways
> 
> 
> creating an array with numbers from 0 to 9 i would use
> @a = (0...9);
> for the reverse
> @a = reverse(0..9);
> 
> cycling trough 0 to n (n verly large)
> I'd do
> $n=100000;
> foreach $v (0..$n){ dowith($v) }
> # If I understood well the (0..$n) would NOT create a list, but act as
> iterator
> 
> for the reverse I'd hesitate to use reverse() as it creates probably
> the entire list first
> so I'd do either
> foreach $v_up (0..$n) { $v_down = $n-$v; dowith($v); }
> 
> or foreach( $v=$n;$v>=0;$v--){ dowith($v); }
> 
> 
> 
> Does anybody have a 'nicer' way ?

Not any nicer, but different:

  my $v = $n;
  while( $v-- >= 0 ) {
    dowith($v);
  }

-- 
Jim Gibson


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

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 V11 Issue 1793
***************************************


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