[22559] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4780 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 29 00:06:32 2003

Date: Fri, 28 Mar 2003 21:05:13 -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           Fri, 28 Mar 2003     Volume: 10 Number: 4780

Today's topics:
        And... <amiba128@sd6.so-net.ne.jp>
    Re: And... (Tad McClellan)
    Re: And... <amiba128@sd6.so-net.ne.jp>
        can't find this module Net::YahooMessenger <kellygreer1@hell.rr.com>
    Re: CGI.pm or roll-your-own? <noreply@gunnar.cc>
    Re: CGI.pm or roll-your-own? (Randal L. Schwartz)
    Re: CGI.pm or roll-your-own? <flavell@mail.cern.ch>
    Re: CGI.pm or roll-your-own? <usenet@delete.orange-triangle.net>
    Re: confused about tie <glex_nospam@qwest.net>
    Re: counting repetition in an array with Perl <goldbb2@earthlink.net>
    Re: DBI problem <glex_nospam@qwest.net>
    Re: DBI problem <goldbb2@earthlink.net>
    Re: Desktop rotator <andrew_harton@agilent.com>
    Re: doubts on \n <goldbb2@earthlink.net>
        Having trouble with Hashes & ODBC (Thomas B)
    Re: Having trouble with Hashes & ODBC <goldbb2@earthlink.net>
    Re: how to turn these 2 steps into 1 <idont@thinkso.net>
    Re: how to turn these 2 steps into 1 <abigail@abigail.nl>
    Re: I wrote a module! <jkeen@concentric.net>
    Re: implicit vs explicit variable usage in loop w/ rang (Tad McClellan)
        match all but this <istink@real.bad.com>
    Re: match all but this <jkeen@concentric.net>
    Re: match this except if it's between that (Tad McClellan)
    Re: match this except if it's between that <michael.p.broida@boeing.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 28 Mar 2003 20:25:11 -0600
From: "Ami" <amiba128@sd6.so-net.ne.jp>
Subject: And...
Message-Id: <3e85034f$0$55953$45beb828@newscene.com>

If the people, access a Web page, has the cookie,
   the page is displayed.
But the man, access a Web page, doesn't have the cookie,
   the page isn't displayed and jump to another page.
I want to know a script for the purpose as prohibition direct link.

#!/usr/bin/perl
if ( index ( $ENV{'HTTP_COOKIE'} , 'hello' ) < 0 ) {
     print "Location: http://www.usa.com/\n\r";
}

Am I right ?
Is the script right ?




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

Date: Fri, 28 Mar 2003 21:22:42 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: And...
Message-Id: <slrnb8a4c2.38l.tadmc@magna.augustmail.com>

Ami <amiba128@sd6.so-net.ne.jp> wrote:

> Subject: And...


Please put the subject of your article in the Subject of your article.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 28 Mar 2003 21:50:14 -0600
From: "Ami" <amiba128@sd6.so-net.ne.jp>
Subject: Re: And...
Message-Id: <3e851767$0$34738$45beb828@newscene.com>

Oh, surely !
It's my mistake.
I have a problem to my English, because I am Japanese are for American against
Iraq.

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnb8a4c2.38l.tadmc@magna.augustmail.com...
> Ami <amiba128@sd6.so-net.ne.jp> wrote:
>
> > Subject: And...
>
>
> Please put the subject of your article in the Subject of your article.
>
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas




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

Date: Sat, 29 Mar 2003 03:40:45 GMT
From: "Kelly Greer" <kellygreer1@hell.rr.com>
Subject: can't find this module Net::YahooMessenger
Message-Id: <1B8ha.8149$Pk6.386849@twister.southeast.rr.com>

hi group,

Can't find this module Net::YahooMessenger
Any idea where I can get it?  Doesn't seem to be in CPAN.  Neither does
Net::YMSG.
A Google search didn't yield much.

Thanks,

Kelly Greer
kellygreer1@nospam.com
Change nospam to yahoo




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

Date: Sat, 29 Mar 2003 00:56:01 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <b62ner$15r00$1@ID-184292.news.dfncis.de>

