[16553] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3965 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 9 14:10:33 2000

Date: Wed, 9 Aug 2000 11:10:22 -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: <965844621-v9-i3965@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 9 Aug 2000     Volume: 9 Number: 3965

Today's topics:
        help parsing excel .cvs files coughlan@gothaminteractive.com
    Re: help parsing excel .cvs files <memmett@fraser.sfu.ca>
    Re: help parsing excel .cvs files <jeff@vpservices.com>
    Re: help parsing excel .cvs files <claytons@nortelnetworks.com>
    Re: How to source a shell script in perl sankarmukh@my-deja.com
    Re: how to USE perl 5.6's assert.pl? <ren.maddox@tivoli.com>
        HTTP::Request::Common::$DYNAMIC_FILE_UPLOAD <wall@bacon.ethz.ch>
    Re: Impossible RegEx Problem <rickysregistration@hotmail.com>
        Interesting problem: starting coprocesses in Korn Shell <rana@hotseat.hobl.lucent.com>
    Re: Is "close()" really necesary? <flavell@mail.cern.ch>
    Re: Is "close()" really necesary? <bart.lateur@skynet.be>
    Re: Large-File Reformatting Problem (Regexp gurus, et a (Greg Bacon)
    Re: Large-File Reformatting Problem (Regexp gurus, et a <ren.maddox@tivoli.com>
    Re: Large-File Reformatting Problem (Regexp gurus, et a <ren.maddox@tivoli.com>
    Re: Newbie questions: What exactly is $_? <juex@deja.com>
        open filehandle to a array or variable <stevehaysom@hotmail.com>
    Re: open filehandle to a array or variable <Peter.Dintelmann@dresdner-bank.com>
    Re: open filehandle to a array or variable <ren.maddox@tivoli.com>
    Re: Oracle connectivity using Perl <newsposter@cthulhu.demon.nl>
    Re: Ordered set of permutations algorithm (Rafael Garcia-Suarez)
    Re: Ordered set of permutations algorithm (Logan Shaw)
    Re: Ordered set of permutations algorithm <abe@ztreet.demon.nl>
        Overriding Builtin Functions <stage3@us.ibm.com>
        Perl Jobs Galore!  Find them here. <anonymous@cotse.com>
    Re: perl sql (delimited) <newsposter@cthulhu.demon.nl>
        problem perl/cgi Apache web server on win 98 Help! <lorraine.macfarlin@manchesteronline.co.uk>
    Re: Problem with Net::Telnet <guenther.degenfelder@datev.de>
    Re: Regular expression to check for non-alphanumeric? <rickysregistration@hotmail.com>
    Re: Regular expression to check for non-alphanumeric? <ren.maddox@tivoli.com>
        Set cookie from SSI <michaelw@gmx.at>
        Sort of a sort problem. <jimmy.lantz@ostas.lu.se>
    Re: Sort of a sort problem. <andras@mortgagestats.com>
    Re: Sort of a sort problem. (Rafael Garcia-Suarez)
    Re: Sort of a sort problem. <ren.maddox@tivoli.com>
    Re: When does it pay to presize an array? <dan@tuatha.sidhe.org>
    Re: When does it pay to presize an array? <ren.maddox@tivoli.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 09 Aug 2000 15:24:05 GMT
From: coughlan@gothaminteractive.com
Subject: help parsing excel .cvs files
Message-Id: <8mrt2b$puq$1@nnrp1.deja.com>

Can someone please help me out with parsing an an exported excel .cvs
file?

I want to break up excel file rows into arrays. The file will contain
all kinds of text.

A simple split command won't work becasue quotes and commas in the data
look like this:

col1, col2, "col3 has a comma - ,", col4, "col5 has ""quotes""! "

I know this wheel has been invented before.  If someone can point me to
a module or subroutine that I can use, I'd greatly appreciate it.  As
you can tell, I'm no perl expert.

Thanks,

Mike Coughlan


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 09 Aug 2000 09:22:58 -0700
From: Matthew Emmett <memmett@fraser.sfu.ca>
Subject: Re: help parsing excel .cvs files
Message-Id: <yvw9k8dqieu5.fsf@fraser.sfu.ca>


Mike,

coughlan@gothaminteractive.com writes:

> Can someone please help me out with parsing an an exported excel
> .cvs file?

Try using the Text::CSV module [1].

Here is some sample code...

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

use strict;
use Text::CSV;

my $csv = Text::CSV->new();

while (<>) {
  $csv->parse($_);
  
  my @r = $csv->fields();

  # now @r contains the cells!
}
################

Matt


1. Searching for 'CSV' on http://search.cpan.org reveals this module.




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

Date: Wed, 09 Aug 2000 09:31:54 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: help parsing excel .cvs files
Message-Id: <3991877A.C1C7E414@vpservices.com>

coughlan@gothaminteractive.com wrote:
> 
> Can someone please help me out with parsing an an exported excel .cvs
> file?
> 
> I want to break up excel file rows into arrays. The file will contain
> all kinds of text.
> 
> A simple split command won't work becasue quotes and commas in the data
> look like this:
> 
> col1, col2, "col3 has a comma - ,", col4, "col5 has ""quotes""! "


This question is addressed in perlfaq4.   If your needs are one time and
simple, use something like Text::ParseWords or the Friedl regex.  If you
need to do multiple searches or sorting, then use DBD::CSV or DBD::RAM
which both treat a CSV file as a SQL accessible database and let you
select, order, and loop through data easily as well as selectively
choose fields to display.

-- 
Jeff


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

Date: Wed, 09 Aug 2000 12:51:13 -0400
From: Clayton Scott <claytons@nortelnetworks.com>
Subject: Re: help parsing excel .cvs files
Message-Id: <39918C01.9B6CACF3@nortelnetworks.com>

coughlan@gothaminteractive.com wrote:
> 
> Can someone please help me out with parsing an an exported excel .cvs
> file?

	I assume you mean "csv" (comma seperated value) files. 
 Have a look on CPAN (www.cpan.org) for Text::CSV or Text::CSV_XS. 
 They will help you do what you need. I would start at
http://search.cpan.org.

Clayton


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

Date: Wed, 09 Aug 2000 17:03:33 GMT
From: sankarmukh@my-deja.com
Subject: Re: How to source a shell script in perl
Message-Id: <8ms2t2$utf$1@nnrp1.deja.com>

Thanks for the suggestion. I still will have this logistics problem -
Exporting user etc from Korn and then running Perl.

There are developer written 50 scripts in Perl. I was planning to
request to source their Perl files . But it seems I can't pass the
variables to Perl. Again, it works for other ksh scripts.

Thanks again and if you have any ideas, please let me know.

Regards,

Sankar




In article <sp2pjt8q63a183@corp.supernews.com>,
  Greg Bacon <gbacon@hiwaay.net> wrote:
> In article <8mrno4$lnh$1@nnrp1.deja.com>,
>      <sankarmukh@my-deja.com> wrote:
>
>
> Don't do that.  You're creating new scalars where the originals would
> do just fine.  (This bad habit can burn you in some cases.)  It's
better
> to say
>
>     $ftp->login ($user, $hspw) || die "Can't login";
>
> : print "Current dir is ", $ftp->pwd, "\n"; $ftp->quit;
> :
> : The cntrlFile is:
> :
> : hbcmgd003:/u/ctssmuk> more cntrlFile
> : #!/bin/ksh
> : set -- `crypt ftp_00 <passfile.enc`
> : user=$1
> : hspw=$2
> : fppw=$3
> : jcpw=$4
>
> Export user, hspw, fppw, and jcpw.  Then call your Perl program from
> the bottom of your Korn shell script.
>
> Greg
> --
> guru, n.:
>         A person in T-shirt and sandals who took an elevator ride with
>         a senior vice-president and is ultimately responsible for the
>         phone call you are about to receive from your boss.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 09 Aug 2000 09:43:10 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: how to USE perl 5.6's assert.pl?
Message-Id: <m3lmy6bim9.fsf@dhcp11-177.support.tivoli.com>

dkcombs@netcom.com (David Combs) writes:

> So, please, how DOES one call something like "assert()", other than
> simply lifing the code in inserting it into my own program
> or library-module?

% perl -le 'require "assert.pl"; assert(0, "BLAH!");'

panic: ASSERTION BOTCHED: 0 

$ = &main::panic('ASSERTION BOTCHED: 0', '') from file /usr/local/ActivePerl-5.6/lib/5.6.0/assert.pl line 15

$ = &main::assert(0, 'BLAH!') from file -e line 1


-- 
Ren Maddox
ren@tivoli.com


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

Date: 09 Aug 2000 19:44:55 +0200
From: Ernst-Udo Wallenborn <wall@bacon.ethz.ch>
Subject: HTTP::Request::Common::$DYNAMIC_FILE_UPLOAD
Message-Id: <uisnsenxbc.fsf@bacon.ethz.ch>




Hi,

this question has been asked a few times before on this forum
(i found a few entries in dejanews), but so far there seems
to be no good answer. But maybe i'm wrong and i am just missing
something obvious. The question is: How do you use the
DYNAMIC_FILE_UPLOAD variable mentioned in the HTTP::Request::Common
perldoc?

I have been trying something in the lines of

#!/usr/bin/perl -wT

use strict;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST $DYNAMIC_FILE_UPLOAD);

$DYNAMIC_FILE_UPLOAD=1;
my $ua=LWP::UserAgent->new();
my $request   =  HTTP::Request::Common::POST
  'http://localhost/cgi-bin/upload.cgi',
  Content_Type => 'form-data',
  Content => [ 'upload' => [ 'foo.bar' ] ];
my $size = (stat 'foo.bar')[7];

$request->content_length($size);
print $request->as_string();
my $response=$ua->request($request);

for my $key (sort keys %$response) {
  print "$key => $response->{$key}\n";
}



Without the DYNAMIC_FILE_UPLOAD line the thing
works on my SuSE 6.4 box (kernel 2.2.16, apache 1.3.12,
perl 5.005_03, libwww-perl-5.48). With the variable set to 1,
as the perldoc recommends, i get an internal server error.

The script above is the prototype for an application
that is supposed to connect from a unix box to a Windows
IIS server, using a proxy and authorization via $ua->proxy and
$ua->authorization_basic.

The files to be uploaded are larger than the memory of
the client, and without DYNAMIC_FILE_UPLOAD i get an occasional
'out of memory' crash. I can see why, but i don't see a workaround.

Help, please?


-- 
Ernst-Udo Wallenborn
Laboratorium fuer Physikalische Chemie
ETH Zuerich


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

Date: Wed, 09 Aug 2000 16:50:47 GMT
From: "Earthlink News" <rickysregistration@hotmail.com>
Subject: Re: Impossible RegEx Problem
Message-Id: <HZfk5.31591$0W4.822324@newsread2.prod.itd.earthlink.net>


Keith Calvert Ivey <kcivey@cpcug.org> wrote in message
news:39a19398.11324817@news.newsguy.com...
> "Earthlink News" <rickysregistration@hotmail.com> wrote:
>
> You might want to read Mark-Jason Dominus's three-part article
> on symbolic references (it's not as long as it sounds):
>
>     http://www.plover.com/~mjd/perl/varvarname.html
>

Hi Keith,

Thanks for that link; I read the first two parts armed with my defense of
"Hey, the config file is under my control, so it's cool"... all set, that
is, until I got to the 3rd part.  Doh!

Definitely food for thought...


Rick.





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

Date: Wed, 09 Aug 2000 13:48:09 -0400
From: Ahmad Rana <rana@hotseat.hobl.lucent.com>
Subject: Interesting problem: starting coprocesses in Korn Shell via Perl
Message-Id: <39919959.123E7C97@hotseat.hobl.lucent.com>

Ok, here's the problem:

testProcess is an executable process in Korn Shell. In Korn Shell, if you want
to start it as a coprocess with its own stdin and stdout, you execute the
following shell-script:

$ testProcess |&
$ exec 3<&p
$ exec 4>&p

Now the file descriptor 3 can be used to refer to the stdout of the coprocess
running in the background, and 4 as the stdin. In other words, if you want to
read the output of the testProcess in the parent shell, you give the command:

$ read -u3 line
$ echo $line

This will write the output of the testProcess to stdout. Similarly:

$ print -u4 "take this\n"

will send the string "take this\n" to the stdin of the co-process testProcess.

Question:

Will the following perl script work?

  exec "testProcess|&";
  exec("exec","3<&p");
  exec("exec", "4>&p");

to replace the first segment of the shell script, and if it would, how to read
this into perl variables. In other words, how to open a file-descriptor in perl
using not its name but its numeric descriptor.

Thanks,
Ahmad.


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

Date: Wed, 9 Aug 2000 16:51:38 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Is "close()" really necesary?
Message-Id: <Pine.GHP.4.21.0008091648140.23130-100000@hpplus03.cern.ch>

On 9 Aug 2000, Andreas Kahari wrote:

> The documentation states that you don't have to close() the handle if
> you IMMEDIATELY are going to do another open() on it.

And note that if you placed a lock on an opened file, it will be
implicitly unlocked when you close it.  So if the lock was intended
to persist (as for example when you wanted to read the contents
of a file, update them, and write the updated contents back, blocking
interference by any* other process), then you better not close and
re-open the file, but hold it open throughout the procedure.

*of course the other processes need to respect the lock protocol too,
since in general file locking is only advisory.




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

Date: Wed, 09 Aug 2000 16:14:30 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Is "close()" really necesary?
Message-Id: <1i03psgnmmd01nrd9te7s4kv8j8db8pnun@4ax.com>

Javier Hijas wrote:

>"Programming Perl" recommends no to use it as a file will be closed when
>you reopen them, so, when should I use this function?

Amongst others, when you want to finalize the file. For example, if you
want to use this file as input when launching an external program, you'd
better make sure that the file is complete, nothing left pending in a
buffer.

On Windows, you can not use rename() to replace an older file, if it
isn't closed.

And, of course, if you locked a file so others can't (shouldn't) touch
it, closing that file will release the lock. But somebody already wrote
that.

-- 
	Bart.


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

Date: Wed, 09 Aug 2000 15:39:55 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Large-File Reformatting Problem (Regexp gurus, et al.)
Message-Id: <sp2uqbd563a177@corp.supernews.com>

In article <8mrq5v$1aa$1@cnn.Princeton.EDU>,
    Christopher J. Mackie <cjmackie@princeton.edu> wrote:

: The proper format is a number of lines of text (1 to approx. 280k
: lines ending in single newlines) separated by exactly one blank line
: (i.e., '\n\n').  The errors consist only of excess whitespace between
: the texts (an unknown and presumably variable number of extra
: newlines, plus, perhaps, some whitespace interspersed-with and/or
: bracketing the newlines).  I have to remove the excess whitespace and
: newlines, leaving only '\n\n', and without removing any of the
: legitimate, line-ending newlines in the interior of the texts.
: 
: $/="";
: while (<>) {
:      s/^[\n\s]+//s; # strip beginning whitespace, incl. newlines
:      s/[\n\s]+$//s; # strip ending whitespace, incl. newlines

\n is part of \s, so

    s/^\s+//s;
    s/\s+\z//;

will suffice.  I like using \z for clarity here.

:      # remove whitespace in any interior blank lines ('1 while' to
:      # ensure overlapping problems get fixed on additional passes)
:      1 while (s/\n\s+\n/\n\n/g);

Remember that the + quantifier is greedy and that \s includes \n.
Using

    s/\n\s+\n/\n\n/g;

you'll capture a blank (but non-empty) line followed by zero or more
blank or empty lines without fear over missing any.

:      # more than two interior newlines becomes two newlines
:      s/\n\n\n+/\n\n/g;

The previous s/// guarantees that this will never succeed.

:      s/\n*$/\n\n/s; # replace final newlines

This will always succeed.  I'd add the pair of newlines at output.

:      # skip outputting line if I've retrieved a (by-error) empty
:      # document (well-formatted texts contain no punctuation or other
:      # non-alpha characters, so \w is fine as a test)
:      next unless /\w/;
: 
:      print;
: }

That makes your filter look like

    $/ = "";
    while (<>) {
        # skip empty records
        next unless /\w/;

        # zap trailing and leading whitespace
        s/^\s+//s;
        s/\s+\z//;

        # turn a single blank line into an empty line
        # compress runs of empty or blank lines into one empty line
        s/\n\s+\n/\n\n/g;

        # add record terminator
        print $_, "\n\n";
    }

Greg
-- 
I have not finished with a woman until I have had her all three ways.
    -- John F. Kennedy.


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

Date: 09 Aug 2000 11:24:12 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Large-File Reformatting Problem (Regexp gurus, et al.)
Message-Id: <m37l9qbdxv.fsf@dhcp11-177.support.tivoli.com>

Ren Maddox <ren.maddox@tivoli.com> writes:

Oops... forgot about extra blank lines....

> # untested
> my $text;
> while(<>) {
>   if (/\S/) {                # Does this line have non-white-space?
>     $text .= $_;
>   } else {
>     print $text, "\n";
      # should be:
      print $text, "\n" if $text;
>     $text = "";
>   }
> }
> print $text, "\n" if $text;  # This will catch the last block if it
>                              # does not have a trailing blank line and
>                              # will also add a trailing blank line
>                              # (leave off the "\n" to prevent that)

Oh, and I did test it, despite my comment to the contrary... :)

-- 
Ren Maddox
ren@tivoli.com


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

Date: 09 Aug 2000 10:56:07 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Large-File Reformatting Problem (Regexp gurus, et al.)
Message-Id: <m3d7jibf8o.fsf@dhcp11-177.support.tivoli.com>


One problem this will have is that the $/="" behavior will not trigger
if a line is not completely blank.  So extra whitespace characters
between the newlines will cause two groups of texts to be treated as
one.

I think you will have to do line by line processing to avoid this.

# untested
my $text;
while(<>) {
  if (/\S/) {                # Does this line have non-white-space?
    $text .= $_;
  } else {
    print $text, "\n";
    $text = "";
  }
}
print $text, "\n" if $text;  # This will catch the last block if it
                             # does not have a trailing blank line and
                             # will also add a trailing blank line
                             # (leave off the "\n" to prevent that)



-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 9 Aug 2000 10:51:25 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Newbie questions: What exactly is $_?
Message-Id: <39919a1d$1@news.microsoft.com>

<fathacka@my-deja.com> wrote in message news:8mq1pc$k3b$1@nnrp1.deja.com...
> Hi,
>
> I did, but I still don't understand what it meant.  It says:
> "The default input and pattern-searching space."
>
> It goes on to give a few examples.  It also says where it is used.
> However, it still doesn't answer some questions I have.  Does it have a
> default value upon entering a subroutine, like @_ does or is it undef?

Neither nor. $_ is a global variable, entering a procedure doesn't affect
it's value (details see below).

> Is $_ at all affiliated with @_, or does it have some fundamental
> difference?

They have nothing to do with each other.

There are some Perl functions (in the widest meaning) which set $_ (e.g. all
loop constructs like for or while) or use $_ as default if no other variable
is specified (e.g. s or print). For details you should consult the man page
for each function.

Therefore you can write e.g.

foreach (@myarray) {     # loops through all elements of @myarray,
             #setting $_ to the value of each element in turn
    s/foo/bar/;        # substitutes the text "foo" with "bar" in $_
    print;            # prints the value of $_ , i.e. effectively the
            # whole array after substituting foo with bar
}

jue







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

Date: Wed, 9 Aug 2000 16:30:02 +0100
From: "Stephen Haysom" <stevehaysom@hotmail.com>
Subject: open filehandle to a array or variable
Message-Id: <3991791d$1@news.telinco.net>

Hi

I was wondering if it is possible to open a filehandle to an array or scalar
variable, or open the filehandle to a temporary file, as I only need the
information to be stored temporarily.

Thanks

Steve Haysom




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

Date: Wed, 9 Aug 2000 18:39:47 +0200
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: open filehandle to a array or variable
Message-Id: <8ms1f4$6704@intranews.dresdnerbank.de>

    Hi,

Stephen Haysom schrieb in Nachricht <3991791d$1@news.telinco.net>...
>I was wondering if it is possible to open a filehandle to an array or
scalar
>variable,

    sorry, but I do not quite understand what you mean. A
    filehandle refers to a file (whatever your OS presents
    you as a "file"). Can you give me some more details
    please?

> or open the filehandle to a temporary file, as I only need the
>information to be stored temporarily.

    sure you can open temporary files. IO::File even offers a
    method new_tmpfile.

        Peter Dintelmann





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

Date: 09 Aug 2000 11:29:49 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: open filehandle to a array or variable
Message-Id: <m34s4ubdoi.fsf@dhcp11-177.support.tivoli.com>

"Stephen Haysom" <stevehaysom@hotmail.com> writes:

> I was wondering if it is possible to open a filehandle to an array or scalar
> variable, or open the filehandle to a temporary file, as I only need the
> information to be stored temporarily.

Please clarify what you are trying to do.  I cannot tell if you are
wanting to read data into an array or scalar, attach an array or
scalar to a file (perldoc perltie), or write some data from an array
or scalar to a file.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 9 Aug 2000 15:26:29 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Oracle connectivity using Perl
Message-Id: <8mrt75$p73$3@internal-news.uu.net>

Peter_Gadsby <peter_gadsbyNOpeSPAM@hfcbank.co.uk.invalid> wrote:

> I'm using IE5 and the code seems to work fine, but users running
> on IE4 the process seems to hang.

> When I modify the script in question ( add a comment, or
> whatever ) the script will then work in both ie4, and ie5.

  If you have a problem with browsers, it seems unlikely that
something is wrong with the Perl/Oracle interface. Perhaps you
are generating incorrect HTML?

Erik



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

Date: Wed, 09 Aug 2000 15:09:38 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Ordered set of permutations algorithm
Message-Id: <slrn8p2tbf.l0p.rgarciasuarez@rafael.kazibao.net>

Keith Scollick wrote in comp.lang.perl.misc:
>Hi all,
>  I have a set of elements that can range anywhere from one to approximately
>ten elements.  What I want to do is create a set of all ordered combinations
>(i.e. the elements on the left stay to the left of any and all elements to
>the right)
>not limited to just returning the combinations with the same number of
>elements
>as the original list (i.e. for a three element list, I want each combination
>of
>two as well).
>
>  For example, given a list (1, 2, 3, 4, 5).  I want to return an array
>containing
>(each element is separated by a comma):
>
>1, 2, 3, 4, 5, 1 2, 1 3, 1 4, 1 5, 2 3, 2 4, 2 5, 3 4, 3 5,
>1 2 3, 1 2 4, 1 2 5, 1 3 4, 1 3 5, 2 3 4, 2 3 5, 3 4 5,
>1 2 3 4, 1 2 3 5, 1 2 4 5, 1 3 4 5, 2 3 4 5, 1 2 3 4 5
>
>  Is there a good way of doing this?  I'm getting bogged down in the
>recursive nature of all this.

An idea for a non recursive algorithm :

  @list = qw(1 2 3 4 5);
  for my $i (1..(1<<($#list+1))) {
    my @result_list = ();
    for my $j (0..$#list) {
      push @result_list, $list[$j] if (1<<$j) & $i;
    }
    print "@result_list\n";
  }

Basically this takes binary numbers 00001 to 11111 and uses it as a mask
for extracting elements of @list.

There are probably ways to improve this code.

-- 
Rafael Garcia-Suarez


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

Date: 9 Aug 2000 11:54:17 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Ordered set of permutations algorithm
Message-Id: <8ms2bp$dck$1@provolone.cs.utexas.edu>

In article <8mrpag$db4$1@tomm.stsci.edu>,
Keith Scollick <scollick@stsci.edu> wrote:
>  I have a set of elements that can range anywhere from one to approximately
>ten elements.  What I want to do is create a set of all ordered combinations

>  For example, given a list (1, 2, 3, 4, 5).  I want to return an array

>1, 2, 3, 4, 5, 1 2, 1 3, 1 4, 1 5, 2 3, 2 4, 2 5, 3 4, 3 5,
>1 2 3, 1 2 4, 1 2 5, 1 3 4, 1 3 5, 2 3 4, 2 3 5, 3 4 5,
>1 2 3 4, 1 2 3 5, 1 2 4 5, 1 3 4 5, 2 3 4 5, 1 2 3 4 5

Actually, by your definition, your array should contain the
empty set as well.  But anyway...

>  Is there a good way of doing this?  I'm getting bogged down in the
>recursive nature of all this.

Recursion is a way to do it.  I believe the trick is to think of it in
terms of picking an element, then recursive iterating over all the
other combinations.  You should get a number of results back; each
these results should be concatenated with the element you just picked
to form a single result.  Thus for this input:

	(1, 2, 3)

let's assume you pick 1.  You then have a sublist of (2, 3).  The
recursive call should give you back a result like this:

	(2), (3), (2, 3)

You prepend your 1 onto each of these results and that gives you this:

	(1, 2), (1, 3), (1, 2, 3)

Now pick 2 instead and repeat.  Then pick 3 and repeat.  Then return
the list you just built.

The interesting thing about this problem is that subproblems recur
frequently in it.  This means it could benefit from a dynamic
programming approach, and possibly a great deal since the subproblems
are going to be repeated pretty frequently.  I haven't thought of a
dynamic programming algorithm for it yet, though.  ;-)

  - Logan


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

Date: Wed, 09 Aug 2000 19:36:35 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Ordered set of permutations algorithm
Message-Id: <4q43ps85skveccgdmf3u312i9sl8dnvudm@4ax.com>

On Wed, 9 Aug 2000 10:19:59 -0400, "Keith Scollick" <scollick@stsci.edu>
wrote:

> Hi all,
>   I have a set of elements that can range anywhere from one to approximately
> ten elements.  What I want to do is create a set of all ordered combinations
> (i.e. the elements on the left stay to the left of any and all elements to
> the right)
> not limited to just returning the combinations with the same number of
> elements
> as the original list (i.e. for a three element list, I want each combination
> of
> two as well).
> 
>   For example, given a list (1, 2, 3, 4, 5).  I want to return an array
> containing
> (each element is separated by a comma):
> 
> 1, 2, 3, 4, 5, 1 2, 1 3, 1 4, 1 5, 2 3, 2 4, 2 5, 3 4, 3 5,
> 1 2 3, 1 2 4, 1 2 5, 1 3 4, 1 3 5, 2 3 4, 2 3 5, 3 4 5,
> 1 2 3 4, 1 2 3 5, 1 2 4 5, 1 3 4 5, 2 3 4 5, 1 2 3 4 5
> 

you missed some :-)

>   Is there a good way of doing this?  I'm getting bogged down in the
> recursive nature of all this.
> 
This is a slight change from what I posted yesterday. 
make_combi() returns a list of lists (ordered)

#!/usr/bin/perl -w
use strict;

my @list = (1..5);

print join ", ", map "@$_" => make_combi(@list);

sub make_combi {
	my(@list) = @_;
	my @q = ( [] );
	for my $e (@list) {
		@q = map { @$_ == @list? $_ : ([@$_, $e], $_) } @q;
	}

	return map $_->[-1] => 
		sort { $a->[0] <=> $b->[0] }
			map [join('', @$_), $_] => grep @$_ => @q;
}

-- 
Good luck,
Abe


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

Date: Wed, 09 Aug 2000 11:12:17 -0500
From: Garrett Rolfs <stage3@us.ibm.com>
Subject: Overriding Builtin Functions
Message-Id: <399182E1.D67EB8FF@us.ibm.com>

Greetings,

I am attempting to create a module, written entirely in perl, that will
override builtin IO functions such as open, close, read, sysopen, etc. 
My purpose is create functions that are tolerant to distributed file
system (AFS and DFS in this case) file server outages.  My prototype has
been progressing well with my first attempt of overriding the stat
function.  However, I have run into some questions in my attempts to
override other functions.  I have looked through the docs and the FAQ. 
Hopefully I have not missed the answers.  Here are my questions:

1. Can print and printf be overridden?  In my prototype I added print
and printf to my module's @EXPORT list. I understand the ramifications
of using @EXPORT, this is just a prototype at this point. When I "use"
my module in a script, the print and printf functions in my module are
not called.  In the perlsub manpage I noticed that it said "most"
builtin functions can be overridden.  Are print and printf not included
in most?

2. I have run into the problem with the open function in the form of:

   open FH, "</tmp/somefile" or die "$!\n";

My open functions receives FH has a string.  How can I take that string
and set FH to be an open filehandle in my caller's package?

3.  I have also run into problems with read and sysread.  They both take
a scalar to hold the results of the read.  My functions receive the
value of the scalar, not a reference to the scalar.  I assume the
builtin functions use some "magic" to treat the scalar as a reference. 
I changed my functions to croak if they don't receive a reference to a
scalar, but that makes it hard to give existing scripts distributed file
system tolerance by adding a simple "use mymodule qw(funcs..)"
statement.

Any insight and/or suggestions is appreciated.

Regards,

-Garrett Rolfs


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

Date: Wed, 9 Aug 2000 12:57:02 -0400
From: "PerlPrincess" <anonymous@cotse.com>
Subject: Perl Jobs Galore!  Find them here.
Message-Id: <200008091657.MAA06894@anon.cotse.com>


Hi -

i found so many programming job listings here... 
http://jobs.naccbjobs.com
this site is strictly for computer professionals. it 
helped me.... good luck! 
 




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

Date: 9 Aug 2000 15:22:22 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: perl sql (delimited)
Message-Id: <8mrsve$p73$2@internal-news.uu.net>

Logan Shaw <logan@cs.utexas.edu> wrote:
> In article <3990A66B.FC3179AA@rochester.rr.com>,
> Bob Walton  <bwalton@rochester.rr.com> wrote:

>>Your database is returning whitespace past the end of your data that you
>>appear to wish not to have, and the above will remove it.

> Note that that regular expression will delete all spaces so that
> "   billy bob   " would get changed into "billybob" instead of
> "billy bob".  Therefore, I suggest this as a replacement for
> your print statement:

Or this might do the trick (from DBI documentation):

     ChopBlanks (boolean, inherited)
         This attribute can be used to control the trimming of
         trailing space characters from fixed width character
         (CHAR) fields. No other field types are affected, even
         where field values have trailing spaces.

Erik



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

Date: Wed, 9 Aug 2000 17:13:48 +0100
From: "shebang" <lorraine.macfarlin@manchesteronline.co.uk>
Subject: problem perl/cgi Apache web server on win 98 Help!
Message-Id: <2pfk5.63$lA4.1270781@news0>

Hi,

Can anyone assist in solving a problem I am having running a perl cgi script
on Apache server for win98.

All CGI script alias etc. enabled in httpd.conf and server running fine.
Perl scripts processed at command line no problem.
But CGI run fails . error message in Logs  is can't spawn child process.
I can run the script fine on a live server on Unix - so the code is not a
problem,
just handing it on a localhost machine.

Apologies if this should have been posted to a cgi or server newsgroup, but
I could do with some help:-}







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

