[16555] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3967 Volume: 9

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

Date: Wed, 9 Aug 2000 15:10:29 -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: <965859028-v9-i3967@ruby.oce.orst.edu>
Content-Type: text

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

Today's topics:
    Re: Executing Unix commads on a IIS request <alesr@siol.net>
    Re: Executing Unix commads on a IIS request (NP)
    Re: get the website content <nospam@nospam.com>
    Re: help parsing excel .cvs files <bart.lateur@skynet.be>
        HELP!! with Install on HP-UX.. where to start!?? btaneja@hotmail.com
    Re: HELP!! with Install on HP-UX.. where to start!?? btaneja@my-deja.com
        How do I dislpay all the conents in a file? thirdgc@my-deja.com
    Re: How do I dislpay all the conents in a file? <care227@attglobal.net>
    Re: How do I dislpay all the conents in a file? <amonotod@netscape.net>
    Re: How do I dislpay all the conents in a file? thirdgc@my-deja.com
    Re: How do I dislpay all the conents in a file? <amonotod@netscape.net>
    Re: How to source a shell script in perl (Greg Bacon)
    Re: how to USE perl 5.6's assert.pl? <tim@ipac.caltech.edu>
    Re: HTML Table To Text --How? <meyersx@meyersanalytics.com>
    Re: Interesting problem: starting coprocesses in Korn S (Greg Bacon)
    Re: is mysql faster using Perl or PHP? <alesr@siol.net>
    Re: Large-File Reformatting Problem (Regexp gurus, et a <cjmackie@princeton.edu>
        Need help with simple cgi code <peterclones@hotmail.com>
    Re: Newbie questions: What exactly is $_? <lr@hpl.hp.com>
    Re: Newbie questions: What exactly is $_? fathacka@my-deja.com
    Re: Newbie questions: What exactly is $_? (Jon S.)
    Re: Newbie questions: What exactly is $_? (Tim)
    Re: Ordered set of permutations algorithm <scollick@stsci.edu>
    Re: Ordered set of permutations algorithm <jeff@yoak.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 09 Aug 2000 20:20:23 +0200
From: marvin <alesr@siol.net>
Subject: Re: Executing Unix commads on a IIS request
Message-Id: <3991A0E6.573A@siol.net>

pularis@my-deja.com wrote:
> 
> Hi Perl God(s),
> 
>   I am running IIS on NT server 4.0.As an enhancement to the server I
> want to add the functioanlity of being able to execute commands on a
> unix host ( running Solaris ) and somehow magically get the output back
> to the IIS/NT server and display the result as an HTML page. The idea
> being able to provide a web based interface to execute commads on a unix
> host. All n every help will be deeply appreciated. Thanks a much
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.
I do the same thing, but unfortunately also from Unix/Solaris, which
has rsh command.
I am using Perl for that. This way I can supervise more than 20 serves
from one point.

For example:

my @ARRAY=`rsh -l <myname> <host_to_watch> <command>`
foreach $LINE (@ARRAY)
{
   print $LINE,"<BR>\n";
}

But you must ensure security in your <host_to_watch> security files.

You can do it globaly in 
/etc/hosts.equiv
<web server host name> +

or putting same line in .rhosts file, which is in home
directory of <myname> user.


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

Date: Wed, 09 Aug 2000 18:42:32 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: Executing Unix commads on a IIS request
Message-Id: <sChk5.16339$wX5.218337@news5.giganews.com>

On Wed, 09 Aug 2000 20:20:23 +0200, marvin <alesr@siol.net> wrote:
:
: I do the same thing, but unfortunately also from Unix/Solaris, which
: has rsh command.

rsh is terrible, tho.  Why not use ssh with a NULL RSA key or whatever?

-- 
Nate II



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

Date: 9 Aug 2000 20:58:09 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: get the website content
Message-Id: <8msgl1$kt4$0@216.155.33.80>

In article <398E15C7.88A5FAB3@poboxes.com>, unplug <unplug@poboxes.com> 
wrote:

 | Hi all,
 |   Is it possible to get the website content using Perl??
 | Any example about it??
 | 
 | Rgds,
 | unplug

LWP::UserAgent
LWP::Simple
HTML::Parser
etc etc

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: Wed, 09 Aug 2000 21:19:20 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: help parsing excel .cvs files
Message-Id: <nei3pscff37p7d5uq7ap2dr13suf9kpphn@4ax.com>

coughlan@gothaminteractive.com wrote:

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

Look up the modules Text::CSV and Text::CSV_XS from CPAN. If it's a
Windows perl, look for the Windows-specific port at
<http://www.activestate.com/PPMPackages/5.6/zips/Text-CSV_XS.zip> (or
replace "5.6" with "5.005" if running a slightly older version).

