[22507] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4728 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 19 03:05:53 2003

Date: Wed, 19 Mar 2003 00:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 19 Mar 2003     Volume: 10 Number: 4728

Today's topics:
    Re: Adding Perl library to default OS X Server install (Tony L. Svanstrom)
    Re: Array reference argument to subroutine problem (Tad McClellan)
    Re: Array reference argument to subroutine problem (Tad McClellan)
    Re: Array reference argument to subroutine problem <me@verizon.invalid>
        Can we integrate PERL into PHP ? (Sushant)
        Cannot get authenticated to Yahoo's SMTP servers while  <aknntp@yahoo.com>
        Device::Serial port conundrum (Roger Dooley)
    Re: disable pattern metacharacters? (Tad McClellan)
        Find and replace a block of lines with PERL <kunal.patel@motorola.com>
    Re: Find and replace a block of lines with PERL (Tad McClellan)
    Re: Find and replace a block of lines with PERL (Tad McClellan)
    Re: Find&Replace only in a certain scope <mstep@t-online.de>
    Re: frames without files ? <ericosman@rcn.com>
    Re: how to check file size (very large! > 2GB) using Pe <thepoet@nexgo.de>
        Mangled Regular Expressions with '|' Operator <keenan1REMOVE@adelphiaNOSPAM.net>
    Re: Mangled Regular Expressions with '|' Operator <me@verizon.invalid>
    Re: Mangled Regular Expressions with '|' Operator (Tad McClellan)
    Re: Mangled Regular Expressions with '|' Operator <REMOVEsdnCAPS@comcast.net>
    Re: Mangled Regular Expressions with '|' Operator <abigail@abigail.nl>
    Re: new Perl feature request: call into shared libs <nospam-abuse@ilyaz.org>
    Re: new Perl feature request: call into shared libs <para@tampabay.rr.com>
        OT: Borland's equivalent to -o or -Fo <nospam-abuse@ilyaz.org>
    Re: OT: Borland's equivalent to -o or -Fo <asu1@c-o-r-n-e-l-l.edu>
    Re: remote control with perl <josef.moellers@fujitsu-siemens.com>
    Re: text filter <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 19 Mar 2003 05:34:36 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Adding Perl library to default OS X Server install
Message-Id: <1fs222m.2f0h2n1kmk0nyN%tony@svanstrom.com>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:

> perl.h is part of a standard Perl installation.  Under 10.1.5 it's under
> /Library/Perl/darwin/CORE/perl.h, though that may have changed.  

 10.2.4 (non-server, as if that should matter in this case):

/System/Library/Perl/darwin/auto/Apache/include/modules/perl/mod_perl.h
/System/Library/Perl/darwin/CORE/perl.h


-- 
# Per scientiam ad libertatem! // Through knowledge towards freedom! #
# Genom kunskap mot frihet! =*= (c) 1999-2002 tony@svanstrom.com =*= #

    perl -e'print$_{$_} for sort%_=`lynx -source svanstrom.com/t`'


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

Date: Tue, 18 Mar 2003 17:16:50 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Array reference argument to subroutine problem
Message-Id: <slrnb7fa72.20j.tadmc@magna.augustmail.com>

dw <me@verizon.invalid> wrote:
> "Jim Cochrane" <jtc@flatland.dimensional.com> wrote in message
> news:slrnb7f4h1.pe7.jtc@flatland.dimensional.com...

>> how to use references to pass more than one array to a
>> subroutine and distinguish between the two arrays in the subroutine.


> In the line marked "One," backslashes were added to indicate that a
> reference to the array should be passed.
> 
> Well... somehow in the code, the backslashes didn't get added.  The correct
> line should be:
>    firstSub( \(1..5), \("A".."E"));


Why/how does that end up working? (I tried it with 5.6.1 & 5.8.0).

perlref.pod says we should be getting 10 references from that, not 2:

   Taking a reference to an enumerated list is not the same
   as using square brackets--instead it's the same as creating
   a list of references!

       @list = (\$a, \@b, \%c);
       @list = \($a, @b, %c);      # same thing!


Am I missing something in the docs, or does that just happen to 
work by "accident"?


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


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

Date: Tue, 18 Mar 2003 17:09:23 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Array reference argument to subroutine problem
Message-Id: <slrnb7f9p3.20j.tadmc@magna.augustmail.com>

Jim Cochrane <jtc@flatland.dimensional.com> wrote:

> how to use references to pass more than one array to a
> subroutine and distinguish between the two arrays in the subroutine.


> What's up here?  


There are no arrays present, only lists.

(you should always be turning "use strict" on you know...)


> Is the page wrong? 


Teaching people to program without strictures is wrong, so: Yes.


> firstSub( (1..5), ("A".."E"));


