[21850] in Perl-Users-Digest
Perl-Users Digest, Issue: 4054 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 1 00:06:35 2002
Date: Thu, 31 Oct 2002 21:05:09 -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, 31 Oct 2002 Volume: 10 Number: 4054
Today's topics:
2 different results from while loop... (havoc)
Re: 2 different results from while loop... <vm.mayer@comcast.net>
Re: 2 different results from while loop... <jurgenex@hotmail.com>
Re: [OT] Re: Open a HTML page not using redirect <jurgenex@hotmail.com>
can_write and tcp connect question <smackdab1@hotmail.com>
Declaring 2 Dimensional Hashes <hal@thresholddigital.com>
format print size (Mike)
Re: free GUI debugger for perl <nuba@turmalina.dcc.ufmg.br>
Re: free GUI debugger for perl <goldbb2@earthlink.net>
Re: free GUI debugger for perl <rereidy@indra.com>
I need help with a regular expression in perl (Pularis)
Re: I need help with a regular expression in perl <wksmith@optonline.net>
Re: log files for previous month <pasdespam_desmond@zeouane.org>
Re: perl error with oracle <rereidy@indra.com>
problem with hash content disappearing - unable to debu (P.J Douillard)
Referencing anonymous references... <mankypro@yahoo.com>
Re: Referencing anonymous references... <ddunham@taos.com>
Re: Referencing anonymous references... <mankypro@yahoo.com>
Re: Regex Pattern Evaluation <goldbb2@earthlink.net>
Re: regexp question <goldbb2@earthlink.net>
Re: regexp question <mgjv@tradingpost.com.au>
Re: using Expect.pm, Tty.pm, Pty.pm <goldbb2@earthlink.net>
Re: while vs. foreach <Spam_Sucks@rr.com>
Re: Why is this an infine loop??? <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 31 Oct 2002 17:45:08 -0800
From: mike-_-@excite.com (havoc)
Subject: 2 different results from while loop...
Message-Id: <d87cc458.0210311745.7f817669@posting.google.com>
Okay, I got a text file that looks like this:
-----
1 #id number
SomeUser #username
SomeUser's Info #info on someuser
-----
2
OtherUser
OtherUsers Info
The file goes on for about 10 more users. Now I seen a perl script get
the info from such a file like this:
open(FILE,"somefile.txt");
while(<FILE>){
my $id = <FILE>;
my $name = <FILE>;
my $info = <FILE>;
print "Info on $name (ID: $id) - $info";
}
close(FILE);
Now I didn't understand why each time it looped through somefile.txt,
it didn't assign any variable with the spacer line (-----) as a value.
But it worked, so I didn't worry about it and preceeded to use the
same syntax for another function that compared id's and got the email
address from the second file:
[second file with the emails]
-----
1 #id number
one@email.com #email addy
-----
2
two@email.com
-----
3
three@email.com
And this file also went on for the same amout of users in the first
file. Here's how I tried to get the info:
@ids = qq/1 2 3 4/;
open(EMAIL,"emails.txt");
while(<EMAIL>){
my $id = <EMAIL>;
my $email = <EMAIL>;
chomp($id);
foreach $i (@ids){
if ($id eq $i){
print "Email for id# $id: $email"
}}
}
close(EMAIL);
Now it works fine and gets the email for id# 1, but as it loops
through the rest of the file, $id always gets assigned the spacer line
as the value.
To remedy the situation I added a third variable in the second
function:
my $id = <EMAIL>;
my $email = <EMAIL>;
my $spacer = <EMAIL>;
The script works fine now, but can anyone explain to me why the code
acts like this for the second function and not the first one?
------------------------------
Date: Thu, 31 Oct 2002 21:08:43 -0500
From: Mike Mayer <vm.mayer@comcast.net>
Subject: Re: 2 different results from while loop...
Message-Id: <vm.mayer-BD2B5B.21084331102002@news-east.giganews.com>
In article <d87cc458.0210311745.7f817669@posting.google.com>,
mike-_-@excite.com (havoc) wrote:
> Okay, I got a text file that looks like this:
>
> -----
> 1 #id number
> SomeUser #username
> SomeUser's Info #info on someuser
> -----
> 2
> OtherUser
> OtherUsers Info
>
>
> The file goes on for about 10 more users. Now I seen a perl script get
> the info from such a file like this:
>
> open(FILE,"somefile.txt");
> while(<FILE>){
> my $id = <FILE>;
> my $name = <FILE>;
> my $info = <FILE>;
>
> print "Info on $name (ID: $id) - $info";
> }
> close(FILE);
>
> Now I didn't understand why each time it looped through somefile.txt,
> it didn't assign any variable with the spacer line (-----) as a value.
> But it worked, so I didn't worry about it and preceeded to use the
> same syntax for another function that compared id's and got the email
> address from the second file:
The <FILE> statement within your while statement is not just
testing if FILE contains more info.... It is reading the next line
and assigning it to $_. That's where your -----'s are going.
> [second file with the emails]
> -----
> 1 #id number
> one@email.com #email addy
> -----
> 2
> two@email.com
> -----
> 3
> three@email.com
>
> And this file also went on for the same amout of users in the first
> file. Here's how I tried to get the info:
>
> @ids = qq/1 2 3 4/;
>
> open(EMAIL,"emails.txt");
> while(<EMAIL>){
> my $id = <EMAIL>;
> my $email = <EMAIL>;
> chomp($id);
>
> foreach $i (@ids){
> if ($id eq $i){
> print "Email for id# $id: $email"
> }}
> }
> close(EMAIL);
>
>
> Now it works fine and gets the email for id# 1, but as it loops
> through the rest of the file, $id always gets assigned the spacer line
> as the value.
>
> To remedy the situation I added a third variable in the second
> function:
>
> my $id = <EMAIL>;
> my $email = <EMAIL>;
> my $spacer = <EMAIL>;
>
> The script works fine now, but can anyone explain to me why the code
> acts like this for the second function and not the first one?
When I ran the above script, it worked exactly as you were expecting.
Well almost... I assume that you wanted @ids to be a 4 element array.
As stated, it will be a one element array containing "1 2 3 4".
Check out qq and qw in perldoc perlop.
mike
------------------------------
Date: Fri, 01 Nov 2002 04:03:28 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: 2 different results from while loop...
Message-Id: <k2nw9.43155$iV1.38768@nwrddc02.gnilink.net>
havoc wrote:
> Okay, I got a text file that looks like this:
>
> -----
> 1 #id number
> SomeUser #username
> SomeUser's Info #info on someuser
> -----
> 2
> OtherUser
> OtherUsers Info
>
>
> The file goes on for about 10 more users. Now I seen a perl script get
> the info from such a file like this:
>
> open(FILE,"somefile.txt");
> while(<FILE>){
> my $id = <FILE>;
> my $name = <FILE>;
> my $info = <FILE>;
>
> print "Info on $name (ID: $id) - $info";
> }
> close(FILE);
>
> Now I didn't understand why each time it looped through somefile.txt,
> it didn't assign any variable with the spacer line (-----) as a value.
That is a dirty programming trick:
The "while (<FILE>)" reads a line, too. And this happens to be the line
containing the dashes.
This is not what I call error-tolerant programming and the programmer who
did that would not have passed my class.
jue
------------------------------
Date: Fri, 01 Nov 2002 03:58:47 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: [OT] Re: Open a HTML page not using redirect
Message-Id: <XZmw9.43136$iV1.3190@nwrddc02.gnilink.net>
[Please do not top post]
[Please do not blindly fullquote (removed all the broken stuff]
ee ee wrote:
> I disagree that it's nothing to do with Perl - i'm trying to control
> HTML from within Perl using the Perl commands, ok there is an element
> of HTML in there but you guys seem to have the broadest knowledge
> because Perl is such an all encompasing language ;)
Then I guess you would ask your Mercedes dealer about how to prepare a
Thanksgiving Dinner, too, because you happen to transport the groceries in
your family car?
After all, Mercedes has such a wide variety of cars from limousines to SUV,
trucks, and busses.
jue
------------------------------
Date: Fri, 01 Nov 2002 00:44:20 GMT
From: "smackdab" <smackdab1@hotmail.com>
Subject: can_write and tcp connect question
Message-Id: <E7kw9.60675$C53.2856918@news2.west.cox.net>
I am connecting to a few TCP sockets and then I am doing a can_write() on
the my $select object...
I want to see if there is any connect text. (ie: welcome FTP, or IIS web
server, etc.)
So, I do a: $sock->sysread($buf, 1024);
On my linux box, I get some text from the SSH port, but the FTP doesn't show
any text.
But both of them *seem* to show text in my Win2K network packet monitor...
If you connect to a valid TCP port, do they normally respond with a connect
string?
Is this the correct way to grab that text?
thanks a bunch!!1
------------------------------
Date: Fri, 01 Nov 2002 04:14:48 GMT
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Declaring 2 Dimensional Hashes
Message-Id: <Ycnw9.188457$qM2.63904@sccrnsc02>
I know I can delcare a hash with:
my (%myhash);
but what how do I declare a 2 dimensional hash, one I can reference like
this:
$myhash{$myvar1}{$myvar2}
Is just declaring it like above enough for two or three dimensional hashes,
or is there some way I need to specify it's a hash with two or more
dimensions?
Thanks!
Hal
------------------------------
Date: 31 Oct 2002 15:37:45 -0800
From: neal7@yahoo.com (Mike)
Subject: format print size
Message-Id: <18ad30a8.0210311537.182efde4@posting.google.com>
using Perl 5.6 under Windows 2000
what is the best way to format the font size for a print file.
is there some module to best handle this
thanks
------------------------------
Date: Thu, 31 Oct 2002 23:26:50 +0000 (UTC)
From: Nuba <nuba@turmalina.dcc.ufmg.br>
Subject: Re: free GUI debugger for perl
Message-Id: <apse7q$a1s$1@dcc.ufmg.br>
eddie wang <eddiekwang@hotmail.com> wrote:
: what are my options if i want to get a free GUI debugger for perl? is
: avaiable for both Windows and Unix?
Hello Eddie
I use DDD as the debugger for my perl programs. Don't know if there' a windows
version out there - probably not.. give google a try for more info:
> ddd - The Data Display Debugger
Anyway, I'm just a newbie, so you better wait for more experienced perl coders to
express themselfs on this matter.
Just my tiny contribution...
All good things,
Nuba
--
,::::,
:: : Nuba Rodrigues Princigalli _____________
:. O-O: | '\\\\\\
: > Web Design and Development | ' ____|_
____\ - ._. Computational Mathematics | + '||::::::
/' \ -::' .' | '||_____|
/. ,- O < \ www.nuba.tk '________|_____|
(\ <' ' |\ / '-.___ nuba@dcc.ufmg.br ___/____|___\___
_.\__\________\_\___/), |\\____________________| _ ' <<<:|
|_________'___o_o|
------------------------------
Date: Thu, 31 Oct 2002 19:08:28 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: free GUI debugger for perl
Message-Id: <3DC1C5FC.D65F002@earthlink.net>
eddie wang wrote:
>
> Hi, everyone.
> what are my options if i want to get a free GUI debugger for perl? is
> avaiable for both Windows and Unix?
ptkdb
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 31 Oct 2002 19:22:59 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: free GUI debugger for perl
Message-Id: <3DC1E583.4C9932DA@indra.com>
eddie wang wrote:
>
> Hi, everyone.
> what are my options if i want to get a free GUI debugger for perl? is
> avaiable for both Windows and Unix?
>
> thank you in advance!
>
> eddy
ptkdb (needs Tk). Works everywhere you need Perl to be.
--
Ron Reidy
Oracle DBA
------------------------------
Date: 31 Oct 2002 17:13:15 -0800
From: pularis@go.com (Pularis)
Subject: I need help with a regular expression in perl
Message-Id: <aef550d9.0210311713.48a5eeca@posting.google.com>
Can someone please tell me what the perl regular expresssion to find a
string in a line which looks like XYZ0000000000 ( 3 alpahbets followed
by 8 digits )
what I need to do is once this is found in a line I need to create an
html link
to somehting. I need to keep everything else the same.
For example if the line has
there is an itme nunmber XYZ12323231 in stock
I want ot replace it with
There is an item number <link> in stock
I would greatly appreciate any help. Thanks
------------------------------
Date: Fri, 01 Nov 2002 02:00:39 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: I need help with a regular expression in perl
Message-Id: <bflw9.1371$S44.927@news4.srv.hcvlny.cv.net>
"Pularis" <pularis@go.com> wrote in message
news:aef550d9.0210311713.48a5eeca@posting.google.com...
> Can someone please tell me what the perl regular expresssion to find a
> string in a line which looks like XYZ0000000000 ( 3 alpahbets followed
> by 8 digits )
> what I need to do is once this is found in a line I need to create an
> html link
> to somehting. I need to keep everything else the same.
>
> For example if the line has
>
> there is an itme nunmber XYZ12323231 in stock
>
> I want ot replace it with
>
> There is an item number <link> in stock
>
> I would greatly appreciate any help. Thanks
What have you tried?
$string = 'There is an item number XYZ1232323123 in stock';
$link = 'anythingyoulike.com''
$string =~ s/[A-Za-z]{3}\d{8}/$link/;
Bill
------------------------------
Date: Fri, 1 Nov 2002 03:35:13 +0000
From: Desmond Coughlan <pasdespam_desmond@zeouane.org>
Subject: Re: log files for previous month
Message-Id: <slrnas3tjh.jg.pasdespam_desmond@lievre.voute.net>
Le Thu, 31 Oct 2002 16:11:58 GMT, robertbu <robert.bunney@hotmail.com> a écrit :
> I'm new to perl, so the test program below is probably not
> "good perl," but it provides you a starting point.
{ snip stupendously good script that's around 30,000 ft above what I'm
capable of }
Wow ... erm, reassure me. You say 'I'm new to perl'. What do you mean by
'new' ? I ask because I'm just finishing off my first seven days of swotting
perl, and there's _no way_ I could have done a script like that ... :-(
--
Desmond Coughlan |CUNT#1 YGL#4 YFC#1 YFB#1 UKRMMA#14 two#38
desmond @ zeouane.org |BONY#48 ANORAK#11
http: // www . zeouane . org
------------------------------
Date: Thu, 31 Oct 2002 19:20:44 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: perl error with oracle
Message-Id: <3DC1E4FC.996331EC@indra.com>
Jerry Preston wrote:
>
> Ron,
>
> How do I install the oracle client? Where do I find it?
>
> Thanks,
>
> Jerry
>
> "Ron Reidy" <rereidy@indra.com> wrote in message
> news:3DC13BDE.87756AEB@indra.com...
> > Jerry Preston wrote:
> > >
> > > Hi!
> > >
> > > I just setup a new server with solaris 8 and installed perl5.6.1 and all
> > >
> > > seems to be working great except that I get the following error:
> > >
> > > DBD::Oracle initialisation failed: Can't locate
> auto/DBD/Oracle/ORA_OCI.al
> > >
> > > in @INC (@INC contains:
> > >
> > > /export/home/kthmgr/lib/perl5/site_perl/5.6.0/sun4-solaris
> > >
> > > /usr/local/lib/perl5/5.6.1/sun4-solaris /usr/local/lib/perl5/5.6.1
> > >
> > > /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris
> > >
> > > /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl .)
> at
> > >
> > > /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris/DBD/Oracle.pm line 48
> > >
> > > at /var/apache/cgi-bin/DM4/fo_fails_only.cgi line 31
> > >
> > > Any ideas what is wrong? How to fix?
> > >
> > > Thanks,
> > >
> > > Jerry
> > Did you install the Oracle client? What is the output of make? Did you
> > read the README files? Did you install DBI first? etc., etc. ...
> > --
> > Ron Reidy
> > Oracle DBA
You can get Oracle at technet.oracle.com. Read the license agreement.
Read the install docs, concepts docs, dba docs, development docs, etc.
--
Ron Reidy
Oracle DBA
------------------------------
Date: 31 Oct 2002 19:35:46 -0800
From: pjdouillard@snclavalin.com (P.J Douillard)
Subject: problem with hash content disappearing - unable to debug and find why - weird behavior
Message-Id: <4f351142.0210311935.5dbb66db@posting.google.com>
For starters, I'm using the latest ActivePerl, and I'm running it on
W2K sp3. And I'm kind of new to Perl.
When I trace line by line, with perl -d, and into my subroutine, my
script runs fine and my global hash variable has the proper values,
can be access adequately and my output result is correct.
But when I trace the same script and I step over the subroutine, it
seems like my global hash (%colParentGroupList) variable has nothing
in it, and the result becomes wrong. I got the same bad result if I
just run the script (I tried it too on Linux just in case).
I don't know how to address this.
Also, when I'm debugging, the debugger seems to be stock on the same
line a few times (see line below starting with ## HERE ### as a place
where this happens). Sometime it does not affect the output, but
sometime, it just worsen it more ??!!
NOTE: If you notice that I'm not using 'things' correctly, please, let
me know. This routine is in a large script and I had to make it in
relatively short time. I'm learning Perl as I make the script so my
understanding may surely be wrong (and that's why I got this error,
I'm sure). Thx in advance for all the pointers (besides reading the
FAQ!) you can tell me!
This is how I called this routine:
&processNode(\@nodeLines, $startIndex, $endIndex);
@nodeLines is filled prior to the call by: push (@nodeLines, $line);
$line is just a line from a file
$startIndex and $endIndex are the index of the position of the lines
in the file
%colParentGroupList is declared as:
my %colParentGroupList in the "main" section.
Real data could be:
$line = \\qcque1_lglprod\d$\acadr14\;D_LGLQC\QUE1-CAD-14;Read;
$startIndex = 1
$endIndex = 1
Thank you for anything!
P.J
Here is the code of the subroutine:
===============================================================================
sub processNode {
my ($nodeLinesRef, $sIndex, $eIndex) = @_;
my %curNodePermission = (); # this hash is local
my @tmpArray;
my $path;
my $account;
my $dirFile;
my $tempLocalGroup;
my $curLocalGroup;
my $curSuffix;
my $localGroup;
my $suffix;
my $tempLocalGroupName;
my $curMembers;
my $members;
my $added;
# Find distinct permission
#print "\nPermissions to process...\n";
foreach $line (@$nodeLinesRef) {
$line =~ /(.*;)(.*;)(.*;)/;
$path = $1;
$account = $2;
$dirFile = $3;
$tempLocalGroupName =
'L01'.&genLocalName($path).'01-'.&getSuffix($dirFile);
if (exists $curNodePermission{$tempLocalGroupName}) {
# Add only members
push @{$curNodePermission{$tempLocalGroupName}}, $account;
}
else {
# Add a new permission to collection
$#tmpArray = 0; # empty tmp array of members
push (@tmpArray, $account);
$curNodePermission{$tempLocalGroupName} = [ @tmpArray ];
}
}
# Now for each permission in %curNodePermission, try to find them
# in %colParentGroupList <-THIS IS THE GLOBAL HASH VARIABLE
while ( ($curLocalGroup, $curMembers) = each %curNodePermission) {
$curLocalGroup =~ /(.*-)(.*$)/;
$curSuffix = $2;
# Check now in %colParentGroupList
$added = 0;
# Ok sometime, on the second time this routine is called,
%colParentGroupList
# is empty, but should contains a key and an array added the call
before.
# Sometime, it's ok and it works fine?! WHY??
while ( ($localGroup, $members) = each %colParentGroupList) {
$localGroup =~ /(.*-)(.*$)/;
$suffix = $2;
# Check only members of group of same permission
if ($curSuffix eq $suffix) {
# Are the members the same?
if (&compareMembers(\@{$curMembers}, \@{$members})) {
# Yes, then use the group found in %colParentGroupList to fix the
security
for (my $i=$sIndex; $i<=$eIndex; $i++) {
chomp($lines[$i]);
$lines[$i] .= '(parent)'.&fixGroup($localGroup); # removes the
'-' from the group name
}
$added = 1;
last; # exit inner while loop
}
}
}
if (!$added) { # A group was not found, so use the new and add it
to %colParentGroupList
for (my $i=$sIndex; $i<=$eIndex; $i++) {
chomp($lines[$i]);
$lines[$i] .= '(new)'.&fixGroup($curLocalGroup);
}
## HERE ## $colParentGroupList{$curLocalGroup} = [ @{$curMembers} ];
}
}
}
I
------------------------------
Date: Thu, 31 Oct 2002 16:40:50 -0800
From: DataMunger <mankypro@yahoo.com>
Subject: Referencing anonymous references...
Message-Id: <13BEA22919731CC0.4D1FE4CA89628CF1.2B6AF08AF4DC2D20@lp.airnews.net>
Hello Perl Gurus,
I have a question about how to (more) elegantly refer to a hash of
anonymous references. Consider the data structure
my $tokens = {
record_delimiters => {
'valueBegin' => "(",
'valueEnd' => ")",
'fieldValue' => " ",
'record' => ".",
'endOfFile' => "*EOF*"
},
}
where record_delimiters are anon references. What is the best way to
refer to and iterated over the references?
I can say
print "$tokens-{record_delimiters}->{record}\n";
but I cannot say
foreach (values $tokens->{record_delimiters}) {
print;
}
what is the cannonical way to refer to items such as these?
Cheers,
DM
------------------------------
Date: Fri, 01 Nov 2002 01:09:53 GMT
From: Darren Dunham <ddunham@taos.com>
Subject: Re: Referencing anonymous references...
Message-Id: <Xns92B8AE9965619ddunhamtaoscom@64.164.98.7>
DataMunger <mankypro@yahoo.com> wrote in
news:13BEA22919731CC0.4D1FE4CA89628CF1.2B6AF08AF4DC2D20@lp.airnews.net:
> I can say
>
> print "$tokens-{record_delimiters}->{record}\n";
>
> but I cannot say
>
> foreach (values $tokens->{record_delimiters}) {
> print;
> }
My rule #1 for problems with references like this...
If you have a reference that you want to act like a hash/array, stick it in
a %{} or a @{} and then try it.
So
foreach (values %{ $tokens->{record_delimiters} }) ...
is the way to go. Some things can cope with the shortcut of not doing
this, some things can't.
--
Darren Dunham
ddunham@taos.com
------------------------------
Date: Thu, 31 Oct 2002 19:46:47 -0800
From: DataMunger <mankypro@yahoo.com>
Subject: Re: Referencing anonymous references...
Message-Id: <90F5A0E38C66D7D2.8A40898D8689C908.5367CD459AB782EF@lp.airnews.net>
Thanks Darren,
I was attempting to coerce it with %{} but I was failing to wrap the
entire expression in the curly braces. I was only wrapping the
$tokens portion. I should know better too :-)
Cheers,
DM
On Fri, 01 Nov 2002 01:09:53 GMT, Darren Dunham <ddunham@taos.com>
appears to have written:
>DataMunger <mankypro@yahoo.com> wrote in
>news:13BEA22919731CC0.4D1FE4CA89628CF1.2B6AF08AF4DC2D20@lp.airnews.net:
>
>> I can say
>>
>> print "$tokens-{record_delimiters}->{record}\n";
>>
>> but I cannot say
>>
>> foreach (values $tokens->{record_delimiters}) {
>> print;
>> }
>
>My rule #1 for problems with references like this...
>
>If you have a reference that you want to act like a hash/array, stick it in
>a %{} or a @{} and then try it.
>
>So
>
>foreach (values %{ $tokens->{record_delimiters} }) ...
>
>is the way to go. Some things can cope with the shortcut of not doing
>this, some things can't.
------------------------------
Date: Thu, 31 Oct 2002 19:31:43 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Regex Pattern Evaluation
Message-Id: <3DC1CB6F.276093FA@earthlink.net>
Phileas Fog wrote:
>
> Hello,
>
> I'm sorry if my question is excessively stupid but I have limited Perl
> experience (less than 1KLOC to date) and
> I'm trying to find a way to do a an eval of the substitution pattern
> in a regex in a simple way.
> That is not
>
> my %MACROS = (
> "#macro", "<macro>$1</macro>"
> );
Change this to
my %MACROS = (
"#macro", sub{ "<macro>$1</macro>" }
);
> my $data = "#macro(Hello World)"
> $data =~ s/$macro\((.+?)\)/$MACROS{$macro}/og
And this to:
$data =~ s/$macro\((.+?)\)/&$MACROS{$macro}()/oge;
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 31 Oct 2002 19:28:53 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: regexp question
Message-Id: <3DC1CAC5.9D657B8E@earthlink.net>
Alex Gittens wrote:
>
> This probably isn't that hard, but it is beyond me right now... I am
> trying to add a 'www.' to a url if it isn't already there. Here is the
> regexp I'm currently using:
>
> s{http://([^w][^w]?[^w]?[^.]?.*)}{http://www.\1};
>
> It doesn't match url's like http://walkingdead.net however. The only
> changes I can thing of making make it fail for urls like
> http://aaa.org. Can anyone suggest a better regexp?
s <^http://(?!www\.)> <http://www.> ;
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Fri, 01 Nov 2002 00:43:11 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: regexp question
Message-Id: <slrnas3jk3.kud.mgjv@verbruggen.comdyn.com.au>
On 31 Oct 2002 12:56:54 -0800,
Alex Gittens <alex@gittens.net> wrote:
> This probably isn't that hard, but it is beyond me right now... I am
> trying to add a 'www.' to a url if it isn't already there. Here is the
> regexp I'm currently using:
>
> s{http://([^w][^w]?[^w]?[^.]?.*)}{http://www.\1};
Since this part of URLs is case-insensitive, I've added some flags
for that.
$url =~ s#^http://#http://www.#i
unless $url =~ m#^http://www\.#i;
Or you could use negative lookaheads. See the perlre documentation.
$url =~ s#^http://(?!www\.)#http://www.#i
Which of these you choose depends on what you find most legible, or,
if it is in a time-critical piece of code, benchmark and pick the
fastest.
I would probably use the URI::URL module to deal with these things.
Then you can deal with the hostnames directly.
Also, you should enable warnings in your programs, which would have
warned you about not using \1 in the right hand side of s///.
Martien
--
|
Martien Verbruggen | Useful Statistic: 75% of the people make up
Trading Post Australia | 3/4 of the population.
|
------------------------------
Date: Thu, 31 Oct 2002 18:37:20 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: using Expect.pm, Tty.pm, Pty.pm
Message-Id: <3DC1BEB0.2BFEE85B@earthlink.net>
John M Bach wrote:
>
> hi,
>
> i need to 'use' these modules instead of making them part of the perl
> installation (so i can port the code without requiring remote sites
> to install expect and pty).
>
> i'm not sure what is causing the problem with the below code:
>
> use lib "/db/IO-Tty-0.97_01";
> use Pty 0.97;
> use Tty 0.97;
[snip]
> Pty version 0.97 required--this is only version at try1.pl line 4.
> BEGIN failed--compilation aborted at try1.pl line 4.
Although the distrubution is '0.97_01', the module Pty.pm does not have
that as it's $VERSION variable. Simply change your code to say:
use Pty;
use Tty;
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 31 Oct 2002 23:55:51 GMT
From: "Luther Barnum" <Spam_Sucks@rr.com>
Subject: Re: while vs. foreach
Message-Id: <bqjw9.92466$r7.1757398@twister.tampabay.rr.com>
Your right, it is a little excessive but it allows him to modify the line
any way he chooses before he prints.
Luther
"Wyzelli" <wyzelli@yahoo.com> wrote in message
news:uw2w9.16$gG5.74227@vicpull1.telstra.net...
> "Luther Barnum" <Spam_Sucks@rr.com> wrote in message
> news:NmIv9.28826$fa.573116@twister.tampabay.rr.com...
> > >
> > How about:
> >
> > open(CURRENT,">>$name" . "_" . "$n3" . ".txt");
> > foreach $line (@tempdata) {
> > chomp($line);
> > print CURRENT ("$line\n");
>
> Why chomp the newline just to add it back again?
>
> Wyzelli
> --
> $j='on the job';$h='hacker';$p='Perl';for(reverse(1..100)){
> $s=($_!=1)?'s':'';$t=($_!=1)?'one of those':'that';
> print"$_ $h$s of $p $j,\n$_ $h$s of $p.\nIf $t $h$s should code a bug,\n";
> $_--;$s=($_==1)?'':'s';print"There'd be $_ $h$s of $p $j!\n\n";}print"*use
> strict*";
>
>
>
------------------------------
Date: Thu, 31 Oct 2002 18:24:34 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Why is this an infine loop???
Message-Id: <3DC1BBB2.1F3D9418@earthlink.net>
El Senor wrote:
[snip]
> Also, can you explain why the following results in an infinite
> loop:
>
> while( $current_website->{html} =~ /<.*?>/gs ) {
> $num_tags++;
> }
>
> But this does not result in an infinite loop and properly counts
> the number of HTML tags:
> my $temp = $current_website->{html};
> while( $temp =~ /<.*?>/gs ) {
> $num_tags++;
> }
My guess is that $current_website is a reference to a tied hash; each
time you fetch an item from it, eg, with ->{html}, the fetched item is a
newly created scalar, with it's pos() set to zero.
Consider the following:
perl -le "print $1 while $ENV{PATH} =~ m/([^;]+)/g"
and:
perl -Tle "print $1 while $ENV{PATH} =~ m/([^;]+)/g"
(Change "" to '', and [^;] to [^:], if on unix)
%ENV is magical, in tie-like manner. If tainting is off, then it
returns the same scalar for a particular key, each time that element is
fetched; but if tainting is on, it has to return a new (tainted) sv each
time an element is fetched.
*But*, if you fetch an element, and store it in an ordinary variable,
then you can use m//g on it without risking any kind of infinite loop...
even if tainting is on.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
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 4054
***************************************