-- 
	Bart.


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

Date: Wed, 09 Aug 2000 21:07:49 GMT
From: btaneja@hotmail.com
Subject: HELP!! with Install on HP-UX.. where to start!??
Message-Id: <8msh72$aac$1@nnrp1.deja.com>



I have downloaded a Perl 5.6 version of HP-UX, untar-ed it and read
it .. Basically I need to :

rm -f config.sh Policy.sh
        sh Configure
        make
        make test
        make install


BUT WHERE IS THE MAKE FILE ??
I HAVE UNZIPPED IN /home/root
and the INSTALL/ readme is in:
/home/root/perl/perl/perl-RUN/opt/perl5/doc


But no matter where I do "make", I get:

# make
Make: No arguments or description file.  Stop.


HELP!
thanks, Bruce


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


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

Date: Wed, 09 Aug 2000 21:26:34 GMT
From: btaneja@my-deja.com
Subject: Re: HELP!! with Install on HP-UX.. where to start!??
Message-Id: <8msia5$b7l$1@nnrp1.deja.com>



sorry forgot to mention this is on a HP-UX 11.0
and the Perl I downloaded is a binary install..

the question is then do I even do a make?? can
I just ignore the install/ readme files and untar
under /opt/perl5 (e.g.) and it will all work??

thanks!!
-Bruce
bruce@ereliable.com


In article <8msh72$aac$1@nnrp1.deja.com>,
  btaneja@hotmail.com wrote:
>
>
> I have downloaded a Perl 5.6 version of HP-UX, untar-ed it and read
> it .. Basically I need to :
>
> rm -f config.sh Policy.sh
>         sh Configure
>         make
>         make test
>         make install
>
> BUT WHERE IS THE MAKE FILE ??
> I HAVE UNZIPPED IN /home/root
> and the INSTALL/ readme is in:
> /home/root/perl/perl/perl-RUN/opt/perl5/doc
>
> But no matter where I do "make", I get:
>
> # make
> Make: No arguments or description file.  Stop.
>
> HELP!
> thanks, Bruce
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


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


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

Date: Wed, 09 Aug 2000 18:13:09 GMT
From: thirdgc@my-deja.com
Subject: How do I dislpay all the conents in a file?
Message-Id: <8ms6vg$2am$1@nnrp1.deja.com>

I am writing a perl script for a message board on my website. I need
some help with a small part, how can I display all the contents in the
file. For example I have a file with the date and time of the last post
for a certain topic and I need the date to be displayed on the main
board. I have tried using server side include but that didn't work. I
also tried:

open(time1, "</home/3gc/www/ctb/posts/$file\.time") || dienice("Can't
open /home/3gc/www/ctb/posts/$file\.time: $! \n");
@time1 = <time1>;
close(time1);

print "$time1\n";

It's probably something simple that I'm forgetting to do. Thanks in
advance for any help you can give.


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


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

Date: Wed, 09 Aug 2000 14:23:36 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: How do I dislpay all the conents in a file?
Message-Id: <3991A1A8.25BECB46@attglobal.net>

thirdgc@my-deja.com wrote:
> 
> I am writing a perl script for a message board on my website. I need
> some help with a small part, how can I display all the contents in the
> file. For example I have a file with the date and time of the last post
> for a certain topic and I need the date to be displayed on the main
> board. I have tried using server side include but that didn't work. I
> also tried:
> 
> open(time1, "</home/3gc/www/ctb/posts/$file\.time") || dienice("Can't
> open /home/3gc/www/ctb/posts/$file\.time: $! \n");
> @time1 = <time1>;

Here you read the file into an array.  Each line of the file
gets an entry in the array.  This array is called @time1, and its 
elements can be accessed like:  $time1[0]

> close(time1);
> 
> print "$time1\n";
> 

And here you print a scalar called $time1, which has no relation
to the aforementioned array.  Using strict would have given you 
a clue that this value was undefined and only used once.


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

Date: Wed, 09 Aug 2000 18:27:58 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: How do I dislpay all the conents in a file?
Message-Id: <8ms7r7$2tc$1@nnrp1.deja.com>

In article <8ms6vg$2am$1@nnrp1.deja.com>,
  thirdgc@my-deja.com wrote:
> I am writing a perl script for a message board on my website. I need
> some help with a small part, how can I display all the contents in the
> file. For example I have a file with the date and time of the last

Keep in mind that although the following works the way you want, it is
*very* insecure!  I *_would_not_* put this on a real server...

#!perl -w
# ssi.pl
# Script to implement server side includes
# amonotod
# Implementation on my system:
#<!--#exec cgi="/cgi-bin/ssi.pl/path/from/webroot/to/file.html"-->

use strict;

unless (-e $ENV{PATH_TRANSLATED} ) {
  die "Requested file does not exist!\n";
}
unless (open (HtMl, "$ENV{PATH_TRANSLATED}") ) {
  die "Requested file could not be opened!\n";
}
my @lines = (<HtMl>);
print "\n";
foreach (@lines) {
  print $_;
}
exit;


HTH,
amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


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


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

Date: Wed, 09 Aug 2000 19:32:06 GMT
From: thirdgc@my-deja.com
Subject: Re: How do I dislpay all the conents in a file?
Message-Id: <8msbjm$61f$1@nnrp1.deja.com>

Thanks for the reply.What could happen if I did actually use that.
Could people do something to the server or just be able to view the
perl source code. Is there another way? The file I'm trying to display
is only one line and another is just one number.


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


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

Date: Wed, 09 Aug 2000 20:06:04 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: How do I dislpay all the conents in a file?
Message-Id: <8msdj9$7g1$1@nnrp1.deja.com>

In article <8msbjm$61f$1@nnrp1.deja.com>,
  thirdgc@my-deja.com wrote:
> Thanks for the reply.What could happen if I did actually use that.
> Could people do something to the server or just be able to view the
> perl source code. Is there another way? The file I'm trying to display
> is only one line and another is just one number.

While I haven't been able to step outside of the webroot using that
code, I have been able to get any file I want, and dump it's contents to
the screen.  If the exact path of a file is known, and the name of the
script is known, instant compromise.  Although it would not be real
security, you can set up a cgi directory that is not named cgi-bin, then
put the renamed script file in that directory, with an ACL for denial of
directory listing.  That is really just obfuscation, though; like I
said, not real security.

HTH,
amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


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


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

Date: Wed, 09 Aug 2000 19:57:46 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: How to source a shell script in perl
Message-Id: <sp3dtq2jn4t132@corp.supernews.com>

In article <8ms2t2$utf$1@nnrp1.deja.com>,
     <sankarmukh@my-deja.com> wrote:

: 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.

That's the way Unix environment inheritance works.  Sourcing in a
shell script from another shell script is equivalent to requiring
in a Perl library from a Perl program.  Another option for you
would be to maintain separate Perl and Korn shell implementations
of your environment modifier.

Greg
-- 
It has been discovered that C++ provides a remarkable facility for concealing
the trival details of a program--such as where its bugs are. 
    -- David Keppel


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

Date: Wed, 09 Aug 2000 11:32:56 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: how to USE perl 5.6's assert.pl?
Message-Id: <3991A3D8.D8B795EA@ipac.caltech.edu>

David Combs wrote:
> 
> 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?

The '.pl' ending is a clue that it's not a module ('.pm') and therefore cannot
be use'd. See perldoc -f require. If assert.pl's directory is in @INC (perl -wle
'print "@INC"'), it will be found and loaded by

require 'assert.pl';

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Wed, 09 Aug 2000 14:26:16 -0500
From: Dennis Meyers <meyersx@meyersanalytics.com>
Subject: Re: HTML Table To Text --How?
Message-Id: <3ob3ps09qfsaoo4u97qml9don59fn4m9os@4ax.com>

Andreas,

Thanks for the pointer to HTML::TableExtract!

You're right, it does do exactly what I want.

Thanks also to Matt Sisk, the author of HTML::TableExtract.  You Module saved me
an enormous amount of coding time!

Dennis



Andreas@dus-spot.de (Andreas Schmidt) wrote:

>Hello Dennis,
>
>you should try HTML::TableExtract, available on CPAN of course. It
>does exactly, what you want...
>
>Bye, Andreas
>
>
>-------------------------------------------------
> Andreas Schmidt
> WWW: http://www.dus-spot.de
> E-Mail: Andreas@dus-spot.de
>-------------------------------------------------



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

Date: Wed, 09 Aug 2000 20:25:00 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Interesting problem: starting coprocesses in Korn Shell via Perl
Message-Id: <sp3fgsmtn4t92@corp.supernews.com>

In article <39919959.123E7C97@hotseat.hobl.lucent.com>,
    Ahmad Rana  <rana@hotseat.hobl.lucent.com> wrote:

: 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.

This is from the IPC::Open2 manpage:

NAME
    IPC::Open2, open2 - open a process for both reading and writing

SYNOPSIS
        use IPC::Open2;
        $pid = open2(\*RDR, \*WTR, 'some cmd and args');
          # or
        $pid = open2(\*RDR, \*WTR, 'some', 'cmd', 'and', 'args');

DESCRIPTION
    The open2() function spawns the given $cmd and connects $rdr for
    reading and $wtr for writing. It's what you think should work
    when you try

        open(HANDLE, "|cmd args|");

:                                   In other words, how to open a
: file-descriptor in perl using not its name but its numeric descriptor.

The documentation on open in the perlfunc manpage describes how to do
this.  You can't use the described syntax to cast ksh magic though.

Greg
-- 
I see you've cross-posted this to comp.lang.c and comp.lang.c++. The first
thing you need to do is decide which language you are programming in.
    -- Lawrence Kirby


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

Date: Wed, 09 Aug 2000 20:25:30 +0200
From: marvin <alesr@siol.net>
Subject: Re: is mysql faster using Perl or PHP?
Message-Id: <3991A21A.910@siol.net>

Rafael Garcia-Suarez wrote:
> 
> Bart Lateur wrote in comp.lang.perl.misc:
> >
> >I think he's talking about CGI. Every single request from the browser
> >would demand a new connection to the database. That *could* be pretty
> >slow. I think that that time is pretty independent on which language you
> >use to make this tick.
> >
> >What would be better, is have an permanent connection to the dB, for
> >example in an independent process, and request it's info from *that*. I
> >dunno, but I thought that Apache+mod_perl has a way to do that.
> 
> Yes -- it's called Apache::DBI. But mod_perl must be compiled into
> apache and the mod_perl scripts must conform to the mod_perl coding
> guidelines, that are more strict than for CGI programs.
> 
> >Now, if
> >PHP had a way to do that behind the scenes, yes it would be faster than
> >the plain perl, straightforward code solution. I don't know if it does.
> 
> I think mod_php can do that. But php installed as a CGI program can't
> do, for sure.
> 
> So, the relevant question is: how to configure apache. And the relevant
> group is comp.infosystems.www.servers.<some_platform>.
> 
> --
> Rafael Garcia-Suarez

It is the same speed, if you're running single SQL command, since
SQL command is distributed to MySQL server, and then accepting
its output back to the client.
If you have a lot of work in database, I would definetly prefer use of
MySQL stored procedure. Notice, that speed again would be the same from
Perl or whatever. Difference would not be noticable for you.

Regards
Me


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

Date: Wed, 9 Aug 2000 14:10:55 -0400
From: "Christopher J. Mackie" <cjmackie@princeton.edu>
Subject: Re: Large-File Reformatting Problem (Regexp gurus, et al.) -- Thanks
Message-Id: <8ms6t2$5qo$1@cnn.Princeton.EDU>

Thanks Greg & Ren;  I implemented Greg's suggestions, and they seem to work
fine.  Ren, you are correct about $/ -- in fact, that's what was making me
unsure how to proceed, as it meant that slurping in texts wouldn't
automatically give me one text at a time, and if the $/ break happened to
come in the wrong place, might even worsen the problem.

My hunch is that the '$/="";' approach is faster than line-slurping, which
is why I went with Greg's suggestions.  If I get some leisure, I'll test the
line-reading v. chunk-reading approaches for speed.
Thanks again to you both,  --Chris

"Greg Bacon" <gbacon@HiWAAY.net> wrote in message
news: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: Wed, 9 Aug 2000 16:17:31 -0500
From: "Peter" <peterclones@hotmail.com>
Subject: Need help with simple cgi code
Message-Id: <fQjk5.26$Lc.2151@news1.mts.net>

I'm a newbie with cgi scripting so need a quick hand in writing this simple
code.  I'm trying to write a script that grabs the 'HTTP_REFERER' info from
the Environment variables and prints it to a text file.  Each time the
script is run I'd like it to add it to the list that's already there in the
text file.  I know this is terrible easy to do but I'm merely a beginner.
Here's what I have so far:

#!/usr/bin/perl

$caller = $ENV{'HTTP_REFERER'};

open SITES,">sites.txt";

print $caller;

close SITES;



This little test doesn't work right now for some reason.  All my paths and
chmods are correct, I know that for sure.  Please correct this so it will
work, and keep adding the info to the text file rather than overwrite it.

Much Appreciated!  Peter





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

Date: Wed, 9 Aug 2000 11:33:31 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Newbie questions: What exactly is $_?
Message-Id: <MPG.13fb43d1e66ed53298ac53@nntp.hpl.hp.com>

In article <39919a1d$1@news.microsoft.com> on Wed, 9 Aug 2000 10:51:25 -
0700, Jürgen Exner <juex@deja.com> says...

 ...

> foreach (@myarray) {     # loops through all elements of @myarray,
>              #setting $_ to the value of each element in turn
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                aliasing $_ to each element in turn

>     s/foo/bar/;        # substitutes the text "foo" with "bar" in $_

and in each element of @myarray.

>     print;            # prints the value of $_ , i.e. effectively the
>             # whole array after substituting foo with bar
> }

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 09 Aug 2000 19:02:43 GMT
From: fathacka@my-deja.com
Subject: Re: Newbie questions: What exactly is $_?
Message-Id: <8ms9sg$4lb$1@nnrp1.deja.com>

Thanks for the responses, Tim and Larry.  It was exactly what I was
looking for!


In article <MPG.13fa337a7f8771eb98ac4e@nntp.hpl.hp.com>,
  Larry Rosler <lr@hpl.hp.com> wrote:
> In article <8mq1pc$k3b$1@nnrp1.deja.com> on Tue, 08 Aug 2000 22:32:12
> GMT, fathacka@my-deja.com <fathacka@my-deja.com> says...
> > 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?
>
> It is a global variable, whose value is unchanged on entry to a
> subroutine.  If the subroutine changes it and returns, $_ retains the
> changed value.  Unless this is desired, any subroutine that changes $_
> should use a localized copy (`perldoc -f local`).
>
>   sub foo {
>       local $_ = $_; # Make a localized copy.
>       s/bar/baz/;
>       print;         # "baz\n"
>   }
>
>   $_ = "bar\n";
>   foo();
>   print;             # "bar\n";
>
> > Is $_ at all affiliated with @_, or does it have some fundamental
> > difference?
>
> No relationship whatever.
>
> > Thanks
>
> You're welcome.  In the future, you'll be more welcome if you
> intersperse your remarks within or after the post you are responding
to,
> instead of blindly quoting it at the end of your response.
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
>


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


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

Date: Wed, 09 Aug 2000 19:51:53 GMT
From: jonceramic@nospammiesno.earthlink.net (Jon S.)
Subject: Re: Newbie questions: What exactly is $_?
Message-Id: <3991accf.21565733@news.earthlink.net>

On Tue, 08 Aug 2000 23:22:59 GMT, SPAM+indigo@dimensional.com (Tim)
wrote:
>Some commands put stuff into $_, and others take stuff out.  You
>should only use $_ if you understand both.  
>
>Here is an example:
>
># Warning - untested code fragments
>
># Without $_
>
>for my $element (@array)
>{
>    $element =~ s/abc/xyz/g;
>    print "$element\n";
>}
>
># With $_
>
>for (@array)
>{
>    s/abc/xyz/g;
>    print "$_\n";
>}

Ok then, here's a newbie followup question...

Other than as an easier way to type things in and keep them looking
tidy, is there any particular benefit or reason to use $_ or @_ in
certain situations?  I already use @_ when pulling an array of passed
variables in .pm subroutines, but otherwise, it just seems like a
coding preference and timesaver.  I find it easier to use the full
name $foo rather than $_ just because I can keep track of my variables
better.  I expect that at some point, I'll be comfortable enough not
to do this, but for now, as a newbie, it's too much to grok at once.

Am I missing something where using $_ is preferred or imperative?

TIA,

Jon


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

Date: Wed, 09 Aug 2000 21:03:06 GMT
From: SPAM+indigo@dimensional.com (Tim)
Subject: Re: Newbie questions: What exactly is $_?
Message-Id: <8F8B98AAEindigodimcom@166.93.207.145>

jonceramic@nospammiesno.earthlink.net (Jon S.) wrote in 
<3991accf.21565733@news.earthlink.net>:

>Ok then, here's a newbie followup question...
>
>Other than as an easier way to type things in and keep them looking
>tidy, is there any particular benefit or reason to use $_ or @_ in
>certain situations?  

Nope.

>I already use @_ when pulling an array of passed
>variables in .pm subroutines, but otherwise, it just seems like a
>coding preference and timesaver.  

That's true for $_.  You are never required to use it.  But you if want
a sub to see its param list, one way or another, you will wind up using
@_.


>I find it easier to use the full
>name $foo rather than $_ just because I can keep track of my variables
>better.  I expect that at some point, I'll be comfortable enough not
>to do this, but for now, as a newbie, it's too much to grok at once.

Sounds like an excellent plan.  Perl has a nice way of letting you
code useful programs in proto-Perl baby talk until you are ready for
bigger and better things.

>Am I missing something where using $_ is preferred or imperative?

Don't think so.  If fact, while far from a majority view, there are
a few Perl folks out there who consider $_ bad style, and never use
it at all.

Personally, I try to be a Perl minimalist.  A named variable might be
more intuitive, but it is also one more name you have to keep track
of.  I find the fewer squiggly bits on my screen, the faster I can
digest each chunk of program logic.

-T


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

Date: Wed, 9 Aug 2000 13:41:19 -0400
From: "Keith Scollick" <scollick@stsci.edu>
Subject: Re: Ordered set of permutations algorithm
Message-Id: <8ms541$ejo$1@tomm.stsci.edu>

Very nice.

Thank you very much.

--Keith
scollick@stsci.edu

"Rafael Garcia-Suarez" <rgarciasuarez@free.fr> wrote in message
news: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: Wed, 09 Aug 2000 15:50:51 -0800
From: "Jeff Yoak" <jeff@yoak.com>
Subject: Re: Ordered set of permutations algorithm
Message-Id: <8msga702g8o@news2.newsguy.com>


[posted and mailed]

In article <8mrpag$db4$1@tomm.stsci.edu>, "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).

I don't know about the ordering requirement, but I though it might be good
to call your attention to Algorithm::Permute .  It may do what you need.

Cheers,
Jeff



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

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


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