There are not _any_ arrays in that line of code.

There is a single _list_ containing 10 elements (the parenthesis
are not needed, they do not change anything).

   perldoc -q "list.*array"

      What is the difference between a list and an array?


Here is how you really pass two (anonymous) arrays:

    firstSub( [1..5], ["A".."E"]);


> sub firstSub {
>     my($ref_firstArray, $ref_secondArray) = @_;


Have a look at what those variables contain:

    print "ref_firstArray is [$ref_firstArray]\n";
    print "ref_secondArray is [$ref_secondArray]\n";


>     print("The first array is  @{$ref_firstArray}.\n");


There is no @1 array, so nothing is printed for that part.


>     print("The second array is @{$ref_secondArray}.\n");


There is no @2 array either.


I cannot access the web page you speak of, but I don't need to
in order to tell that the author is not a very good Perl programmer.

I suggest not learning from him/her.


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


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

Date: Tue, 18 Mar 2003 23:55:07 GMT
From: "dw" <me@verizon.invalid>
Subject: Re: Array reference argument to subroutine problem
Message-Id: <vlOda.52551$68.1503@nwrdny01.gnilink.net>


"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnb7fa72.20j.tadmc@magna.augustmail.com...
> dw <me@verizon.invalid> wrote:
> > "Jim Cochrane" <jtc@flatland.dimensional.com> wrote in message
> > news:slrnb7f4h1.pe7.jtc@flatland.dimensional.com...
>
> >> how to use references to pass more than one array to a
> >> subroutine and distinguish between the two arrays in the subroutine.
>
>
> > In the line marked "One," backslashes were added to indicate that a
> > reference to the array should be passed.
> >
> > Well... somehow in the code, the backslashes didn't get added.  The
correct
> > line should be:
> >    firstSub( \(1..5), \("A".."E"));
>
>
> Why/how does that end up working? (I tried it with 5.6.1 & 5.8.0).
>
> perlref.pod says we should be getting 10 references from that, not 2:
>
>    Taking a reference to an enumerated list is not the same
>    as using square brackets--instead it's the same as creating
>    a list of references!
>
>        @list = (\$a, \@b, \%c);
>        @list = \($a, @b, %c);      # same thing!
>
>
> Am I missing something in the docs, or does that just happen to
> work by "accident"?
>

Thank you Tad.  I wasn't thinking so I just glazed over the fact that the
reference gets distributed across the contents of the list.  However, it
appears to work this way when you use the range operator.  According to
perlop for the range operator, "In list context, it returns an array of
values..."  So in this example, the \(1..5) is referencing the list returned
by the range operator.  You will notice that doing \(1..5) is different from
\(1,2,3,4,5).

print Data::Dumper->Dump([\(1..5)]);
$VAR1 = [
          1,
          2,
          3,
          4,
          5
        ];

print Data::Dumper->Dump([\(1,2,3,4,5)]);
$VAR1 = \1;
$VAR2 = \2;
$VAR3 = \3;
$VAR4 = \4;
$VAR5 = \5;

It's was a bad example.  My first instinct was to use brackets, but reading
the note I just assumed it was right (with the exception of forgetting the
backslashes in the actual code).







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

Date: 18 Mar 2003 22:27:11 -0800
From: sushant.shah@i-link.co.in (Sushant)
Subject: Can we integrate PERL into PHP ?
Message-Id: <eebd033d.0303182227.15128a31@posting.google.com>

Hi Group, 
   I am new to this group. I have some doubts about wether is it
possible to have PHP modules itegrated with existing Perl made site?

   We already have site made with Perl. Now for some new modules,
which are in PHP, we want to integrate those module in existing Perl
site.

   Is is possible to do so? Is there any documentation available? 

   Waiting for Favourable Reply.

Thanks and Regards,

Sushant Shah


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

Date: Wed, 19 Mar 2003 00:54:57 -0500
From: AK <aknntp@yahoo.com>
Subject: Cannot get authenticated to Yahoo's SMTP servers while sending mail using Net::SMTP
Message-Id: <8c1g7vcsf2eq58q2nli3q7u1jgi2gohjp7@4ax.com>

With my limited Perl knowledge, I've run out of things to try with
Net::SMTP - but if someone has any pointers getting this to work with
Net::SMTP, I'd appreciate it...

The next thing I am planning to try this with is Mail::Sender. What's
the emoticon for "cross your fingers" :-)

Btw, I should mention that all my shenanigans with Perl are being done
on a Win2K machine using ActivePerl 5.8...

- AK

--------------------------
my script:
--------------------------
use strict;
use warnings;
use Net::SMTP;

my 
(
    $smtp,
    $SMTPServer,
    $SMTPUsername, 
    $SMTPUserEmail,
    $SMTPPassword,
    $ToEmailAddress,
    $Recipient1,
    $Subject,
    $Message
);

