[24610] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6786 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 10 00:06:46 2004

Date: Fri, 9 Jul 2004 21:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 9 Jul 2004     Volume: 10 Number: 6786

Today's topics:
    Re: Active State <matthew.garrish@sympatico.ca>
        Bitwise comparison failing (corky)
        CGI: print $x =~ s/\n/<br>\n/g; <ken_sington@nospam_abcdefg.com>
    Re: CGI: print $x =~ s/\n/<br>\n/g; <mritty@gmail.com>
    Re: CGI: print $x =~ s/\n/<br>\n/g; <1usa@llenroc.ude>
        Code Style -- here-docs -- How do you make them look go (MST)
    Re: Code Style -- here-docs -- How do you make them loo <mritty@gmail.com>
    Re: Code Style -- here-docs -- How do you make them loo <gnari@simnet.is>
    Re: double quotes vs. single quotes (was Re: hash as ar <tadmc@augustmail.com>
    Re: double quotes vs. single quotes (was Re: hash as ar <abigail@abigail.nl>
    Re: double quotes vs. single quotes (was Re: hash as ar <abigail@abigail.nl>
    Re: hash as argument <krahnj@acm.org>
    Re: hash as argument <abigail@abigail.nl>
    Re: hash as argument <ahamm@mail.com>
    Re: hash as argument <ahamm@mail.com>
    Re: hash as argument <ahamm@mail.com>
    Re: Invalid Page Fault With Win32::GUI Under Win98 <matthew.garrish@sympatico.ca>
    Re: Negation of RegEx <tadmc@augustmail.com>
    Re: Negation of RegEx <abigail@abigail.nl>
    Re: perl vs Unix grep ctcgag@hotmail.com
    Re: print $x =~ s/\n/<br>\n/g; <gnari@simnet.is>
    Re: Writing a Lisp interpreter in Perl? <dmagda+trace040423@ee.ryerson.ca>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 9 Jul 2004 17:53:29 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Active State
Message-Id: <rtEHc.36719$WM5.2059190@news20.bellglobal.com>


"timgerr" <tim@-123nospan-mtgallagher.com> wrote in message
news:ccm3fm$p88$1@newshost.mot.com...
>
> Sorry for the lack of information.  I am trying to get the Device::Modem
> http://search.cpan.org/~cosimo/Device-Modem-1.36/docs/Modem.pod
> and  Device::SerialPort
>

For one, you don't want Device::SerialPort. Please read the faq:

What are the requisites of Device::Modem?

You must have:

- A working computer with a standard RS-232 serial port
- An AT-compliant device (a modem will do perfectly here :-)
- A working Perl installation
- Device::SerialPort module installed if you are on some unix platform.
Win32::SerialPort module installed if you are on Win32 platform.

Sounds like if you install Win32::SerialPort you can probably just download
the source and save it to your lib directory. Device::Modem is just a layer
on top of that module.

ppm install http://www.bribes.org/perl/ppm/Win32-SerialPort.ppd

Matt




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

Date: 9 Jul 2004 18:51:26 -0700
From: twistdpair@hotmail.com (corky)
Subject: Bitwise comparison failing
Message-Id: <e2d5abce.0407091751.12204ebb@posting.google.com>

I have a function that manages security for various hyperlinks on the
web. Each user has an integer representation of a binary number (24
security on/off switches) stored in the database. Each link has a link
ID associated. This function takes the link ID, looks through a list
of restricted link ID / security pairs, and denies the user access to
a link if there is a match.

For instance, GetLinkSecurity (2, <user's security mask as integer>)
would pass the function a link ID of 2 and the user's security mask.
The function then looks through the list of link ID / security bit
pairs to see if the user should be denied access.

The problems started when I added a new security bit with an integer
value of 8388608 (24 bits). The function stopped working properly for
users with that security bit turned on. I don't know if it's some
overflow condition or something, and I can't find any reference to
capacity in the camel book.

I'm not a regular Perl programmer, so please forgive me if the
question is basic.

The function follows:

sub GetLinkSecurity {
    &LogItem("--> GetLinkSecurity()");
	my ($link, $knowrights) = @_;
	my ($linknum, $badright);
	my ($secflag) = 1;
	open(LINKSEC, "linksec.txt");
	while(<LINKSEC>){
		chomp;
		($linknum, $badright) = split;
		if ($linknum == $link) {
			if (($knowrights & $badright) == $badright) {
				$secflag = 0;
			}
		}
	}
	close LINKSEC;
	return($secflag);
}

Here is a sample of data in the linksec.txt file:

1	8
1	131072
1	524288
2	8
2	131072
2	524288
3	8
3	131072
3	524288
4	8
4	131072
4	524288
5	8
5	131072
5	524288
6	8
6	131072
6	524288

Thanks,

Corky


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

Date: Fri, 09 Jul 2004 20:46:50 -0400
From: Ken Sington <ken_sington@nospam_abcdefg.com>
Subject: CGI: print $x =~ s/\n/<br>\n/g;
Message-Id: <SKednRPN4rj4oXLdRVn-tw@speakeasy.net>

In this test:

#!/usr/bin/perl -T
print "content-type: text/html \n\n";

use warnings;
use strict;

use CGI qw/param/;
my $x=param("x");

print qq{
<form method="GET">
<textarea name="x" cols="50" rows="20">$x</textarea><br>
<input type="submit">
</form>
};


print "<hr>\n";

my $s=length($x);
print $s;
print "<br>\n";

print $x =~ s/\n/<br>\n/g; #This one here...



=================


This: print $x =~ s/\n/<br>\n/g;

doesn't do this:
$x =~ s/\n/<br>\n/g;
print $x;


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

Date: Fri, 9 Jul 2004 21:03:05 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: CGI: print $x =~ s/\n/<br>\n/g;
Message-Id: <20040709205524.U15079@barbara.cs.rpi.edu>

On Fri, 9 Jul 2004, Ken Sington wrote:

> This: print $x =~ s/\n/<br>\n/g;
>
> doesn't do this:
> $x =~ s/\n/<br>\n/g;
> print $x;


No, it doesn't.  You're printing the return value of the substitution.
That is, you're printing the return value of the s/// operation.  The
substitute operator returns the number of substitutions it made.  It does
not return the new value of the binded variable.

Another way to illustrate:

$x = "123def789";
$num = ($x =~ s/[a-z]/#/g);
print "Substitutions: $num\n";
print "String: $x\n";

This prints 3 first, because the substitution happened three times (one
for each letter it replaced).   It then prints the new string, '123###789'

Paul Lalli


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

Date: 10 Jul 2004 01:43:56 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: CGI: print $x =~ s/\n/<br>\n/g;
Message-Id: <Xns9521DD143D11Basu1cornelledu@132.236.56.8>

Ken Sington <ken_sington@nospam_abcdefg.com> wrote in 
news:SKednRPN4rj4oXLdRVn-tw@speakeasy.net:

> In this test:
> 
> #!/usr/bin/perl -T
> print "content-type: text/html \n\n";

Another reason to use CGI.pm. See:

http://www.w3.org/Protocols/HTTP/Object_Headers.html#z16


-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


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

Date: 9 Jul 2004 17:58:13 -0700
From: mst@fiftyvolts.com (MST)
Subject: Code Style -- here-docs -- How do you make them look good?
Message-Id: <ec46364f.0407091658.2d53af12@posting.google.com>

Usually I use perl for system admin type things, but recently I've
been writing a flurry of CGI scripts. In the process I find my self
using (abusing?) here-docs to print chunks of HTML code. I find that
no matter how hard I try I just can't find a style of writing a
here-doc that pleases me I've tried things like this:

if($test) {
    print <<HTML
   <p>Some html $Junk!</p>
   <p>$More junk</p>
HTML
}

and that isn't so bad. What irks me is if the here-doc isn't at the
end of a block I need to throw a ; on a line all by its lonesome. This
leaves me trying to creatively position code chunks such that the
here-doc is at the end of a block (which usually results in less
readablility in the end). The readablity of my code is fairly
important as eventually I will be passing it off to a much less
seasoned perl programmer.

What do you guys think? Should I forget it and switch to using
multiple print qq()'s? Is there a better way to format the here-doc?
Maybe I just have a stick up my butt; however I wanted to see what
kind of feedback I'd get from the .misc crowd.


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

Date: Fri, 9 Jul 2004 21:09:43 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Code Style -- here-docs -- How do you make them look good?
Message-Id: <20040709210541.L15079@barbara.cs.rpi.edu>

On Fri, 9 Jul 2004, MST wrote:

> Usually I use perl for system admin type things, but recently I've
> been writing a flurry of CGI scripts. In the process I find my self
> using (abusing?) here-docs to print chunks of HTML code. I find that
> no matter how hard I try I just can't find a style of writing a
> here-doc that pleases me I've tried things like this:
>
> if($test) {
>     print <<HTML
>    <p>Some html $Junk!</p>
>    <p>$More junk</p>
> HTML
> }
>
> and that isn't so bad. What irks me is if the here-doc isn't at the
> end of a block I need to throw a ; on a line all by its lonesome.

No you don't.  You need to put a semi-colon after the first heredoc
marker:

if ($test) {
    print <<HTML;
    <p>Some html here</p>
HTML
    print "this prints!\n";
}


> This
> leaves me trying to creatively position code chunks such that the
> here-doc is at the end of a block (which usually results in less
> readablility in the end). The readablity of my code is fairly
> important as eventually I will be passing it off to a much less
> seasoned perl programmer.
>
> What do you guys think? Should I forget it and switch to using
> multiple print qq()'s?

Why multiple?

print qq
(this is one line
here's another.
and a third\n);

That will print the three lines as written, because qq obeys whitespace,
including newlines.

>  Is there a better way to format the here-doc?
> Maybe I just have a stick up my butt; however I wanted to see what
> kind of feedback I'd get from the .misc crowd.

The other thing you might want to consider is using one of the templating
modules available on CPAN.  I've never used any of them extensively, so I
can't recommend one above the other.   Others can, I'm sure.


Paul Lalli


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

Date: Sat, 10 Jul 2004 01:09:27 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Code Style -- here-docs -- How do you make them look good?
Message-Id: <ccnfgp$9qo$1@news.simnet.is>

"MST" <mst@fiftyvolts.com> wrote in message
news:ec46364f.0407091658.2d53af12@posting.google.com...
>
> if($test) {
>     print <<HTML
>    <p>Some html $Junk!</p>
>    <p>$More junk</p>
> HTML
> }
>
> and that isn't so bad. What irks me is if the here-doc isn't at the
> end of a block I need to throw a ; on a line all by its lonesome.

I think you suffer from a misconception. the ; belongs at the
end of the print line. it just happens that you can leave it out
in this case, but it is clearer if you don't.

gnari







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

Date: Fri, 9 Jul 2004 18:26:11 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: double quotes vs. single quotes (was Re: hash as argument)
Message-Id: <slrnceuacj.a05.tadmc@magna.augustmail.com>

Dale Henderson <nilram@hotpop.com> wrote:

>      This makes me wonder if perhaps 'This is a string' is faster than
>      "This is a string"


No need to wonder, just find out:

   perldoc Benchmark


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


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

Date: 10 Jul 2004 01:45:31 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: double quotes vs. single quotes (was Re: hash as argument)
Message-Id: <slrnceuihr.4g9.abigail@alexandra.abigail.nl>

Dale Henderson (nilram@hotpop.com) wrote on MMMCMLXV September MCMXCIII
in <URL:news:87pt75m0ji.fsf@camel.tamu-commerce.edu>:
 .. >>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:
 ..  
 ..     TM> Joe Smith <Joe.Smith@inwap.com> wrote:
 ..  
 ..  
 ..     TM> The programmer's choice of quotes is a note to (him|her)self:
 ..  
 ..     TM>   "interpolation or backslash escapes are here!"
 ..     TM> or
 ..     TM>   'nothing special going on here'
 ..  
 ..  
 ..       This makes me wonder if perhaps 'This is a string' is faster than
 ..       "This is a string" because in the first example the interpreter
 ..       can just use the string as is. But in the second the interpreter
 ..       must scan the string looking for interpolation or backslash
 ..       and construct a new string to use.


There's no interpreter.

There's the compiler. And the compiler looks at a string only *once*.
And regardless whether it's a single quoted or a double quoted string, the
compiler needs to look at every character anyway - after all, it needs to
find the closing delimiter, and it needs to special case backslashes too.

If you think that the speed difference between using double quotes or
single quotes is important to you, you shouldn't be programming in Perl
in the first place. 


Abigail
-- 
use   lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";


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

Date: 10 Jul 2004 01:56:26 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: double quotes vs. single quotes (was Re: hash as argument)
Message-Id: <slrnceuj6a.4g9.abigail@alexandra.abigail.nl>

Tad McClellan (tadmc@augustmail.com) wrote on MMMCMLXV September MCMXCIII
in <URL:news:slrncetb3u.93h.tadmc@magna.augustmail.com>:
:)  Joe Smith <Joe.Smith@inwap.com> wrote:
:) > Sherm Pendley wrote:
:) >> And don't use double-quotes on strings unless it's necessary.
:) > 
:) > Has Larry Wall made a statement on this?
:)  
:)  
:)  Not that I know of, but I've heard both Randal Schwartz and
:)  Tom Christiansen say that they always use double quotes...
:)  
:)  I'm of the "use double quotes only if you _need_ double quotes" camp,
:)  because I'm just a Regular Guy and not a Genius Hacker.
:)  
:)  The rules are different between those demographics.  :-)
:)  
:)  I need all the "brain cycles" available to solve the problem,
:)  I don't have excess that I can spend on checking for edge cases.
:)  
:)  
:)  
:)  The programmer's choice of quotes is a note to (him|her)self:
:)  
:)     "interpolation or backslash escapes are here!"
:)  or
:)     'nothing special going on here'
:)  
:)  
:)  Double quotes without interpolation or backslash escapes tricks
:)  the maintenance programmer into spending more debugging time on 
:)  that string than is necessary.
:)  
:)  (assuming a string of more than just a few characters)

