[12811] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 221 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 22 00:07:24 1999

Date: Wed, 21 Jul 1999 21:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 21 Jul 1999     Volume: 9 Number: 221

Today's topics:
    Re: ****Perl tutorials!!!!**** <Webdesigner@NewWebSite.com>
    Re: a bit of a bind.. (Andrew M. Langmead)
    Re: a bit of a bind.. <tchrist@mox.perl.com>
    Re: Fun with Net:NNTP (Neko)
    Re: gethostbyname on NT <tigrank@inreach.com>
    Re: How to give Passwords on STDIN (Tad McClellan)
        index.cgi script help <mike@customautotrim.com>
    Re: Listing Files (Martien Verbruggen)
        LWP::UserAgent and/or site not remembering? (PaperCut)
    Re: LWP::UserAgent and/or site not remembering? (PaperCut)
        Need Help with Virtual Avenue (Rich)
    Re: Need Help with Virtual Avenue (Rich)
    Re: newbie question: how put files from dir in array (Tad McClellan)
    Re: perl cgi (Martien Verbruggen)
    Re: perl cgi <Webdesigner@NewWebSite.com>
    Re: Perl Examples on Parsing HTML (Martien Verbruggen)
    Re: perl system call problems (Andrew M. Langmead)
    Re: problem with hash of arrays <badri@wpi.edu>
    Re: Programming problem (Neko)
        question about this code snip (Michael Shavel)
    Re: question about this code snip (elephant)
    Re: recursive anonymous functions -- problem (Tramm Hudson)
    Re: regular Expression <tchrist@mox.perl.com>
    Re: setuid and opening a file for writing (Mark Francis)
        special case : split this string... <gabriel@asiaep.com>
    Re: Stop parent but not child process (Anno Siegel)
    Re: Testing for the existing of a key in a hash (Abigail)
    Re: Testing for the existing of a key in a hash <uri@sysarch.com>
    Re: Timeout question (Anno Siegel)
    Re: Trouble with Error Message (Tad McClellan)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Thu, 22 Jul 1999 03:42:38 GMT
From: Floyd Morrissette <Webdesigner@NewWebSite.com>
Subject: Re: ****Perl tutorials!!!!****
Message-Id: <7n63vc$geg$1@nnrp1.deja.com>

In article <1dvb92n.4s4d519ccu2oN@p37.tc17.metro.ma.tiac.com>,
  rjk@linguist.dartmouth.edu (Ronald J Kimball) wrote:

>
> I'm using Netscape Navigator 4.04.  I turned on Images, Java, and
> JavaScript.  It's *still* a blank page.
>
> But hey, at least I got a pop-up window with a banner ad, so it's not
> totally broken.
>

Works with IE. Obviously one of those pages for IE only. They have
alienated about half the Internet world.



--
Get your web site from http://www.NewWebSite.com
Consultation is always free.
Help with cgi scripts.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Thu, 22 Jul 1999 02:33:09 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: a bit of a bind..
Message-Id: <FF933A.Mw6@world.std.com>

Marshall Culpepper <marshalc@americasm01.nt.com> writes:

>hi...i've got a little subroutine madness i could use some help on...
>i have 3 subs..lets call them sub_1 sub_2 and sub_3...here's an example
>of what i'm trying to do