$SMTPServer         = "smtp.mail.yahoo.com";
$SMTPUsername       = 'outemail';
$SMTPPassword       = "password";
$SMTPUserEmail      = 'outemail@yahoo.com';
$Recipient1         = 'aknntp@yahoo.com';
$Subject            = "foo\n";
$Message            = "bar\n";

$smtp = Net::SMTP->new(
    $SMTPServer,
    Debug   => 1,           # Enable debugging information
    )
    or die "Cannot create a new Net::SMTP object: $!\n";
print "\n";
print '$smtp->domain=' . $smtp->domain,"\n";
print '$smtp->banner=' . $smtp->banner,"\n";
print '$smtp->help=' . $smtp->help,"\n";

$smtp->auth( $SMTPUsername, $SMTPPassword );

$smtp->mail($SMTPUserEmail);
$smtp->to($Recipient1);
$smtp->bcc($SMTPUserEmail);
$smtp->data();
$smtp->datasend($Message);
$smtp->dataend();

$smtp->quit();

--------------------------
Output
--------------------------

Net::SMTP: Net::SMTP(2.24)
Net::SMTP:   Net::Cmd(2.21)
Net::SMTP:     Exporter(5.566)
Net::SMTP:   IO::Socket::INET(1.26)
Net::SMTP:     IO::Socket(1.27)
Net::SMTP:       IO::Handle(1.21)

Net::SMTP=GLOB(0x1c4b820)<<< 220 smtp017.mail.yahoo.com ESMTP
Net::SMTP=GLOB(0x1c4b820)>>> EHLO localhost.localdomain
Net::SMTP=GLOB(0x1c4b820)<<< 250-smtp017.mail.yahoo.com
Net::SMTP=GLOB(0x1c4b820)<<< 250-AUTH LOGIN PLAIN
Net::SMTP=GLOB(0x1c4b820)<<< 250-PIPELINING
Net::SMTP=GLOB(0x1c4b820)<<< 250 8BITMIME

$smtp->domain=smtp017.mail.yahoo.com
$smtp->banner=smtp017.mail.yahoo.com ESMTP

Net::SMTP=GLOB(0x1c4b820)>>> HELP
Net::SMTP=GLOB(0x1c4b820)<<< 214 qmail home page:
http://pobox.com/~djb/qmail.html
$smtp->help=qmail home page: http://pobox.com/~djb/qmail.html

Net::SMTP=GLOB(0x1c4b820)>>> AUTH LOGIN
Net::SMTP=GLOB(0x1c4b820)<<< 334 VXNlcm5hbWU6
Net::SMTP=GLOB(0x1c4b820)>>> b3V0ZW1haWw=
Net::SMTP=GLOB(0x1c4b820)<<< 334 UGFzc3dvcmQ6
Net::SMTP=GLOB(0x1c4b820)>>> YWFqdW5r