Date: Wed, 9 Aug 2000 17:43:50 +0200
From: "Guenther Degenfelder" <guenther.degenfelder@datev.de>
Subject: Re: Problem with Net::Telnet
Message-Id: <39917bb8$1@news.datev.de>


<jpalloz@my-deja.com> schrieb im Newsbeitrag
news:8mro61$m3q$1@nnrp1.deja.com...
> In article <39912ea0$1@news.datev.de>,
>   "Guenther Degenfelder" <guenther.degenfelder@datev.de> wrote:
> >
> > <jpalloz@my-deja.com> schrieb im Newsbeitrag
> > news:8mq02o$iuv$1@nnrp1.deja.com...
> > > I need to use Net::Telnet to telnet into a propeitary database
> > > interface, similiar to sqlplus.
> > >
> > > The idea is to telnet into this database from an outside perl/cgi,
> > > and then either create new records or update existing ones.
> > >
> > > The problem is this particular interface has no prompt. The cursor
> > > simply blinks at the beginning of the line waiting for you to issue
> > > your commands.
> >
> > The login-method is waiting for the prompts 'user:' and 'password:'
> (or
> > seomething else?!) and then prints the UserID and Password. This is
> done
> > with
> >     $t->waitfor('/user:/');
> >     $t->print($UserID);
> >     $t->waitfor('/password:/');
> >     $t->print($Password);
> >
> > If you have problems with YOUR shape of prompts, you have to another
> >     $t->waitfor('/something else/');
> >     $t->print($UserID);
> >     ...
> >
> > But be careful:
> > Don't send your $Password to unknown prompts!    ;-)
> >
> >     Guenther
> >
> >
>
> Guenther,
>
> Thank you for the response. The login/password stuff doesn't have any
> prompt, like $user: $password: , as a matter of fact as I stated earlier
> in my message there is no prompt in this database interface. The cursor
> simply blinks at the far left spot on the line, and I actually think
> this is the crux of all my problems. This Telnet module seems to be very
> dependent, from the doc I've read, on having some kind of discernable
> prompt to work with. Anyway, do you have any more suggestions. I've
> tried using the double carriage return as a prompt because that signals
> the end of a command in this database interface, but that has not worked
> either.
>
> Any help would be greatly appreciated.
>
> Thanks,
>
> John P.
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