Tintin wrote:
> "Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
> news:b61pq7$t9vl$1@ID-184292.news.dfncis.de...
> 
>>The latest CGI thing I wrote without using CGI.pm is a CGI module:
>>     http://www.cpan.org/modules/by-authors/id/G/GU/GUNNAR/
>>
>>It's a trivial module, and I believe that the code is good enough for
>>its purpose. Nevertheless, please feel free to criticize it, and let
>>me know if I know what I'm doing. Maybe, if you would find a security
>>hole or something, you'd shut my mouth on this topic. Maybe. ;-)
> 
> Here's the relevant sub from the module
> 
> sub readform {
>     %in = ();
>     read STDIN, my $input, $ENV{'CONTENT_LENGTH'};
>     $input =~ s/\+/ /g;
>     for (split /&/, $input) {
>         my ($name, $value) = split /=/;
>         $value =~ s/%(..)/pack 'c', hex $1/ge;
>         $in{$name} = $value;
>     }
> 
>     # trim whitespace in message headers
>     for (qw/name email subject/) {
>         $in{$_} =~ s/^\s+//;
>         $in{$_} =~ s/\s+$//;
>         $in{$_} =~ s/\s+/ /g;
>     }
> 
>     # Windows fix
>     $in{'message'} =~ s/\r\n/\n/g;
> }
> 
> 1.  Only supports POST requests.
> 2.  Open to buffer overflows.
> 3.  Doesn't handle ; as a parameter separator
> 
> And probably a few others that more CGI savvy people will know.

Thanks for your comments, Tintin!

My first reaction is that just looking at that subroutine is to 
evaluate it out of context. It's *not* a parsing routine for general 
use; it's a subroutine designed for this particular module. (You can 
see the context from a user perspective by clicking the email link in 
the signature below.)

It's true that it only supports POST requests, and that's very 
intentional. Actually, the fact that the module ignores querystrings 
is a security detail. And since it only takes POST requests from the 
form, there is no need to include ';' as a separator.

As regards buffering, it should be noted that the module only sends a 
plain text message with the text submitted via the form. Nevertheless, 
this makes me think of setting a max size, so that the module simply 
rejects submissions exceeding a certain size in bytes. Just put it on 
the to-do list. ;-)

Again, thanks.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Sat, 29 Mar 2003 02:01:59 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <8d31735e7e58db6d7e1935985f917463@news.teranews.com>

>>>>> "Tintin" == Tintin  <me@privacy.net> writes:

Tintin>         $in{$name} = $value;

Tintin> 1.  Only supports POST requests.
Tintin> 2.  Open to buffer overflows.
Tintin> 3.  Doesn't handle ; as a parameter separator

4. doesn't handle multivalue options.  Common problem.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Sat, 29 Mar 2003 02:29:02 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <Pine.LNX.4.53.0303290144040.25345@lxplus071.cern.ch>

On Sat, Mar 29, Gunnar Hjalmarsson inscribed on the eternal scroll:

> It's true that it only supports POST requests, and that's very
> intentional.

OK, let's take that as 'given' then - your decision.

> Actually, the fact that the module ignores querystrings
> is a security detail.

Could you expand a bit on that, please?  I can't quite see how
the difference could be, in and of itself, a security issue.

> And since it only takes POST requests from the
> form, there is no need to include ';' as a separator.

Well, you have a valid point there, _given_ your original design
decision.  Caveat: I haven't looked at the whole thing properly yet,
I'm only commenting on what you posted to the thread.

best


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

Date: Sat, 29 Mar 2003 02:37:54 GMT
From: Edwin Horneij <usenet@delete.orange-triangle.net>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <6G7ha.243772$L1.68620@sccrnsc02>

Tintin wrote:

>"Edwin Horneij" <usenet@delete.orange-triangle.net> wrote in message
>news:fNRga.238422$3D1.126800@sccrnsc01...
>  
>
>>The reason beginners don't like to use CGI.pm is because, for a
>>beginner, the documentation is incomprehensible.
>>    
>>
>
>Really!  There are loads of simple examples, which I would have thought
>would be simple enough to follow.
>
That was not my experience. I also noticed that the HTML it generated 
was not standards-compliant, but since the module was presented as a 
black box, I had no idea how to go about fixing that.

>>Also, if the beginner is coming from a background in a specialized web
>>scripting language like PHP, CGI support is built into the language.
>>Someone like that thinks of external modules as something to use for
>>highly specialized purposes, but thinks of CGI as core functionality.
>>    
>>
>
>CGI is part of the Perl core.
>  
>
You have to learn how to use it _in addition_ to learning how to use 
Perl (which is already difficult). From a beginner's POV that makes it 
not a part of Perl.