Net::SMTP=GLOB(0x1c4b820)<<< 535 authorization failed (#5.7.0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^ AK: This is the basic problem right now ^^

Net::SMTP=GLOB(0x1c4b820)>>> MAIL FROM:<outemail@yahoo.com>

Net::SMTP=GLOB(0x1c4b820)<<< 530 authentication required - for help go
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^ AK: This problem is probably Yahoo's requirement for Pop
authentication prior to authorizing SMTP, which is different, I
believe, from the initial authentication failure above ^^

to http://help.yahoo.com/help/us/mail/pop/pop-11.html
Net::SMTP=GLOB(0x1c4b820)>>> RCPT TO:<aknntp@yahoo.com>
Net::SMTP: Unexpected EOF on command channel at try_netsmtp.pl line 39



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

Date: 18 Mar 2003 20:45:56 -0800
From: rogdooley@yahoo.com (Roger Dooley)
Subject: Device::Serial port conundrum
Message-Id: <1461e3b9.0303182045.3c09f1b4@posting.google.com>

I'm having a problem reading from a serial port under Perl.  I have an
HVAC system that will respond in various ways to commands sent to it. 
I am able to use minicom to send a command and receive a reply, but
when I try the same in Perl, I just see the lights on the device
verifying that a command has been sent.  I don't receive a reply when
I try to read from the device.  The funny thing is that if I start
minicom after killing the perl script, minicom receives the reply. 
I've also been able to open the port as a file on my laptop and have
the port function properly, but not on the machine that I need it
running on.

Here's part of the code:

$output_string = "sn3 t?\n"; 
$count_out = $port->write($output_string);
  warn "write failed\n"         unless ($count_out);
  warn "write incomplete\n"     if ( $count_out !=
length($output_string) );
$port->write_drain;

$read_string = $port->input; #  I've tried various ways to read 
print "$read_string\n";


The program exits with and empty string.  For some reason, I can't get
the script to read.  Any reason why the reads would be blocked?  Any
suggestions on debugging this?

Thanks


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

Date: Tue, 18 Mar 2003 16:44:09 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: disable pattern metacharacters?
Message-Id: <slrnb7f89p.20j.tadmc@magna.augustmail.com>

Bing Du Test <bing-du@tamu.edu> wrote:

> I have some vague memory that \Q may help get around. 


   perldoc -f quotemeta


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


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

Date: Tue, 18 Mar 2003 18:42:18 -0600
From: "KP" <kunal.patel@motorola.com>
Subject: Find and replace a block of lines with PERL
Message-Id: <b58ef5$ne8$1@newshost.mot.com>

I need to replace multiple lines in a text file

eg: File.txt

Line 1> Token 1
Line 2> 22222222222222222222222222222222
Line 3> 00000000000000000000000000000000

I need to replace the above lines with
Line 1> NEW Token
Line 2> 33333333333333333333333333333333
Line 3> 11111111111111111111111111111111

only if the first "n" lines (3 in this example) are a perfect match.

I got the script to work if the token exists on only one line.  eg: If the
script finds "Token 1", it will replace it with "NEW Token" but it does not
look at the next 3 lines to see if they match.

Any clues on how to fix this  ?
===============================================
Usage :> perl find_replace.pl <String to replace> <String to replace with>

foreach $f (@file_list)
{
 chomp ($f);
 #print $f, "\n";
 $tmp_file = $f;

 # retrieve complete file
 open (IN, $tmp_file) or die "cannot open $tmp_file";
 {
  undef $/;
  $infile = <IN>;
 }
     close (IN) || die("Error Closing File: $tmp_file $!");

 $infile =~ s/$lhs/$rhs/g;


 # write complete file
      open (OUT, ">$tmp_file") || die("Error Writing to File: $tmp_file
$!");
 print OUT $infile;

 close (OUT) || die("Error Closing File: $tmp_file $!");




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

Date: Tue, 18 Mar 2003 20:17:03 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Find and replace a block of lines with PERL
Message-Id: <slrnb7fkov.29s.tadmc@magna.augustmail.com>


[ comp.lang.perl does not exist ]


KP <kunal.patel@motorola.com> wrote:

> Any clues on how to fix this  ?

>  $infile =~ s/$lhs/$rhs/g;


We need two things to be able to evaluate a pattern match.

We have zero of the things we need.

To evaluate a match, we need:

   The pattern. What is in $lhs?

   The string that the pattern is to be matched against. What is in $infile?

If you had posted a complete program, as suggested in the
Posting Guidelines, then we could have surely answered your question.

But you didn't, so we can't.


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


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

Date: Tue, 18 Mar 2003 20:17:53 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Find and replace a block of lines with PERL
Message-Id: <slrnb7fkqh.29s.tadmc@magna.augustmail.com>

KP <kunal.patel@motorola.com> wrote:

>  {
>   undef $/;


You should localize changes that you make to global variables:

   {
    local $/;


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


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

Date: Wed, 19 Mar 2003 07:40:57 +0100
From: Marek Stepanek <mstep@t-online.de>
Subject: Re: Find&Replace only in a certain scope
Message-Id: <BA9DCF89.5880%mstep@t-online.de>

On 15.03.2003 23:15 Uhr, in article
6g977vg5jfo283mjj316pu93d8b3ais9on@4ax.com, "w i l l" <will@com.yahoo>
wrote:

> id first look at HTML::TableExtract or HTML::TokeParser to seperate
> your data from your HTML.
> 
> -w i l l 
> 
> 
> On Sat, 15 Mar 2003 10:44:08 +0100, Marek Stepanek <mstep@t-online.de>
> wrote:
> 

Thank you Will,


but my question was not to strip out the HTML of my file. In contrary, like
that I would cut out my delimiters, which I need for my replace-scope.

Come on, perlers! Is there no means to make an replace only in a certain
scope ??? ( In my example in a <table> with _keyword_ </table> ) I asked
this question already in a mailing list and never got an answer ! I have
already the impression, that this is not possible with perl ...


greetings marek


______________________________________________________________________
___PODIUM_INTERNATIONAL_//_the_embassy_for_talented_young_musicians___
_______Marek_Stepanek__mstep_[at]_PodiumInternational_[dot]_de________
__________________http://www.PodiumInternational.de___________________
______________________________________________________________________

 



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

Date: Tue, 18 Mar 2003 23:37:23 -0500
From: Eric Osman <ericosman@rcn.com>
Subject: Re: frames without files ?
Message-Id: <3E77F403.6080105@rcn.com>

> <SCRIPT>
> function frame1() {
>    return "<HTML><BODY>Text for Frame1</BODY></HTML>";
> }
> 
> function frame2() {
>    return "<HTML><BODY>Text for Frame2</BODY></HTML>";
> }
> 
> <FRAMESET>
>  <FRAME SRC="javascript:frame1()">
>  <FRAME SRC="javascript:frame2()">
> </FRAMESET>
> 
> 


The above doesn't seem to work.  However, as this part of the problem is
not about perl, I'll go ask in the javascript conference.

It seems that the functions aren't getting defined "in time" for the SRC
usages.

After getting an error, I can manually type in "javascript:frame1()" and
it executes.

/Eric



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

Date: Wed, 19 Mar 2003 07:57:22 +0100
From: "Christian Winter" <thepoet@nexgo.de>
Subject: Re: how to check file size (very large! > 2GB) using Perl
Message-Id: <3e782088$0$23352$9b4e6d93@newsread4.arcor-online.net>

"Yong Liu" <yongliu@uiuc.edu> wrote:
> Hi,
>
> I have got a problem using either -s $filename or stat $filename to get
> the correct information about the file size. Here is what I got:
>
> output of -s $filename
> File Size: -1522664308 bytes
>
> output of stat $filename:
> 50331653 629146686 33184 1 22909 10245 0 -1522664308 1048004742
1047655840
> 1047655840 131072 5414720
>
> The actual file size should be:2772302988 bytes (using ls -al)

Hi,

was your Perl configured with option
uselargefiles=define and compilerflag
-D_LARGE_FILE? IIRC you need this two
options to use the large file system
calls (stat64 etc.) on irix. Or if that
doesn't work, use64bitint=define and
-DUSE_64_BIT_INT may also be worth a try.

(currently used configuration can be
viewed with "perl -V").

HTH
-Christian



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

Date: Wed, 19 Mar 2003 03:50:30 GMT
From: Tom Keenan <keenan1REMOVE@adelphiaNOSPAM.net>
Subject: Mangled Regular Expressions with '|' Operator
Message-Id: <keenan1REMOVE-533193.22503018032003@news1.news.adelphia.net>


System:
Mac OS X 10.2.4

When I write a Perl script,
and it contains an alternation operator (|)
in a regular expression,
the pattern never seems to match correctly.

For example, the following little script should 'accept' a
string of 1s and 0s containing an even number of 1s,
and 'reject'  anything else.
In fact, it 'accepts' ANY string.

 #! /usr/bin/perl
 print "Input a string of 1's and 0's: ";
 while (<>){
   chomp;
   if (/^0*|(0*10*10*)*$/){
      print "accepted\n";
    }
   else {print "rejected\n"};
 }

But it works fine if I write it like this:

 #! /usr/bin/perl
 print "Input a string of 1's and 0's: ";
 while (<>){
   chomp;
   if (/^(0*10*10*)*$/ || /^0*$/){
      print "accepted\n";
    }
  else {print "rejected\n"};
 }


Am I missing some completely obvious problem???
Is there something strange about the Perl interpreter in OS X?

Tom


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

Date: Wed, 19 Mar 2003 04:23:42 GMT
From: "dw" <me@verizon.invalid>
Subject: Re: Mangled Regular Expressions with '|' Operator
Message-Id: <ihSda.73341$gi1.48384@nwrdny02.gnilink.net>


"Tom Keenan" <keenan1REMOVE@adelphiaNOSPAM.net> wrote in message
news:keenan1REMOVE-533193.22503018032003@news1.news.adelphia.net...
> For example, the following little script should 'accept' a
> string of 1s and 0s containing an even number of 1s,
> and 'reject'  anything else.
> In fact, it 'accepts' ANY string.
>
>    if (/^0*|(0*10*10*)*$/){
>       print "accepted\n";
>     }
>    else {print "rejected\n"};
>  }
>

This is the same as /^0*/ || /(0*10*10*)*$/
The first part matches anything that starts with a 0.  The second part
matches the end of ANY string.

I think what you really wanted to do was /^(0*|(0*10*10*)+)$/
Note the plus since you want to make sure it matches that pattern.  However,
I guess I would use:
   /^0*(10*10*)*$/
or
   if (tr/1/1/ %2 == 0)

dw




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

Date: Tue, 18 Mar 2003 23:14:17 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Mangled Regular Expressions with '|' Operator
Message-Id: <slrnb7fv59.2ou.tadmc@magna.augustmail.com>

Tom Keenan <keenan1REMOVE@adelphiaNOSPAM.net> wrote:

> When I write a Perl script,
> and it contains an alternation operator (|)
> in a regular expression,
> the pattern never seems to match correctly.


Your problem has nothing to do with alternation.


> In fact, it 'accepts' ANY string.

>    if (/^0*|(0*10*10*)*$/){
                        ^
                        ^

That matches zero or more.

There are at least zero of those in every string, so every string matches.

Beware of writing patterns that match the empty string!


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


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

Date: Tue, 18 Mar 2003 23:16:27 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Mangled Regular Expressions with '|' Operator
Message-Id: <Xns93432C43681Asdn.comcast@216.166.71.239>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Tom Keenan <keenan1REMOVE@adelphiaNOSPAM.net> wrote in news:keenan1REMOVE-
533193.22503018032003@news1.news.adelphia.net:

>    if (/^0*|(0*10*10*)*$/){

This used to trip me up too, until I learned that in regular expressions, 
"|" has extremely low precedence.  So the above expression is actually:

    /(^0*) | (0*10*10* $)/

(spaces added for clarity, parentheses added to show precedence, not 
capture, your parentheses removed for clarity).

I think what you want is:

   /^(0*|(0*10*10*))$/

- -- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPnf9HWPeouIeTNHoEQKrLgCghL6f42XPohv8dyABHrhqU/LK9nUAoLQY
1MDBTCjDOg4jzUqVanp0xZ5Y
=YAH8
-----END PGP SIGNATURE-----


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

Date: 19 Mar 2003 06:55:52 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Mangled Regular Expressions with '|' Operator
Message-Id: <slrnb7g53o.u4a.abigail@alexandra.abigail.nl>

dw (me@verizon.invalid) wrote on MMMCDLXXXVII September MCMXCIII in
<URL:news:ihSda.73341$gi1.48384@nwrdny02.gnilink.net>:
&&  
&&  "Tom Keenan" <keenan1REMOVE@adelphiaNOSPAM.net> wrote in message
&&  news:keenan1REMOVE-533193.22503018032003@news1.news.adelphia.net...
&& > For example, the following little script should 'accept' a
&& > string of 1s and 0s containing an even number of 1s,
&& > and 'reject'  anything else.
&& > In fact, it 'accepts' ANY string.
&& >
&& >    if (/^0*|(0*10*10*)*$/){
&& >       print "accepted\n";
&& >     }
&& >    else {print "rejected\n"};
&& >  }
&& >
&&  
&&  This is the same as /^0*/ || /(0*10*10*)*$/
&&  The first part matches anything that starts with a 0.  The second part
&&  matches the end of ANY string.

And the first matches the beginning of ANY string.

&&  I think what you really wanted to do was /^(0*|(0*10*10*)+)$/
&&  Note the plus since you want to make sure it matches that pattern.  However,
&&  I guess I would use:
&&     /^0*(10*10*)*$/
&&  or
&&     if (tr/1/1/ %2 == 0)


tr/1/1/ % 2 == 0 matches 'a1a1', but that should be rejected.



Abigail
-- 
#!/opt/perl/bin/perl -w
$\ = $"; $SIG {TERM} = sub {print and exit};
kill 15 => fork for qw /Just another Perl Hacker/;


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

Date: Wed, 19 Mar 2003 00:14:26 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: new Perl feature request: call into shared libs
Message-Id: <b58cp2$t8g$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Matt Taylor
<para@tampabay.rr.com>], who wrote in article <Egyda.84612$lW3.3144455@twister.tampabay.rr.com>:
> > See above recipe; which translates the calling convention into
> > reordering of arguments.

> Convention is more than reordering of arguments.

I'm talking about input assignment calling convention.  With the
scheme I proposed one can call a function which expects any (given in
advance) input assignment calling convention by just rearranging the
arguments given to Perl-or-C wrapper.

Given that "Convention is more than reordering of arguments", my
proposal gives a "magnificent simplification" of a hard problem.  ;-)

> > > It may be supported in GCC 3.x, but I doubt it. Most industrial-strength
> > > compilers do not support more than 3 registers for a register call
> scheme
> > > for 2 reasons:

  [one of them was the register spill]

I rechecked the code I was almost ready to code in assembler using SP.
[As I said in the previous message, I managed to simplify it so that
even gcc could fit everything inside a tight loop into registers.]
The logic is close to

  while (a != b) {
    a += b[c];
    c -= a[d];
    d += etc;
  }

Such a code would not cause a register spill even with regparam(6).
However, the actual code is inside a loop like this:

   do {
     char *a = a_init, *b = b_init;

     CODE AS ABOVE.
   } while (d != c);

This could is much harder to fit in registers, since a_init etc should
be preserved during the loop.  Thus this would cause the register spill.

Now comes my point: If I understand things correct, this spill is
irrelevant if the loop is run only once!  Indeed, one needs to push
a_init and b_init to stack.  However, since in the case
1-loop-iteration-only neither the stack pointer, nor the values on
stack are going to be accessed, this pushing is going to take
negligible time with out-of-order processing.

This the regparam(6) calling convention may cause significant savings
even if spill happens.

> > > Also, you can't simply "duplicate" parameters and expect it to work.
> They
> > > exist in one place, and it's either in a register or on the stack.
> >
> > ???  Since the callee does not care about extra values on stack, and
> > extra values in registers, your arguments is not only wrong, it also
> > makes no sense.  ;-) To call a function which expects the argument A
> > on stack, and B in %esi, you call the interface as

> This is not always true. In "standard" Windows convention, the callee cleans
> the stack. The asm code I posted worked regardless of callee or caller
> cleaning the stack.

I do not see any relevance of this to the input convention (as far as
there is a register to keep the initial value of the stack pointer).

> >   my $n_a = 0; # place holder
> >   call_params($function, $A, $B, ($n_a) x 5);
> >
> > (here I assume that the 6th argument from the end is duplicated in
> > %esi).  Rearranging $A, $B, and $n_a, one can satisfy all the input
> > calling conventions (which preserve a given register, e.g., %ebp).
> 
> If the first argument went in esi, this would not work. The function would
> see the second argument as A, the third as B, etc.

> I've never seen arguments passed -both- on the stack and in a
> register on x86.

You mean the same argument, right?  Who would *know* that it is
duplicated (except us?).  The callee takes one parameter from SP[4],
and it is there ($A).  The callee takes another parameter from %esi,
and it is there ($B).  The callee has no chance to know that $B is
also in SP[8], and that we filled 5 other registers with 0, since the
callee (supposedly) does not read these locations.  [If it does, we
can fill them too ;-]

Ilya





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

Date: Wed, 19 Mar 2003 02:50:17 GMT
From: "Matt Taylor" <para@tampabay.rr.com>
Subject: Re: new Perl feature request: call into shared libs
Message-Id: <JVQda.1167$M7.131309@twister.tampabay.rr.com>

"Ilya Zakharevich" <nospam-abuse@ilyaz.org> wrote in message
news:b58cp2$t8g$1@agate.berkeley.edu...
> [A complimentary Cc of this posting was sent to
> Matt Taylor
> <para@tampabay.rr.com>], who wrote in article
<Egyda.84612$lW3.3144455@twister.tampabay.rr.com>:
> > > See above recipe; which translates the calling convention into
> > > reordering of arguments.
>
> > Convention is more than reordering of arguments.
>
> I'm talking about input assignment calling convention.  With the
> scheme I proposed one can call a function which expects any (given in
> advance) input assignment calling convention by just rearranging the
> arguments given to Perl-or-C wrapper.
>
> Given that "Convention is more than reordering of arguments", my
> proposal gives a "magnificent simplification" of a hard problem.  ;-)

A simplification from the API's perspective. A nightmare to work with,
though. Somebody has to do the work of deciding where parameters go. You can
delegate this to the caller, or you can handle it yourself, but somebody has
to decide.

> > > > It may be supported in GCC 3.x, but I doubt it. Most
industrial-strength
> > > > compilers do not support more than 3 registers for a register call
> > scheme
> > > > for 2 reasons:
>
>   [one of them was the register spill]
>
> I rechecked the code I was almost ready to code in assembler using SP.
> [As I said in the previous message, I managed to simplify it so that
> even gcc could fit everything inside a tight loop into registers.]
> The logic is close to
<snip>

Not sure what the register spill had to do with calling conventions, but
yes, regparm(6) -could- be faster. The "standard" convention allows eax,
ecx, and edx to be modified without preservation. The logic here lies in
allowing the compiler some flexibility to cache values in the other regs.
They otherwise have to go back to the stack. If ebx, esi, and edi were also
free like this, you would spill more often.

> This the regparam(6) calling convention may cause significant savings
> even if spill happens.

It might simply because it moves the latency. If the OOOE engine handles it
well, it could be a win. Anyway, it's moot since nobody (except Watcom)
supports this.

> > > > Also, you can't simply "duplicate" parameters and expect it to work.
> > They
> > > > exist in one place, and it's either in a register or on the stack.
> > >
> > > ???  Since the callee does not care about extra values on stack, and
> > > extra values in registers, your arguments is not only wrong, it also
> > > makes no sense.  ;-) To call a function which expects the argument A
> > > on stack, and B in %esi, you call the interface as
>
> > This is not always true. In "standard" Windows convention, the callee
cleans
> > the stack. The asm code I posted worked regardless of callee or caller
> > cleaning the stack.
>
> I do not see any relevance of this to the input convention (as far as
> there is a register to keep the initial value of the stack pointer).