Really? I find that extremely hard to believe. Perhaps it would be true
if people are reading texts by looking and interpreting each character
separately, just like six year olds that just learned to read yesterday.

I do hope the average maintaince programmer is well beyond that stage,
and just like normal readers absorb larger units that individual characters
at once. When I see a string, I think 'string'. I don't think 'double quoted
string', nor do I think 'single quoted string'. And I certainly don't go
into panic mode "oh gosh, this is a double quoted string but it doesn't
interpolate a variable. Mayday! Mayday! Mayday!", what some, otherwise
gifted, Perl programmers give the impression of doing when encountering a
double quoted string that happens to interpolate an empty set of variables.


:) > Using double quotes in a situation where single quotes could also
:)                           ^^^^^^^^^^^
:) > be used is not a programming error.  
:)  
:)  
:)  But then you have to remember to analyse the situation everytime
:)  you want to quote a string.
:)  
:)     $re = "func\(\)";
:)     print "matched [$1]\n" if /($re)/;   # matches "func" without parens
:)  
:)  
:)  Gets false matches with "", would have worked fine the 1st time with ''.

That's why that's better written as:

    $re = "func[(][)]";

and no matter how often you process it, the parens will never be special
for the regex engine.

:) > It is a matter of style.
:)  
:)  Yes, but that is what style choices are for.
:)  
:)  Either to make debugging easier, or to reduce the chances of
:)  inserting bugs in the first place.
:)  
:)  The above-mentioned "rule" does both.