Reading your first mail twice i see in your examplex that you are doing a
telnet in a telnet?!
    ...
    $t->open(Host => FirstHost...
    ...
    $t->cmd("telnet SecondHost...
    ...
Why you are not 'telnetting' the SecondHost directly?!

The printing of the commands to the SecondHost with only
    $t->print(@ListWithLotsOfTextWithoutBreak);
could cause a problem in reading your commands by the SecondHost, because he
wants to get the next input after printing his 'newline-prompt' only. Your
interrupt the printing with some
    $waitfor('/[\n]*/');

The proper syntax should be
    LOGIN
    USER:superuser
    PASS:hello1234
but you implemented
    @list = ( "LOGIN" , "USER:superuser" , "PASS:hello1234" , "\n", ...
Where are the '\n' after 'LOGIN' and 'USER...'?

No further suggestions at the moment...

Regards

    Guenther




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

Date: Wed, 09 Aug 2000 17:09:38 GMT
From: "Earthlink News" <rickysregistration@hotmail.com>
Subject: Re: Regular expression to check for non-alphanumeric?
Message-Id: <mfgk5.31622$0W4.827331@newsread2.prod.itd.earthlink.net>


Troy Rasiah <troyr@vicnet.net.au> wrote in message
news:ke3k5.79791$N4.2008046@ozemail.com.au...
> if ($variablename=~/\W+/) {
>   print "there is an alphanumeric character in the string";
> }
>
> Unfortunately that won't let commas or dots thru either....so you'll have
to
> modify it a bit

Hi,

You could also use alternation, a la:

@list = qw/some Word32 83f.doc kd*a i92)#7.2dk 23/;

foreach (@list) {
    unless (m%^(\w|,|\.)+$%) {
        print "$_ ain't alphanumeric,.\n";
    }
}

Hope that helps,


Rick.





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

Date: 09 Aug 2000 09:11:05 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Regular expression to check for non-alphanumeric?
Message-Id: <m3og32bk3q.fsf@dhcp11-177.support.tivoli.com>

"Robert Brooks" <studentfl@hotmail.com> writes:

> if this string contains something other then alphanumeric characters,
> periods, or commas do this

if ($string =~ /[^\w.,]|_/) {
  # this does what you ask, assuming _ is to be excluded from
  # alphanums, but what about white space?  Maybe: /[^\w\s.,]|_/
}

-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 9 Aug 2000 18:44:37 +0200
From: "Michael Winter" <michaelw@gmx.at>
Subject: Set cookie from SSI
Message-Id: <8ms32a$l3p$1@bird.wu-wien.ac.at>

Hi,

is it possible to set a cookie from a SSI? It seems to be a problem,
because

#!/usr/bin/perl
print "Set-Cookie: COOKIETEST=WORKING; expires=Tue, 02-Jan-2011 00:00:00
GMT\n";
#etc...

simply outputs the line as HTML data...

If it is not possible directly, how would you set a cookie if you want
the initial call being made from a SSI? (I want to use this script to
set a cookie even if JavaScript is disabled, and that's the only way I
could think of...)


Thank you very much for your help,

Michael




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

Date: Wed, 09 Aug 2000 17:24:04 +0200
From: Jimmy Lantz <jimmy.lantz@ostas.lu.se>
Subject: Sort of a sort problem.
Message-Id: <39917794.482502AF@ostas.lu.se>

Hi guys,
I have the following problem:
I have a directories with files called,

abod130
dfo131
abe132
abod133
dfo134
abe135
abod136
dfo137
etc.....

I need to make a script which does the following 
##Pseudocode##:

- Sorts the files in numerical order regardless of prefix into an array.
I'm thinking that I could use some kind of map or sort routine but i
would appreciate a link or a pointer to a tutorial.

Thankful for any help.
Jimmy Lantz


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

Date: Wed, 09 Aug 2000 11:41:36 -0500
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: Sort of a sort problem.
Message-Id: <399189C0.24E8BFE1@mortgagestats.com>

Jimmy Lantz wrote:

> Hi guys,
> I have the following problem:
> I have a directories with files called,
>
> abod130
> dfo131
> abe132
> abod133
> dfo134
> abe135
> abod136
> dfo137
> etc.....
>
> I need to make a script which does the following
> ##Pseudocode##:
>
> - Sorts the files in numerical order regardless of prefix into an array.
>

You could do something like this:

sub JimmySort
    {
    my($alpha,$beta)=($a,$b);
    $alpha=~s/\D//; #zap all non-digits
    $beta=~s/\D//;
    $alpha<=>$beta;
    }

@filelist=qw/dfo131 abe132 abod133 dfo134 abe135 abod136 dfo137/;

@sorted_filelist=sort JimmySort @filelist;

Read up on the sort function if this isn't obvious to you.

Andras



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

Date: Wed, 09 Aug 2000 15:44:29 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Sort of a sort problem.
Message-Id: <slrn8p2vcq.l3m.rgarciasuarez@rafael.kazibao.net>

Jimmy Lantz wrote in comp.lang.perl.misc:
>Hi guys,
>I have the following problem:
>I have a directories with files called,
>
>abod130
>dfo131
>abe132
>abod133
>dfo134
>abe135
>abod136
>dfo137
>etc.....
>
>I need to make a script which does the following 
>##Pseudocode##:
>
>- Sorts the files in numerical order regardless of prefix into an array.
>I'm thinking that I could use some kind of map or sort routine but i
>would appreciate a link or a pointer to a tutorial.

Here are the links (not surprisingly, to the perl documentation bundled
with it):
  perldoc -f readdir
  perldoc -f sort
  man perlre
(the last one, for knowing how to extact the numerical part of the
filenames).

-- 
Rafael Garcia-Suarez


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

Date: 09 Aug 2000 11:12:12 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Sort of a sort problem.
Message-Id: <m3aeembehv.fsf@dhcp11-177.support.tivoli.com>

Jimmy Lantz <jimmy.lantz@ostas.lu.se> writes:

> Hi guys,
> I have the following problem:
> I have a directories with files called,
> 
> abod130
> dfo131
> abe132
> abod133
> dfo134
> abe135
> abod136
> dfo137
> etc.....
> 
> I need to make a script which does the following 
> ##Pseudocode##:
> 
> - Sorts the files in numerical order regardless of prefix into an array.
> I'm thinking that I could use some kind of map or sort routine but i
> would appreciate a link or a pointer to a tutorial.

Perhaps someone else will post a good tutorial reference -- I'm not
sure what to reference.  But this will do the trick:

# assume filenames are in @files

# Schwartzian transform definitely useful here
print map $_->[1],
        sort { $a->[0] <=> $b->[0] }
          map [ /\d+$/g, $_ ],
            @files;



-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 09 Aug 2000 17:10:03 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: When does it pay to presize an array?
Message-Id: <Lfgk5.14667$f_5.73232@news1.rdc1.ct.home.com>

Andrew J. Perrin <aperrin@demog.berkeley.edu> wrote:

> True enough - here you go.  Also, see that exchange I noted above -
> there's also comparable code there.  The results follow; I would still
> love to see some code that demonstrates the utility of presizing an array!

For very large arrays, presizing is a win, since you temporarily need
both the current array (#array elements * 4) and the new array( #array
elements *8) in bytes. Depending on how close you are to the limits of
your memory, this could push you over the edge. (Arrays are generally
presized in powers of two)

					Dan


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

Date: 09 Aug 2000 09:02:56 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: When does it pay to presize an array?
Message-Id: <m3r97ybkhb.fsf@dhcp11-177.support.tivoli.com>


Perhaps the results can be explained by the fact that nothing else is
going on between each time the array needs to grow.  So the call to
(presumably) realloc is able to simply increase the size of the
existing chunk of memory.   Or not....?

-- 
Ren Maddox
ren@tivoli.com


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3965
**************************************


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