Yes, which is what that code did. It saved esp in ebp.

> > >   my $n_a = 0; # place holder
> > >   call_params($function, $A, $B, ($n_a) x 5);
> > >
> > > (here I assume that the 6th argument from the end is duplicated in
> > > %esi).  Rearranging $A, $B, and $n_a, one can satisfy all the input
> > > calling conventions (which preserve a given register, e.g., %ebp).
> >
> > If the first argument went in esi, this would not work. The function
would
> > see the second argument as A, the third as B, etc.
>
> > I've never seen arguments passed -both- on the stack and in a
> > register on x86.
>
> You mean the same argument, right?  Who would *know* that it is
> duplicated (except us?).  The callee takes one parameter from SP[4],
> and it is there ($A).  The callee takes another parameter from %esi,
> and it is there ($B).  The callee has no chance to know that $B is
> also in SP[8], and that we filled 5 other registers with 0, since the
> callee (supposedly) does not read these locations.  [If it does, we
> can fill them too ;-]

Either I am not following your description or it breaks when $A gets passed
in esi and $B gets passed in [sp+4] (which is the usual mechanism).

-Matt




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

Date: Wed, 19 Mar 2003 00:19:14 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: OT: Borland's equivalent to -o or -Fo
Message-Id: <b58d22$tdj$1@agate.berkeley.edu>

