[16876] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4288 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 11 18:05:47 2000

Date: Mon, 11 Sep 2000 15:05:25 -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: <968709925-v9-i4288@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 11 Sep 2000     Volume: 9 Number: 4288

Today's topics:
        5.6.0 shebang under NT (was Re: how to match the hole s (Andrew J. Perrin)
    Re: 5.6.0 shebang under NT (was Re: how to match the ho <randy_734@my-deja.com>
    Re: 5.6.0 shebang under NT (was Re: how to match the ho (Andrew J. Perrin)
    Re: 5.6.0 shebang under NT (was Re: how to match the ho <randy_734@my-deja.com>
    Re: ActivePerl 613 dropping # from directory name <bcaligari@my-deja.com>
    Re: C&C: Apche: How can I prevent denial of service? (brian d foy)
        categories <nckdistr@pacbell.net>
        Change Windows Desktop BG <jluongonospam@draper.com>
    Re: Creating the http-header without using CGI.pm nobull@mail.com
        cwd, iis, ActiveState Perl 613 <scotts@itinet.com>
    Re: debugger oddity (Michael P. Soulier)
        Disable Apache shebang line "feature"? <dmgreer@airmail.net>
    Re: Disable Apache shebang line "feature"? <anders@wall.alweb.dk>
    Re: Disable Apache shebang line "feature"? (Tim Hammerquist)
        Expanding variables in strings questions kjeldahl@hotmail.com
    Re: Expanding variables in strings questions <tina@streetmail.com>
    Re: Expanding variables in strings questions (Craig Berry)
    Re: Expanding variables in strings questions (Craig Berry)
    Re: File I/O to access file on same server, different a <bkennedy@hmsonline.com>
    Re: Getting started w/ Perl <gphil111@my-deja.com>
        help in writing a card game <kelley.a.kent@intel.com>
    Re: Holy moly! Substitution on 10-kb scalar takes over  (Sean McAfee)
        How do I access a drive on the network? <mark_shutt@hotmail.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 11 Sep 2000 14:10:54 -0400
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: 5.6.0 shebang under NT (was Re: how to match the hole string by first word? (need help))
Message-Id: <u66o2pzo1.fsf_-_@demog.berkeley.edu>

Randy <randy_734@my-deja.com> writes:

> I noticed that you included the shebang line in your listing and also
> mentioned that you are using NT.  I'm using 5.006 on NT and find that
> #!perl -w      
> doesn't work.  It doesn't do anything.
> 

What do you mean, exactly, by "doesn't work"?  It's true that the NT
shell doesn't interpret shebangs (#!...) for what interpreter to send
the script to; that's a limitation of the NT shell. Your options
include associating file extensions, upgrading to bash for NT as your
shell, or starting the script as "perl scriptname".

However, it does "work" in that perl successfully sets the appropriate
flags, in this case -w, for the script. Are you finding that it
doesn't do that? I would be surprised. If so, pls. post code.

-- 
----------------------------------------------------------------------
Andrew Perrin - Solaris-Linux-NT-Samba-Perl-Access-Postgres Consulting
       aperrin@igc.apc.org - http://demog.berkeley.edu/~aperrin
----------------------------------------------------------------------


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

Date: Mon, 11 Sep 2000 19:13:08 GMT
From: Randy <randy_734@my-deja.com>
Subject: Re: 5.6.0 shebang under NT (was Re: how to match the hole string by first word? (need help))
Message-Id: <39bd2d6d.20151140@207.126.101.100>

What I meant was including the line:

#!perl -w

within a Perl script on my system does not cause Perl to issue
warnings.  If I add the -w to the command line it issues warnings.  If
I use the command:

use warnings;

it issues warnings.  On my system, the shebang does not seem to set
the warnings flag.  I am starting the script from a DOS batch file.


aperrin@demog.berkeley.edu (Andrew J. Perrin) wrote:

>Randy <randy_734@my-deja.com> writes:
>
>> I noticed that you included the shebang line in your listing and also
>> mentioned that you are using NT.  I'm using 5.006 on NT and find that
>> #!perl -w      
>> doesn't work.  It doesn't do anything.
>> 
>
>What do you mean, exactly, by "doesn't work"?  It's true that the NT
>shell doesn't interpret shebangs (#!...) for what interpreter to send
>the script to; that's a limitation of the NT shell. Your options
>include associating file extensions, upgrading to bash for NT as your
>shell, or starting the script as "perl scriptname".
>
>However, it does "work" in that perl successfully sets the appropriate
>flags, in this case -w, for the script. Are you finding that it
>doesn't do that? I would be surprised. If so, pls. post code.
>
>-- 
>----------------------------------------------------------------------
>Andrew Perrin - Solaris-Linux-NT-Samba-Perl-Access-Postgres Consulting
>       aperrin@igc.apc.org - http://demog.berkeley.edu/~aperrin
>----------------------------------------------------------------------



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

Date: 11 Sep 2000 15:23:38 -0400
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: Re: 5.6.0 shebang under NT (was Re: how to match the hole string by first word? (need help))
Message-Id: <uwvgiohqd.fsf@demog.berkeley.edu>

Randy <randy_734@my-deja.com> writes:

> What I meant was including the line:
> 
> #!perl -w
> 
> within a Perl script on my system does not cause Perl to issue
> warnings.  If I add the -w to the command line it issues warnings.  If
> I use the command:
> 
> use warnings;
> 
> it issues warnings.  On my system, the shebang does not seem to set
> the warnings flag.  I am starting the script from a DOS batch file.
> 

Hmm, seems odd to me - I'll try it tomorrow at work where I have 5.6.0
for NT installed. Here at home I have 5.005_03 for NT, and what you're
saying doesn't happen, and I have 5.0.6 for Linux, which works fine:

achebe:~> perl test.pl
Use of uninitialized value in concatenation (.) at test.pl line 5.

achebe:~> cat test.pl
#!perl -w

$foo = 'hi andy';
undef $foo;
print "$foo\n";


-- 
----------------------------------------------------------------------
Andrew Perrin - Solaris-Linux-NT-Samba-Perl-Access-Postgres Consulting
       aperrin@igc.apc.org - http://demog.berkeley.edu/~aperrin
----------------------------------------------------------------------


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

Date: Mon, 11 Sep 2000 21:40:01 GMT
From: Randy <randy_734@my-deja.com>
Subject: Re: 5.6.0 shebang under NT (was Re: how to match the hole string by first word? (need help))
Message-Id: <39bd504e.29080921@207.126.101.100>

The problem is with the method I am using to run the script.

@rem = '
@echo off
e:\perl\bin\perl %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
goto EndOfPerl
@rem ';

#!perl -w
print "foo\n";
print $foo;

__END__
:EndOfPerl

It is the DOS "wrapper" that is keeping -w from working.


aperrin@demog.berkeley.edu (Andrew J. Perrin) wrote:

>Randy <randy_734@my-deja.com> writes:
>
>> What I meant was including the line:
>> 
>> #!perl -w
>> 
>> within a Perl script on my system does not cause Perl to issue
>> warnings.  If I add the -w to the command line it issues warnings.  If
>> I use the command:
>> 
>> use warnings;
>> 
>> it issues warnings.  On my system, the shebang does not seem to set
>> the warnings flag.  I am starting the script from a DOS batch file.
>> 
>
>Hmm, seems odd to me - I'll try it tomorrow at work where I have 5.6.0
>for NT installed. Here at home I have 5.005_03 for NT, and what you're
>saying doesn't happen, and I have 5.0.6 for Linux, which works fine:
>
>achebe:~> perl test.pl
>Use of uninitialized value in concatenation (.) at test.pl line 5.
>
>achebe:~> cat test.pl
>#!perl -w
>
>$foo = 'hi andy';
>undef $foo;
>print "$foo\n";
>
>
>-- 
>----------------------------------------------------------------------
>Andrew Perrin - Solaris-Linux-NT-Samba-Perl-Access-Postgres Consulting
>       aperrin@igc.apc.org - http://demog.berkeley.edu/~aperrin
>----------------------------------------------------------------------



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

Date: Mon, 11 Sep 2000 21:15:52 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: ActivePerl 613 dropping # from directory name
Message-Id: <8pji1i$btv$1@nnrp1.deja.com>

In article <Pn5v5.22$pB3.6049@nntp0.chicago.il.ameritech.net>,
  "John Roth" <johnroth@ameritech.net> wrote:
> I've been doing a little file work on Win 98 with Active Perl,
> and I found, to my chagrin, that it silently deletes the # character
> from the file name. I'm using the 613 build.
>
> The relevant chunk of code is as follows:
>
> opendir( DIRHAND, ".") or die "cannot open directory";
> @dirlist = readdir DIRHAND;
> closedir DIRHAND;
> @shortlist = grep /^TimeOut/, @dirlist;
> @sortedfiles = sort @shortlist;
> foreach $infile (@sortedfiles) {
>   print "$infile\n";
> }

worked fine on win2k with ActivePerl build 617

B


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


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

Date: Mon, 11 Sep 2000 15:56:09 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: C&C: Apche: How can I prevent denial of service?
Message-Id: <brian-ya02408000R1109001556090001@news.panix.com>

In article <u9em2qc0s7.fsf@wcl-l.bham.ac.uk>, nobull@mail.com posted:

> nl1753@my-deja.com writes:

> > Hi here!
> > How can i limit the number of connections or sockets that one IP-Adress
> > is allowed to open on Port 80?
> > I wrote a little Perl script that opens 1000 Sockets without closing
> > them, and it made Apache not working any more. That´s why I´am asking.

> So let's get this straight you are asking how to protect Apache from a
> DOS attack.  You are choosing to ask this is a Perl newsgroup because
> you used a test program written in Perl to confirm that Apache was
> vulnerable.

well, there are things like Apache::Throttle and Randal's nifty
speed bump handler that he describes in one of his WebTechniques
columns.

   http://www.stonehenge.com/merlyn/WebTechniques/

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>


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

Date: Mon, 11 Sep 2000 13:28:22 -0700
From: Nolan Brame <nckdistr@pacbell.net>
Subject: categories
Message-Id: <39BD4066.907192E4@pacbell.net>

I using wwwboard by mattscript is the a way that I could add categories.
Thanks in advance Nolan Brame



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

Date: Mon, 11 Sep 2000 15:35:52 -0400
From: "James M. Luongo" <jluongonospam@draper.com>
Subject: Change Windows Desktop BG
Message-Id: <39BD3418.EF377E9D@draper.com>

How would I use Perl for Windows to randomly change my windows desktop
background each time I logged into my computer?


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

Date: 11 Sep 2000 19:26:19 +0100
From: nobull@mail.com
Subject: Re: Creating the http-header without using CGI.pm
Message-Id: <u966o2bx9w.fsf@wcl-l.bham.ac.uk>

"Tom Klinger" <tom@tomklinger.com> writes:

> I found out that most ISP's (or only mine?) have old CGI.pm modules
> installed.

> Therefore I've to generate the header on my own. Because of the missing
> CGI.pm module I ask myself if this would work:

Why not just put GCI.pm in your private module directory.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Mon, 11 Sep 2000 16:59:14 -0500
From: "Scott Schaumann" <scotts@itinet.com>
Subject: cwd, iis, ActiveState Perl 613
Message-Id: <SBcv5.384$dw6.56389@nnrp1.sbc.net>

I've got a simple script that reports the cwd. It's being called via the web
(cgi.pm) and consistently returns the wrong answer. My web server is IIS (4)
on WinNT 4. I'm finding that the the directory returned is the root of the
virtual directory in which the code resides, instead of the actual
subdirectory. Has anyone seen this? Know how to fix it?

Scott Schaumann
Interchange Technologies
scotts@itinet.com




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

Date: 11 Sep 2000 20:50:53 GMT
From: msoulier@nortelnetworks.com (Michael P. Soulier)
Subject: Re: debugger oddity
Message-Id: <8pjgjd$8oh$1@bmerhc5e.ca.nortel.com>

In article <39bceba4$1@cs.colorado.edu>, Tom Christiansen wrote:

>What is the scope that owns that lexical?  It's the eval STRING
>which each command executes under, of course.  So why are you my()ing
>it?  In this scenario, you're saying "make sure this goes away after
>this statement".  If you are trying to set the variable in the
>currently executing scope, even if that's a lexical, you'd better
>now do that.

    So this is just because I started the debugger with -de 0 instead of
providing a script where it can have file scope then?

[wmerh0sw-msoulier-test]$ cat try
#!/bnr/projects/pegasus/perl5 -w

use FileHandle;

my $filehandle = new FileHandle;

print "done\n";
[wmerh0sw-msoulier-test]$ perl -d ./try

Loading DB routines from perl5db.pl version 1.0401
Emacs support available.

Enter h or `h h' for help.

main::(./try:5):        my $filehandle = new FileHandle;
  DB<1> n
main::(./try:7):        print "done\n";
  DB<1> x $filehandle
0  FileHandle=GLOB(0x401a4034)
   -> *Symbol::GEN0

    Ah. Better. I didn't realize that -de 0 had such different behaviour. 

    Thanks,

    Mike

-- 
Michael P. Soulier, 1Z22, SKY  Tel: 613-765-4699 (ESN: 39-54699)
Optical Networks, Nortel Networks, SDE Pegasus
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to UNIX
Nortel Linux User's Group Ottawa: (internal) http://nlug.ca.nortel.com:8080


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

Date: Mon, 11 Sep 2000 14:32:49 -0500
From: "Dale Greer" <dmgreer@airmail.net>
Subject: Disable Apache shebang line "feature"?
Message-Id: <ACF6B73C90E1AC9D.7DC2495E67702D36.2D53744722CCEA63@lp.airnews.net>

I've read all the discussions on shebang line shenanigans, but I still don't
see an acceptable solution for me. Is there any way to just disable this
"feature"? Since Apache reads the PATH variable anyway, you can end up just
putting #!perl, which hardly imparts any information, so why can't you just
make Apache ignore the shebang line and use the path variable to look for
Perl? At least one web server I know of does just that. I'm sure you could
go into the Apache code and add some directive to impart this ability to
ignore the shebang line, but hasn't someone already done that by now?

In summary, the solutions presented for this problem are

1. Write a Perl script to change all shebang lines from one environment to
another. Quick, dirty, sucky. If the inventors of Perl had made the shebang
line aliasable, this kind of solution wouldn't be necessary.

2. Add a "ScriptInterpreterSource registry" line to httpd.conf. This only
works if your Perl scripts have the .pl extension. What I've been given to
work with has the .cgi extension. If I make .cgi invoke the Perl
interpreter, my "C/C++" cgi's wont work.

3. Install in a directory structure to mimic that of the Perl source. So now
I have to reinstall Perl, and it will work with the Perl source I have now,
but what if someone sends me some source from a different structure? If the
inventors of Perl had made the shebang line aliasable, this kind of solution
wouldn't be necessary.

4. Use another web server. I can't do that, I'm stuck with Apache.

Dale Greer
dmgreer@airmail.net




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

Date: Mon, 11 Sep 2000 20:05:37 GMT
From: Anders Lund <anders@wall.alweb.dk>
Subject: Re: Disable Apache shebang line "feature"?
Message-Id: <lWav5.181$Tn3.4222@news010.worldonline.dk>

Dale Greer wrote:

> I've read all the discussions on shebang line shenanigans, but I still
> don't see an acceptable solution for me. Is there any way to just disable
> this "feature"? Since Apache reads the PATH variable anyway, you can end
> up just putting #!perl, which hardly imparts any information, so why can't
> you just make Apache ignore the shebang line and use the path variable to
> look for Perl? At least one web server I know of does just that. I'm sure
> you could go into the Apache code and add some directive to impart this
> ability to ignore the shebang line, but hasn't someone already done that
> by now?
> 
> In summary, the solutions presented for this problem are
> 
> 1. Write a Perl script to change all shebang lines from one environment to
> another. Quick, dirty, sucky. If the inventors of Perl had made the
> shebang line aliasable, this kind of solution wouldn't be necessary.
> 
> 2. Add a "ScriptInterpreterSource registry" line to httpd.conf. This only
> works if your Perl scripts have the .pl extension. What I've been given to
> work with has the .cgi extension. If I make .cgi invoke the Perl
> interpreter, my "C/C++" cgi's wont work.
> 
> 3. Install in a directory structure to mimic that of the Perl source. So
> now I have to reinstall Perl, and it will work with the Perl source I have
> now, but what if someone sends me some source from a different structure?
> If the inventors of Perl had made the shebang line aliasable, this kind of
> solution wouldn't be necessary.
> 
> 4. Use another web server. I can't do that, I'm stuck with Apache.
> 
> Dale Greer
> dmgreer@airmail.net
> 
> 

What is wrong with the shebang line? Dig you get a new installation of perl 
to use, which has another location?

Perl people didn't invent the shebang line, it is how unix recognizes how 
to execute a script file. Shell scripts, tcl scripts and many others use 
the shebang line.

If perl was moved, another dirty hack is to leave a symlink in place of the 
old location. If your scripts has the shebang line 
#!/usr/local/bin/perl
but your perl is moved to
/usr/bin/perl

then just
$ln -s /usr/bin/perl /usr/local/bin/perl

-anders
-- 
[ the word wall - and the trailing dot - in my email address
is my _fire_wall - protecting me from the criminals abusing usenet]


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

Date: Mon, 11 Sep 2000 20:11:06 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: Disable Apache shebang line "feature"?
Message-Id: <slrn8rqfqe.jc.tim@degree.ath.cx>

Dale Greer <dmgreer@airmail.net> wrote:
> I've read all the discussions on shebang line shenanigans, but I still don't
> see an acceptable solution for me. Is there any way to just disable this
> "feature"? Since Apache reads the PATH variable anyway, you can end up just
> putting #!perl, which hardly imparts any information, so why can't you just
> make Apache ignore the shebang line and use the path variable to look for
> Perl? At least one web server I know of does just that. I'm sure you could
> go into the Apache code and add some directive to impart this ability to
> ignore the shebang line, but hasn't someone already done that by now?

I'm unsure as to what your problem with the shebang line is.  Is it
actually causing a problem, or just distracting from your code?  ;)

Aside from being excellent practice, having a shebang line in your
script also comes in extremely useful, even if your default command
interpreter doesn't care.  A sample of uses:

1. Almost any Unix shell will consider a script with a shebang line
executable in and of itself.
2. Any Apache server will do the same.
(1 & 2 are true regardless of, and often without, filename extensions.)
3. Shell replacements for Win32: both Cygnus and MKS have considerable
alternatives to Win32's seriously lacking CMD.EXE or *gasp!*
COMMAND.COM.
4. Perl scans any script it's invoked upon for a line matching this
(guesswork) regex:
	m{#!.*?perl}
One reason for this (among many others) is that you can have a switch in
a script and not have to specify it from the command line (or URL) every
time.  For example:

	#!/usr/bin/perl -wT

is a common shebang line for CGI scripts.

> In summary, the solutions presented for this problem are
> 
> 1. Write a Perl script to change all shebang lines from one environment to
> another. Quick, dirty, sucky. If the inventors of Perl had made the shebang
> line aliasable, this kind of solution wouldn't be necessary.

I'm not quite sure what you mean by "aliasable", but the creators of
Perl didn't design the shebang line concept.  In fact, Perl has little
to do with the shebang line; it's mostly for the shell or, in this case,
Apache.  Perl _does_ however scan the shebang line _after_ the
interpreter has been invoked on the script to check for any switches
that may not have been passed by the shell.

And what do you mean by "one environment to another?"

> 2. Add a "ScriptInterpreterSource registry" line to httpd.conf. This only
> works if your Perl scripts have the .pl extension. What I've been given to
> work with has the .cgi extension. If I make .cgi invoke the Perl
> interpreter, my "C/C++" cgi's wont work.

Are you using a cgi-bin directory (aka "ScriptAlias"ed)?  The primary
advantage of Apache (and the shebang line in general) is that it frees
you from the hassle created by Microsoft's putting too much emphasis on
a file's extension.

> 3. Install in a directory structure to mimic that of the Perl source. So now
> I have to reinstall Perl, and it will work with the Perl source I have now,
> but what if someone sends me some source from a different structure? If the
> inventors of Perl had made the shebang line aliasable, this kind of solution
> wouldn't be necessary.

This paragraph makes no sense to me.  And you're still putting blame on
"the inventors of Perl", whereas I haven't seen any evidence Perl is
even at fault.

> 4. Use another web server. I can't do that, I'm stuck with Apache.

My advice:

1. Learn Apache. It's virtually infinitely configurable, and I'm almost
certain you can solve your problem without any modules.  You may,
however, need to modify the directory struct a bit to allow
ScriptAlias'ing.

2. Post any further questions to the apache newsgroup, unless you're
prepared to back your claim that perl has any liability in your problem.

3. Don't try to make Apache (or Perl) like another server/language.
They are both extremely powerful tools which have justly evolved out of
the culture they came from.  (And I'd personally suggest being grateful
your employer even _allows_ you to use Apache, but that's me.)

4. Relax. Read a book...perhaps a book on Apache.  Wrox publishes a
detailed one that I'm sure could help you.

$luck++ while $success < $certain;

-- 
-Tim Hammerquist <timmy@cpan.org>
Pride gets no pleasure out of having something,
only out of having more of it than the next man.
	-- C. S. Lewis


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

Date: Mon, 11 Sep 2000 20:07:43 GMT
From: kjeldahl@hotmail.com
Subject: Expanding variables in strings questions
Message-Id: <8pje1t$6mc$1@nnrp1.deja.com>

I've read perlfaq4 about expanding variables in strings. I'm using the
method of expanding variables from a hash, like below:

  $code =~ s/\$(\w+)/$self->{fieldnames}->{$1}/g;

where $code is the text string and $self->{fieldnames} point to the hash
to be used.

This works great, except for cases where a referenced variable does NOT
exist in the hash. Since I use this code in an eval statement later,
there are actually other variables that will be interpolated when
eval'ing the string that is not part of the hash.

The "straightforward but stupid" solution to this is the following code:

  # Search and replace only $variables that exist in the hash
  my $x = index ($code, '$');
  my $clength = length ($code);
  while (($x >= 0) && ($x < $clength)) {
    my $x2 = $x+1;
    my $char = substr ($code, $x2, 1);
    while (($char =~ /[a-zA-Z_]/) && ($x2 < $clength)) {
      $x2++;
      $char = substr ($code, $x2, 1);
    }
    # If we get here, there is a variable to be interpolated
    # starting at position $x ending at $x2.
    my $varname = substr ($code, $x+1, $x2-$x-1);
    if (exists ($self->{fieldnames}->{$varname})) {
      substr ($code, $x, $x2-$x, $self->{fieldnames}->{$varname});
    }
    $x = index ($code, '$', $x2+1);
  }

In short, this search for instances of $somevariable name and verify
that the actual variable actually exist in the hash and only replace the
variable if a value can be found in the hash.

Any simpler/better ways of doing this?

Thanks in advance,

Marius Kjeldahl


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


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

Date: 11 Sep 2000 21:03:46 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Expanding variables in strings questions
Message-Id: <8pjhbh$dbnfn$5@ID-24002.news.cis.dfn.de>

hi,
In comp.lang.perl.misc kjeldahl@hotmail.com wrote:
> I've read perlfaq4 about expanding variables in strings. I'm using the
> method of expanding variables from a hash, like below:

>   $code =~ s/\$(\w+)/$self->{fieldnames}->{$1}/g;

> where $code is the text string and $self->{fieldnames} point to the hash
> to be used.

> This works great, except for cases where a referenced variable does NOT
> exist in the hash. Since I use this code in an eval statement later,
> there are actually other variables that will be interpolated when
> eval'ing the string that is not part of the hash.

what about that:
 $code =~ s/\$(\w+)/exists $self->{fieldnames}->{$1}?$self->{fieldnames->{$1}:"$1"/eg;

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \__,_\___/\___/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Mon, 11 Sep 2000 21:33:43 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Expanding variables in strings questions
Message-Id: <srqjtn48ct629@corp.supernews.com>

kjeldahl@hotmail.com wrote:
: I've read perlfaq4 about expanding variables in strings. I'm using the
: method of expanding variables from a hash, like below:
: 
:   $code =~ s/\$(\w+)/$self->{fieldnames}->{$1}/g;
: 
: where $code is the text string and $self->{fieldnames} point to the hash
: to be used.
: 
: This works great, except for cases where a referenced variable does NOT
: exist in the hash. Since I use this code in an eval statement later,
: there are actually other variables that will be interpolated when
: eval'ing the string that is not part of the hash.
: 
: The "straightforward but stupid" solution to this is the following code:
[sbs code snipped]

Ow!  Yeah, much easier ways exist.  Voila:

  $code =~ s/\$(\w+)/exists $self->{fieldnames}->{$1} ?
                            $self->{fieldnames}->{$1} :
                            '$' . $1/eg;

That is, if it exists, use it; if it doesn't, reconstruct the original
string by gluing the '$' back on the front.  The /e modifier is what makes
this work.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Every force evolves a form."
   |              - Shriekback


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

Date: Mon, 11 Sep 2000 21:44:56 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Expanding variables in strings questions
Message-Id: <srqkio52ct6157@corp.supernews.com>

Tina Mueller (tina@streetmail.com) wrote:
:  $code =~ s/\$(\w+)/exists $self->{fieldnames}->{$1}?$self->{fieldnames->{$1}:"$1"/eg;

Double quotes aren't needed on the last $1 as you've written it;
unfortunately, you also lose the initial $ in the source.  "\$$1" would
work, or '$'.$1 as I wrote it in my earlier post.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Every force evolves a form."
   |              - Shriekback


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

Date: Mon, 11 Sep 2000 19:53:06 GMT
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: File I/O to access file on same server, different account?
Message-Id: <CKav5.21063$AW2.261884@news1.rdc2.pa.home.com>


"Hal Barnett" <hbarnett@net1.net> wrote in message
news:39BC26B2.6F550600@net1.net...
> This might be a real dumb question, but...
> Is there a way to read and write to text files that are on a different
> account on the same server? In other words if 2 different web sites want
>
> to share their flat files, is it possible to do this using Perl's file
> I/O. I'm guessing that it would be possible if the people running the
> server were to set the permissions to allow this. Is this ever done?

Thats a good guess - yes multiple process can access the same file.  If its
read-only access I imagine the web server knows how to handle it, but for
write access you'll probably want to look into the flock() function:
perldoc -f flock.  But if file locking is a real issue, you may want to
consider using DBI and a real database engine, there are free ones like
mysql.

--Ben Kennedy




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

Date: Mon, 11 Sep 2000 20:28:36 GMT
From: Phil <gphil111@my-deja.com>
Subject: Re: Getting started w/ Perl
Message-Id: <8pjf8m$88v$1@nnrp1.deja.com>

  "Lincoln Marr" <lincolnmarr@nospam.europem01.nt.com> wrote:
>
> "Phil" <gphil111@my-deja.com> wrote in message
> > > Id really like to get into learning perl (specifically for cgi
> > purposes).......... (snip)

> Do you have a Unix box you can get started on? If not then you can
run Perl
> on your windows system, and just ftp your scripts to your site when
you're
> done. Nevertheless it will still be useful to learn basic Unix
commands, as
> you at some stage will probably need to telnet to your server and
change
> file permissions, move files etc.
>
<snip>

> I started learning Perl about 2 and a half months ago (I'm working
full time
> on it though) and in 2 days time my first complete Perl project will
be up
> and running - a web-interfaced flat file database system. Previous to
perl I
> knew only html and javascript, and I didn't have too much trouble
picking up
> the basic concepts behind how it works. But i would highly recommend
> (perhaps even insist) that you get yourself a copy of
O'Reilly's 'Learning
> Perl' and 'Programming Perl' - these books really got me on my way.
>
> Perl readily has plenty of resources available on the web, so how
deep you
> want to learn Perl depends on how much time you have. If you are
working to
> a schedule and have deadlines to meet (as I did) I simply took the
cheats
> way out by finding pre-made scripts online, taking out the guts and
hacking
> them about to suit me (by now the original script is totally
unrecognizable
> though).
>
> However, if you want to become a proper programmer (like many people
in this
> newsgroup) this isn't really the best way to go about it. If you want
your
> programs to just do a simple job and you don't mind how compact your
script
> is or how much memory it takes to run it, then I would recommend
using my
> way of learning it. If, however, you want to develop your scripts to a
> professional standard, make them memory efficient and easy for other
people
> to read and modify, then this will take you a lot longer. Perl's
motto is
> 'there's more than one way to do it' - and this is always the case.
Even if
> you think you've figured out a pretty good way of doing something,
someone
> always comes up with about 10 alternatives you didn't even think of
(at
> least this is what happens with me!!).
>
> So if you're serious about learning Perl, hang around this newsgroup
and
> read the posts - they're often very valuable for learning new things.
After
> a while you'll probably find that you enjoy programming in Perl. I
have been
> surprised at just how many resources are out there on Perl - there is
a real
> international Perl community who are (mostly) helpful enthusiasts.
>
> To get a feel for Perl, just surf around www.perl.com and slowly it
will all
> come together. Hope this helps a bit....
>
> --Lincoln

Thank you & to all the other ppl who have posted their input...  I
think I'm going to try & get Unix running on my current box... its
homemade, and with the components being top brand, I'm pretty sure the
compatibility issue will be a small one.   Mainly, not for the Perl
aspect of it, but for learning another OS, which can only be a good
thing.

So, now I'm going to get started on learning Unix.

Next step is to gather up some books, and start reading, just reading.
I've got a minimum of 2 hours at work I could spend reading over books,
to get familiar with Perl..... eventually starting to work
the "exercises" after time.....

Also, which may set me back as far as the timeline I wanted to follow,
is possibly take some intro computer programming course(s) at the
community college here...  slow, but cant hurt.

I've got no 'deadline' like yourself, as this is purely for personal
knowledge, with a chance of actually perusing more education for making
it a career... who knows

Its weird how dabbling with about 5 script for my websites, has got me
craving the knowledge of how this all works... completely intrigued.

Anything else ya wanna share to help me out

thanks again
Phil


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


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

Date: Mon, 11 Sep 2000 14:53:23 -0700
From: "Kelley Kent" <kelley.a.kent@intel.com>
Subject: help in writing a card game
Message-Id: <8pjk6a$sre@news.or.intel.com>

So I was bored last night and decided to write
a card program in Perl. (Ah yes, writing code
for fun.) Actually I was kinda forced into it cause
I couldn't find a good Spades game on download.com.
Anywho, I was having some difficulties in figuring
out how to implement the deck and the players,
structure-wise.

With regards to the deck: At first a 2 dimension
array seemed ok (rows=suits, columns=values),
and then 4 seperate arrays (one for each suit)
seemed that it might be a better solution, then of
course a hash table came to mind. But neither of
these solutions had anything really going for it, in
my mind.

Haven't given too much thought on how to
represent the players. Thought the deck should come
first.

The AI (or lack there-of) might be a pain, as I'm
planning on just having a one person game with
3 computer opponents. but that's down the road .....

Any thoughts? Ideas? Suggestions? Comments
from the peanut gallery? :-)

--Kelley




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

Date: Mon, 11 Sep 2000 18:13:14 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Holy moly! Substitution on 10-kb scalar takes over *one second*!
Message-Id: <_g9v5.2872$O5.59318@news.itd.umich.edu>

In article <srq6kq28ct669@corp.supernews.com>,
Craig Berry <cberry@cinenet.net> wrote:
>Sean McAfee (mcafee@waits.facilities.med.umich.edu) wrote:
>: $a = do { local (@ARGV, $/) = 'OUT'; <> };
>: $a =~ s/(.*?)\t(\t*)/ /g;

>This could be more efficiently written as
>  $a =~ s/.*?\t+/ /g;

My original tab-expanding substitution looked like this:

$a =~ s/(.*?)\t(\t*)/$1 . " " x (8 - length($1) % 8 + 8 * length($2))/ge;

I modified the replacement part for the purposes of my posting (as I
mentioned) because it was simpler and still displayed the same
long-running-time behavior as the original.  I left the pattern-matching
portion as-is because I presumed it was critical to the problem I was
experiencing.

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


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

Date: Mon, 11 Sep 2000 19:28:44 GMT
From: Mark <mark_shutt@hotmail.com>
Subject: How do I access a drive on the network?
Message-Id: <srqcjc3sct650@corp.supernews.com>

I am writing a utility with a web interface which includes copying a 
user's directory (including all subdirectories and is specified by the 
user) to a directory on the network. I am using Perl CGI scripts on a 
Windows server to accomplish this. I have two questions...

1) How do I get the path to the root of the directory I want to copy? I am 
currenty using a form text field and am prompting the user to enter the 
directory (i.e., c:\directory). I was wondering if there is a way to have 
a browse button used. The HTML <input type=file> tag needs a specific file 
entered, not just a directory path, and doesn't send the path of the file 
as far as I know.

2) Once I have the path of the user's directory, how do I access it? If I 
use C:\directory it will assume the c: drive is the server, not the user's 
c: drive. If it comes down to it, is it possible to temporarily map a 
user's drive? This is on an internal network and the server will have 
access to the user's drive.

Once I am able to access the user's drive and directory, I can use the DOS 
command XCOPY to copy the directory to the server.

Any help is greatly appreciated. Thanks.

Mark

--
Posted via CNET Help.com
http://www.help.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 4288
**************************************


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