[22587] in Perl-Users-Digest
Perl-Users Digest, Issue: 4808 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 3 03:05:47 2003
Date: Thu, 3 Apr 2003 00:05:08 -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 Thu, 3 Apr 2003 Volume: 10 Number: 4808
Today's topics:
Re: .htaccess / $ENV{remote_user} -- How to get the pas <GPatnude@adelphia.net>
Re: .htaccess / $ENV{remote_user} -- How to get the pas (Sam Holden)
Re: Can Perl mimic the awk '/start/,/end/' syntax <goldbb2@earthlink.net>
Re: Can Perl mimic the awk '/start/,/end/' syntax <grazz@nyc.rr.com>
Re: Can Perl mimic the awk '/start/,/end/' syntax <grazz@nyc.rr.com>
Re: Can Perl mimic the awk '/start/,/end/' syntax <mgjv@tradingpost.com.au>
Re: Can Perl mimic the awk '/start/,/end/' syntax (Walter Roberson)
Re: Can Perl mimic the awk '/start/,/end/' syntax <uri@stemsystems.com>
Re: Can Perl mimic the awk '/start/,/end/' syntax (Tad McClellan)
cpan <Ian@junk.net>
File more recent than 7 days ? <hillmw@charter.net>
Re: File more recent than 7 days ? <mbudash@sonic.net>
Re: Loading STDOUT into a variable (Tad McClellan)
looking for duplicates <spamSucks@forgetIt.com>
Re: looking for duplicates <jkeen@concentric.net>
Re: looking for duplicates <jurgenex@hotmail.com>
Re: looking for duplicates <wksmith@optonline.net>
Re: looking for duplicates <goldbb2@earthlink.net>
Re: OO problem with Data::Dumper and IO::Scalar <alex@nospamhoopsie.com>
Re: Problem building perl on WinXP. Help! <crusader@bestweb.net>
Re: regex question <scare.crow@oz.land>
Re: Sample Perl module with callback functions <sun_tong@users.sourceforge.net>
SMS <bsd_devil@web.de>
Re: strict, global vars and 'require' (Tad McClellan)
Which is better - hashes or subroutines <mbear@uq.net.au>
Re: Which is better - hashes or subroutines <tassilo.parseval@rwth-aachen.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 03 Apr 2003 03:06:01 GMT
From: "codeWarrior" <GPatnude@adelphia.net>
Subject: Re: .htaccess / $ENV{remote_user} -- How to get the password submitted at authentication....
Message-Id: <tyNia.27249$TW2.4943608@news1.news.adelphia.net>
"Michael Budash" <mbudash@sonic.net> wrote in message
news:mbudash-23A636.15515102042003@typhoon.sonic.net...
> In article <x0Kia.26935$TW2.4873582@news1.news.adelphia.net>,
> "codeWarrior" <GPatnude@adelphia.net> wrote:
>
> > Anyone know how to grab the password that a user authenticated with via
> > CGI.pm ???
> >
> > I can find $ENV{REMOTE_USER} which gives up the users "login name" but
cant
> > locate the password the user used to authenticate...
> >
> > $login = $Q->remote_user();
> >
> > I need to get the specific password submitted to do some secondary
> > authentication on subdirectories within the htaccess protected
directory...
> >
> >
>
>
> you can't (for obvious reasons)... why not do the "secondary
> authentication on subdirectories within the htaccess protected
> directory" based on the $ENV{REMOTE_USER}?
Because "JSmith" is not unique but the combination "JSmith" & "/FH323xsq"
is.... Thats why I want the password...
>
> --
> Michael Budash
------------------------------
Date: 3 Apr 2003 03:31:18 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: .htaccess / $ENV{remote_user} -- How to get the password submitted at authentication....
Message-Id: <slrnb8nao6.7gm.sholden@flexal.cs.usyd.edu.au>
On Thu, 03 Apr 2003 03:06:01 GMT, codeWarrior <GPatnude@adelphia.net> wrote:
>
> "Michael Budash" <mbudash@sonic.net> wrote in message
> news:mbudash-23A636.15515102042003@typhoon.sonic.net...
>> In article <x0Kia.26935$TW2.4873582@news1.news.adelphia.net>,
>> "codeWarrior" <GPatnude@adelphia.net> wrote:
>>
>> > Anyone know how to grab the password that a user authenticated with via
>> > CGI.pm ???
>> >
>> > I can find $ENV{REMOTE_USER} which gives up the users "login name" but
> cant
>> > locate the password the user used to authenticate...
>> >
>> > $login = $Q->remote_user();
>> >
>> > I need to get the specific password submitted to do some secondary
>> > authentication on subdirectories within the htaccess protected
> directory...
>> >
>> >
>>
>>
>> you can't (for obvious reasons)... why not do the "secondary
>> authentication on subdirectories within the htaccess protected
>> directory" based on the $ENV{REMOTE_USER}?
>
> Because "JSmith" is not unique but the combination "JSmith" & "/FH323xsq"
> is.... Thats why I want the password...
And hope and pray that two JSmith's don't happen to both select
htimSJ as their poasswords.
Anyway, you can't do it. CGI does not provide that information. If you need
it you'll have to use something like mod_perl on Apache (which does have access
to that information). Of course you could read your web server documentation,
maybe it was implemented by idiots who added such a insecure feature to their
implementation of CGI.
--
Sam Holden
------------------------------
Date: Wed, 02 Apr 2003 21:26:16 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Can Perl mimic the awk '/start/,/end/' syntax
Message-Id: <3E8B9BC8.379E4716@earthlink.net>
Demetrius wrote:
>
> What is the Perl way to do:
>
> cat myfile.txt | awk '/start/,/end/'
UUOC: This could have been written as:
awk '/start/,/end/' < myfile.txt
Without using 'cat'.
[snip]
> Can this be done in perl without using a loop and checking each line
> for the first and last line you are looking for?
perl -wlne "print if /start/ .. /end/" myfile.txt
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Thu, 03 Apr 2003 02:16:08 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: Can Perl mimic the awk '/start/,/end/' syntax
Message-Id: <IPMia.378$Tu4.146529@twister.nyc.rr.com>
Demetrius <dcomes@wolfshade.com> wrote:
> What is the Perl way to do:
>
> cat myfile.txt | awk '/start/,/end/'
Perl's range operator is ".."
perl -pe '/useless use/../of cat/' myfile.txt
And it's documented in the perlop manpage.
If you're coming to Perl from awk[*], you might
find the perltrap page handy as well. The first
section is tips for awk users.
[*] I believe the term is "awkwardly"
--
Steve
------------------------------
Date: Thu, 03 Apr 2003 02:23:49 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: Can Perl mimic the awk '/start/,/end/' syntax
Message-Id: <VWMia.4463$an1.2029@twister.nyc.rr.com>
Steve Grazzini <grazz@nyc.rr.com> wrote:
> Demetrius <dcomes@wolfshade.com> wrote:
>> What is the Perl way to do:
>>
>> cat myfile.txt | awk '/start/,/end/'
>
> Perl's range operator is ".."
>
> perl -pe '/useless use/../of cat/' myfile.txt
But that was silly; you have to write the condition:
perl -ne 'print if /start/../end/' myfile.txt
--
Steve
------------------------------
Date: Thu, 03 Apr 2003 02:44:56 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Can Perl mimic the awk '/start/,/end/' syntax
Message-Id: <slrnb8n818.4ba.mgjv@verbruggen.comdyn.com.au>
On 2 Apr 2003 17:59:03 -0800,
Demetrius <dcomes@wolfshade.com> wrote:
> What is the Perl way to do:
>
> cat myfile.txt | awk '/start/,/end/'
UUOC
awk '/start/,/end/' myfile.txt
The perl equivalent:
perl -ne 'print if /start/../end/' myfile.txt
See the perlop documentation for the .. operator, and the perlrun
documentation for the -n switch.
Martien
--
|
Martien Verbruggen | Never hire a poor lawyer. Never buy from a
Trading Post Australia | rich salesperson.
|
------------------------------
Date: 3 Apr 2003 02:52:32 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Can Perl mimic the awk '/start/,/end/' syntax
Message-Id: <b6g7lg$45h$1@canopus.cc.umanitoba.ca>
In article <VWMia.4463$an1.2029@twister.nyc.rr.com>,
Steve Grazzini <grazz@nyc.rr.com> wrote:
:Steve Grazzini <grazz@nyc.rr.com> wrote:
:> perl -pe '/useless use/../of cat/' myfile.txt
:But that was silly; you have to write the condition:
: perl -ne 'print if /start/../end/' myfile.txt
perl -pe 'undef $_ unless /start/../end/' myfile.txt
--
Can a statement be self-referential without knowing it?
------------------------------
Date: Thu, 03 Apr 2003 04:16:09 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Can Perl mimic the awk '/start/,/end/' syntax
Message-Id: <x7istwi5bq.fsf@mail.sysarch.com>
>>>>> "WR" == Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> writes:
WR> In article <VWMia.4463$an1.2029@twister.nyc.rr.com>,
WR> Steve Grazzini <grazz@nyc.rr.com> wrote:
WR> :Steve Grazzini <grazz@nyc.rr.com> wrote:
WR> :> perl -pe '/useless use/../of cat/' myfile.txt
WR> :But that was silly; you have to write the condition:
WR> : perl -ne 'print if /start/../end/' myfile.txt
WR> perl -pe 'undef $_ unless /start/../end/' myfile.txt
bah! that will spit out warnings.
perl -pe '$_ = "" unless /start/../end/' myfile.txt
perl -pe '/start/../end/ or $_ = ""' myfile.txt
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Wed, 2 Apr 2003 23:00:26 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can Perl mimic the awk '/start/,/end/' syntax
Message-Id: <slrnb8nfva.278.tadmc@magna.augustmail.com>
Demetrius <dcomes@wolfshade.com> wrote:
> this is the lines between the tags
^^^^^^^
perldoc -q between
How can I pull out lines between two patterns that are
themselves on different lines?
Please check the FAQ before posting.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 2 Apr 2003 21:36:29 -0500
From: "Ian" <Ian@junk.net>
Subject: cpan
Message-Id: <d5Nia.3727$oA1.643689@news20.bellglobal.com>
Hi,
I'm very new to this. I'm configuring cpan with "o conf init" and I'm
getting asked some questions that I find awkward to answer.
What do you guys use for unzip? Gzip I have and winzip is not command line.
for FTP proxy?
for http proxy?
for no proxy ???
for a nearby continent?
Also what's a good url to give it? www.cpan.org may not be what you all
use.
Looking forward to hear from the experts. Regards Ian.
------------------------------
Date: Thu, 3 Apr 2003 04:49:49 -0600
From: "Michael Hill" <hillmw@charter.net>
Subject: File more recent than 7 days ?
Message-Id: <v8nfbed3dkqhfe@corp.supernews.com>
I have a need to determine if my file is less than 7 days old. Below I find
the date on the file, but don't really know how to see it it is less tahn 7
days from today.
Anyone done this before?
use POSIX 'strftime';
use File::stat;
my $selected = "/home/usr/file.cgi";
my $st = stat($selected) or die "Can't stat($selected): $!\n";
my $modstr = strftime('%b %d %Y', localtime($st->mtime));
#here i need to determine it its less than 7 days.
Mike
------------------------------
Date: Thu, 03 Apr 2003 05:05:00 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: File more recent than 7 days ?
Message-Id: <mbudash-15EA2B.21050202042003@typhoon.sonic.net>
In article <v8nfbed3dkqhfe@corp.supernews.com>,
"Michael Hill" <hillmw@charter.net> wrote:
> I have a need to determine if my file is less than 7 days old. Below I find
> the date on the file, but don't really know how to see it it is less tahn 7
> days from today.
>
> Anyone done this before?
>
> use POSIX 'strftime';
> use File::stat;
> my $selected = "/home/usr/file.cgi";
> my $st = stat($selected) or die "Can't stat($selected): $!\n";
> my $modstr = strftime('%b %d %Y', localtime($st->mtime));
>
> #here i need to determine it its less than 7 days.
>
> Mike
>
>
i usually use:
if (-M $thefile > 7) {
# $thefile is older than 7 days
}
hth-
--
Michael Budash
------------------------------
Date: Wed, 2 Apr 2003 23:27:47 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Loading STDOUT into a variable
Message-Id: <slrnb8nhij.278.tadmc@magna.augustmail.com>
Stephan Bour <sbour@niaid.nih.gov> wrote:
> in article slrnb8k0hv.3tn.tadmc@magna.augustmail.com, Tad McClellan at
> tadmc@augustmail.com wrote on 4/1/03 16:18:
>> Stephan Bour <sbour@niaid.nih.gov> wrote:
>>> in article slrnb8i0a4.27c.tadmc@magna.augustmail.com, Tad McClellan at
>>> tadmc@augustmail.com wrote on 3/31/03 22:02:
>>>
>>>> Stephan Bour <sbour@niaid.nih.gov> wrote:
>>>>
>>>>> system("ifconfig");
>>>>
>>>>> there any way to assign the content of STDOUT to a variable
>>>>
>>>> perldoc -f system
>>>>
>>>> *plonk*
>> Are you saying that you did not know how to look up Perl functions?
>>
>
> I do consider telling me about perldoc help, so thanks.
You're welcome. If you didn't know that, then there are likely to
be other helpful tidbits in the Posting Guidelines:
http://mail.augustmail.com/~tadmc/clpmisc.shtml
> I didn't know about
> that resource and I'm glad it was pointed out to me. In my struggle to learn
> my first programming language I mostly rely on books
Books are a third level resource.
First is the documentation that came with the software you are using.
Second is a Google groups search.
> but sometimes even the
> simplest explanations in those beginner books are unclear to me because I
> have no programming experience.
The usual Perl tutorial book recommendation for non-programmers is:
"Elements of Programming with Perl" by Andrew Johnson
Is that one of the books you have?
> fact is, everyone struggles with the post or don't post question: should I
> ask a question to the list if I know I could possibly find the answer myself
> with two hours
You are not expected to spend 2 hours before posting, more like 10 minutes.
> of intense guess work
I think the problem we're having here is that not reading the docs
for a function that you use is so fundamental that a programmer
cannot envision someone that does not know that, so it "looks like"
the Bad Kind Of Lazy ie. you want us to look it up for you.
We should perhaps keep in mind that not being able to envision
something does not mean that the something does not exist. :-)
(how's that for a triple negative? Makes your head hurt, doesn't it?)
> while it would take a knowledgeable
> person 5 minutes to point me in the right direction?
5 minutes from the answerer
200 minutes for every reader of the group to scan the question
(6 seconds: 0.1 * 2000 people)
205 minutes to get your answer.
The Questioner and the Answerer are not the only participants.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 03 Apr 2003 02:29:47 GMT
From: "Scaramouche" <spamSucks@forgetIt.com>
Subject: looking for duplicates
Message-Id: <v0Nia.1111$gF2.12@nwrddc03.gnilink.net>
i think i know how to open a file and read each line in it:
open(INFILE, "in.txt") or die "Error (in): $!";
while(<INFILE>){
}
but how can i return in some way duplicates found. i'm trying to find
duplicate numbers within the file. this file however, also has some text
within it.
thanks
------------------------------
Date: 03 Apr 2003 02:51:28 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: looking for duplicates
Message-Id: <b6g7jg$k6j@dispatch.concentric.net>
"Scaramouche" <spamSucks@forgetIt.com> wrote in message
news:v0Nia.1111$gF2.12@nwrddc03.gnilink.net...
> i think i know how to open a file and read each line in it:
>
> open(INFILE, "in.txt") or die "Error (in): $!";
>
> while(<INFILE>){
> }
>
> but how can i return in some way duplicates found. i'm trying to find
> duplicate numbers within the file. this file however, also has some text
> within it.
>
Something like this?
my (%seen);
while (<DATA>) {
next unless (/\d+/);
my @nums = $_ =~ /(\d+)/g;
foreach my $n (@nums) {
$seen{$n}++;
}
}
foreach (sort {$a cmp $b} keys %seen) {
print "$_ was a dupe\n" if $seen{$_} > 1;
}
__DATA__
This line has 1 2 3 numbers in it.
This line has 456 3 numbers in it.
This line has no numbers in it.
Output:
3 was a dupe
------------------------------
Date: Thu, 03 Apr 2003 02:53:30 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: looking for duplicates
Message-Id: <KmNia.3451$c%5.680@nwrddc02.gnilink.net>
Scaramouche wrote:
> i think i know how to open a file and read each line in it:
>
> open(INFILE, "in.txt") or die "Error (in): $!";
>
> while(<INFILE>){
> }
>
> but how can i return in some way duplicates found. i'm trying to find
> duplicate numbers within the file. this file however, also has some
> text within it.
Put the stuff you want to test for duplicates into a hash (as keys).
And then you can either report "Duplicate" whenever you are trying to add a
new key which exists already.
Or your use the value as a counter and after scanning through the whole file
you can report "Duplicate" for each key that has a counter greater than 1.
jue
------------------------------
Date: Thu, 03 Apr 2003 03:04:57 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: looking for duplicates
Message-Id: <txNia.1940$B8.1364977@news4.srv.hcvlny.cv.net>
"Scaramouche" <spamSucks@forgetIt.com> wrote in message
news:v0Nia.1111$gF2.12@nwrddc03.gnilink.net...
> i think i know how to open a file and read each line in it:
>
> open(INFILE, "in.txt") or die "Error (in): $!";
>
> while(<INFILE>){
> }
>
correct
> but how can i return in some way duplicates found. i'm trying to find
> duplicate numbers within the file. this file however, also has some
text
> within it.
The trick is to use a hash to keep track of things previously seen. You
are not clear about the format of your file. I made up an example which
I believe is consistent with everything that you specified. I used DATA
rather than opening a file because you already know open and I wanted to
emphasize the data.
use strict;
use warnings;
my %prev;
foreach (<DATA>){
print if exists $prev{$_} and /^\d+/ and !/^#/;
$prev{$_} = 1;
}
__END__
# 15 and 17 are the only duplicate numbers
barf
17
22
186
15
foo
foo
15
99
17
Hope this helps,
Bill
------------------------------
Date: Wed, 02 Apr 2003 23:44:24 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: looking for duplicates
Message-Id: <3E8BBC28.FB3F88CB@earthlink.net>
James E Keenan wrote:
[snip]
> Something like this?
>
> my (%seen);
> while (<DATA>) {
> next unless (/\d+/);
> my @nums = $_ =~ /(\d+)/g;
> foreach my $n (@nums) {
> $seen{$n}++;
> }
> }
I prefer shorter code like:
my %seen;
while( <DATA> ) {
++$_ for @seen{/\d+/g};
}
or perhaps the slightly evil:
my %seen;
++$_ for @seen{ map /\d+/g, <DATA> };
(but only if I know that <DATA> is fairly small.)
> foreach (sort {$a cmp $b} keys %seen) {
> print "$_ was a dupe\n" if $seen{$_} > 1;
> }
The 'cmp' operator is a stringwise comparison, and is the default
comparator that sort uses. I suspect that you meant to write '<=>',
which does numeric comparison, instead.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Thu, 03 Apr 2003 03:09:36 GMT
From: <alex@nospamhoopsie.com>
Subject: Re: OO problem with Data::Dumper and IO::Scalar
Message-Id: <QBNia.48245$OV.160446@rwcrnsc54>
Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
>> alex@nospamhoopsie.com wrote:
>>
>>> When I run the above script, I get the following error:
>>
>>> Can't locate object method "FETCH" via package "IO::Scalar"
> The above runs fine for me on 5.8.0 ($Data::Dumper::VERSION = 2.12). I
> get the errors you mentioned with 5.6.1 and Data::Dumper version 2.102.
Confirmed.
> Therefore, the most obvious solution would be to use 5.8.0.
Thanks for your help. Much appreciated.
> Tassilo
--Alex
------------------------------
Date: Thu, 03 Apr 2003 02:19:25 -0000
From: Bill <crusader@bestweb.net>
Subject: Re: Problem building perl on WinXP. Help!
Message-Id: <Xns9351D8E9C1C06crusaderbestwebnet@216.168.3.50>
"Tintin" <me@privacy.net> wrote in
news:b6ebsk$45lk8$1@ID-172104.news.dfncis.de:
>
> "Bill" <crusader@bestweb.net> wrote in message
> news:Xns9350C874DC6B2crusaderbestwebnet@216.168.3.50...
>> I am new to the concept of building sources. I am trying to build
>> perl 5.8.0 in Windows XP with the Mingw32 GCC version 2.95.2 and
>> dmake-4.1pl1- win32 as told in the perl readme.win32. I followed all
>> of the directions.......
>> I left the configuration like this:
>>
>> OS *:= win32
>> OSRELEASE *:= borland
>> OSENVIRONMENT *:= bcc50
>> What do I put for osrelease and osenvironment when using Mingw32
>> GCC?
>> Anyway this is what happened when I tried too build. Can anyone tell
>> me whats happening?
>
> Are you that keen to compile your own version of Perl? What's wrong
> with installing Activestate Perl?
> http://www.activestate.com/
>
>
>
Well I want to start to get some practice at this. I have a sun
workstation I am going to setup and I'm also thinking about putting
FreeBSD on my PC's hard drive.
------------------------------
Date: Thu, 03 Apr 2003 08:58:25 +0200
From: Eric Moors <scare.crow@oz.land>
Subject: Re: regex question
Message-Id: <pan.2003.04.03.08.58.24.508118.15829@oz.land>
On Wed, 02 Apr 2003 18:54:59 +0200, Wolf Behrenhoff wrote:
> Eric Moors wrote:
>>
>> On Wed, 02 Apr 2003 14:08:08 +0200, Anno Siegel wrote:
>>
>> > That's a FAQ: "perldoc -q 'with commas'" finds it. Okay, you want a
>> > "-" instead of a ",", but that's the whole difference.
>>
>> I've read the FAQ entry, but I still don't understand why my solution
>> doesn't work. I'm learning perl at the moment, and used regexes before,
>> kinda thought I understood them too. But why my solution fails still
>> isn't obvious to me. (The FAQ solution works great ofcourse)
>
> Because this line is wrong:
> $pattern =~ s{^([01]*)([01]{4})(\.[01]{4})*} {$1\.$2$3};
Damn. It should have had a $ at the end.
Otherwise $3 will match nothing I guess.
(Still doesn't solve the error in it you described though)
> it should be
> $pattern =~ s{^([01]*)([01]{4})((\.[01]{4})*)} {$1\.$2$3};
> ^ ^
> This is because your parentheses only match and capture ONE block.
> Because you put the '*' outside the parens they don't capture the whole
> string.
>
> Simplified:
> 'aaa' =~ m/^(a)*$/;
> print $1; # prints 'a' but not 'aaa'.
You're right. I totally overlooked this.
Looks that in my regex, $3 contains the last possible match. I mean that
if the last term would match .0001.0001.1100.1010 $3 would contain .1010
instead of the entire match. I didn't notice this because of the small
input number I used, with almost all zero's. Thanks for pointing this out.
Eric
------------------------------
Date: Thu, 03 Apr 2003 04:52:24 GMT
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Re: Sample Perl module with callback functions
Message-Id: <c6Pia.5304$k21.618599@news20.bellglobal.com>
Thank you VERY MUCH for the comprehensive explanation! I appreciate
it a lot.
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> writes:
> Also sprach * Tong *:
>
> > Can somebody give me an example of Perl module that allow user
> > define their own callback functions?
>
> There are a couple of modules on the CPAN that make use of callbacks.
> Have a look at for instance Net::IRC (the documentation of it refers to
> them as 'handlers').
> [...]
> HTML::Parser works exactly like this.
HTML Parser is the first module that I turned to for the
tutorial. But I gave it up less than half the way and turned instead
to some easy cookie cutters.
Thanks for your explanations, which is much much easier for me to
comprehend.
cheers
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
Date: Thu, 3 Apr 2003 09:42:54 +0200
From: "BSD" <bsd_devil@web.de>
Subject: SMS
Message-Id: <b6gl6s$4g4ql$1@ID-172702.news.dfncis.de>
i want to send SMS message to my mobile using my Mobile_Service_Provider
web page where I can enter my mobile phone no. and password and then i can
compose a SMS message with Field to "..." subject "..." message"..." so can
any one tell me which Perl module should I use to implememt this issue ?
BSD
------------------------------
Date: Wed, 2 Apr 2003 23:05:04 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: strict, global vars and 'require'
Message-Id: <slrnb8ng80.278.tadmc@magna.augustmail.com>
joe <tunmaster@hotmail.com> wrote:
> Just recently I started writing my scripts using the correct codes, that is
> I use the 'strict' function. This function requires a variable to be
> declared using 'my varName'. But when I import a script via 'require
> plop.cgi', this script doesn't see the vars declared in the main script!
>
> Can
> anone help me out here...?!?
"Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 03 Apr 2003 17:10:25 +1000
From: Matthew Braid <mbear@uq.net.au>
Subject: Which is better - hashes or subroutines
Message-Id: <b6gmp2$itf$1@bunyip.cc.uq.edu.au>
Hi all,
I've written a small package to handle multiple languages in a GUI
(using perl/tk). It does this by loading a set of tags/values from a
config file (in the form of PHRASENAME = text in whatever language).
Use is similar to:
my $l = Language->load('english'); # Lots of detail dropped
print "The english phrase stored for FOOBAR is ", $l->FOOBAR, "\n";
(Assuming there is a line in the config file for 'english' like:
FOOBAR = Foobar, a commonly used programming placeholder
)
At the moment the phrases are held internally as keys/values in the
object hash with an AUTOLOAD of:
sub AUTOLOAD {
my $self = shift;
my $var = $AUTOLOAD;
$var =~ s/^.+:://;
return $self->{$var} if exists $self->{$var};
die "Unknown word or phrase: $var\n";
}
What I'd like to know is if there is a more efficient way of doing this.
I've thought of using subroutines, so that when the language file is
loaded the Language package does something like:
# $key is the name of the phrase, $val is the text of the phrase
...
$self->make_sub($key, $val); # Error checking dropped
...
sub make_sub {
my $self = shift;
my ($key, $val) = @_;
eval "no warnings; sub $key {return \$val}";
return 0 if $@;
return 1;
}
This has a bonus of not allowing people to reach into the code and
change the phrases (which is very easy for the current system), but I
dont't know if this is more/less efficient, considered bad coding
practice etc.
Any comments?
MB
------------------------------
Date: 3 Apr 2003 07:33:25 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Which is better - hashes or subroutines
Message-Id: <b6go45$8f3$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Matthew Braid:
> I've written a small package to handle multiple languages in a GUI
> (using perl/tk). It does this by loading a set of tags/values from a
> config file (in the form of PHRASENAME = text in whatever language).
> Use is similar to:
>
> my $l = Language->load('english'); # Lots of detail dropped
> print "The english phrase stored for FOOBAR is ", $l->FOOBAR, "\n";
>
> (Assuming there is a line in the config file for 'english' like:
> FOOBAR = Foobar, a commonly used programming placeholder
> )
>
> At the moment the phrases are held internally as keys/values in the
> object hash with an AUTOLOAD of:
>
> sub AUTOLOAD {
> my $self = shift;
> my $var = $AUTOLOAD;
> $var =~ s/^.+:://;
> return $self->{$var} if exists $self->{$var};
> die "Unknown word or phrase: $var\n";
> }
>
> What I'd like to know is if there is a more efficient way of doing this.
Currently the problem of the above is that AUTOLOAD is triggered each
time a configuration variable is retrieved, regardless pf whether it had
been previously read.
> I've thought of using subroutines, so that when the language file is
> loaded the Language package does something like:
>
> # $key is the name of the phrase, $val is the text of the phrase
> ...
> $self->make_sub($key, $val); # Error checking dropped
> ...
> sub make_sub {
> my $self = shift;
> my ($key, $val) = @_;
> eval "no warnings; sub $key {return \$val}";
> return 0 if $@;
> return 1;
> }
That would tackle the above problem but it still appears to be too much
work for the interpreter. You could do the compilation in AUTOLOAD once
a value has been requested without making use of string-eval:
sub AUTOLOAD {
my ($self) = @_;
(my $var = $AUTOLOAD) =~ s/^.+:://;
return if $var eq 'DESTROY';
if (exists $self->{$var}) {
*$AUTOLOAD = sub () { $self->{$var} };
goto &$AUTOLOAD;
} else {
die "Unknown word or phrase: $var\n";
}
}
First of all, by changing the first line of AUTOLOAD @_ is kept
untouched which is later necessary for goto()ing to the newly created
method. The empty prototype should make it possible for perl to inline
the new method (not sure whether it works for dynamically created code,
but it shouldn't hurt).
With the above, only requested variables are compiled into methods. The
first look-up will be slow but any subsequent requests are pretty fast.
Also, it wont mess up your caller-stack since 'goto FUNC_REF' will
replace the currently running subroutine with the new one.
> This has a bonus of not allowing people to reach into the code and
> change the phrases (which is very easy for the current system), but I
> dont't know if this is more/less efficient, considered bad coding
> practice etc.
There are several options how to achieve that. Another one would be to
have a simple hash protected by a closure inside your class. But it
would change the interface slightly:
{
my %config;
sub populate_config {
my $self = shift;
# fill %config here
...
}
sub get {
my ($self, $key) = @_;
return $config{ $key };
}
}
You'd have to call '$self->get("FOOBAR")' and no longer have methods for
each configuration variable. Also, the above AUTOLOAD should be quicker
for any subsequent invocation of the same variable.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
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 4808
***************************************