>>I'm still a beginner, so trust me on this.
>>    
>>
>
>As a Perl beginner (a few years ago), I quickly recognised the value of
>using well written modules to make my life much easier.
>  
>
I wasn't arguing against using CGI.pm. The question was, "why do 
beginners resist using modules?" I was attempting to explain the 
beginner mindset, as I see it.



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

Date: Fri, 28 Mar 2003 17:20:55 -0600
From: Jeff D Gleixner <glex_nospam@qwest.net>
Subject: Re: confused about tie
Message-Id: <uK4ha.67$XU3.60907@news.uswest.net>

mfield wrote:
> Hi, I am new to the tie thing so this question may be way off but here
> it goes.
> I have a perl script (CGI) that runs a whole bunch of times and each
> time it needs to add a new key/value combination to a global hash. I
> need the script to actually tie the hash the first time the script is
> run in a session but to simply add to the hash every time after this. I
> have tried things like:

A CGI is stateless, meaning it doesn't retain %hash between calls.  Just
like if you run the script from the command line.  Each time it runs,
it knows nothing about what happened before, unless you save the
information and read it each time.

If you want to do anything with your "myhash" DBM file (read, write,
delete) you will always do the tie.  The tie allows you to access the fields
in the DBM file conveniently as a hash.  It's similar to always having
to open a file to read or write it, it doesn't just magically appear in
your script.




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

Date: Fri, 28 Mar 2003 23:03:39 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: counting repetition in an array with Perl
Message-Id: <3E851B1B.A5519189@earthlink.net>

dw wrote:
[snip]
> foreach $idx1 (sort keys %data) {
>   foreach $idx2 (sort keys %{$data{$idx1}}) {
>     print OUTDB "$idx1 $idx2 $data{$idx1}{$idx2}\n"
>   }
> }

These are numbers, so a numeric comparison is needed.

foreach $idx1 (sort { $a <=> $b } keys %data) {
   foreach $idx2 (sort { $a <=> $b } keys %{$data{$idx1}}) {
      print OUTDB "$idx1 $idx2 $data{$idx1}{$idx2}\n"
   }
}

Also, you might get a small speed gain by doing the following:

foreach $idx1 (sort { $a <=> $b } keys %data) {
   my $subhash = $data{$idx1};
   foreach $idx2 (sort { $a <=> $b } keys %$subhash) {
      print OUTDB "$idx1 $idx2 $$subhash{$idx2}\n"
   }
}

-- 
$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: Fri, 28 Mar 2003 17:12:00 -0600
From: Jeff D Gleixner <glex_nospam@qwest.net>
Subject: Re: DBI problem
Message-Id: <8C4ha.64$XU3.59812@news.uswest.net>

[...]
> If the table does exist then what it's supposed to do is get the article id
> ($row[0]) of the first record returned by the original SELECT statement.
> However, it skips the while() block altogether, so the SELECT statement
> doesn't appear to be returning any records even though there are loads in
> the table.
  [...]
 From perldoc DBI:

            If there are no more rows or if an error occurs, then
            fetchrow_array returns an empty list. You should check
            $sth->err afterwards (or use the RaiseError attribute)
            to discover if the empty list returned was due to an
            error.

In short, add error checking, it should help pinpoint your problem.

Also, unless this is just a test case, if you really only want the first
value of the first column, add "limit 1" to your SQL and use 'select article 
from..'?



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

Date: Sat, 29 Mar 2003 00:12:28 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: DBI problem
Message-Id: <3E852B3C.E00F6FBF@earthlink.net>



Bigus wrote:
> 
> I have the following code which updates a table in an Access database on
> Win2k:
> 
> # check if table exists & create it if not
> $sth = $db->prepare("SELECT * FROM $groupdb ORDER BY article DESC");

Given that you really only want one article, how about:

$sth = $db->prepare(qq[
   SELECT max(article) FROM $groupdb
]);