I want to make my Perl modules compilable with Borland-on-Win too.
Unfortunately, MakeMaker does not provide enough constants for custom
compiling.  I want to compile a C file into an OBJ file.  With gcc, it
is

  $(CC) -c -o file.obj file.c

With M$ VC it is

  $(CC) -c -Fofile.obj file.c

How one does it with Borland?

Thanks,
Ilya



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

Date: 19 Mar 2003 00:45:28 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: OT: Borland's equivalent to -o or -Fo
Message-Id: <Xns9342C8FDBEC18asu1cornelledu@132.236.56.8>

Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote in news:b58d22$tdj$1
@agate.berkeley.edu:

> I want to make my Perl modules compilable with Borland-on-Win too.
> Unfortunately, MakeMaker does not provide enough constants for custom
> compiling.  I want to compile a C file into an OBJ file.  With gcc, it
> is
> 
>   $(CC) -c -o file.obj file.c
> 
> With M$ VC it is
> 
>   $(CC) -c -Fofile.obj file.c
> 
> How one does it with Borland?

checking the help file included with the bcc55 command line compiler, 

-o<filename>	Compile .OBJ to filename

seems like what you are looking for.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Wed, 19 Mar 2003 08:42:10 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: remote control with perl
Message-Id: <3E781F52.5D037B72@fujitsu-siemens.com>

