[19220] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1415 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 31 11:05:59 2001

Date: Tue, 31 Jul 2001 08:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <996591913-v10-i1415@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 31 Jul 2001     Volume: 10 Number: 1415

Today's topics:
        Accessing https URLs <michael.vonk@nrl.navy.mil>
    Re: Annoying emacs cperl mode error <bkennedy99@Home.com>
        automated testing <ericm@iol.ie>
    Re: automated testing <ilya@martynov.org>
    Re: chess in perl (Anno Siegel)
    Re: Cleaning replacing the value of a constant <bernie@fantasyfarm.com>
    Re: Cleaning replacing the value of a constant <bernie@fantasyfarm.com>
    Re: Cleaning replacing the value of a constant <godzilla@stomp.stomp.tokyo>
    Re: Cleaning replacing the value of a constant <godzilla@stomp.stomp.tokyo>
    Re: Cleaning replacing the value of a constant <godzilla@stomp.stomp.tokyo>
    Re: Entire File Contents from Command line (Chandramohan Neelakantan)
        Error installing packages using ActiveState ppm (Anthony_Barker)
        FAQ: Why don't my <<HERE documents work? <faq@denver.pm.org>
        Finding All Combinations <caughran@chem.uga.edu>
        Help on Array ? (Tim)
    Re: Help on Array ? <yanoff@yahoo.com>
    Re: Help on Array ? <holland@origo.ifa.au.dk>
    Re: Help on Array ? <andras@mortgagestats.com>
    Re: Help Please <mjcarman@home.com>
    Re: Help with an array and foreach <godzilla@stomp.stomp.tokyo>
    Re: Help with an array and foreach <paul.johnston@dsvr.co.uk>
    Re: Help with an array and foreach <holland@origo.ifa.au.dk>
    Re: How to loop over files whose names are listed in a  (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 31 Jul 2001 10:39:08 -0400
From: "Michael G. Vonk" <michael.vonk@nrl.navy.mil>
To: michael.vonk@nrl.navy.mil
Subject: Accessing https URLs
Message-Id: <3B66C30C.8D4ADF7@nrl.navy.mil>

Hello,

I am using Active Perl 5.6 Build 623 on Windows NT 4.0
and am trying to get the contents of a URL using https.  I see
in the lwpcook documentation that an SSL interface for LWP
must be installed.  But I do not see any README.SSL
file that tells how to do this.  Can someone tell me what I
need to do?

Thanks,
Michael G. Vonk
michael.vonk@nrl.navy.mil


PS.  Here is the lwpcook documentation:

HTTPS
URLs with https scheme are accessed in exactly the same way as with http
scheme, provided that an SSL interface module for LWP has been properly
installed (see the README.SSL file found in the libwww-perl distribution
for more details). If no SSL interface is installed for LWP to use, then
you will get ``501 Protocol scheme 'https' is not supported'' errors
when accessing such URLs.

Here's an example of fetching and printing a WWW page using SSL:

  use LWP::UserAgent;
  my $ua = LWP::UserAgent->new;
  my $req = HTTP::Request->new(GET => 'https://www.helsinki.fi/');
  my $res = $ua->request($req);
  if ($res->is_success) {
      print $res->as_string;
  } else {
      print "Failed: ", $res->status_line, "\n";
  }





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

Date: Tue, 31 Jul 2001 14:11:51 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: Annoying emacs cperl mode error
Message-Id: <H0z97.55465$EP6.12709198@news1.rdc2.pa.home.com>


"kj0" <kj0@mailcity.com> wrote in message
news:9k3jev$qa2$1@panix3.panix.com...
>
>
> In my_script.pl, emacs' cperl mode fails to fontify all the text after
> the line:
>
>   my $pat = qr/<[^<]*?>/;
>
> If I hit M-g M-g, I get the error message:
>   Fontifying my_script.pl... (regexps................)
>   End of `qr/ ... /' string/RE not found: (scan-error Unbalanced
parentheses 2263 7191)
>
> How can I fix this problem?
>
> (I'm using emacs 20.5.1)

I couldn't duplicate the error with 20.7.1, nor was M-g M-g bound to
anything, perhaps the bindings have changed?  Anyway, usually in a regexp
some extraneous backslashing will help the syntax recognition, try using \<
and \>.  It doesn't affect the validity of the Perl syntax.  In an unrelated
note, you should try HTML::Parser which can make life much pleasant for
html-parsing.

--Ben Kennedy




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

Date: Tue, 31 Jul 2001 12:27:02 GMT
From: "Eric Mosley" <ericm@iol.ie>
Subject: automated testing
Message-Id: <qux97.17779$N97.11381@news.iol.ie>

Hi,

Does anybody know of any tools for automating the testing of web forms onto
cgi perl processing programs?

Very simply, all it has to do is accept the URL of a web form and submit the
form with test data in different configurations.

Anything like that exist?

Eric




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

Date: 31 Jul 2001 16:35:50 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: automated testing
Message-Id: <87y9p5mg2h.fsf@abra.ru>


EM> Hi,
EM> Does anybody know of any tools for automating the testing of web
EM> forms onto cgi perl processing programs?

EM> Very simply, all it has to do is accept the URL of a web form and
EM> submit the form with test data in different configurations.

EM> Anything like that exist?

Look at HTTP::WebTest

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 31 Jul 2001 10:36:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: chess in perl
Message-Id: <9k61o6$spq$1@mamenchi.zrz.TU-Berlin.DE>

According to Alan Barclay <gorilla@elaine.furryape.com>:
> In article <abf786a.0107261006.3b9708c0@posting.google.com>,
> Sean Mintz <stmintz@yahoo.com> wrote:
> >The code is at http://www.coe.uh.edu/~smintz/goober/new/Goober.pm
> >
> >Please help me! Speed is -very- important and I don't know what else
> >to do to make it faster.
> 
> The procedure for making any program faster is
> 
> 1) Check the algorythmn. If you've got the wrong algorythmn, then you

Apologies for the pedantry, but please: "algorithm".

Anno


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

Date: Tue, 31 Jul 2001 09:12:49 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: Cleaning replacing the value of a constant
Message-Id: <5b9dmtgkv44fjlb8h2dadub4u6bj885qeb@news.supernews.net>

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:

} Bernie Cosell wrote:
} 
} (snipped)
}  
} > In my other thread [on problems with fcntl file locking] I discovered that
} > in my Perl installation, the constant F_SETLKW has the wrong value
} 
} Perhaps the wrong value based on system specific variables.

Almost certainly.  Turns out that it is the version of Perl that is
*bundled* with RH7.1, so we didn't compile it or have any control over its
Config.  [obviously this is something that we could do something about, but
for the nonce, I was only interested in patching-around the bad constant
and getting on with things].

} > [probably all the fcntl locking-constants do,
} 
} They work ok on Solaris / UNIX at least those I have tested
} which does not include your F_SETLKW constant.

Someone emailed me that *some* version of Solaris showed a similar problem.
Obviously, other versions don't.  The machinery in the [C-world] fcntl.h
header file is pretty complicated, with #ifdef's on top of #ifdefs's, and
so it appears that there are at least *some* Unix setups where the
C-compiler derives one set of values for those constants, but the Perl
Config stuff ends up using a different value.    I was going to report this
as a bug to RedHat [who are the folks who configured and built the Perl
we're running]...

} This may or may not help you. I am running a Win32 box which
} does not allow file locking. However, I was able to pull a
} few tricks and gleen some information.

} This is what I did. At line 95 - 96 in fcntl.pm this is found:
} 
} 95	F_SETLKW
} 96	F_SETLKW64
} 
} This was modified to read:
} 
} 95	F_SETLKW7
} 96	F_SETLKW64
} 
} You should find this somewhere between lines 90 to 100, inclusive
} in your copy of fcntl.pm for modification. Unfortunately, I cannot
} determine what number is correct not being able to run this module
} on a Win32 box. I tagged on "7" and took a chance. However, this 
} modification will at least import F_SETLWK into your main package.
} Perhaps you can run some tests, run some experiments, and determine
} how to define this macro to work on your machine.

Ah --- I still don't quite understand how the 'export' finds the values of
the various constants to export, but I do have a similar table in Fcntl.pm:

                 F_SETFD
                 F_SETFL
                 F_SETLK
                 F_SETLK64
                 F_SETLKW
                 F_SETLKW64
                 F_SETOWN
                 F_SHARE

At the least, I could edit-out the entry for F_SETLKW and then that
wouldn't have my main:: symtabl "polluted" with the wrong value, which I
suspect I could then assign properly.

  tnx..
    /Bernie\
-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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

Date: Tue, 31 Jul 2001 09:12:50 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: Cleaning replacing the value of a constant
Message-Id: <pdbdmtojkfdlr5up249oh70gd8efmsbq82@news.supernews.net>

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:

} Bernie Cosell wrote:
} 
} (snipped a lot)
}  
} > In my other thread [on problems with fcntl file locking] I discovered that
} > in my Perl installation, the constant F_SETLKW has the wrong value
}  
} > so I'd like to 'correct' that.  I tried:
}  
} >    use Fcntl;
} >    use constant F_SETLKW => 7 ;
} 
} According to documentation for fcntl, this syntax,
} 
} use Fcntl ":Fcompat";
} 
} ...should import only the old fashion Fwhatever symbols,
} like fasync, fnonblock, but not the F_ whatever symbols
} with which you are currently working; f_setlkw.
} 
} Being a rogue programmer, as is my habit, I ignored what
} documentation indicates and experimented. I am able to
} successfully import F_SETLKW into main:: using this
} syntax, which should not work, but does:
} 
} use Fcntl ":Fcompat";
} use constant F_SETLKW;

doesn't work [or at least doesn't do anything useful] on RedHat.  I can do
the ":Fcompat", but that just makes using Fcntl, at all, problematic, since
I lose F_WRLCK and such, and if I"m gong to use constant all the F_ values,
Fcntl.pm didn't do me any good...

Aha... but that DOES point at the solution for my little problem.  Just do
an explict-import.  This works fine:

   use Fcntl qw(F_WRLCK F_RDLCK);
   use constant F_SETLKW => 7;

I still don't understand how Fcntl gets the values for the constants it
exports [from an XS file I assume, yes??] but at the least I can block the
erroneous value of F_SETLKW..  Thanks!

  /Bernie\

} 
} As indicated in my other article, I cannot venture too far
} on this with my Win32 box not supporting file lock. However,
} you might consider using this "wrong" syntax above and
} discover if your F_SETLKW works right. With this rogue
} syntax, it is being defined as a macro and, is being
} successfully imported, with NO modification to fcntl.pm
} as exemplified in my parallel article.
} 
} Here is my test code which will print main:: contents.
} You will find your constant in there but, this time,
} F_SETLKW64 will NOT be present, which is a good sign.
} 
} #!perl
} 
} print "Content-type: text/plain\n\n";
} 
} use Fcntl ":Fcompat";
} use constant F_SETLKW;
} 
} foreach $key_name (keys %main::)
}  {  print "$key_name \n"; }
} 
} print "done";
} 
} exit;
} 
} You will discover it is much easier to view this long
} list with a browser; scrolling and searching are afforded.
} 
} 
} Godzilla!

-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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

Date: Tue, 31 Jul 2001 06:45:19 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Cleaning replacing the value of a constant
Message-Id: <3B66B66F.7FB135BA@stomp.stomp.tokyo>

Bernie Cosell wrote:
 
> Godzilla! wrote:
> } Bernie Cosell wrote:

(snipped)

> I still don't understand how Fcntl gets the values for the constants it
> exports [from an XS file I assume, yes??] but at the least I can block the
> erroneous value of F_SETLKW..  Thanks!


Yes, I believe so. I find no math or number conversion within
the module itself setting hardcode numbers for symbol syntax.
You should be able to open and examine your associated xs file.
This is very difficult on a Win32 box. Those xs files are binary
compiled into Dynamic Link Libraries and given names which do not
point to any specific module. There are more than a dozen, with
most having a direct dependency upon other dll files.

It is of interest dependent can be correctly spelled as either
dependent or dependant even dependance but dependency cannot be
spelled as dependancy, rather only as dependency.

This seems analogous to how a Win32 box operates with fcntl being
available but unusable. Win32 has both dependent and dependant but
you cannot hold any dependency upon either actually working.


Godzilla!


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

Date: Tue, 31 Jul 2001 07:29:15 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Cleaning replacing the value of a constant
Message-Id: <3B66C0BB.AF437FA3@stomp.stomp.tokyo>

Bernie Cosell wrote:
 
> Godzilla! wrote:
> } Bernie Cosell wrote:

(snipped)

> Aha... but that DOES point at the solution for my little problem.  Just do
> an explict-import.  This works fine:
 
>    use Fcntl qw(F_WRLCK F_RDLCK);
>    use constant F_SETLKW => 7;

 
#!perl

print "Content-type: text/plain\n\n";

use Fcntl qw(F_WRLCK F_RDLCK);
use constant F_SETLKW => 7;

print F_SETLKW * 1;

print "\n\n";

print F_SETLKW * 2;

exit;


PRINTED RESULTS:
________________

7

14



Godzilla!


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

Date: Tue, 31 Jul 2001 07:59:06 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Cleaning replacing the value of a constant
Message-Id: <3B66C7BA.71A03F41@stomp.stomp.tokyo>

Bernie Cosell wrote:
 
> Godzilla! wrote:
> } Bernie Cosell wrote:

(snipped)

> } > so I'd like to 'correct' that.  I tried:

> } >    use Fcntl;
> } >    use constant F_SETLKW => 7 ;

> } According to documentation for fcntl, this syntax,

> } use Fcntl ":Fcompat";

> } ...should import only the old fashion Fwhatever symbols,
> } like fasync, fnonblock, but not the F_ whatever symbols
> } with which you are currently working; f_setlkw.

> } Being a rogue programmer, as is my habit, I ignored what
> } documentation indicates and experimented. I am able to
> } successfully import F_SETLKW into main:: using this
> } syntax, which should not work, but does:

> } use Fcntl ":Fcompat";
> } use constant F_SETLKW;
 
> doesn't work [or at least doesn't do anything useful] on RedHat.  I can do
> the ":Fcompat", but that just makes using Fcntl, at all, problematic, since
> I lose F_WRLCK and such, and if I"m gong to use constant all the F_ values,
> Fcntl.pm didn't do me any good...



* rogue demure smile *

Godzilla!
--

TEST SCRIPT:
____________

#!perl

print "Content-type: text/plain\n\n";

use Fcntl ":Fcompat";

use constant F_SETLKW => 2;
use constant F_WRLCK => 4;
use constant F_RDLCK => 6;

print F_SETLKW * 1;

print "\n\n";

print F_WRLCK * 1;

print "\n\n";

print F_RDLCK * 1;

print "\n\n";

foreach $key_name (keys %main::)
 {  print "$key_name \n"; }

exit;


PRINTED RESULTS:
________________

2

4

6

(following results are snipped)

key_name 
FSYNC 
FASYNC 
FNONBLOCK 

F_RDLCK 

FNDELAY 
FLARGEFILE 
Fcntl:: 
FDSYNC 
FTRUNC 
FRSYNC 

F_WRLCK 

_<Fcntl.c 
FDEFER 

F_SETLKW 

FCREAT 
FEXCL 
FAPPEND 

main::


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

Date: 31 Jul 2001 04:24:10 -0700
From: grip62501@yahoo.com (Chandramohan Neelakantan)
Subject: Re: Entire File Contents from Command line
Message-Id: <35fbdd3b.0107310324.208a6287@posting.google.com>

> The shorted pure perl way I know is this:
> 
>   use FileHandle;
>   ..
>   @file = (new FileHandle "filename")->getlines();
> 
> Pedants note that this does close the file!
> 
> Paul


 Thanks for the wealth of info. Thanks to John Krahn too.

regards
CM


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

Date: 31 Jul 2001 06:37:43 -0700
From: anthony_barker@hotmail.com (Anthony_Barker)
Subject: Error installing packages using ActiveState ppm
Message-Id: <899f842.0107310537.3e7ce53b@posting.google.com>

Hi

I am using 5.6.1 of ActiveState perl (unfortunately must be Windoze).
Trying to install different pod packages.

Get the error:

Error installing package 'Net-DNS': Read a PPD for 'Net-DNS', but it
is not intended for this build of Perl (MSWin32-x86-multi-thread).

Also go to activestate site directly, download and install from hard
drive - same error. Tried many other packages... all same error.

Is there a problem with this version of ActiveState? I read somewhere
else that another person downgraded his version and the error went
away.

Any suggestions?

Anthony Barker


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

Date: Tue, 31 Jul 2001 12:19:32 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: Why don't my <<HERE documents work?
Message-Id: <onx97.13$Ivk.171028992@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  Why don't my <<HERE documents work?

    Check for these three things:

    1. There must be no space after the << part.
    2. There (probably) should be a semicolon at the end.
    3. You can't (easily) have any space in front of the tag.
    If you want to indent the text in the here document, you can do this:

        # all in one
        ($VAR = <<HERE_TARGET) =~ s/^\s+//gm;
            your text
            goes here
        HERE_TARGET

    But the HERE_TARGET must still be flush against the margin. If you want
    that indented also, you'll have to quote in the indentation.

        ($quote = <<'    FINIS') =~ s/^\s+//gm;
                ...we will have peace, when you and all your works have
                perished--and the works of your dark master to whom you
                would deliver us. You are a liar, Saruman, and a corrupter
                of men's hearts.  --Theoden in /usr/src/perl/taint.c
            FINIS
        $quote =~ s/\s*--/\n--/;

    A nice general-purpose fixer-upper function for indented here documents
    follows. It expects to be called with a here document as its argument.
    It looks to see whether each line begins with a common substring, and if
    so, strips that substring off. Otherwise, it takes the amount of leading
    whitespace found on the first line and removes that much off each
    subsequent line.

        sub fix {
            local $_ = shift;
            my ($white, $leader);  # common whitespace and common leading string
            if (/^\s*(?:([^\w\s]+)(\s*).*\n)(?:\s*\1\2?.*\n)+$/) {
                ($white, $leader) = ($2, quotemeta($1));
            } else {
                ($white, $leader) = (/^(\s+)/, '');
            }
            s/^\s*?$leader(?:$white)?//gm;
            return $_;
        }

    This works with leading special strings, dynamically determined:

        $remember_the_main = fix<<'    MAIN_INTERPRETER_LOOP';
            @@@ int
            @@@ runops() {
            @@@     SAVEI32(runlevel);
            @@@     runlevel++;
            @@@     while ( op = (*op->op_ppaddr)() );
            @@@     TAINT_NOT;
            @@@     return 0;
            @@@ }
        MAIN_INTERPRETER_LOOP

    Or with a fixed amount of leading whitespace, with remaining indentation
    correctly preserved:

        $poem = fix<<EVER_ON_AND_ON;
           Now far ahead the Road has gone,
              And I must follow, if I can,
           Pursuing it with eager feet,
              Until it joins some larger way
           Where many paths and errands meet.
              And whither then? I cannot say.
                    --Bilbo in /usr/src/perl/pp_ctl.c
        EVER_ON_AND_ON

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           04.36
-- 
    This space intentionally left blank


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

Date: Tue, 31 Jul 2001 11:00:52 -0400
From: Joel Caughran <caughran@chem.uga.edu>
Subject: Finding All Combinations
Message-Id: <3B66C824.CD1D1FF5@chem.uga.edu>

I working on a problem where I need to find all of the combinations of n
out of a set of m items.  I've got two systems that I can use but
neither works well.  I'm hoping someone has an alternative.

I can use a set of n for loops to create the combinations.  If I want
combinations of 4 ($n=4) then the following look would work.

for $i (0..$m-($n-1)) {
  for $j ($i+1..$m-($n-2)) {
    for $k ($j+1..$m-($n-3) {
      for $l ($k+1..$m-($n-4) {
        print "$i, $j, $k, $l \n";
      }
    }
  }
}

Problem is that it has to be hard coded into the program.  If I want to
change n to 3 or 5, I have to modify the program.

I can use a function that is called recursivly to find the
combinations.  Here is one where I pass the function the number of items
in each combination and the array of items to be used:

sub combinations {
	my($number_items_to_return, @values) = @_;
	my(@combinations) = ();

	if ($number_items_to_return == 1) {
		for (my($i)=0; $i<@values; $i++) {
			push @combinations, [ $values[$i] ];
		}
	} else {
          for (my($i)=0; $i<=@values-$number_items_to_return; $i++) {
               #    Setup some temporary arrays and make sure they are
blank;
               my(@subcombinations, @temp_array) = ();

               #    Build array of remaining items
               for (my($j)=$i+1; $j<@values; $j++) {
                    push(@temp_array, $values[$j]);
               }
               #    Get combinations of remaining items
               push @subcombinations,
(combinations($number_items_to_return-1, @temp_array));
               #    Now prepend the inital value to each subcombination
               for (my($j)=0; $j < @subcombinations; $j++) {
                    unshift @{ $subcombinations[$j] }, $values[$i];
               }
               #    Now append the new combinations to the already
existing combinations
			push @combinations, ( @subcombinations );
          }
	}

     #    now return the combinations that have been created.
     return @combinations;
}

Problem here is that the function returns the list of all combinations
at one time.  If it is a small set, that isn't a problem.  If it is a
large set, then it is easy for the system to run out of memory.

I have read about closure functions and have built a couple of simple
iterators.  It seems that it should be possible to build a closure
function that managed a stream of combinations.  So far I can't get a
recursive closure function to work.

Does anyone have any suggestions?

Joel Caughran
-- 
Joel A Caughran                 caughran@chem.uga.edu
Chemistry Learning Center       caughran@uga.edu
Department of Chemistry
University of Georgia           (706) 542-1906 voice
Athens, Georgia 30602-2556      (706) 542-9454 fax


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

Date: 31 Jul 2001 07:34:14 -0700
From: tvn007@hotmail.com (Tim)
Subject: Help on Array ?
Message-Id: <21724be2.0107310634.58579dc6@posting.google.com>

Hi,

Could someone please help me on this ?

Below is my script:


@in1=(10); #Please DO NOT MODIFY the ARRAY 
@in2=(AB);
$"="";
for ($i=0;$i<=2;$i++){

	print "@in1[$i] @in2[$i]\n";
}

THe ouput of the script above is:

10 AB

However, I would like the output to be

1 A
0 B

Any help would be greatly appriciate !!


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

Date: Tue, 31 Jul 2001 09:43:50 -0500
From: Scott Yanoff <yanoff@yahoo.com>
To: Tim <tvn007@hotmail.com>
Subject: Re: Help on Array ?
Message-Id: <3B66C426.EADE4FEC@yahoo.com>

Tim wrote:
> 
> Hi,
> 
> Could someone please help me on this ?
> 
> Below is my script:
> 
> @in1=(10); #Please DO NOT MODIFY the ARRAY
> @in2=(AB);
> $"="";
> for ($i=0;$i<=2;$i++){
> 
>         print "@in1[$i] @in2[$i]\n";
> }
> 
> THe ouput of the script above is:
> 
> 10 AB
> 
> However, I would like the output to be
> 
> 1 A
> 0 B

If you are really populating the arrays within your script, I think you
might want to look at comma-separating the values within the array as
follows:

 @in1=(1, 0); #Please DO NOT MODIFY the ARRAY
 @in2=("A", "B");

Good luck,

-Scott
yanoff@yahoo.com | http://www.yanoff.org | AOL IM: SAY KJY


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

Date: 31 Jul 2001 16:53:11 +0200
From: Steve Holland <holland@origo.ifa.au.dk>
Subject: Re: Help on Array ?
Message-Id: <w47y9p58814.fsf@origo.ifa.au.dk>

tvn007@hotmail.com (Tim) writes:

> Could someone please help me on this ?
> 
> Below is my script:
> 
> 
> @in1=(10); #Please DO NOT MODIFY the ARRAY 
> @in2=(AB);
> $"="";
> for ($i=0;$i<=2;$i++){
> 
> 	print "@in1[$i] @in2[$i]\n";
> }
> 
> THe ouput of the script above is:
> 
> 10 AB
> 
> However, I would like the output to be
> 
> 1 A
> 0 B
> 
> Any help would be greatly appriciate !!

     Use the split operator.

@in1 = (10);
@in2 = (AB);
@in1_characters = split(//,$in1[0]);
@in2_characters = split(//,$in2[0]);
for ( $i=0; $i<=$#in2_characters; $i++ ) {
    print "$in1_characters[$i] $in2_characters[$i]\n";
}
~


=====================================================================
               To find out who and where I am look at:
               http://www.nd.edu/~sholland/index.html
  Spammers: Please send spam to: abuse@aol.com and abuse@yahoo.com
=====================================================================

perl -e '$i="\124a\153e\040o\156e\040d\157w";$o="\040\157n\040t\150e\040w\141l\154$/";$O=$i."\156\040\141n\144\040\160a\163s\040i\164\040\141r\157u\156d";$i=$|;$I=$=/$=;$l="\040\142o\164t\154e\163\040\157f\040b\145e\162";while(){$_=($i==$%)?"N":"N-$i";$i++;$_="$_$l$o$_$l$/$O$/N-$i$l$o$/";print;sleep$I}'


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

Date: Tue, 31 Jul 2001 10:57:00 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: Help on Array ?
Message-Id: <3B66C73B.F553EDED@mortgagestats.com>



Tim wrote:

> @in1=(10); #Please DO NOT MODIFY the ARRAY
> @in2=(AB);

Here you are assigning one-element lists to your arrays. Either
comma-separate the items in your list :
@in1=(1, 0); #Please DO NOT MODIFY the ARRAY
@in2=('A', 'B');
or perhaps use split//.

>
> $"="";
> for ($i=0;$i<=2;$i++){
>
>         print "@in1[$i] @in2[$i]\n";
> }
>
> THe ouput of the script above is:
>
> 10 AB
>
> However, I would like the output to be
>
> 1 A
> 0 B



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

Date: Tue, 31 Jul 2001 08:28:26 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Help Please
Message-Id: <3B66B27A.424297B5@home.com>

Subject: Help Please

This is a lousy subject. Virtually every new thread is someone looking
for help. This article will help you pick a good subject:

http://www.perl.com/CPAN-local/authors/Dean_Roehrich/subjects.post

News Only wrote:
> 
> Can someone help me with a perl script.

Almost certainly. What script would you like help with?

Oh, I see, you don't have one. You want someone to write one for you.
This ng isn't a script-writing service, it's a discussion group. We're
happy to help, but you have to make an effort to help yourself first,
okay?
 
> What I would like it to do is.
> 
> 1. Find all files in a folder with todays date. -----    f:\folder

use File::Find

> 2. read the modify date and time.   -----   07/28/2001  12:53:42 AM

perldoc -f stat (or, the -M function)

> 3. Delete all lines in the files containing a "string"  ----- delete
> "any test here"

perlfaq5: "How do I change one line in a file/delete a line/insert...?"

> 4. Change the modify date back to the original one. -----   07/28/2001
> 12:53:42 AM

Perl doesn't have a builtin to do this, which means you'll need to farm
it out to you OS. You'll want to use either system() or backticks (``)
to do this.

> 5. Must be able to read long file names like "urls_072840000.log"

Also dependant on your OS. Perl doesn't care.

-mjc


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

Date: Tue, 31 Jul 2001 06:18:48 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Help with an array and foreach
Message-Id: <3B66B038.5C0E8012@stomp.stomp.tokyo>

Helgi Briem wrote:
 
> Godzilla! wrote:
> >Ryan Gralinski wrote:

(snipped)

> >> What i need to know, is how can i start this loop
> >> at $start element of the array
> >> f.e instead of starting at $covers[0] start at $covers[1000]

> >Due due to perl core automation, you cannot do this
> >with a foreach loop; it starts at element zero. There
> >is no trick I know of to do this. Perhaps others know.
 
> Not so.  For and foreach are exactly the same
> in function. Foreach is just a more grammatical
> way of writing some things.


I can easily surmise the end of your right index
finger is heavily calloused from reading and,
your brain is still infant soft and tender.

Godzilla!


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

Date: Tue, 31 Jul 2001 14:11:24 +0100
From: Paul Johnston <paul.johnston@dsvr.co.uk>
Subject: Re: Help with an array and foreach
Message-Id: <3B66AE7C.72F3AA95@dsvr.co.uk>

Hi,

> What i need to know, is how can i start this loop
> at $start element of the array
> f.e instead of starting at $covers[0] start at $covers[1000]

If you prefer elegancy to efficiency:

for my $cover (@covers[1000 .. $#covers])
{
  ...
}

If you require efficiency:

for(my $i = 1000; $i <= $#covers; $i++)
{
  my $cover = $covers[$i];
  ...
}

BTW, for can be used in place of foreach, and I like to make my code 4
characters shorter.
If you don't understand what "my" does, don't worry about it for now.

Paul


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

Date: 31 Jul 2001 16:25:41 +0200
From: Steve Holland <holland@origo.ifa.au.dk>
Subject: Re: Help with an array and foreach
Message-Id: <w471ymx9nve.fsf@origo.ifa.au.dk>

Philip Newton <pne-news-20010731@newton.digitalspace.net> writes:
> On 31 Jul 2001 00:42:25 +0200, Steve Holland <holland@origo.ifa.au.dk wrote:

> >      The quick and dirty anwser is to use a while loop instead of
> > foreach.

> Or use for(;;), which is probably more appropriate here if you're
> going to use that sort of construct.

> > my $i = 3;
> > while ($i <= $#x ) {
> >     print "\@x[$i] = @x[$i]\n";
> >     $i++;
> > }

> This is equivalent to

>     for(my $i = 3; $i <= $#x; $i++) {
>         print "\$x[$i] = $x[$i]\n";
>     }

> except for the scoping of $i (though you can declare it with "my
> $i;" before the loop if you want to read it afterwards) and for the
> replacement of your array slice with a proper (scalar) array
> element.

     It's my ForTran roots showing through...

=====================================================================
               To find out who and where I am look at:
               http://www.nd.edu/~sholland/index.html
  Spammers: Please send spam to: abuse@aol.com and abuse@yahoo.com
=====================================================================

perl -e '$i="\124a\153e\040o\156e\040d\157w";$o="\040\157n\040t\150e\040w\141l\154$/";$O=$i."\156\040\141n\144\040\160a\163s\040i\164\040\141r\157u\156d";$i=$|;$I=$=/$=;$l="\040\142o\164t\154e\163\040\157f\040b\145e\162";while(){$_=($i==$%)?"N":"N-$i";$i++;$_="$_$l$o$_$l$/$O$/N-$i$l$o$/";print;sleep$I}'


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

Date: 31 Jul 2001 13:18:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to loop over files whose names are listed in a file
Message-Id: <9k6b68$7ng$1@mamenchi.zrz.TU-Berlin.DE>

According to Benjamin Goldberg  <goldbb2@earthlink.net>:

> This is a read a line at a time version:
> 
> open(my $filelist, "<", "files_list.txt")
> 	or die "Couldn't open files_list.txt: $!\n";
> while(<$filelist>) {
> 	chomp;
> 	my $fichier_out=$fichier . ".tmp";
> 	remplacerBreves($_,$fichier_out);
> }
> close $filelist;
> 
> This is a loop over a list version:
> foreach( do {
> 	open(my $filelist, "<", "files_list.txt")
> 		or die "Couldn't open files_list.txt: $!\n";
> 	<$filelist> } ) {
> 	chomp;
> 	my $fichier_out=$fichier . ".tmp";
> 	remplacerBreves($_,$fichier_out);
> }
> 
> I don't bother to close $filelist in this version, because a lexically
> scoped variable, and the file closes automagically when all references
> go out of scope.

Why do you offer the slurping solution at all?  It makes no sense to
slurp a file this way.  The code is less clear, it uses more memory
and there is absolutely no advantage.

Come to look at it closer, shouldn't it be 

    $fichier_out = $_ . '.tmp';  # output file to match the input file

And, while we're there, why not just

    remplacerBreves( $_, $_ . 'out');

Anno


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

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.  

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


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