[30610] in Perl-Users-Digest
Perl-Users Digest, Issue: 1853 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 13 11:09:43 2008
Date: Sat, 13 Sep 2008 08:09:10 -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 Sat, 13 Sep 2008 Volume: 11 Number: 1853
Today's topics:
Re: -I switches on shebang line <whynot@pozharski.name>
Re: FAQ 8.29 Why can't my script read from STDIN after <hjp-usenet2@hjp.at>
How to get Perlscript in ASP / IIS to execute command l <jack_posemsky@yahoo.com>
Re: How to get Perlscript in ASP / IIS to execute comma <vilain@NOspamcop.net>
Re: How to get Perlscript in ASP / IIS to execute comma <jurgenex@hotmail.com>
Re: Minimal path <rvtol+news@isolution.nl>
Re: Minimal path (fidokomik\)
new CPAN modules on Sat Sep 13 2008 (Randal Schwartz)
Re: Requiring Lexical $_ / Obliterating Global $_? <m@rtij.nl.invlalid>
Re: Requiring Lexical $_ / Obliterating Global $_? <rvtol+news@isolution.nl>
Re: Requiring Lexical $_ / Obliterating Global $_? <hjp-usenet2@hjp.at>
Re: Requiring Lexical $_ / Obliterating Global $_? <hjp-usenet2@hjp.at>
simple regex not working <john1949@yahoo.com>
Re: simple regex not working <someone@example.com>
Re: simple regex not working <rvtol+news@isolution.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 13 Sep 2008 11:14:49 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: -I switches on shebang line
Message-Id: <pc9sp5xij8.ln2@carpet.zombinet>
Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth xhoster@gmail.com:
*SKIP*
>> This behavior doesn't seem specific to 5.10.0, it is seen in various
>> 5.8 as well. If invoked like "perl foo.pl" then the foo and bar
>> still go at the end, rather than beginning, but the weird first entry
>> is omitted.
> This is all to do with the way #! lines are parsed by the OS, and by
> perl. The OS treats everything after the first space as a single
> argument (to avoid needing to parse quoting in the kernel), and
> effectively invokes perl as
> /home/xho/perl_10/bin/perl "-Ifoo -Ibar -l" foo.pl
[a bit of explanation for unwary reader] Please note that Ben talks
about OS. When at command line you type C<perl -Ifoo -Ibar whatever>
that's shell that parses. In case C<./foo.pl> after some usual
maintanance shell forks-execs and then that's the kernel that looks what
would eat that text. The rest you know.
> perl prepends "foo -Ibar -l" to @INC, as documented, then constructs its
> default @INC. Then it finds the #! line itself, parses it for more
> options, and any -I found then go at the *end* of @INC. I don't know if
> this is documented anywhere, but it happens at least as far back as 5.6.
> In simple terms: #! parsing is highly dodgy, and perl's efforts to make
> it less so don't always help. I would 'use lib', instead.
BTW, it should be a (the?) problem for any interpreter. Thanks for
explanation. Personally I'll be very careful tinkering with shebang.
--
Torvalds' goal for Linux is very simple: World Domination
------------------------------
Date: Sat, 13 Sep 2008 10:49:42 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 8.29 Why can't my script read from STDIN after I gave it EOF (^D on Unix, ^Z on MS-DOS)?
Message-Id: <slrngcmvl8.jev.hjp-usenet2@hrunkner.hjp.at>
On 2008-09-10 07:03, PerlFAQ Server <brian@stonehenge.com> wrote:
> 8.29: Why can't my script read from STDIN after I gave it EOF (^D on Unix, ^Z on MS-DOS)?
>
> Some stdio's set error and eof flags that need clearing. The POSIX
> module defines clearerr() that you can use. That is the technically
> correct way to do it. Here are some less reliable workarounds:
[...]
>
> 4 If that doesn't work, give up on your stdio package and use sysread.
... or recompile your perl to use perlio.
hp
------------------------------
Date: Fri, 12 Sep 2008 22:38:35 -0700 (PDT)
From: Jack <jack_posemsky@yahoo.com>
Subject: How to get Perlscript in ASP / IIS to execute command line system calls
Message-Id: <81de48d6-6a36-47b9-b348-02efa47d3078@p31g2000prf.googlegroups.com>
Hi folks,
These system calls work find in the .pl world, but in IIS when
Perlscript is running inside of an ASP webpage, nothing happens. I
changed the folder properties under IIS to give "script source access"
and added "write" permissions, but still it doesnt seem to work.. any
ideas out there ?
$syscall0 = "move e:\\tmp\\file1.jpg e:\\file1.jpg ";
system("$syscall0");
Thank you,
Jack
------------------------------
Date: Fri, 12 Sep 2008 23:25:41 -0700
From: Michael Vilain <vilain@NOspamcop.net>
Subject: Re: How to get Perlscript in ASP / IIS to execute command line system calls
Message-Id: <vilain-74D347.23254112092008@comcast.dca.giganews.com>
In article
<81de48d6-6a36-47b9-b348-02efa47d3078@p31g2000prf.googlegroups.com>,
Jack <jack_posemsky@yahoo.com> wrote:
> Hi folks,
>
> These system calls work find in the .pl world, but in IIS when
> Perlscript is running inside of an ASP webpage, nothing happens. I
> changed the folder properties under IIS to give "script source access"
> and added "write" permissions, but still it doesnt seem to work.. any
> ideas out there ?
>
> $syscall0 = "move e:\\tmp\\file1.jpg e:\\file1.jpg ";
> system("$syscall0");
>
> Thank you,
> Jack
Is there a "shell" environment on XP? I don't count the DOS "shell".
You might want to try a UNIX-compatible environment like Cygwin. But my
guess is you're out of luck. You'll have to rethink this code for the
XP environment.
Or try a CPAN module that works on XP.
http://search.cpan.org/~geotiger/File-Xcopy-0.12/Xcopy.pm
http://search.cpan.org/modlist/File_Name_System_Locking
http://search.cpan.org/~yves/Win32API-File-0.1001/File.pm
--
DeeDee, don't press that button! DeeDee! NO! Dee...
[I filter all Goggle Groups posts, so any reply may be automatically by ignored]
------------------------------
Date: Sat, 13 Sep 2008 05:34:35 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How to get Perlscript in ASP / IIS to execute command line system calls
Message-Id: <p8bnc41g9gubailn0s2daa0okvfaegtseb@4ax.com>
Michael Vilain <vilain@NOspamcop.net> wrote:
> Jack <jack_posemsky@yahoo.com> wrote:
>> These system calls work find in the .pl world, but in IIS when
>> Perlscript is running inside of an ASP webpage, nothing happens. I
>> changed the folder properties under IIS to give "script source access"
>> and added "write" permissions, but still it doesnt seem to work.. any
>> ideas out there ?
>>
>> $syscall0 = "move e:\\tmp\\file1.jpg e:\\file1.jpg ";
>> system("$syscall0");
>
>Is there a "shell" environment on XP? I don't count the DOS "shell".
That is of course your choice. Perl however doesn't let prejudices get
in the way and works with the DOS command interpreter without problems.
>You might want to try a UNIX-compatible environment like Cygwin. But my
>guess is you're out of luck. You'll have to rethink this code for the
>XP environment.
BS. As the OP said himself explicitely:
"These system calls work find in the .pl world"
Obviously there is no problem with perl calling DOS commands via
system().
He should rethink this code because there is no good reason to shell out
an action for which there is a perfectly fine Perl command. Why not use
rename() in the first place?
However I have a hunch that that won't help him either because the
problem seems to be related to IIS/ASP rather then to Perl on XP. As the
mantra says:
<quote from "My CGI script runs from the command line but not the
browser.">
If you can demonstrate that you've read the following FAQs
and
that your problem isn't something simple that can be easily
answered, you'll probably receive a courteous and useful
reply
to your question if you post it on
comp.infosystems.www.authoring.cgi (if it's something to do
with
HTTP, HTML, or the CGI protocols). Questions that appear to
be
Perl questions but are really CGI ones that are posted to
comp.lang.perl.misc may not be so well received.
</quote>
jue
------------------------------
Date: Sat, 13 Sep 2008 12:44:27 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Minimal path
Message-Id: <gagcr8.1kg.1@news.isolution.nl>
Petr Vileta (fidokomik) schreef:
> I have array of paths an I need to extract minimal path commont to
> all of these. Exple
> my @paths=('/vra/test/aaa/', '/var/test/bbb', '/var/test/ccc');
> my $minpaths = minpath@paths);
> print $minpath;
>
> The result shouu be '/var/test/'
Use each part as a key in a H(oH)+, then traverse the datastructure
until keys > 1;
A quick+ugly way to build it:
perl -MData::Dumper -wle'
my %h;
for (@ARGV) { s~^/~\$h{~; s~/?$~}~; s~/~}{~g;
print; eval "$_=1 unless exists $_" }
print Dumper \%h;
' /var/test/aaa/ /var/test/bbb /var/test/ccc/ddd /var/test
$h{var}{test}{aaa}
$h{var}{test}{bbb}
$h{var}{test}{ccc}{ddd}
$h{var}{test}
$VAR1 = {
'var' => {
'test' => {
'bbb' => 1,
'aaa' => 1,
'ccc' => {
'ddd' => 1
}
}
}
};
A nice+clean way would use a recursive sub.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sat, 13 Sep 2008 16:33:00 +0200
From: "Petr Vileta \(fidokomik\)" <stoupa@practisoft.cz>
Subject: Re: Minimal path
Message-Id: <gagiuf$6j6$1@adenine.netfront.net>
Dr.Ruud wrote:
> Petr Vileta (fidokomik) schreef:
>
>> I have array of paths an I need to extract minimal path commont to
>> all of these. Exple
>> my @paths=('/vra/test/aaa/', '/var/test/bbb', '/var/test/ccc');
>> my $minpaths = minpath@paths);
>> print $minpath;
>>
>> The result shouu be '/var/test/'
>
> Use each part as a key in a H(oH)+, then traverse the datastructure
> until keys > 1;
>
> A quick+ugly way to build it:
>
> perl -MData::Dumper -wle'
> my %h;
> for (@ARGV) { s~^/~\$h{~; s~/?$~}~; s~/~}{~g;
> print; eval "$_=1 unless exists $_" }
> print Dumper \%h;
> ' /var/test/aaa/ /var/test/bbb /var/test/ccc/ddd /var/test
>
> $h{var}{test}{aaa}
> $h{var}{test}{bbb}
> $h{var}{test}{ccc}{ddd}
> $h{var}{test}
>
> $VAR1 = {
> 'var' => {
> 'test' => {
> 'bbb' => 1,
> 'aaa' => 1,
> 'ccc' => {
> 'ddd' => 1
> }
> }
> }
> };
>
>
> A nice+clean way would use a recursive sub.
Well, but how to get string '/var/test/' as result of this function? Please take
a look to next examples to see what I need to be returned from my hypotetical
function minpath().
Example1:
my @paths=('/var/test/aaa/', '/var/test/bbb', '/var/test/ccc', '/var/test');
print minpath( @paths );
$> /var/test/
Example2:
my @paths=('/var/test/aaa/', '/var/test/bbb', '/var/test', '/var/other');
print minpath( @paths );
$> /var/
Example3:
my @paths=('/var/test/aaa/', '/var/test/bbb', '/home/test');
print minpath( @paths );
$> /
I thinked up this code:
#!/usr/bin/perl
use strict;
print minpath( '/var/test/aaa', '/var/test/bbb', '/var/test/ccc',
'/var/test'),"\n";
print minpath( '/var/test/aaa', '/var/test/bbb', '/var/test/ccc', '/var/test',
'/var'),"\n";
print minpath( '/var/test/aaa', '/var/test/bbb', '/var/test/ccc',
'/home/test'),"\n";
sub minpath
{
my @paths = @_;
return '' unless( @paths );
my $p;
for ( @paths )
{
unless(defined $p)
{
$p=$_;
next;
}
if(length($_) < length($p) and $p=~m/^$_.+$/)
{
$p=$_;
}
elsif($_=~m/^$p.*$/) {}
else
{
for my $c(1 .. length($_)-1)
{
if(substr($_,0,-$c) eq substr($p,0,length($_)-$c))
{
$p=substr($_,0,-$c);
last;
}
}
}
}
return $p;
}
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail.
Send me your mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
-- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
------------------------------
Date: Sat, 13 Sep 2008 04:42:21 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sat Sep 13 2008
Message-Id: <K74AEL.1LE3@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
AI-Genetic-Pro-0.1
http://search.cpan.org/~strzelec/AI-Genetic-Pro-0.1/
Efficient genetic algorithms for professional purpose
----
Acme-CPANAuthors-Austrian-0.01
http://search.cpan.org/~marcel/Acme-CPANAuthors-Austrian-0.01/
We are CPAN authors using CodeRepos
----
Acme-CPANAuthors-Austrian-0.02
http://search.cpan.org/~marcel/Acme-CPANAuthors-Austrian-0.02/
We are CPAN authors using CodeRepos
----
Acme-CPANAuthors-Austrian-0.03
http://search.cpan.org/~marcel/Acme-CPANAuthors-Austrian-0.03/
We are CPAN authors using CodeRepos
----
Acme-CPANAuthors-Austrian-0.04
http://search.cpan.org/~marcel/Acme-CPANAuthors-Austrian-0.04/
We are CPAN authors using CodeRepos
----
App-sh2p-0.03
http://search.cpan.org/~clive/App-sh2p-0.03/
Perl program to aid for conversion from UNIX shell to Perl
----
AutoLoader-5.67
http://search.cpan.org/~smueller/AutoLoader-5.67/
load subroutines only on demand
----
CGI-Cookie-XS-0.16
http://search.cpan.org/~agent/CGI-Cookie-XS-0.16/
HTTP Cookie parser in pure C
----
CPAN-Reporter-1.1701
http://search.cpan.org/~dagolden/CPAN-Reporter-1.1701/
Adds CPAN Testers reporting to CPAN.pm
----
CPANPLUS-Dist-Fedora-0.0.2
http://search.cpan.org/~shlomif/CPANPLUS-Dist-Fedora-0.0.2/
a cpanplus backend to build Fedora/RedHat rpms
----
Catalyst-Authentication-Credential-HTTP-1.004
http://search.cpan.org/~bobtfish/Catalyst-Authentication-Credential-HTTP-1.004/
HTTP Basic and Digest authentication for Catalyst.
----
Cookie-XS-0.11
http://search.cpan.org/~agent/Cookie-XS-0.11/
HTTP Cookie parser in C (Please use CGI::Cookie::XS instead)
----
Crypt-OpenSSL-CA-0.18
http://search.cpan.org/~domq/Crypt-OpenSSL-CA-0.18/
The crypto parts of an X509v3 Certification Authority
----
DB-CouchDB-Schema-0.3.01
http://search.cpan.org/~zaphar/DB-CouchDB-Schema-0.3.01/
A Schema driven CouchDB module
----
DBD-ODBC-1.16_4
http://search.cpan.org/~mjevans/DBD-ODBC-1.16_4/
ODBC Driver for DBI
----
Data-InputMonster-0.002
http://search.cpan.org/~rjbs/Data-InputMonster-0.002/
consume data from multiple sources, best first; om nom nom!
----
Data-InputMonster-0.003
http://search.cpan.org/~rjbs/Data-InputMonster-0.003/
consume data from multiple sources, best first; om nom nom!
----
Data-InputMonster-Util-Catalyst-0.001
http://search.cpan.org/~rjbs/Data-InputMonster-Util-Catalyst-0.001/
InputMonster sources for common Catalyst sources
----
Data-Swap-0.08
http://search.cpan.org/~xmath/Data-Swap-0.08/
Swap type and contents of variables
----
Data-Visitor-0.20
http://search.cpan.org/~nuffin/Data-Visitor-0.20/
Visitor style traversal of Perl data structures
----
DateTime-Format-DBI-0.032
http://search.cpan.org/~cfaerber/DateTime-Format-DBI-0.032/
Find a parser class for a database connection.
----
DateTime-Locale-0.42
http://search.cpan.org/~drolsky/DateTime-Locale-0.42/
Localization support for DateTime.pm
----
Devel-MemUsed-0.01
http://search.cpan.org/~jkutej/Devel-MemUsed-0.01/
returns how much memory as allocated since the Devel::MemUsed object construction
----
File-ShareDir-PAR-0.01
http://search.cpan.org/~smueller/File-ShareDir-PAR-0.01/
File::ShareDir with PAR support
----
GoferTransport-http-1.017
http://search.cpan.org/~timb/GoferTransport-http-1.017/
----
Graphics-ColorNames-WWW-1.00
http://search.cpan.org/~cfaerber/Graphics-ColorNames-WWW-1.00/
WWW color names and equivalent RGB values
----
Gtk2-Ex-Xor-2
http://search.cpan.org/~kryde/Gtk2-Ex-Xor-2/
----
Kephra-0.3.10_6
http://search.cpan.org/~lichtkind/Kephra-0.3.10_6/
crossplatform, GUI-Texteditor along perllike Paradigms
----
LCFG-Build-PkgSpec-0.0.24
http://search.cpan.org/~sjquinney/LCFG-Build-PkgSpec-0.0.24/
Object-oriented interface to LCFG build metadata
----
LCFG-Build-Skeleton-0.0.8
http://search.cpan.org/~sjquinney/LCFG-Build-Skeleton-0.0.8/
LCFG software package generator
----
LCFG-Build-Tools-0.0.38
http://search.cpan.org/~sjquinney/LCFG-Build-Tools-0.0.38/
LCFG software release tools
----
LCFG-Build-VCS-0.0.21
http://search.cpan.org/~sjquinney/LCFG-Build-VCS-0.0.21/
LCFG version-control infrastructure
----
Module-Build-0.2808_04
http://search.cpan.org/~ewilhelm/Module-Build-0.2808_04/
Build and install Perl modules
----
Net-EPP-0.10
http://search.cpan.org/~gbrown/Net-EPP-0.10/
----
Net-ParseWhois-0.7
http://search.cpan.org/~riffer/Net-ParseWhois-0.7/
An extendable alternative to Net::Whois for parsing whois information.
----
PAR-0.983
http://search.cpan.org/~smueller/PAR-0.983/
Perl Archive Toolkit
----
PAR-Dist-0.32
http://search.cpan.org/~smueller/PAR-Dist-0.32/
Create and manipulate PAR distributions
----
PHP-Serialization-0.28
http://search.cpan.org/~bobtfish/PHP-Serialization-0.28/
simple flexible means of converting the output of PHP's serialize() into the equivalent Perl memory structure, and vice versa.
----
Padre-Debugger-0.01
http://search.cpan.org/~szabgab/Padre-Debugger-0.01/
client side code for perl debugger
----
Parse-CPAN-Distributions-0.01
http://search.cpan.org/~barbie/Parse-CPAN-Distributions-0.01/
Provides an index for current CPAN distributions
----
Rose-DB-0.745
http://search.cpan.org/~jsiracusa/Rose-DB-0.745/
A DBI wrapper and abstraction layer.
----
Rose-DB-Object-0.771
http://search.cpan.org/~jsiracusa/Rose-DB-Object-0.771/
Extensible, high performance object-relational mapper (ORM).
----
Rose-HTMLx-Form-Field-Serial-0.002
http://search.cpan.org/~karman/Rose-HTMLx-Form-Field-Serial-0.002/
represent auto-increment columns in a form
----
Rose-HTMLx-Form-Related-0.08
http://search.cpan.org/~karman/Rose-HTMLx-Form-Related-0.08/
RHTMLO forms, living together
----
SVN-Mirror-0.75
http://search.cpan.org/~clkao/SVN-Mirror-0.75/
Mirror remote repository to local Subversion repository
----
Sub-Clone-0.02
http://search.cpan.org/~nuffin/Sub-Clone-0.02/
Clone subroutine refs for garbage collection/blessing purposes
----
Template-Provider-Preload-0.03
http://search.cpan.org/~adamk/Template-Provider-Preload-0.03/
Preload templates to save memory when forking
----
Test-Group-0.14
http://search.cpan.org/~domq/Test-Group-0.14/
Group together related tests in a test suite
----
Test-Trap-0.1.2
http://search.cpan.org/~ebhanssen/Test-Trap-0.1.2/
Trap exit codes, exceptions, output, etc.
----
Test-UniqueTestNames-0.03
http://search.cpan.org/~heumann/Test-UniqueTestNames-0.03/
Make sure all of your tests have unique names
----
Text-Template-Simple-0.54_06
http://search.cpan.org/~burak/Text-Template-Simple-0.54_06/
Simple text template engine
----
Tk-EntrySet-0.04
http://search.cpan.org/~lamprecht/Tk-EntrySet-0.04/
display/edit a list of values in a Set of Widgets.
----
Tk-PerlInheritanceTree-0.05
http://search.cpan.org/~lamprecht/Tk-PerlInheritanceTree-0.05/
Display a graphical representation of the inheritance tree for a given class-name.
----
VisualDreams-Yubikey_online-0.05
http://search.cpan.org/~wildchild/VisualDreams-Yubikey_online-0.05/
----
WWW-Myspace-0.87
http://search.cpan.org/~stevenc/WWW-Myspace-0.87/
Access MySpace.com profile information from Perl
----
XML-Encoding-2.05
http://search.cpan.org/~shay/XML-Encoding-2.05/
A perl module for parsing XML encoding maps.
----
XML-RSS-1.34
http://search.cpan.org/~shlomif/XML-RSS-1.34/
creates and updates RSS files
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Sat, 13 Sep 2008 10:23:01 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Requiring Lexical $_ / Obliterating Global $_?
Message-Id: <pan.2008.09.13.08.22.59@rtij.nl.invlalid>
On Fri, 12 Sep 2008 16:58:14 +0000, Tim McDaniel wrote:
> Currently I do
> local $_;
> at the start of each sub, but it's an annoyance and it's not fail-safe
> (I can forget).
>
> Just found out about Perl 5.10. Pretty cool.
>
> Lexical $_
>
> The default variable $_ can now be lexicalized, by declaring it like
> any other lexical variable, with a simple
> my $_;
>
> The operations that default on $_ will use the lexically-scoped
> version of $_ when it exists, instead of the global $_.
>
> In a map or a grep block, if $_ was previously my'ed, then the $_
> inside the block is lexical as well (and scoped to the block).
>
> In a scope where $_ has been lexicalized, you can still have access
> to the global version of $_ by using $::_, or, more simply, by
> overriding the lexical declaration with our $_. (Rafael
> Garcia-Suarez)
>
> I like the convenience of the implicit USE of $_ in things like
> "s/foo/bar/", but I've had an abhorrence of implicitly-declared
> variables since FORTRAN days, and hatred of accidental variable leakage
> since C.
>
> Is there any way that I can dispose of any possibility of accidentally
> using the global dynamic variable $_? That is, where by default
>
> foreach (@array)
>
> errors out (ideally at compile time), requiring that I do
>
> foreach my $_ (@array)
>
> or declare it per sub or whatever I like?
If I read that correctly, using 'my $_;' once at the top of your program
should do what you want.
HTH,
M4
------------------------------
Date: Sat, 13 Sep 2008 12:19:00 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Requiring Lexical $_ / Obliterating Global $_?
Message-Id: <gagbc9.1fg.1@news.isolution.nl>
Tim McDaniel schreef:
> Currently I do
> local $_;
> at the start of each sub
Why? At least I never needed to do that, and I assume virtually nobody
does.
The rule is simple:
Either a sub can change $_ in a documented way, or it leaves it
untouched.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sat, 13 Sep 2008 13:46:08 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Requiring Lexical $_ / Obliterating Global $_?
Message-Id: <slrngcna01.jev.hjp-usenet2@hrunkner.hjp.at>
On 2008-09-13 08:23, Martijn Lievaart <m@rtij.nl.invlalid> wrote:
> On Fri, 12 Sep 2008 16:58:14 +0000, Tim McDaniel wrote:
>> Currently I do
>> local $_;
>> at the start of each sub, but it's an annoyance and it's not fail-safe
>> (I can forget).
>>
>> Just found out about Perl 5.10. Pretty cool.
>>
>> Lexical $_
[...]
>>
>> I like the convenience of the implicit USE of $_ in things like
>> "s/foo/bar/", but I've had an abhorrence of implicitly-declared
>> variables since FORTRAN days, and hatred of accidental variable leakage
>> since C.
>>
>> Is there any way that I can dispose of any possibility of accidentally
>> using the global dynamic variable $_? That is, where by default
>>
>> foreach (@array)
>>
>> errors out (ideally at compile time), requiring that I do
>>
>> foreach my $_ (@array)
>>
>> or declare it per sub or whatever I like?
>
> If I read that correctly, using 'my $_;' once at the top of your program
> should do what you want.
I don't think so. In that case, if he forgets to declare $_ in a sub,
the globally defined lexical $_ will be used, which isn't much of an
improvement over using the predefined $_. In both cases the omission
will not be noticed and two subs may inadvertently change the same $_.
hp
------------------------------
Date: Sat, 13 Sep 2008 13:51:12 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Requiring Lexical $_ / Obliterating Global $_?
Message-Id: <slrngcna9g.jev.hjp-usenet2@hrunkner.hjp.at>
On 2008-09-13 10:19, Dr.Ruud <rvtol+news@isolution.nl> wrote:
> Tim McDaniel schreef:
>> Currently I do
>> local $_;
>> at the start of each sub
>
> Why? At least I never needed to do that, and I assume virtually nobody
> does.
I needed to do that in a number of cases. I've never made a habit of it
although I can see why that might be a good idea.
>
> The rule is simple:
> Either a sub can change $_ in a documented way, or it leaves it
> untouched.
>
Right. And if your sub should leave $_ untouched, but either changes it
itself (e.g., by using "while (<>) {}") or calls another sub which does,
then adding "local $_;" at the start ensures that your sub indeed leaves
$_ untouched (as far as the caller can tell).
hp
------------------------------
Date: Sat, 13 Sep 2008 13:03:20 +0100
From: "John" <john1949@yahoo.com>
Subject: simple regex not working
Message-Id: <gaga64$2qr$1@news.albasani.net>
Hi
I'm trying to match a string beginning a letter A to R followed by any
letter (from S to Z) or any digit.
if ($x =~ /([A-Ra-r][S-Zs-z0-9]+)/) {$error=""; return}
Well, it does not work.
Any ideas?
Regards
John
------------------------------
Date: Sat, 13 Sep 2008 05:13:22 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: simple regex not working
Message-Id: <A7Oyk.2030$Il.1624@newsfe09.iad>
John wrote:
>
> I'm trying to match a string beginning a letter A to R followed by any
> letter (from S to Z) or any digit.
>
> if ($x =~ /([A-Ra-r][S-Zs-z0-9]+)/) {$error=""; return}
>
> Well, it does not work.
>
> Any ideas?
You are not telling it to match only at the beginning of the string:
if ( $x =~ /^([A-Ra-r][S-Zs-z0-9]+)/ ) {
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: Sat, 13 Sep 2008 14:40:16 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: simple regex not working
Message-Id: <gagjeg.1e8.1@news.isolution.nl>
John W. Krahn schreef:
> John wrote:
>> I'm trying to match a string beginning a letter A to R followed by
>> any letter (from S to Z) or any digit.
>> if ($x =~ /([A-Ra-r][S-Zs-z0-9]+)/) {$error=""; return}
>> Well, it does not work.
>
> You are not telling it to match only at the beginning of the string:
> if ( $x =~ /^([A-Ra-r][S-Zs-z0-9]+)/ ) {
Also the capturing and the quantifier are likely not wanted:
if ( $x =~ /^[A-Ra-r][S-Zs-z0-9]/ ) {$error=""; return}
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 1853
***************************************