stinkbomb wrote:

> here's what I'm doing:
> I want to run an mp3 jukebox.
> this would run on linux box.
> lets say I have perl as a daemon.
> it would play all mp3s and loop them after the last one.
> I want to perhaps have a remote user launch a web browser and send
> commands like
> raise volume
> lower volume
> skip file
> back a file
> ...
> blah...
> =

> I'm wondering if anyone has tried such a back end with a perl script.

All(?) web pages which have a .pl extension are written in perl. There
even exists a mod_perl extension to Apache. So the answer to your
question is: "Yes".

-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: Wed, 19 Mar 2003 00:15:43 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: text filter
Message-Id: <x7d6kous7l.fsf@mail.sysarch.com>

>>>>> "A" == Abigail  <abigail@abigail.nl> writes:

  A> Uri Guttman (uri@stemsystems.com) wrote on MMMCDLXXXVI September MCMXCIII
  A> in <URL:news:x7el54we1z.fsf@mail.sysarch.com>:
  A> }} >>>>> "A" == Abigail  <abigail@abigail.nl> writes:
  A> }}  
  A> }}   A> In this case, s/// beats the shit out of y///.
  A> }}  
  A> }}  i knew enough to say generally since there are always edge cases that
  A> }}  break rules like tr/// is always faster than s///. but this is a total
  A> }}  failure case, can you find one where data changes happen?


  A> I don't think that total failure cases for s/// or y/// should be
  A> considered 'edge cases', they are common enough.

i agree.

  A> Cases that have matches are much harder to benchmark, as you need to
  A> copy the string in each iteration, making it harder to compare the s///
  A> and y///.

then you usually make a null entry which just does the copy. you 
have to do some analysis of the results to subtract out the copy time
per iteration. the percentage table output is no longer valid then.

  A> Using strings of the form:

  A>     ('a' x 100) . ' '
    
  A> or
  A>     ('a' x 100) . ' ' . ('a' x 100)
    
  A> shows y/// to be a few % faster than s///.

is that with or without the copy in the timings? i recall benchmarks
here that when you subtract out the copy, tr beats s/// handily.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class


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

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


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