>sub_1{
>    open(FILE,'file');


Filehandles are global to the current package. When you open an
already open filehandle, perl performs and implicit close on it
first. If you want to prevent this behavior, you need to do something
to keep the filehandle local to the subroutine.

One solution would be to use the local() function to tell perl to
create a new, temporary filehandle for use until the end of the
subroutines scope:

sub sub_1 {
  local(*FILE);
  open FILE, 'file' or warn "Error opening file: $!\n";
 ...

Another would be to use the IO:File module and store the IO::File
object in a lexically local scalar:

sub sub_1 {
   my $file;
   $file = IO::File->new('file') or warn "Error opening file: $!\n";
 ...


-- 
Andrew Langmead


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

Date: 21 Jul 1999 20:38:07 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: a bit of a bind..
Message-Id: <3796840f@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    aml@world.std.com (Andrew M. Langmead) writes:
:Another would be to use the IO:File module and store the IO::File
:object in a lexically local scalar:
:
:sub sub_1 {
:   my $file;
:   $file = IO::File->new('file') or warn "Error opening file: $!\n";

Which is pretty much just a nasty and slow way of writing it in
100% Pure Perl.  I'd be more apt to do something like this:

    my $fh = do { local *FH };
    open($fh, $filename) || die "can't open $filename: $!";

--tom
-- 
    Some are born to perl, some achieve perl, and some have perl
    thrust upon them.  


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

Date: 22 Jul 1999 03:16:47 GMT
From: tgy@chocobo.org (Neko)
Subject: Re: Fun with Net:NNTP
Message-Id: <7n62ev$nrk$1@216.39.141.200>

On Wed, 21 Jul 1999 11:20:24 -0500, Darren greer
<dgreer@websightsolutions.com> wrote:

>#!/usr/bin/perl

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

Especially when things aren't working.

>use Net::NNTP;
>use Getopt::Long;
>use HTTP::Request;
>use Net::Cmd;

You never use Getopt::Long, HTTP::Request, or Net::Cmd.  Well, Net::Cmd gets
used indirectly.

>$base = '/usr/local/home/trainor/cgi';

It looks like this may be a CGI script.  If so, be sure to test on the
command line first.

>chdir($base) or die "Could not cd to $base\n";

You check for errors.  Good.  It may be helpful to include $! in your error
message.

>my $newsptr = Net::NNTP->new('news.mixcom.com');

You fail to check if this succeeds.  You may want to include $newptr->message
in your error message.

>$newsptr->group("wi.forsale");

No error check.  Also, consider a 'test' newsgroup instead of 'forsale'.

>$Test[0] = "From: Darren Greer\n";
>$Test[1] = "Newsgroups: wi.forsale\n";
>$Test[2] = "Subject: Test\n";
>$Test[3] = "\n";
>$Test[4] = "This is a test\n";

Use a here-doc for clarity:

$test = <<TEST
From: Darren Greer
Newsgroups: wi.forsale
Subject: Test

This is a test
TEST

>$newsptr->post(@Test);

No error check.

>$newsptr->quit;


-- 
Neko | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=


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

Date: Wed, 21 Jul 1999 19:04:18 -0700
From: Tigran <tigrank@inreach.com>
To: "Uwe W. Gehring" <gehring@politik.uni-mainz.de>
Subject: Re: gethostbyname on NT
Message-Id: <37967C21.D870C676@inreach.com>

Use this:

 ( $name, $alias, $addtype, $length,  @addrs ) = gethostbyname
('ftp.netscape.com');
 ( $a, $b, $c, $d ) = unpack ( 'C4', $addrs[0] );
 $ip_address = join ( ".", $a, $b, $c, $d  );
 print "$ip_address \n";

Tigran.


"Uwe W. Gehring" wrote:

> Hi,
>
> is there a known bug in gethostbyname with ActiveState Perl (newest
> relaease) on a NT box? When I use gethostbyname with an ip-name I get
> not only one number, but a couple of numbers and names. Unfortunately,
> no one of them is the right ip-number. The DNS server is well
> configured, I believe and I don't use WINS or LMHOST-file.
>
> TIA
>
> Uwe W. Gehring



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

Date: Wed, 21 Jul 1999 15:13:02 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How to give Passwords on STDIN
Message-Id: <u365n7.rn8.ln@magna.metronet.com>

osman durrani (osman@focomedia.de) wrote:

: Tom Christiansen schrieb in Nachricht <3795dbe9@cs.colorado.edu>...
: >
: >:: $passwd = <STDIN>;


: actually i wanted to know how can i get a password but not have the
: passwaord visible on the STDIN.


   Then you should have asked for that.


: This way you see the actuall password ,so it is not very good if you want to
: keep your password secrete from prying eyes.


   A crappy specification yields a crappy solution.

   No surprise there, so it makes sense to decrapify your 
   specification *before* the design and implementation phases.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 21 Jul 1999 19:09:07 -0700
From: Mike <mike@customautotrim.com>
Subject: index.cgi script help
Message-Id: <37967D43.B87E5059@customautotrim.com>


I am on a server that uses an index.cgi file that redirects all requests
for my main domain (http://customautotrim.com) to
http://customautotrim.com/index.html with this command:

if($url eq "") {$url="http://www.customautotrim.com/index.html"}

I want it to be
if($url eq "") {$url="http://www.customautotrim.com/"}

The problem is that the index.html always shows up in the address bar.
My host says I can't change the script like that, and there is not a
scipt  anywhere that I can use to achieve my goal.

Does anyone know of a fix for this, or know where I can get help?

thanks

mike
--
Custom Auto Trim and Graphics, Inc.
http://customautotrim.com







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

Date: Thu, 22 Jul 1999 02:47:22 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Listing Files
Message-Id: <_Cvl3.190$0S6.7605@nsw.nnrp.telstra.net>

In article <7n330a$3ei$1@bgtnsc02.worldnet.att.net>,
	"Kevin M. Sproule" <kmsproule@worldnet.att.net> writes:

>                                     I thought the whole idea of perl is that
> there is more than one way to do it! (timtowdi)  Most responders to posts
> seem to think that there is only one way to do it.

You can get a screw into a block of wood with a hammer or with a
screwdriver (or other tools and implements). Most people will quickly
agree on which of the above is the better way to do it.

There may be more ways of doing things, but often you'll find that one
of these various ways is the better one. Sometimes you'll find more
than one good way.

Martien
-- 
Martien Verbruggen                  | My friend has a baby. I'm writing down
Interactive Media Division          | all the noises the baby makes so later
Commercial Dynamics Pty. Ltd.       | I can ask him what he meant - Steven
NSW, Australia                      | Wright


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

Date: Thu, 22 Jul 1999 03:13:52 GMT
From: PaperCut@papel.com (PaperCut)
Subject: LWP::UserAgent and/or site not remembering?
Message-Id: <379774db.29456542@news.remarq.com>

Hi, I am trying to auto fetch real time stock quotes from
rtq.thomsoninvest.net The site uses a combination of cookies and
login/password.  I can get as far as summiting my userid and password
and having the site accept the login and issusing a cookie.  After the
login, the site issues <META HTTP-EQUIV="Refresh"
CONTENT="0;URL=../private/quotes/index.sht"> trying to redirect me to
the page.  But perl cannot really do anything with this.

When I issue a 2nd request (this time for the actual fetching of
quotes) the site does not remember that I logged in already.  How can
I have it so the site remembers my login.  Below is the script.
Thanks.


use HTTP::Cookies;
use LWP;
use HTTP::Request::Common qw(POST);

$cookie_jar = HTTP::Cookies->new(
                   File     => "d:\\perl\\eg\\cookies.txt",
                   AutoSave => 1, ignore_discard => 1  );

  $ua = new LWP::UserAgent;
  $ua->agent("Mozilla/4.61");

   my $req = POST 'http://rtq.thomsoninvest.net/cgi-bin/login',
     [ userid => 'username', password => 'password', key => 'I' ];
   my $res = $ua->request($req);
   $cookie_jar->extract_cookies($res);

   $req->content_type('application/x-www-form-urlencoded');
   $req->content('match=www&errors=0');

    print $res->as_string;  	# for debugging

    $req2 = new HTTP::Request('GET',
'http://rtq.thomsoninvest.net/private/cgi-bin/tipsheet_ts?ticker=ibm&group=ts');

     $res2 = $ua->request($req2);
     
      print $res2->as_string;


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

Date: Thu, 22 Jul 1999 03:57:15 GMT
From: PaperCut@papel.com (PaperCut)
Subject: Re: LWP::UserAgent and/or site not remembering?
Message-Id: <379895f6.37932477@news.remarq.com>

On Thu, 22 Jul 1999 03:13:52 GMT, PaperCut@papel.com (PaperCut) wrote:

>Hi, I am trying to auto fetch real time stock quotes from
>rtq.thomsoninvest.net The site uses a combination of cookies and
>login/password.  I can get as far as summiting my userid and password
>and having the site accept the login and issusing a cookie.  After the
>login, the site issues <META HTTP-EQUIV="Refresh"
>CONTENT="0;URL=../private/quotes/index.sht"> trying to redirect me to
>the page.  But perl cannot really do anything with this.
>
>When I issue a 2nd request (this time for the actual fetching of
>quotes) the site does not remember that I logged in already.  How can
>I have it so the site remembers my login.  Below is the script.
>Thanks.
>
>
>use HTTP::Cookies;
>use LWP;
>use HTTP::Request::Common qw(POST);
>
>$cookie_jar = HTTP::Cookies->new(
>                   File     => "d:\\perl\\eg\\cookies.txt",
>                   AutoSave => 1, ignore_discard => 1  );
>
>  $ua = new LWP::UserAgent;
>  $ua->agent("Mozilla/4.61");
>
>   my $req = POST 'http://rtq.thomsoninvest.net/cgi-bin/login',
>     [ userid => 'username', password => 'password', key => 'I' ];
>   my $res = $ua->request($req);
>   $cookie_jar->extract_cookies($res);
>
>   $req->content_type('application/x-www-form-urlencoded');
>   $req->content('match=www&errors=0');
>
>    print $res->as_string;  	# for debugging
>
>    $req2 = new HTTP::Request('GET',
>'http://rtq.thomsoninvest.net/private/cgi-bin/tipsheet_ts?ticker=ibm&group=ts');
>
>     $res2 = $ua->request($req2);
>     
>      print $res2->as_string;


Ok, solved it myself,  just had to add
$cookie_jar->add_cookie_header($req2);  after the HTTP::Request line.
Thanks anyway.


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

Date: Thu, 22 Jul 1999 02:18:43 GMT
From: XXX@hotmail.com (Rich)
Subject: Need Help with Virtual Avenue
Message-Id: <37967e96.222924684@news.giganews.com>


I made a very simple script and tried to run it on my web site on
Virtual Avenue. It keeps giving me an "Internal Server Error." As far
as I know I'm doing every thing right and there is NO CLUE as to what
the problem is!!! Can someone who is using Virtual Avenue give me one
of their simple perl scripts and the corresponding html code so I can
get SOMETHING to work on Virtual Avenue? I need to find out what I
need to do to make a perl script work on this stupid web server. They
give you almost no information about what to do. I am really stuck
right now.



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

Date: Thu, 22 Jul 1999 03:36:01 GMT
From: XXX@hotmail.com (Rich)
Subject: Re: Need Help with Virtual Avenue
Message-Id: <379690e3.227609809@news.giganews.com>


I found out what the GODDAMN problem was. I found out I had to upload
the perl script file as an ASCII instead of a binary (I use WS_FTP).
This never made a difference with HTML files, but I guess it does with
perl. Now I can finally move on. You know how I found out? I
downloaded a freeware script and in the instructions for the script,
it included troubleshooting information. It really sucks that I would
have to find out by this roundabout way and it wasn't mentioned in any
of the Virtual Avenue FAQs or my Perl book.



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

Date: Wed, 21 Jul 1999 15:06:19 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: newbie question: how put files from dir in array
Message-Id: <bn55n7.rn8.ln@magna.metronet.com>

Filip M. Gieszczykiewicz (fmgst+@pitt.edu) wrote:
: In Article <2rbim7.2kj.ln@magna.metronet.com>, through puissant locution, tadmc@metronet.com (Tad McClellan) soliloquized:
: >iLs (iLs@cyberdude.com) wrote:
: >: Hi, I'm just learning perl and wondering how I could put all the file names
: >: of a certain dir. in an array ?
: >: Can somebody show me an example ?
: >
: >   type
: >      perldoc -f readdir
: >   on a properly installed perl, and see the example given there.

: Is there any _particular_ reason why no one recommended:

: @files = glob("$DIR/$PATTERN");

: ??? I use this especially if I want a certain pattern, say
: $PATTERN="*.[Hh][Tt][Mm]*"; then do a foreach $file (@files)...


   I use globs _only_ for throw-away scripts.

   There are several particular reasons why opendir/readdir/grep
   is "better" than globbing:


      1) it's faster (doesn't spawn another process)


      2) it's more portable (doesn't depend on the vagaries of
                             the shell used to expand the globs)


      3) it does not have the limits that some shells have
         ("too many arguments" error message)


      4) full-power regular expressions instead of wimpy filename
         pattern matching.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 22 Jul 1999 02:51:24 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: perl cgi