> if(!$sth->execute)
> {
>    if(!$db->do("CREATE TABLE $groupdb (article number,poster text(255),refs
> memo,subject text(255),thedate text(16),client text(255),messageid
> text(255))")){$msg = "Failed to create table $groupdb"; &dberror();}

You're assuming that the only possible failure is from nonexistance of
the table?  That's not good -- there are a whole variety of possible
reasons for failure.

I would move the table creation to *before* the statement preparation,
and write it as:

   $db->do(qq[
      CREATE TABLE IF NOT EXISTS $groupdb (
         article number,
         poster text(255),
         refs memo,
         subject text(255),
         thedate text(16),
         client text(255),
         messageid text(255)
      )
   ]);

[snip]
> What it does is checks if the table exists by attempting to perform a
> SELECT query. If the table doesn't exist it creates it.

Is this program being run by a CGI?  If so, then there's a race
condition -- two difference CGI instances could be accessing this script
at the same time, and thus both might end up trying to create the table.

> That works fine and therefore the if() block is working.
> 
> If the table does exist then what it's supposed to do is get the
> article id ($row[0]) of the first record returned by the original
> SELECT statement.
> However, it skips the while() block altogether, so the SELECT
> statement doesn't appear to be returning any records even though there
> are loads in the table.

If the 'else' block containing the 'while' block is never entered, then
there's a problem.

If the 'else' block is entered, but the body of the 'while' block isn't
entered, then there's a *different* problem.

Without more info, we can't help you.

Also, what is $DBI::errstr just below the while loop?

> Any ideas what could be going wrong? I have recently changed over from
> WIN32::ODBC where this worked fine. ie: I've made no changes to the
> actual statement. $groupdb in the select statement is still correctly
> defined with the tablename "news_games".
> 
> Changing over form WIN32::ODBC is not going well :-(

I've heard of a "Win32::ODBC" module, but not a "WIN32::ODBC" module. 
(Perl is case-sensitive.)

-- 
$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: Wed, 26 Mar 2003 17:20:40 -0000
From: "Andrew Harton" <andrew_harton@agilent.com>
Subject: Re: Desktop rotator
Message-Id: <1048699243.957901@cswreg.cos.agilent.com>

Dl wrote:
> I would like to make a desktop changer that changes every week.  I
> have perl experience but not in a win32 environment.  Any suggestions
> to code or faq's or tutorials would be appreciated.  Thanks.
>
> -D

Are you talking about something that changes the desktop wallpaper
on a scheduled basis?
If so, I have a script that does that which I can send you.

regards,
Andrew

--
$s="acehJklnoPrstu ";$_="4dbce078c32ae92a6e30152a";
split//;for(0..$#_){print substr($s,hex $_[$_],1);}




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

Date: Fri, 28 Mar 2003 22:52:04 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: doubts on \n
Message-Id: <3E851864.D33EF653@earthlink.net>

ctcgag@hotmail.com wrote:
> 
> Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> > ctcgag@hotmail.com wrote:
> > >
> > > toddrw69@excite.com (trwww) wrote:
> > [snip]
> > > > there is no \015 in the string
> > >
> > > On Windows
> > >
> > > > because the OS stripped it out for you
> > > > ( unless FH has been binmode()ed ).
> > >
> > > On linux, the \015 isn't stripped out.
> >
> > What happens, on linux, when you do:
> >
> >    binmode( FH, ":crlf" );
> 
> They're still there.
> 
> >
> > ?
> >
> > (This question assumes that perl is compiled with perlio enabled)
> 
>     useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
> 
> So I guess it wasn't.
> 
> If I convince someone to recompile perl with perlio, will crlf then
> tolerate \015\012 at line endings, or will it demand them (i.e. not
> recognize a lone \012 as a line ending)?

Reading line-by-line is done in two stages -- first, the filter reads
and munges the data, then it's turned into seperate lines based on the
contents of the $/ variable.

I don't think that :crlf alters bare \012s in any way, so it should not
interfere with reading lines.

Note that 5.8 is compiled with perlio by default, so instead of
suggesting that your users recompile, suggest that they upgrade.

-- 
$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: 28 Mar 2003 17:03:39 -0800
From: thomas@shurflo.com (Thomas B)
Subject: Having trouble with Hashes & ODBC
Message-Id: <866f534e.0303281703.62f12d1a@posting.google.com>

I'm trying to create a general utility to list the fields and data of
any specified table on an SQL server.  I created one manually but it
was done picking bits and pieces from a number of sources.  I still
don't understand how to extract the data myself from a hash after
trying every variation I can think of.

If I use the code: 
%Data = $Data->DataHash(ProjectID, CityID,CityName,Zip); 

I can manually do everything I want with the above statement, but it
takes time for me to figure out the column names and write custom code
that is unique to each table.  I want to create a general-purpose
utility so I can browse SQL tables and data.  When I try to look at
the data without the above statement, I get the following:

C:\temp>perl swe1.pl
Win32::ODBC=HASH(0x15d54fc)1
Win32::ODBC=HASH(0x15d54fc)1
Win32::ODBC=HASH(0x15d54fc)1
Win32::ODBC=HASH(0x15d54fc)1
Win32::ODBC=HASH(0x15d54fc)1
Win32::ODBC=HASH(0x15d54fc)1
Win32::ODBC=HASH(0x15d54fc)1
Win32::ODBC=HASH(0x15d54fc)1
Win32::ODBC=HASH(0x15d54fc)1
Win32::ODBC=HASH(0x15d54fc)1


Here is the current source code:
 
use Win32::ODBC;

$sql_cmd = "select * FROM Bug";

# After you setup an ODBC connection called SWise on the local PC:
$Data = new Win32::ODBC("FileList"); 

$Data->Sql($sql_cmd);
$cnt = 0;

while($Data->FetchRow()){
	$cnt ++;
	if ($cnt > 10) {
	exit;
	}

#	$Data->DumpData();

    undef %Data;   #why do I undef %Data here?  Faq said to do it...

###   I want to generalize this 
###    %Data = $Data->DataHash(ProjectID, CityID,CityName,Zip); 
###

#	foreach $key (keys (%Data)) {
#		print "$Data{$key}\n";
#	}
	print $Data,"1\n";
#   %Data = $Data->DataHash(ProjectID, CityID,CityName,Zip); 
} # end while loop

$Data->Close();


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

Date: Fri, 28 Mar 2003 22:24:18 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Having trouble with Hashes & ODBC
Message-Id: <3E8511E2.880F8562@earthlink.net>

Thomas B wrote:
> 
> I'm trying to create a general utility to list the fields and data of
> any specified table on an SQL server.  I created one manually but it
> was done picking bits and pieces from a number of sources.  I still
> don't understand how to extract the data myself from a hash after
> trying every variation I can think of.

Have you tried reading the documentation which comes with perl?
Type, from your commandline, each of the following:

   perldoc perldata
   perldoc perlsyn
   perldoc perlreftut
   perldoc perldsc
   perldoc perllol
   perldoc perlref
   
Also, consider using the Data::Dumper module for printing out your data,
instead of worrying yourself over how to figure out it's contents.

-- 
$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: Fri, 28 Mar 2003 20:45:17 -0500
From: "Chris W" <idont@thinkso.net>
Subject: Re: how to turn these 2 steps into 1
Message-Id: <QlCdnc_wcssVZxmjXTWcpg@comcast.com>


"Abigail" <abigail@abigail.nl> wrote in message
news:slrnb89hp3.a57.abigail@alexandra.abigail.nl...
> joe dekk (no_email@none.abc) wrote on MMMCDXCVI September MCMXCIII in
> <URL:news:3E84C269.4000903@none.abc>:
> ()  $p=~ s/\/+/\//g;
> ()  $p=~ s/\/+$//g;
>
> Take your pick:
>
>     1) $p =~ s !/+(?=/|$)!!g;

Any chance I could get you to explain this one?  I understand part of it,
but I don't know how the (?=/|$) part works.




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

Date: 29 Mar 2003 02:46:58 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: how to turn these 2 steps into 1
Message-Id: <slrnb8a292.ang.abigail@alexandra.abigail.nl>

Chris W (idont@thinkso.net) wrote on MMMCDXCVII September MCMXCIII in
<URL:news:QlCdnc_wcssVZxmjXTWcpg@comcast.com>:
[]  
[]  "Abigail" <abigail@abigail.nl> wrote in message
[]  news:slrnb89hp3.a57.abigail@alexandra.abigail.nl...
[] > joe dekk (no_email@none.abc) wrote on MMMCDXCVI September MCMXCIII in
[] > <URL:news:3E84C269.4000903@none.abc>:
[] > ()  $p=~ s/\/+/\//g;
[] > ()  $p=~ s/\/+$//g;
[] >
[] > Take your pick:
[] >
[] >     1) $p =~ s !/+(?=/|$)!!g;
[]  
[]  Any chance I could get you to explain this one?  I understand part of it,
[]  but I don't know how the (?=/|$) part works.


Postive look-ahead.  (?=PAT) matches a zero-width string, that is
followed by the pattern PAT.

(?=/|$) means: followed by a / or the end of the string.

Abigail
-- 
sub _ {$_ = shift and y/b-yB-Y/a-yB-Y/                xor      !@ _?
       exit print                                                  :
            print and push @_ => shift and goto &{(caller (0)) [3]}}
            split // => "KsvQtbuf fbsodpmu\ni flsI "  xor       & _


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

Date: 29 Mar 2003 03:55:56 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: I wrote a module!
Message-Id: <b635gc$9dv@dispatch.concentric.net>


"Kevin Pfeiffer" <pfeiffer@iu-bremen.de> wrote in message
news:1888443.9Rdd6ioVVB@sputnik.tiros.net...
> Okay, perhaps not sooo exciting, but it was for me. I have a script which
> needed to be 'expanded' but I didn't want to extensively modify it. So I
> took my new function and placed it in a module (created using h2xs).
>
> And, after some tweaking (normal for my beginner efforts), it worked!
Easier
> than I thought.
>
> -Night!
>
I hope you sleep well.  But perhaps you could tell us what your module does
and where we can view it?




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

Date: Fri, 28 Mar 2003 16:56:12 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: implicit vs explicit variable usage in loop w/ range regexp
Message-Id: <slrnb89koc.25v.tadmc@magna.augustmail.com>

Upstart <stimonyhall@netscape.net> wrote:


> while (my $line = <>) {
>         if ($line =~ /^BEGIN:/.../^END:/) {


You should always enable warnings when developing Perl code.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 28 Mar 2003 22:02:47 -0500
From: istink <istink@real.bad.com>
Subject: match all but this
Message-Id: <3E850CD7.ACEBDF85@real.bad.com>

how do I match all occurrences of this word but not when its between
these symbols?

I have:
$str="word123 word123 (word123) word123";

with this:
s/word123/X/g
I find 4 occurrences

s/[word123]/X/g
wont work.

I can imagine this sudo code:
s/word123 _but_not_inside \(.*\)/X/g
 
great for html code.
where:
<font color="red">my red keyboard</font>
I would want to replace "red" in the text with blue but I don't want
to replace the "red" in the font tag.


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

Date: 29 Mar 2003 03:42:18 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: match all but this
Message-Id: <b634mq$9dr@dispatch.concentric.net>


"istink" <istink@real.bad.com> wrote in message
news:3E850CD7.ACEBDF85@real.bad.com...
> how do I match all occurrences of this word but not when its between
> these symbols?
>
> great for html code.
> where:
> <font color="red">my red keyboard</font>
> I would want to replace "red" in the text with blue but I don't want
> to replace the "red" in the font tag.

On this list you will probably be counselled to avoid home-grown solutions
for parsing HTML code and to instead study a well-tested Perl module such as
HTML::Parser:

    perldoc HTML::Parser




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

Date: Fri, 28 Mar 2003 16:59:36 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: match this except if it's between that
Message-Id: <slrnb89kuo.25v.tadmc@magna.augustmail.com>

stinkbomb <user@someserver123abc.com> wrote:

> If I'm doing something like HTML I only want to match "hello" if it's
> outside of the lt-gt brackets.


Use a module that understands HTML for processing HTML data.

Regexes won't do it.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 29 Mar 2003 01:27:09 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: match this except if it's between that
Message-Id: <3E84F66D.DFA4FBF9@boeing.com>

stinkbomb wrote:
> 
> I'm trying to match this string but only if it's not between something.
> 
> if my string is
> abc hello abc hello abc (hello) abc hello
> I got it to match  "hello" 4 times.
> If I'm doing something like HTML I only want to match "hello" if it's
> outside of the lt-gt brackets.
> so I want to match "hello" 3 times.
> I'm using parentheses in my test, but I'd like to do this with other
> chars also.

	Here's a first cut at a different substitution line
	than you had:

	    $new =~ s/([^(])($match)([^)])/$1$fontO$2$fontC$3/ig;

	Put that in your example in place of your substitution.
	It does nothing to the first pushed line (which does not
	contain the $match string, but does INSERT the $fontO and
	$fontC strings around the first "side" and last "SiDe" but
	NOT the "(inside)" of the second pushed line.

	Dunno if that's exactly what you want, but the key is
	the character class [] with the negation ^ inside.

	The [^\(] will match ANY one character EXCEPT a "(" before
	the $match.  And the [^\)] will match ANY one character
	EXCEPT a ")" after $match.  The trailing "/ig" says to do
	it regardless of upper/lower case and everywhere in the
	string.

	I put three groups () in the match string and changed the
	substitution string to put those three parts in place.
	If you don't want the $match to be in the output, remove
	$2 from the substitution string.  $1 and $3 must be there
	or you lose the characters before and after $match.

	Other than that, I'm out of ideas.

		Mike


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

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 4780
***************************************


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