[22059] in Perl-Users-Digest
Perl-Users Digest, Issue: 4281 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 18 14:06:23 2002
Date: Wed, 18 Dec 2002 11:05:14 -0800 (PST)
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, 18 Dec 2002 Volume: 10 Number: 4281
Today's topics:
Re: comment on 2 or 4 spaces indentation (Paul Cody Johnston)
extracting data from a column <snotrocket88@hotmail.com>
Re: extracting data from a column (Tad McClellan)
Re: ExtUtils::MakeMaker: installing scripts to sbin? (Paul Cody Johnston)
foreach not working as I expected <lou.moran@gellerandwind.com>
Re: foreach not working as I expected (Helgi Briem)
Re: foreach not working as I expected (Tad McClellan)
Re: foreach not working as I expected (Tad McClellan)
Re: foreach not working as I expected <lou.moran@gellerandwind.com>
Re: foreach not working as I expected <nobull@mail.com>
Re: foreach not working as I expected <lou.moran@gellerandwind.com>
Re: foreach not working as I expected <richard@zync.co.uk>
Re: FTPing without Net::FTP (Helgi Briem)
Re: FTPing without Net::FTP (Helgi Briem)
Re: FTPing without Net::FTP <BROWNHIK@Syntegra.Bt.Co.Uk>
HELP on counter script <branmh@cox-internet.com>
Re: How to access to last expression? (i5513)
Re: Linux vs. SunOS: $1 $2 match <emagnuss@yahoo.com>
oracle 9i compatible perl version (farooq)
Oracle PL/SQL split function? Perl wannabe UTF8 code pa <ekulis@apple.com>
PDK, PerlMsi question (Russ)
Re: Perl websites ? <yanoff@yahoo.com>
Re: PerlCE on PocketPC <jeff@vpservices.com>
Profile-Path on Win32::Netadmin::UserCreate <v.kattoll@gmx.de>
Re: stdin binary or text ? <bjm-nntp@vsca.ca>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Dec 2002 10:59:28 -0800
From: pcj-google@inxar.org (Paul Cody Johnston)
Subject: Re: comment on 2 or 4 spaces indentation
Message-Id: <9d4ea49.0212181059.3752f0ba@posting.google.com>
Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in message news:<arlgj2$t4d$1@korweta.task.gda.pl>...
> In article <3DDE42CB.415D34CD@saicmodis.com>, Gary Fu wrote:
> > Hi,
> >
> > My colleague uses emacs and had hard time to modify Perl program with 2 spaces
> > indentation. He told me that 4 spaces indentation is standard for Perl and the
>
>
> In that case your colleague is an idiot. You can quote me on that.
>
>
> > tab in
> > emacs will do that automatically. However, I'm a vi user, don't use tab (may be
> > expanded
> > to different number of spaces on different editors), prefer with 2 spaces
> > indentation
> > (to save stroke and line spaces).
> > Any comment why 4 spaces indentation is standard or better than 2 spaces for
> > Perl ?
>
>
> There is no such standard.
>
>
> Cheers,
> Bernard
Perl is already a syntactically dense language. 4 spaces is more
readable for a greater percentage of the programming population.
Also, most of the perl code shipped with a standard perl distribution
is 4-spaced.
It would be an interesting study to see if 2-spacing vs 4-spacing is a
stastically significant predictor of whether a program is maintained
or thrown away and rewritten from scratch (perhaps in a different
language).
Paul
------------------------------
Date: Wed, 18 Dec 2002 16:53:05 GMT
From: "Rick L." <snotrocket88@hotmail.com>
Subject: extracting data from a column
Message-Id: <RJ1M9.389025$WL3.116156@rwcrnsc54>
I have to weed through some log files for some specific data. Basically
each log file is made up of 5 columns, all separated by spaces.
Here is a short example of what the log files look like:
number text text2 text3 http://testurl:80
number text text2 text3 http://testurl2:443
What I basically want to do is extract the URL from the 5th column, then
strip off the "http://" and the ":80" or the ":443"
I need to make this solution work for both linux and solaris systems. The
few attempts I've made have failed. I can't seem to isolate that last
column. Could anyone provide any help or point me in the right direction?
I could easily do this with a shell script but I'm trying to teach myself
perl so I want this script to be exclusively perl.
------------------------------
Date: Wed, 18 Dec 2002 11:30:19 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: extracting data from a column
Message-Id: <slrnb01c5b.31s.tadmc@magna.augustmail.com>
Rick L. <snotrocket88@hotmail.com> wrote:
> I have to weed through some log files for some specific data. Basically
> each log file is made up of 5 columns, all separated by spaces.
I'll assume no spaces _within_ fields.
> Here is a short example of what the log files look like:
>
> number text text2 text3 http://testurl:80
> number text text2 text3 http://testurl2:443
>
> What I basically want to do is extract the URL from the 5th column, then
> strip off the "http://" and the ":80" or the ":443"
# untested
while ( <> ) {
my($url) = (split)[4]; # grab the 5th whitespace-separated field
$url =~ s#^http://##;
$url =~ s/:\d+$//;
print "$url\n";
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 18 Dec 2002 10:39:10 -0800
From: pcj-google@inxar.org (Paul Cody Johnston)
Subject: Re: ExtUtils::MakeMaker: installing scripts to sbin?
Message-Id: <9d4ea49.0212181039.3a270192@posting.google.com>
"Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> wrote in message news:<atpbrr$9ee$1@nets3.rz.RWTH-Aachen.DE>...
> Also sprach Paul Cody Johnston:
>
> > brian d foy <comdog@panix.com> wrote in message news:<171220021812209387%comdog@panix.com>...
> >> In article <9d4ea49.0212171337.556f7028@posting.google.com>, Paul Cody
> >> Johnston <pcj-google@inxar.org> wrote:
> >>
> >> > $ perl Makefile.PL INSTALLSCRIPT=/usr/sbin
>
> >> > But of course that puts the onus on the user to put things in the
> >> > right place. Does there not exist the notion of a system binary
> >> > directory in MakeMaker?
> >>
> >>
> >> you can put that directly in your WriteMakefile:
> >>
> >> WriteMakefile(
> >>
> >> ...
> >>
> >> 'INSTALLSCRIPT' => '/usr/sbin',
> >>
> >> ...
> >> );
> >>
> >> you may want consider prompting the user for an installation
> >> location, then putting it where the user wants.
> >
> > Excellent points. Another question: is there a way to access PREFIX
> > from inside the WriteMakefile script? I can think of a way using
> > Data::Dumper, but it would not be the most straightforward solution.
>
> If you want to find out the default PREFIX at runtime, you could use the
> Config module that returns all the settings that were compiled into your
> perl-executable:
>
> use Config;
> print $Config{prefix};
>
> See 'perldoc Config' for a long list of all the queryable keys and their
> meaning.
>
> If you want to set it, you simply use
>
> WriteMakefile(
> ...
> PREFIX => '/path',
> ...
> );
>
> Tassilo
That works if the user does not override on the command line. If the
user says:
$ perl Makefile.PL PREFIX=/usr/local
Then I'd like to be able to set INSTALLSCRIPT to ~usr/local/sbin.
Currently I'm getting this value by poking into the MakeMaker object.
# Make a makefile.
$mm = MM->new($atts);
# Get an array of strings that constitiute the makefile itself.
@lines = $mm->{RESULT};
# Parse it, looking for the string '^PREFIX = (\S+)'
$prefix = parse_lines(@lines);
# Set INSTALLSCRIPT
$atts->{INSTALLSCRIPT} = "$prefix/sbin";
# Output a new Makefile
$mm = MM->new($atts)->flush;
But I'm not sure how portable this will be.
------------------------------
Date: Wed, 18 Dec 2002 11:14:18 -0500
From: Lou Moran <lou.moran@gellerandwind.com>
Subject: foreach not working as I expected
Message-Id: <uf710v8uhvl3u4bhp0ijqnlfk3cambp5f9@4ax.com>
I want to append text to every .txt file
This is the directory listing:
Directory of S:\Shares\NETWOR~1\StandardLoads
12/18/2002 11:02a <DIR> .
12/18/2002 11:02a <DIR> ..
12/18/2002 11:06a 444 addtext.pl
12/18/2002 09:02a 0 Fiduciary_Group.txt
12/18/2002 09:02a 0 Nationwide_Group.txt
12/18/2002 09:02a 0 Relius_Group.txt
12/18/2002 09:02a 0 Sales_Group.txt
12/18/2002 11:02a 74 WordProcessing_Group.txt
This is the code:
#!C:\Perl\bin\perl.exe
#Lou M 121702 @ GW
use warnings ;
use diagnostics ;
use strict ;
my $txt = "Windows 2000 SP3\nWindows Office XP\n" ;
foreach my $file (<*.txt>) #For Each .txt file
#in the directory
#this script runs from
{
open ADDTO, ">> $file" or die "Can't open file: $!" ;
}
#Open all the .txt files
#appendding
print ADDTO $txt; #Write the text
print "Done\n\n" ; #Let the user know it is done
My script only seems to be working on one file Ithe one with 74 bytes,
but (shamefully) I don't know why.
--
There's more than one way to do it, but only some of them work
------------------------------
Date: Wed, 18 Dec 2002 16:32:43 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: foreach not working as I expected
Message-Id: <3e00a193.1196275733@news.cis.dfn.de>
On Wed, 18 Dec 2002 11:14:18 -0500, Lou Moran
<lou.moran@gellerandwind.com> wrote:
>my $txt = "Windows 2000 SP3\nWindows Office XP\n" ;
Perl does not understand (<*.txt>).
For that you use the glob function.
my @files = glob (<$dir/*.txt>);
However, I dislike globbing, and much prefer to
do it myself, ie:
opendir DIR, $dir or die "Cannot opendir $dir:$!\n";
my @files = grep /\.txt$/i, readdir DIR;
>foreach my $file (<*.txt>) #For Each .txt file
foreach (@files) {
> #in the directory
> #this script runs from
As an aside, it is almost always better to give an
explicit path and not to rely on the script being
run in some particular directory. That has bitten
people on the ass a few million times.
> open ADDTO, ">> $file" or die "Can't open file: $!" ;
Since by far the most common problem when failing
to open a file is a malformed file name or path, I
suggest *always* returning the filename, ie:
open ADDTO, ">> $file" or die "Can't open $file: $!" ;
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Wed, 18 Dec 2002 11:03:29 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: foreach not working as I expected
Message-Id: <slrnb01aj1.2se.tadmc@magna.augustmail.com>
Helgi Briem <helgi@decode.is> wrote:
> On Wed, 18 Dec 2002 11:14:18 -0500, Lou Moran
><lou.moran@gellerandwind.com> wrote:
> Perl does not understand (<*.txt>).
Yes it does.
> For that you use the glob function.
> my @files = glob (<$dir/*.txt>);
That is a glob-of-globs...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 18 Dec 2002 11:06:02 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: foreach not working as I expected
Message-Id: <slrnb01anq.2se.tadmc@magna.augustmail.com>
Lou Moran <lou.moran@gellerandwind.com> wrote:
> I want to append text to every .txt file
> my $txt = "Windows 2000 SP3\nWindows Office XP\n" ;
> foreach my $file (<*.txt>) #For Each .txt file
> #in the directory
> #this script runs from
> {
> open ADDTO, ">> $file" or die "Can't open file: $!" ;
> }
If you try to open() an already-opened filehandle, perl will
first close() it, then reopen it.
So you open-then-close every file, leaving only the last file
associated with the ADDTO filehandle.
> print ADDTO $txt; #Write the text
Put the print() _inside_ the loop.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 18 Dec 2002 12:49:02 -0500
From: Lou Moran <lou.moran@gellerandwind.com>
Subject: Re: foreach not working as I expected
Message-Id: <36d10v096nftisvctb0ckh05nknuqj7ref@4ax.com>
On Wed, 18 Dec 2002 11:06:02 -0600, tadmc@augustmail.com (Tad
McClellan) wrote:
SNIP
>If you try to open() an already-opened filehandle, perl will
>first close() it, then reopen it.
>
Got it
>
>
>> print ADDTO $txt; #Write the text
>
>
>Put the print() _inside_ the loop.
Revised code reads: (For those interested):
#!C:\Perl\bin\perl.exe
#Lou M 121702 @ GW
use warnings ;
use diagnostics ;
use strict ;
my $txt = "Windows 2000 SP3\nWindows Office XP\n" ;
#This foreach loop finda files with a .txt extension
#and appends the contents of $txt
foreach my $file (<*.txt>) {
open ADDTO, ">> $file" or die "Couldn't open $file for append.\n";
print ADDTO $txt;
close ADDTO;
}
print "Done\n\n" ; #Let the user know it is done
--
There's more than one way to do it, but only some of them work
------------------------------
Date: 18 Dec 2002 17:41:38 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: foreach not working as I expected
Message-Id: <u98yyn1ay5.fsf@wcl-l.bham.ac.uk>
Lou Moran <lou.moran@gellerandwind.com> writes:
> Subject: foreach not working as I expected
foreach my $var { @list } {
stmnt1;
}
stmnt2;
stmnt1 is executed for each value in @list.
stmnt2 is executed only once.
Why is this not what you expected? :-)
In other words you have your } in the wrong place.
Gee, Lou, you must be kicking yourself!
Still you can comfort yourself with the fact that the c.l.p troll
managed to post an answer to your question that was even more stupid
than the question!
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 18 Dec 2002 12:58:42 -0500
From: Lou Moran <lou.moran@gellerandwind.com>
Subject: Re: foreach not working as I expected
Message-Id: <2od10vcvgph00io7cfesjs037s9du2i8vs@4ax.com>
On 18 Dec 2002 17:41:38 +0000, Brian McCauley <nobull@mail.com> wrote:
>Still you can comfort yourself with the fact that the c.l.p troll
>managed to post an answer to your question that was even more stupid
>than the question!
You know if I wasn't laughing I'd probably be insulted. When did it
go back to PG? I had gotten used to the Japancidal lizard.
--
There's more than one way to do it, but only some of them work
------------------------------
Date: Wed, 18 Dec 2002 18:59:56 +0000
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: foreach not working as I expected
Message-Id: <20021218.185954.1927495994.997@richg.zync>
In article <uf710v8uhvl3u4bhp0ijqnlfk3cambp5f9@4ax.com>, "Lou Moran"
<lou.moran@gellerandwind.com> wrote:
> #!C:\Perl\bin\perl.exe
> #Lou M 121702 @ GW
> use warnings ;
> use diagnostics ;
> use strict ;
> my $txt = "Windows 2000 SP3\nWindows Office XP\n" ; foreach my $file
> (<*.txt>) #For Each .txt file
> #in the directory
> #this script runs from
> {
> open ADDTO, ">> $file" or die "Can't open file: $!" ;
> }
Closing the loop too early ...
> #Open all the .txt files
> #appendding
> print ADDTO $txt; #Write the text
> print "Done\n\n" ; #Let the user know it is done My script only seems
> to be working on one file Ithe one with 74 bytes, but (shamefully) I
> don't know why.
I can't believe no-one else spotted this ... All you do in your loop is
open the files WITH THE SAME FILEHANDLE EACH TIME! There is an implicit
close before another file is opened on the same handle, so when the loop
exits, all you are left with is the last opened file ie the one with 74
bytes
Rich
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Wed, 18 Dec 2002 14:46:54 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: FTPing without Net::FTP
Message-Id: <3e0089b6.1190166088@news.cis.dfn.de>
On Wed, 18 Dec 2002 13:26:51 -0000, "Kevin Brownhill"
<BROWNHIK@Syntegra.Bt.Co.Uk> wrote:
>> >If the OP can't or won't use a module, then this will work.
>>
>> If the OP can't or won't use a module, S/he shouldn't
>> be coding in Perl.
>
>Is that the law or just your opinion?
My opinion and most other knowledgable peoples'.
It's strange how people who would never dream of
implementing a low level protocol from scratch
in a language like Java or C++ will scream themselves
blue in the face on their right to do it in Perl which
often has far easier high level methods to do things.
Really, really strange.
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Wed, 18 Dec 2002 14:48:28 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: FTPing without Net::FTP
Message-Id: <3e008a67.1190343654@news.cis.dfn.de>
On Wed, 18 Dec 2002 13:33:55 -0000, "Kevin Brownhill"
<BROWNHIK@Syntegra.Bt.Co.Uk> wrote:
>> Some of them are suboptimal, though.
>>
>What is the optimal answer to the question
><FTPing without Net::FTP> then?
Copy and paste the code from Net/FTP.pm into your script.
Run as desired.
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Wed, 18 Dec 2002 15:55:37 -0000
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: FTPing without Net::FTP
Message-Id: <atq65p$pmq$1@pheidippides.axion.bt.co.uk>
"Helgi Briem" <helgi@decode.is> wrote in message
news:3e0089b6.1190166088@news.cis.dfn.de...
> On Wed, 18 Dec 2002 13:26:51 -0000, "Kevin Brownhill"
> <BROWNHIK@Syntegra.Bt.Co.Uk> wrote:
>
> >> >If the OP can't or won't use a module, then this will work.
> >>
> >> If the OP can't or won't use a module, S/he shouldn't
> >> be coding in Perl.
> >
> >Is that the law or just your opinion?
>
> My opinion and most other knowledgable peoples'.
>
> It's strange how people who would never dream of
> implementing a low level protocol from scratch
> in a language like Java or C++ will scream themselves
> blue in the face on their right to do it in Perl which
> often has far easier high level methods to do things.
>
> Really, really strange.
I wonder why it is that on this newsgroup, when someone asks a question to
solve a particular problem they have, and someone else gives them a possible
solution, there are always a couple of "regulars" who pedantically state
that this is not the correct way of doing it in Perl and is therefore WRONG.
They state that "most knowledgeable people" wouldn't do it that way, in
order to make the person who gives a straight answer to the question asked
look stupid.
In this case, the original poster was writing a perl script that does a
rather simple task, and wanted to know how to do an FTP transfer without
using the Net::FTP module.
The only person answering that question (me) was flamed by the regulars.
Almost everyone else tells the OP that their question is wrong and they MUST
use the module unless they want their code to be wrong.
Oh, and top posting isn't the most irritating thing on Usenet.
That is a fact, absolutely correct and no knowledgeable person would argue
with it. Anyone who does is WRONG.
------------------------------
Date: Wed, 18 Dec 2002 10:31:36 -0600
From: "Brandon Holland" <branmh@cox-internet.com>
Subject: HELP on counter script
Message-Id: <v018pmc3c1vh20@corp.supernews.com>
counter.cgi
----------------------------------------------------------------------------
#!/usr/bin/perl
$directory = "/path/to/mydirectory/counter/data/";
$count = "$ENV{'DOCUMENT_NAME'}";
open (FILE, "$directory$count");
flock(FILE, 2);
($number,$remote) = split(/:/, <FILE>);
$number++ if $remote ne "$ENV{'REMOTE_ADDR'}";
print "Content-type: text/html\n\n";
print "$number";
truncate(FILE, length("$number:$ENV{'REMOTE_ADDR'}"));
seek(FILE, 0, 0);
print FILE "$number:$ENV{'REMOTE_ADDR'}";
close(FILE);
exit();
----------------------------------------------------------------------------
the problem is the filename in line 6 when line 4 is using
$ENV{'DOCUMENT_NAME'},
but when changing to a real filename instead of $ENV{'DOCUMENT_NAME'} it
works.
I found this script on a web host's web site and added lines 3 and 4. and
changed line 6
------------------------------
Date: 18 Dec 2002 09:55:04 -0800
From: i5513@hotmail.com (i5513)
Subject: Re: How to access to last expression?
Message-Id: <a657ec02.0212180955.1b885994@posting.google.com>
tiltonj@erols.com (Jay Tilton) wrote in message news:<3e005885.45228985@news.erols.com>...
> i5513@hotmail.com (i5513) wrote:
>
> : Hi, I have a problem, I want to work with expresions that contains
> : more than nine sub-expresion:
> : If you have a expresion that has more than nine parenthesis, and you
> : want the last sub-expresion, how can I access it?
>
> There's nothing magical about the number nine.
> You can keep going, e.g. $10, $11, $12 . . .
>
> If you want the very last capture, look in $+ .
Sorry, it's ok. I always have seen on book and Internet $1 .. $9, then
I thought that it was the limit.
Thanks you
------------------------------
Date: Wed, 18 Dec 2002 08:33:02 -0800
From: "Eric" <emagnuss@yahoo.com>
Subject: Re: Linux vs. SunOS: $1 $2 match
Message-Id: <atq800$li6$1@news01.intel.com>
Much thanks to all. I've learned something today about the scope of $1,
$2..., and if/for blocks.
FYI - Bob was right about the perl version. The "working" SunOs was older.
(I know, they are both out of date).
Sun - 5.003
Linux - 5.004_04
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrnavvu0a.865.mgjv@verbruggen.comdyn.com.au...
> On Wed, 18 Dec 2002 02:55:42 GMT,
> Bob Walton <bwalton@rochester.rr.com> wrote:
> > ctcgag@hotmail.com wrote:
> >
> >> "Eric" <emagnuss@yahoo.com> wrote:
> >>
> >>>The following program returned different values on Linux than SunOs.
> >>>(The SunOs had the expected result). Is this a bug, or a "feature".
> >>>
> >>>$_ = "7 x";
> >>>
> >>>if (/^\d/) {
> >>> m/(\d+)\s*(\w+)/;
> >>>} else {
> >>> m/(\w+)/;
> >>>}
> >>>my $a = $1;
> >>>my $b = $2;
> >>>print ":$a:$b:\n";
> >>>
> >>>__Results__
> >>>
> >>>-- sun4u sparc SUNW,Ultra-5_10 --
> >>>:7:x:
> >>>
> >>>-- Linux 2.4.9 --
> >>>:::
> >>>
> >>
> >> I get the same answer (the second one) on both Linux and SunOS.
> >> Both have 5.6.1. What version of Perl do you have on each machine?
> >>
> >> Xho
> >>
> >>
> >
> > The problems have to do with variable scope. The $1 and $2 variables
> > stick around only for the current block. So once the if() block is
> > existed, they go poof. Try:
>
> #!/usr/local/bin/perl -w
> use strict;
>
> $_ = 17;
> if (/(\d+)/)
> {
> print "Here, \$1 is '$1'\n";
> }
> print "There, \$1 is '$1'\n";
>
> produces the same result for various versions of Perl, on various
> platforms (5.005_03 and 5.6.1 on Solaris, 5.6.1 and 5.8.0 on linux),
> and that result is consistent with the fact that $1 is not localised
> to the if() block. And it shouldn't be.
>
> Note, BTW, that the scope of that if() block is from the opening brace
> to the closing brace. The conditional is not part of that block. If
> you have a while() block, things are different. If you have a for()
> block, things are the same as with if. Confusing? You betcha.
>
> To play with that a bit, use something like:
>
> #!/usr/local/bin/perl -w
> use strict;
>
> $_ = 17;
> /(\d)$/;
> print "First, \$1 is $1\n";
> if (/(\d+)/g)
> {
> print "Here, \$1 is '$1'\n";
> /(\d)/;
> print "Now, \$1 is '$1'\n";
> }
> print "There, \$1 is '$1'\n";
>
> And replace the "if" with "for" and "while".
>
> [BTW, this exposes a documentation bug in perlsyn. It states:
>
> Unlike a "foreach" statement, a "while" statement never implicitly
> localises any vari ables.
>
> which, as is shown by the above code (with a while replacing the if)
> is patently not true, since $1 is 7 before the while statement, and 7
> afterwards, but not inbetween. On the other hand, for loops do not
> implicitly localise these variables. I'll report this, if it hasn't
> been reported already.]
>
> > $_ = "7 x";
> > my $a;
> > my $b;
> > if (/^\d/) {
> > m/(\d+)\s*(\w+)/ and
> > ($a,$b)=($1,$2);
> > } else {
> > m/(\w+)/ and
> > $a=$1;
> > }
> > print ":$a:$b:\n";
> >
> > Note that declaring "my $a=$1; in the if block wouldn't work either,
>
> No, it wouldn't, because the _lexical_ scope of that $a variable would
> be limited to the block. Outside of it, you would be accessing the
> _global_ $a (BTW, $a and $b are special. They are not good example
> variables when you talk about scope).
>
> > because the lexical variable $a would go out of scope. See:
> >
> > perldoc perlvar
> >
> > and look for $<digits> .
>
> Yes, but you'd also need to read perlsyn (I am not even sure that it's
> all explained in there, see section Compound statements), and be aware
> quite well of what a block is in Perl, and how some constructions
> limit scope or extend scope slightly. You should probably also read
> what perlre has to say about the scoping of $1 etc, since it is
> slightly different.
>
> It is confusing, and I believe work is being done in Perl 6 to get rid
> of that confusion.
>
> > And BTW, always check a match for success before using the number
> > variables from the match. You might get a surprise if the match doesn't
> > succeed if you don't check.
>
> Indeed. $1 will be set to whatever it was set for before you attempted
> the match.
>
> Martien
> --
> |
> Martien Verbruggen | The four horsemen of the apocalypse are
> Trading Post Australia | called Abort, Retry, Ignore and Fail.
> |
------------------------------
Date: 18 Dec 2002 07:47:03 -0800
From: farooqm@mail.com (farooq)
Subject: oracle 9i compatible perl version
Message-Id: <e8186d7.0212180747.6d4e6296@posting.google.com>
Hello,
I am trying to find out which version of PERL is required to talk to
Oracle 9i database. When we moved to Oracle 8.1.7, we had to upgrade
PERL to version 5.005_03, DBI 1.20 and DBD 1.12. Is there a CPAN or
Oracle site where I can confirm this ?
Thanks
------------------------------
Date: Wed, 18 Dec 2002 09:45:02 -0800
From: Ed Kulis <ekulis@apple.com>
Subject: Oracle PL/SQL split function? Perl wannabe UTF8 code parsing
Message-Id: <BA25F41E.5390%ekulis@apple.com>
Hi,
I'm writing some functions in Oracle PL/SQL that will illustrate the coding
and characters of UTF8 dump strings, and ISO8859-1 codesets.
I'm posting this here as well as in the comp.database.oracle.misc group in
the hope that someone here can help.
Unfortunately, I can't use the Perl DBI or Oracle OCI with perl on this
task.
I'd like to be able to parse a structure like this in PL/SQL.
10, 13, 238.161.191, 194.191,112, 101, 114, 108
where the comma separated elements represent the UTF8 codes which contain
periods if the code is multi-octet. This structure will allow me to specify
character transformations on the codes from the Oracle dump function.
I'll also need to recognize the non-delimited multi-octets from the Oracle
dump function
10, 13, 238, 161, 191, 194, 191, 112, 101, 114, 108
------------- --------
This is easy in perl with a split function and lists but this task is
exclusively in the realm of PL/SQL packages.
I need these functions because converters like Oracle convert substitute an
invert ? for characters that they can't recognize and our down stream
process often choke on invert ?'s as well as other characters.
I can hack this up with crude Oracle character string character functions.
But is there a clever way or function some where that will do this for me?
Here's a dream, is there a perl2plsql converter?
-ed
------------------------------
Date: 18 Dec 2002 10:55:01 -0800
From: bobot@bctonline.com (Russ)
Subject: PDK, PerlMsi question
Message-Id: <7c236493.0212181055.4793937@posting.google.com>
I've been trying to figure out ActiveState's PDK PerlMSI feature with
little success. Does anyone know of a better source for documentation
than that provided by ActiveState or the MSDN Library? Or, better yet,
have an actual functioning output script (the script that produces the
.msi) which they would be willing share so I could at least get an
idea of the proper format. I've tried every approach I can think of
and, although an .msi is created, it never works.
Thanks,
Russ
------------------------------
Date: Wed, 18 Dec 2002 10:02:40 -0600
From: Scott Yanoff <yanoff@yahoo.com>
Subject: Re: Perl websites ?
Message-Id: <3e0099c4$0$590$39cecf19@nnrp1.twtelecom.net>
Hu Ji Rong wrote:
> I am new to Perl, but not programming. What are the best website for Perl?
> Like JavaWorld for java.
http://www.perlfaq.com/
http://learn.perl.org/
Good luck,
--
-Scott
yanoff@yahoo.com | http://www.yanoff.org | AOL IM: SAY KJY
------------------------------
Date: Wed, 18 Dec 2002 09:37:36 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: PerlCE on PocketPC
Message-Id: <3E00B260.9090305@vpservices.com>
brian wrote:
> Jeff Zucker <jeff@vpservices.com> wrote in message news:<3DFB7B62.5090002@vpservices.com>...
>
>>Has anyone got perl working on a pocketPC? Any tips for me? I'm
>>looking to test DBI::PurePerl from my new handheld toy. With DBI and
>>DBI::proxy and the built in WiFi card, it may graduate from being a toy.
>> But first I need to figure out how to install perl.
>>
>
> Well I just got it successfully installed,
Yep, I did too. DBI and DBD::AnyData work (mostly). The total install
including perl, perlIDE, and all the required modules is about 3mb.
--
Jeff
------------------------------
Date: Wed, 18 Dec 2002 18:43:45 +0100
From: Volker Kattoll <v.kattoll@gmx.de>
Subject: Profile-Path on Win32::Netadmin::UserCreate
Message-Id: <ooc10vcsh3ugt3u1pfcfrjp2kekca25i57@4ax.com>
On Win2K and WinNT i want to create User with a script.
This part works.
But I have to set a profil-path for the new created User.
How can I do it.
Thanks
Volker Kattoll
------------------------------
Date: Wed, 18 Dec 2002 16:21:24 GMT
From: Brad Murray <bjm-nntp@vsca.ca>
Subject: Re: stdin binary or text ?
Message-Id: <8g1M9.56622$q52.2293605@news2.telusplanet.net>
cedric <cedric@pimentech.net> wrote:
c> And if in a text stream every forms of newlines will be converted to a
c> single \n ?
c>
c> Because I have a dos file with \r\n and, reading it through stdin, \n does
c> not seam to math \r\n but only \n ...
\n is whatever your text line termination character sequence is for
your operating system. In the case of dos/windows, this means that it
is a carriage return/line feed pair. \n means only newline and not CR
or LF or some combination, and newline is defined by your OS.
In Dos/Windows, your files are opened in text mode by default and must
be set to binary mode with the binmode() function if you need binary
mode.
--
Brad Murray * That's not a straw man. That's a straw chorus line.
VSCA Founder * -- Chris Basken
------------------------------
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.
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 V10 Issue 4281
***************************************