Message-Id: <MGvl3.192$0S6.7605@nsw.nnrp.telstra.net>

In article <7n5s86$dvh$1@nnrp1.deja.com>,
	msdb159@my-deja.com writes:
> Why doesn't straight Perl CGI scale?

What?

What do you mean? Scale in what way? And why does it have anything to
do with CGI?

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | That's funny, that plane's dustin'
Commercial Dynamics Pty. Ltd.       | crops where there ain't no crops.
NSW, Australia                      | 


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

Date: Thu, 22 Jul 1999 03:47:39 GMT
From: Floyd Morrissette <Webdesigner@NewWebSite.com>
Subject: Re: perl cgi
Message-Id: <7n648o$ghf$1@nnrp1.deja.com>

In article <7n5s86$dvh$1@nnrp1.deja.com>,
  msdb159@my-deja.com wrote:
> Why doesn't straight Perl CGI scale?
>

Others here may know what you mean by this but I don't. What do you mean
by scale?

--
Get your web site from http://www.NewWebSite.com
Consultation is always free.
Help with cgi scripts.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Thu, 22 Jul 1999 02:50:37 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Perl Examples on Parsing HTML
Message-Id: <1Gvl3.191$0S6.7605@nsw.nnrp.telstra.net>

In article <7n5sl0$e3f$1@nnrp1.deja.com>,
	drakek51@my-deja.com writes:
> Does anyone know of a resource that has examples of Perl script that
> parses tags from a web page? 

use HTML::Parser

You can obtain it from CPAN. It probably has some examples in the
distribution or so. It does a good job.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | +++ Out of Cheese Error +++ Reinstall
Commercial Dynamics Pty. Ltd.       | Universe and Reboot +++
NSW, Australia                      | 


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

Date: Thu, 22 Jul 1999 03:30:40 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: perl system call problems
Message-Id: <FF95r4.KMt@world.std.com>

n0jokeg@my-deja.com writes:

>Hi, I'm adding taint checking to a program and one thing I need to do is
>get rid of the backticks and use system() so that I dont use the shell.
>However, I need the output of the command to be saved in a variable.
>How can I do this with system?

Taint checking doesn't require you to use system instead of
backticks. It only requires that you not pass insecure data (its
definition of insecure being data that came from outside the program
itself) to dangerous functions (its definition of dangerous being a
function that will manipulate something outside of the program itself.

If you untaint the command line, and set some environment variables
which are potentially dangerous to safe untainted values, you can use
backticks.

Changing your backticks to list system(LIST) or exec(LIST) is
potentially *less* secure, since perl is not taint checking the
elements of the list. (The program you are calling may not be written
in perl, or may not be running with taint checking enabled; who knows
what it might do with the data.)

If you still need to redirect stdoutput from a program that you will
pass an @ARGV list, I'd suggest to use the "open a pipe to yourself"
technique shown in the perlsec man page. (The "open(KID, "-|")"
example)

>Here's what I've got
>(probably not too useful as I guess it's all wrong):

I know that it gets fustrating at time, and that sometimes this
fustration can blur your vision to what is going on. I hope you don't
take it personally if I point out what the code *is* doing so that you
don't go down this path next time.


>open(BTOUT,system @cmd) or die "Couldn't run [@cmd] $!\n";

What perl does here is:


First it calls system() with the list @cmd as an argument. STDOUT is,
as always with system(), the same as the parent process.

system() returns a value to inform the caller how the process it
executed finished. The format of the integer output is a bit
convoluted, but 0 is a common value.

Perl then passes this return value to open(), converting the intenger
to its string interpretation along the way. The OS will then try to
open a file with the name of number. 

If you had a file named, "0", it very possibly could have opened it
for reading.
-- 
Andrew Langmead


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

Date: Wed, 21 Jul 1999 22:54:11 -0400
From: badri <badri@wpi.edu>
Subject: Re: problem with hash of arrays
Message-Id: <379687D3.1E861BBC@wpi.edu>

Anno Siegel wrote:

[snipped]


> >--- Code starts here ----
> >
> >#!/usr/bin/perl -w
> >
> ># Initialization of the variables ;
> >
> >$pos = 0;
> >$number = 0;
> >
> >use MLDBM 'DB_File';
> >use Fcntl;
> >
> >tie (%hash, 'MLDBM', 'testfile.db', O_CREAT|O_RDWR, 0660) or die $!;
>
> [more code snipped]
>
> You can't store references in a tied hash, not without extra
> gymnastics like Storable, Data::Dumper or friends.  Looking
> at cpan, I see a module MLDBM::Serializer::Data::Dumper, which
> may be specially suited for use with MLDBM.
>

But I was able to do it as long as the size of the array size did not exceed
126. No segmentation faults or anything at all. Works just fine. Also when I
had a look at the raw 'testfile.db' file,  it looked ok. It contained all
the elements = 0 except the number modified and also the key. And further
modifications to any of the numbers got reflected in the file properly.
Using MLDBM seems to be enough for the purpose.


> The error should probably be detected before a segfault happens,
> but in any case references contain live pointers which are useless
> in a second run of the same program.
>

Also, pieces of code from the perl literature (like Programming Perl, Perl
Cookbook etc.) seem to suggest that:

$hash{$key}  [@arrayname] would cause a new anonymous reference to be
associated to the appropriate key (which is validated by the fact that the
first run shows the 'testfile.db' looking ok). Also, $referencetolist =
$hash{$key} seems to be the suggested way of getting a reference to modify
the list before re-writing the data to the disk. But as I said earlier, it
fails.

So I was wondering why it cannot work beyond the specified size (126). Any
ideas would be greatly appreciated.

thanks

badri




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

Date: 22 Jul 1999 02:39:25 GMT
From: tgy@chocobo.org (Neko)
Subject: Re: Programming problem
Message-Id: <7n608t$nrk$0@216.39.141.200>

On 22 Jul 1999 00:31:30 GMT, ebohlman@netcom.com (Eric Bohlman) wrote:

>I can see the Spice Perls as a drag act performing at TPC (come to think 
>of it, The Script Kiddies is a plausible name for a boy band as well).

Not enough girls at TPC to form a band?  That sucks. :)

-- 
Neko | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=


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

Date: Wed, 21 Jul 1999 23:04:32 -0400
From: mshavel@erols.com (Michael Shavel)
Subject: question about this code snip
Message-Id: <mshavel-2107992304320001@130.9.16.207>

Hi

I am trying to figure out someone elses code and have a question.
The code is this:

sub padit{

   my ($str, $pad, $places) = @_;

   return ${pad}x($places - length($str)) . $str;

}

Question: Why is $pad refered to as ${pad} in the second line of the above
subroutine? What does it mean when it is written that way?
Could someone please give me some information regarding this. 

Thanks very much

Mike Shavel


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

Date: Thu, 22 Jul 1999 13:17:25 +1000
From: e-lephant@b-igpond.com (elephant)
Subject: Re: question about this code snip
Message-Id: <MPG.12013854e92597c1989b66@news-server>

Michael Shavel writes ..
>   return ${pad}x($places - length($str)) . $str;

you can write any variable like this .. ie. the line could be (if you 
wanted)

  return ${pad}x(${places} - length(${str})) . ${str};

the reason why it's been used in this instance is because if it wasn't 
there then perl would thing that a variable called $padx was being 
referenced .. ie. it wouldn't see the 'x' as an operator .. it could just 
as easily have been written like this

  return $pad x ($places - length($str)) . $str;

-- 
 jason - remove all hyphens for email reply -


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

Date: 21 Jul 1999 21:18:01 -0600
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: recursive anonymous functions -- problem
Message-Id: <7n62h9$ena@llama.swcp.com>

[posted and cc'd to cited author despite absurd "Sp^M Bl0<k!!1!"]

elephant <e-lephant@b-igpond.com> wrote:
(snip)
> you need to learn more about 'my' and how it is scoped in this instance 
> .. the following will work
> 
> #--begin
> my $func;
> $func = sub {
>     my $param = shift;
>     if($param > 1) { 
>         return $param * &$func($param - 1);
>     }
>     else {
>         return 1;
>     }
> }
> #--end

Yes, but why do it that way when you can do it in a pure functional
fashion?  I wish we had automatic tail recursion detection so that this
could be optimized to iterative control and data structure rather than
requring the programmer to munge @_ to produce a tail recursive version.

So, go study your Friedman books some more and be amazed.  I haven't heard
from him yet for permission to release the code for _EOPL_ in Perl.
Soon, maybe real soon now...

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

my $f = sub {
	my $a = shift;
	sub { $a->( $a, my $n = shift, my $r = 1 ) }
}->( sub {
	$_[2] *= $_[1]--;
	$_[1] > 0 ? goto &{$_[0]} : $_[2];
});

print "7! = ", $f->(7), "\n";
print "9! = ", $f->(9), "\n";
__END__

-- 
  o   hudson@swcp.com                 tbhudso@cs.sandia.gov   O___|   
 /|\  http://www.swcp.com/~hudson/          H 505.323.38.81   /\  \_  
 <<   KC5RNF @ N5YYF.NM.AMPR.ORG            W 505.284.24.32   \ \/\_\  
  0                                                            U \_  | 


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

Date: 21 Jul 1999 20:09:31 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: regular Expression
Message-Id: <37967d5b@cs.colorado.edu>

In comp.lang.perl.misc, 
    ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
:Note that for somebody who cannot read, everything looks like proving
:his point.  Did I say anywhere that the old names are going to be
:disabled?  

Yeah, whatever, Ilya.  Welcome to the Black Hole.  Enjoy.

The rest of you should try not to pay too much attention to his frothings.
He just gets pissed when I stop him from screwing up standard Perl or
making horribly ugly things in the core that barely 1/1,000th of the
populace cares about.

--tom
-- 
    "Any computer scientist who praises orthogonality should be sentenced to
    use an Etch-a-Sketch." --Larry Wall


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

Date: Thu, 22 Jul 1999 12:16:03 +1000
From: mark@NO-SPAM.lavalink.com.au (Mark Francis)
Subject: Re: setuid and opening a file for writing
Message-Id: <mark-2207991216030001@kilimanjaro.lavalink.com.au>

In article <1dvbad6.1nzf71e16nieqqN@p37.tc17.metro.ma.tiac.com>,
rjk@linguist.dartmouth.edu (Ronald J Kimball) wrote:

> Mark Francis <mark@NO-SPAM.lavalink.com.au> wrote:
> 
> >                 open (FILE, "> $new_file")
> >                         || die "can't open $new_file: $!";
> 
> > This is almost character for character from perlipc on how to safely write
> > a file when running setuid. But, it still craps out with "Insecure
> > dependency in open while running with -T ....".
> 
> If $new_file came from outside the script (user input, environment
> variable, etc.), did you remember to untaint it?
> 

Thanks for the info. Unfortunately, yes, $new_file is already being
untainted earlier on with:

 if ($new_file =~ /^([a-zA-Z0-9\-_\.]+)$/) {
         $new_file = $1;
 } else {
      ...

Any other suggestions?

cheers,
Mark


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

Date: Thu, 22 Jul 1999 03:15:17 GMT
From: Thien Syh <gabriel@asiaep.com>
Subject: special case : split this string...
Message-Id: <7n62bt$g03$1@nnrp1.deja.com>

i want to split the string into an array of string and return the array
value.
Could somebody help?

----- Personal Information -----
<br>Name (First/Last):a
<br>CompanyName: a
<br>Street: a
<br>City: a
<br>State: a
<br>Zip: a
<br>Country: a
<br>Phone: a
<br>Fax: a
<br>Email: a
<br>

with many thanks,
Gabriel.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 22 Jul 1999 02:23:31 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Stop parent but not child process
Message-Id: <7n5vb3$thl$1@lublin.zrz.tu-berlin.de>

Mike Eiringhaus  <mail@netron.de> wrote in comp.lang.perl.misc:
>Hi!
>
>I want to start a CD writing over the WWW Browser. So the Perl Program
>must send an execution message and terminate displaying to the STDOUT.
>
>The childprocess (i.e. cdrecord) must write the CD over 45 minutes and
>then terminates after sending en Email to the admin.
>
>I have tryed exec and qx/... &/ but it doesnt work.

You have at least twice recommended fork() as a solution to other
people's problems.  Why don't you take some of your own medicine?

Anno


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

Date: 21 Jul 1999 21:33:35 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Testing for the existing of a key in a hash
Message-Id: <slrn7pd0mr.oqh.abigail@alexandra.delanet.com>

John Borwick (John.Borwick@sas.com) wrote on MMCL September MCMXCIII in
<URL:news:3797e686.184535758@newshost.unx.sas.com>:
== On Wed, 21 Jul 1999 09:27:41 -0500, Bruno Pagis
== <pagib@aur.alcatel.com> wrote:
== 
== >Is there a better way than
== >if ($hash{$key} eq ".")
== >to know that a key has no entry in a hash ?
== >I figured out that when a key does not exist, I get a dot returned for
== >the value, but I'm not even sure that it is "standard".
== 
== I would like to see code where $hash{key} returns "." when $hash{key}
== undefined.


Oh dear. A challenge!

I assume you mean when "$hash {key} doesn't exists", as that's the issue
raised by Bruno, but doing it when it's undefined will be possible too.


#!/opt/perl/bin/perl -w

use strict;

package Tie::Silly::Hash;

sub  TIEHASH  {my ($s, $k, $v) = ({}, @_); bless  $s =>  $k                    }
sub    FETCH  {my ($s, $k, $v) =      @_ ; exists $s -> {$k} ? $s -> {$k} : "."}
sub    STORE  {my ($s, $k, $v) =      @_ ;        $s -> {$k} = $v              }
sub   DELETE  {my ($s, $k, $v) =      @_ ; delete $s -> {$k}                   }
sub   EXISTS  {my ($s, $k, $v) =      @_ ; exists $s -> {$k}                   }
sub FIRSTKEY  {my ($s, $k, $v) =      @_ ; keys  %$s;    each %$s              }
sub  NEXTKEY  {my ($s, $k, $v) =      @_ ;               each %$s              }
sub    CLEAR  {my ($s, $k, $v) =      @_ ; undef %$s                           }


=pod

This code is copyright 1999 by Abigail.

This code is free and open software. You may use, copy, modify,
distribute and sell this code (and any modified variants) in any way
you wish, provided you do not restrict others to do the same.

=cut


package main;


tie my %hash, 'Tie::Silly::Hash';

print $hash {"larry wall"}, "\n";


__END__
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: 22 Jul 1999 00:04:44 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Testing for the existing of a key in a hash
Message-Id: <x71ze1fhyb.fsf@home.sysarch.com>

>>>>> "A" == Abigail  <abigail@delanet.com> writes:

  A> John Borwick (John.Borwick@sas.com) wrote on MMCL September MCMXCIII in
  A> == I would like to see code where $hash{key} returns "." when $hash{key}
  A> == undefined.

  A> sub FETCH {my ($s, $k, $v) = @_ ; exists $s -> {$k} ? $s -> {$k} :
  A> "."}

abigail, you are too cute for words.

  A> This code is free and open software. You may use, copy, modify,
  A> distribute and sell this code (and any modified variants) in any way
  A> you wish, provided you do not restrict others to do the same.

as if anyone would.

  A> tie my %hash, 'Tie::Silly::Hash';

  A> print $hash {"larry wall"}, "\n";

are you saying that larry is equivilent to '.'?

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: 22 Jul 1999 03:36:02 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Timeout question
Message-Id: <7n63j2$toc$1@lublin.zrz.tu-berlin.de>

Mike Eiringhaus  <mail@netron.de> wrote in comp.lang.perl.misc:
>Bruce McFarlane wrote:
>> The following block works 99% of the time but occasional the inevitable happens and it goes into a loop. Does perl have a timeout function and can I add it to this block somehow?
>> 
>> while (($tname eq $sname) || ($xname =~ /$sname/m)) {
>>   &retry;
>> }
>
>Try the following:
>
>for($i=XXX; $i && ($tname eq $sname) || ($xname =~ /$sname/m); $i--) { 
>  &retry;
>}
># Where XXX is the max loop count.

Your logic is flawed.  && binds more tightly than ||, so if we have a
perpetual match in $xname =~ /$sname/m, you don't break out of the
loop.  Trond Michelsen has suggested a better way to limit the loop
count, though that was not exactly what the original poster wanted.

For a timeout, see perldoc -f alarm and the %SIG hash in perldoc perlvar.

Anno


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

Date: Wed, 21 Jul 1999 17:12:31 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Trouble with Error Message
Message-Id: <v3d5n7.rn8.ln@magna.metronet.com>

Greg Shalette (gshalet@panix.com) wrote:

: The statement:

: substr($in{"long_description"}, $TempPos, 0) = "<br>";

: where $TempPos is a variable that was just incremented,
                                        ^^^^^^^^^^^^^^^^

   What just happened doesn't matter.

   What matters is the _value_ of $TempPos, and the 
   length($in{"long_description"}).



: is causing the following error message:

: "Premature end of script headers"


   That is not a Perl error message (you can tell because it does
   not appear in the perldiag.pod file that came with perl).

   Maybe it is a error message from some other program. If so, you
   should ask in a newsgroup where such things are discussed, like:

      comp.infosystems.www.authoring.cgi
      comp.infosystems.www.servers.mac
      comp.infosystems.www.servers.misc
      comp.infosystems.www.servers.ms-windows
      comp.infosystems.www.servers.unix



: Other Information:
: This is a CGI script which is putting a <br> tag into a string every so often.
: The reason that this error is weird is that that if I were to replace, just for
: testing purposes, the $TempPos with an integer, or even set a new
: variable that hasn't already been incremented earlier in the program
: to equal an integer, it works fine.  What could have possibly happened to
: this variable to cause that error?


   I think you might be getting some output on STDERR.

   What did it say when you read it in your server error logs?

   You might be walking off of the end of the $in{"long_description"}
   string, resulting in (if you have warnings enabled):

      substr outside of string at ./prog line x.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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


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