Abigail
-- 
($;,$_,$|,$\)=("\@\x7Fy~*kde~box*Zoxf*Bkiaox"," "x25,1,"\r"); 
{vec($_=>1+$"=>$^F<<$^F)=ord($/^substr$;=>$"=int rand 24=>1);              
 print&&select$,,$,,$,,$|/($|+tr/ //c);redo if y/ //>$^F**2};


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

Date: Fri, 09 Jul 2004 22:28:43 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: hash as argument
Message-Id: <40EF1C02.FA96A778@acm.org>

Daedalus wrote:
> 
> > Some more examples of saying that "something special" is going
> > on when nothing special is going on:
> >
> >    m/RE/s;   # when RE does not contain a dot
> >
> >    m/RE/m;   # when RE does not contain ^ or $ anchors
> >
> >    printf "%s\n", 'Hello World';  # printf() w/same formatting as print()
> 
> It makes me think of one thing. Funny how the perl's default seems to be the
> double-quotes-like style. qx//, qw//, m//, s///, qr//, <<EOF.

I think you may have misunderstood how qw// works.

$ perl -le'@x = qw/$a @b c/; print "@x"'
$a @b c


John
-- 
use Perl;
program
fulfillment


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

Date: 10 Jul 2004 02:06:38 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: hash as argument
Message-Id: <slrnceujpe.4g9.abigail@alexandra.abigail.nl>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMCMLXV
September MCMXCIII in <URL:news:ccm3tf$9ra$1@mamenchi.zrz.TU-Berlin.DE>:
%%  Daedalus <daedalus@videotron.ca> wrote in comp.lang.perl.misc:
%% > > So now someone wants to debate whether it's a subject worth arguing about.
%% > > Oy! You just can't win with this group...
%% > 
%% > 
%% > Arguing on programming habits and style is pretty trivial... in both
%% > direction.
%% > We could say that uses of double-quotes should only be prefered when their
%% > behavior is needed, but we could also say that uses of single-quote should
%% > only be prefered when their behavior is needed. Double-quotes make it easier
%% > to add variables or backslash-escapes, while single-quote make it clearer
%% > that there's no interpolation. To me their uses are a matter of choice. But
%% > saying "misuse of double-quotes" or ask to "fix" the thing... Do it because
%% > the majority is doing it, thats not a rule of perl.
%%  
%%  It is a more general rule of human interaction.  It is often useful
%%  to do things in one, agreed-upon way, even if there is no rational
%%  reason why that particular way should be preferred.  Traffic regulations
%%  (beginning with the side of the road you drive on) are often quite
%%  arbitrary, but the advantages of adhering to them are obvious.

I get the traffic story. Traffic rules are good because there are many
people on the road at once, each driving a potentially lethal weapon.
I don't come across hundreds of other programmers whose editors could
harm me when I write a program. 

%%  Similarly, for a programming community, there are advantages in having
%%  conventional preferences for one style over another when technically
%%  two (or more) ways would give the same result.  By using the conventional
%%  style, the author tells the reader "Nothing to see here, move along...".
%%  A deviation from the standard tells the reader to look for the reason.
%%  That makes such code a lot easier to read.

The "conventional style"? Are you now claiming that whatever style you
are defending is "conventional" and that the others are "deviating"?
That's quite presumptuous.

%%  Thus, a set of stylistic conventions gives a language a dimension of
%%  expressiveness it wouldn't have without it.  That is a Good Thing.
%%  The preference of '' over "" and of sub() over &sub belong in this
%%  category.

I think they aren't equivalent. 'sub()' is used far more often than 
'&sub' - that preference has been settled. I highly doubt that the
preference of '' vs "" has been settled.



Abigail
-- 
   my $qr =  qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
      $qr =~  s/$qr//g;
print $qr, "\n";


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

Date: Sat, 10 Jul 2004 12:34:35 +1000
From: "Andrew Hamm" <ahamm@mail.com>
Subject: Re: hash as argument
Message-Id: <2l92v0Fabk9kU1@uni-berlin.de>

Sherm Pendley wrote:
> Andrew Hamm wrote:
>
>> I'm not changing
>
> So now someone wants to debate whether it's a subject worth arguing
> about. Oy! You just can't win with this group...

Not sure I wanted to initiate a debate, but from the comments I'm responding
to (or other comments) it sounds like the debate has been forcibly dominated
by one side. I don't know the personalities 'cos I haven't hung around a
perl group for a few years now, but :

all I was trying to point out is that my style of bug revolves around USING
single quotes. Different people must make different styles of mistakes. The
smart people will learn from their mistakes and establish their style to
overcome their weaknesses. I think it's fairly pointless issuing dogma. I do
some training here in my company on other programming subjects, and I always
back up a statement of dogma with a piece of experience to show why method A
is crap and method B is good. Sometimes someone will make a counter-example.
From their experience. Everyone says "hmmmm" and learns a little more.
Tolerance for ideas removes the arguments.

I'm also a sucker for a cut-n-paste bug. I've lost count of the times I've
pasted a block and then somehow managed to forget to change one critical
component like [$i] into [$j], or $x into $y or all sorts of stupid editing
failures. Yet I still keep on doing cut-n-paste in my coding ;-/




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

Date: Sat, 10 Jul 2004 12:36:51 +1000
From: "Andrew Hamm" <ahamm@mail.com>
Subject: Re: hash as argument
Message-Id: <2l9331F9v439U1@uni-berlin.de>

John J. Trammell wrote:
> Joe Smith  wrote:
>> Using double quotes in a situation where single quotes could also
>> be used is not a programming error.  It is a matter of style.
>
> AOL.  One IMHO legit reason to prefer double quotes is that ' and "
> are more visually distinct than ` and '.

AOL?

> I'd argue the " vs. ' beef isn't in the same league as use strict,
> test return value from open(), avoid C-style loops, and most others.

oooooo hell no. this argument is pocket change in the grand scheme of
things.




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

Date: Sat, 10 Jul 2004 12:38:15 +1000
From: "Andrew Hamm" <ahamm@mail.com>
Subject: Re: hash as argument
Message-Id: <2l934vFa1h33U1@uni-berlin.de>

Tad McClellan wrote:
>
> Some more examples of saying that "something special" is going
> on when nothing special is going on:
>
>    m/RE/s;   # when RE does not contain a dot
>
>    m/RE/m;   # when RE does not contain ^ or $ anchors

or even m/RE/ instead of /RE/  ???   :-D




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

Date: Fri, 9 Jul 2004 18:21:37 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Invalid Page Fault With Win32::GUI Under Win98
Message-Id: <OTEHc.36842$WM5.2068523@news20.bellglobal.com>


"Robert James Kaes" <rjkaes@flarenet.com> wrote in message
news:pan.2004.07.09.20.27.26.686362@flarenet.com...
> Hi All,
> I'm trying to experiment with Win32::GUI using ActiveState Perl 5.8.4
> (build 810) under Windows 98. I'm trying to follow the examples in the
> Win32::GUI tutorial, but the first example in the tutorial is failing.
>
>   use Win32::GUI;
>   use strict;
>   use warnings;
>
>   my $main = Win32::GUI::Window->new(-name => "Main", -width =>
110, -height => 100);
>
>   # This line is failing
>   $main->AddLabel(-text => "Hello, world");


Please don't post to two groups and set the followup to only one; it's
really not a nice thing to do. You'll catch people (like me) unaware at
times and making me post another message is almost enough to get you
ignored.


You forgot to give the control a name:

$main->AddLabel(-text => "Hello, world",
                               -name => 'myLabel');

Should work when you make that correction.

Matt





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

Date: Fri, 9 Jul 2004 18:31:54 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Negation of RegEx
Message-Id: <slrnceuana.a05.tadmc@magna.augustmail.com>


[ Please learn (and then use) the proper form for a followup posting ]


Dan <dan_yuan@trendmicro.com> wrote:
> Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> wrote in message news:<v3lkcc.us3.ln@goaway.wombat.san-francisco.ca.us>...
>> On 2004-07-08, Dan <dan_yuan@trendmicro.com> wrote:
>> > But, I am not allowed to use "!~", I can only use "=~" for this
>> > problem,
>> 
>> Why are you not allowed to use !~?  Sounds like homework to me.
>> 
> I will put regular expressions in a script. 
> No sign "!~" or "=~" allowed in there.


Why is no "!~" or "=~" allowed in there?

I use them in my "scripts" all the time.


If you don't tell us what your real problem is, then we probably
won't be able to help you solve it...


[ snip TOFU ]

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


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

Date: 10 Jul 2004 02:12:04 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Negation of RegEx
Message-Id: <slrnceuk3k.4g9.abigail@alexandra.abigail.nl>

Keith Keller (kkeller-usenet@wombat.san-francisco.ca.us) wrote on
MMMCMLXIV September MCMXCIII in <URL:news:v3lkcc.us3.ln@goaway.wombat.san-francisco.ca.us>:
:}  -----BEGIN xxx SIGNED MESSAGE-----
:}  Hash: SHA1
:}  
:}  On 2004-07-08, Dan <dan_yuan@trendmicro.com> wrote:
:} > But, I am not allowed to use "!~", I can only use "=~" for this
:} > problem,
:}  
:}  Why are you not allowed to use !~?  Sounds like homework to me.


Some cases where you can't use !~:

    First argument of split.
    Entry in a configuration file.
    (sub)pattern to be interpolated in a larger regular expression.
    Argument to a function.


Abigail
-- 
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s};;;
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};                # Perl 5.6.0 broke this...
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))


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

Date: 09 Jul 2004 22:41:04 GMT
From: ctcgag@hotmail.com
Subject: Re: perl vs Unix grep
Message-Id: <20040709184104.849$lC@newsreader.com>

"Al Belden" <abelden@comcast.net> wrote:
> Hi all,
>     I've been working on a problem that I thought might be of interest:
> I'm trying to replace some korn shell scripts that search source code
> files with perl scripts to gain certain features such as:
>
> More powerful regular expressions available in perl

If the scripts you are seeking to replace are currently working, then
the regex available to the shell/grep are evidentally powerful enough.
Are you sure that this is a true reason and not simply a rationalization?
Do the scripts undergo extensive maintenance during which you really pine
for the power of Perl?

> Ability to print out lines before and after matches (gnu grep supports
> this but is not availble on our Digital Unix and AIX platforms)

I'm pretty sure you can compile gnu grep for both of those platforms.

> Make searches case insensitive by default (yes, I know this can be done
> with grep but the shell scripts that use
> grep don't do this)

I think that, before trying to rewrite those scripts into Perl, I would try
to rewrite them using Perl.  In other words, use Perl to edit the scripts
to add an -i to each grep.

>
> We're talking about approx. 5000 files spread over 15 directories.

If you rewrite into perl, would you be able to reduce this to a much
smaller number of files that parameterize some of the variation now
represented as a multiplicity of scripts?

> To
> date it has proven quite difficult (for me) to match the performance of
> the Korn shell scripts using perl scripts and still obtain the line
> number and context information needed.

Is it very important that you match the performance of the Korn shell
scripts?  If they are twice as slow, will anyone notice?


> The crux of the problem is that I
> have seen the best performance from perl when I match with the /g option
> on a string that represents the current slurped file:
>
> local $/;
> my $curStr = <FH>;
> my $compiledRegex = qr/$srchStr/;
> while ($curStr =~ /$compiledRegex/g)
> {
>     # write matches to file for eventual paging
> }
>
> This works well except that when each match is found I need the line
> number the match has been found in. As far as I can tell from reading and
> research there is no variable that holds this information as I am not
> reading from the file at this point. I can get the information in other
> ways such as:
>
> 1. Reading each file a line at a time, testing for a match and keeping a
> line counter or using $NR or $..
> 2. Reading the file into an array and processing a line at a time
> 3. Creating index files for the source files that store line offsets and
> using them with the slurp method in the paragraph above

If you add the runtime of the matching program itself to the runtime of the
index generating program, is this still faster than 1 or 2?

> 4. Creating an in-memory index for each file that contains a match and
> using it for subsequent matches in that file
>
> 1, 2 and 4 above suffer performance degradation relative to unix grep. #3
> provides good performance and is the method I am currently using but it
> requires creating and maintaining index files. I was wondering if I could
> tie a scalar to a file and use the slurping loop above. Then perhaps $NR
> and $. would contain the current line number as the file would be read as
> the loop is traversed. Any other ideas would be welcome

If the question is performance, tie'ing is almost never the answer.

Unix grep is very good at what it does.  It will be very, very hard
to beat it at its own game without resorting to xs-type stuff.  I wouldn't
even bother trying.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Sat, 10 Jul 2004 01:03:48 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: print $x =~ s/\n/<br>\n/g;
Message-Id: <ccnf67$9pd$1@news.simnet.is>

"Ken Sington" <ken_sington@nospam_abcdefg.com> wrote in message
news:SKednRPN4rj4oXLdRVn-tw@speakeasy.net...
> In this test:

[snip code that emits malformed html]

> This: print $x =~ s/\n/<br>\n/g;
>
> doesn't do this:
> $x =~ s/\n/<br>\n/g;
> print $x;

that's right. and what's more, this is true even
in a non-CGI situation.

the print prints the result of the s///g operation,
which is not the $x

gnari









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

Date: 09 Jul 2004 20:25:27 -0400
From: David Magda <dmagda+trace040423@ee.ryerson.ca>
Subject: Re: Writing a Lisp interpreter in Perl?
Message-Id: <86n0281zew.fsf@number6.magda.ca>

"Steven Pow" <sap6210@rit.edu> writes:

> bad idea, just for something to try.  I can def see some ugliness
> (regex in Lisp? *groan).

http://www.google.com/search?q=lisp+regex

-- 
David Magda <dmagda at ee.ryerson.ca>, http://www.magda.ca/
Because the innovator has for enemies all those who have done well under
the old conditions, and lukewarm defenders in those who may do well 
under the new. -- Niccolo Machiavelli, _The Prince_, Chapter VI


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6786
***************************************


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