[18652] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 820 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 2 14:06:03 2001

Date: Wed, 2 May 2001 11:05:20 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <988826719-v10-i820@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 2 May 2001     Volume: 10 Number: 820

Today's topics:
    Re: [OT: language religion ] Re: Should Perl be first? (Rudolf Polzer)
    Re: Another regexp question (Rudolf Polzer)
    Re: Another regexp question (Greg Bacon)
    Re: auto-update index of file dates <dan@nospam_dtbakerprojects.com>
    Re: Capturing the output of perl -c myfile.pl <jfreeman@tassie.net.au>
        closing a hung pipe <jsalmon@thesalmons.org>
    Re: closing a hung pipe nobull@mail.com
    Re: FAQ 3.8:   Is there a ctags for Perl? <bowman@montana.com>
    Re: Hacker Challenge. Can you break this script for me? <pne-news-20010502@newton.digitalspace.net>
    Re: Hacker challenge. Can you break this script for me? <jfreeman@tassie.net.au>
    Re: Hacker challenge. Can you break this script for me? <jfreeman@tassie.net.au>
    Re: Hacker challenge. Can you break this script for me? <jfreeman@tassie.net.au>
    Re: Hacker challenge. Can you break this script for me? <jfreeman@tassie.net.au>
    Re: Hacker challenge. Can you break this script for me? <jfreeman@tassie.net.au>
    Re: Hacker Challenge. Can you break this script for me? <jfreeman@tassie.net.au>
    Re: Help: Time issue <dassing@wettzell.ifag.de>
    Re: Help: Time issue <ack@ivu.de>
    Re: How to: Create Regex which extracts N number of wor <notmyrealemail@example.com>
    Re: How to: Create Regex which extracts N number of wor <ren@tivoli.com>
        IMAP server in perl? <stefan@inty.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 2 May 2001 18:29:01 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: [OT: language religion ] Re: Should Perl be first?
Message-Id: <slrn9f0ded.251.eins@www42.t-offline.de>

Billy Chambless <bchambless@nrlssc.navy.mil> wrote:
> > C++ is much more used because it is more powerful.
> 
> Hmmm... the part before the "because" seems to be true in the Wintel world,
> partly because nobody seems to be in the C-compiler-for-Wintel business
> any more, but I'm seeing a lot more C than C++ on Unix.
> 
> As far as "powerful" goes, I'm not sure what you mean.
> Are there programs that can be written in C++ that can't be written in C?
> Or are you referring to ease of use? Java certainly seems (to me) easier to
> use than C++.

I meant things like generic programming using template<>s, overloading of
functions _and_ operators. Perl only supports the latter; you cannot really
(yes, you _can_ hack it in a complicated way, see "use sub") overload functions 
like sqrt so you revert to a $x->sqrt() syntax.

> OBOnTopic: Whatever language one writes production code in, Perl is a must
> for tools, etc.

Of course. On UNIX Perl is 1st choice.


-- 
#!/usr/bin/perl -W -- WARNING: This will print 22,307 bytes! <strictsafe!>
use strict;for(my$y=-1;$y<1;$y+=.1){for(my$x=-1.9;$x<.4;$x+=.03){print'+';
my$X=my$Y=0;for(0..99){($X,$Y)=($X*$X-$Y*$Y+$x,2*$X*$Y+$y);print"\b "if$X*
$X+$Y*$Y>9;}}print"\n"};print''.reverse"\nHPAJ \a!rezloP .R yb torblednaM"


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

Date: Wed, 2 May 2001 18:30:50 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: Another regexp question
Message-Id: <slrn9f0dhp.251.eins@www42.t-offline.de>

Bart Lateur <bart.lateur@skynet.be> wrote:
> Rudolf Polzer wrote:
> 
> >> >s/(regex)p/\1/gi;
> >> 
> >> You should enable warnings.
> >
> >Of course. But this is not an error.
> 
> It is, or it should be. \1 has a meaning outside regexes: it's a
> reference to the scalar 1.

OK, but the real problem with it is that it is ambigous. "\1" in "" strings
means "\cA" or "\x01".

-- 
#!/usr/bin/perl -W -- WARNING: This copies a random file from
use strict;my$s;my$n=0;for # the  current  directory  to your 
(<*>){++$n;int rand$n or$s # signature  file.   Use  at  your
=$_};`cp $s ~/.signature`; # own risk! (c) 2001 Rudolf Polzer


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

Date: Wed, 02 May 2001 16:33:28 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Another regexp question
Message-Id: <tf0dmol4ipd33f@corp.supernews.com>

In article <pchuet8l1ogkedh8m9apulnffirp5qbfob@4ax.com>,
    Bart Lateur  <bart.lateur@skynet.be> wrote:

: Rudolf Polzer wrote:
: 
: >Of course. But this is not an error.
: 
: It is, or it should be. \1 has a meaning outside regexes: it's a
: reference to the scalar 1.

Oh yeah, I forgot that perl doesn't do any disambiguation.

Greg
-- 
That's the best thing since instant grits.
    -- Boss Hogg


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

Date: Wed, 02 May 2001 16:12:12 GMT
From: Dan Baker <dan@nospam_dtbakerprojects.com>
Subject: Re: auto-update index of file dates
Message-Id: <3AF0307C.BDB96A69@nospam_dtbakerprojects.com>



Jason Pratt wrote:
> 
> Dan, I don't want it to do any mailing or anything like that.  I just need
> it to show the updated files.  Say I update test1.zip and test2.exe.  Then
> on the left table of the site, would show:
> 
> "Files last updated"
> test1.zip - 05/02/01
> test2.exe - 05/02/01
> 
> Each file could then be clicked on to be downloaded. 
----------------------------

I see.... well, the easiest solution is to add a NetMind button like I 
suggested. I use it on a lot of sites where the client want to allow
surfers to "opt-in" for automatic updates. Check out
http://www.NormsGallery.com for instance. I really like this solution
because it encourages re-visits, and is client controlled so you arent
spamming them with unwanted newsletters...

However, for a more custom solution.... are you using ws_ftp or some
other ftp program that generates a log file when you update files? If
so, you might want to just write a little script that chews on the log
file and rebuilds your index page at the time of upload rather than mess
with SSI. Or, write yourself a server-side utility that you can execute
on the server via a telnet shell that would rebuild your index page ONCE
rather than force SSI to run every time a surfer views the page.

D


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

Date: Thu, 03 May 2001 02:25:16 +1000
From: Jfreeman <jfreeman@tassie.net.au>
Subject: Re: Capturing the output of perl -c myfile.pl
Message-Id: <3AF034EC.E8ED4AC8@tassie.net.au>

Martien Verbruggen wrote:

> On Tue, 01 May 2001 21:31:35 +1000,
>         Jfreeman <jfreeman@tassie.net.au> wrote:
> >
> >          Because it has proven impossible to capture the output from perl -c
> > here is what I currently use:
>
> Has it proven to be impossible, or couldn't you find a way to do it?

I have not been able to find a way to do it

>
> #!/usr/local/bin/perl -w
> use strict;
> my $p = $ARGV[0] || $0;
> my @lines = `perl -c $p 2>&1`;
> print @lines;
>
> Or isn't this what you mean?

No this does not work, as I said I read the redirection FAQ. Here is the output of
several versions of the script above on Win32

C:\>type test.pl

#!/usr/local/bin/perl -w
use strict;
my $p = $ARGV[0] || $0;
my @lines = `perl -c $p 2>&1`;
print @lines;

C:\>perl test.pl
test.pl syntax OK

C:\>type test.pl

#!/usr/local/bin/perl -w
use strict;
my $p = $ARGV[0] || $0;
my @lines = `perl -c $p 2>&1`;
#print @lines;


C:\>perl test.pl
test.pl syntax OK

C:\>type test.pl

#!/usr/local/bin/perl -w
use strict;
my $p = $ARGV[0] || $0;
my @lines = `perl -c $p 2>&1`;
print "Hello World\n";
for (@lines) {
    print "Found :$_\n";
}
print "Hello World\n";

C:\>perl test.pl
test.pl syntax OK
Hello World
Hello World

C:\>

As you can see it does not capture, just bore straigh on out to STDOUT. Presumably
what you sent works for you so I guess it relates to Windoze.

>
>
> The perlopentut documentation has some info on redirection. So does
> the section on qx// in the perlop documentation.

Thanks, I will have a look. I have developed a functional workaround now anyway. I
make the script print synatx OK then exit and capture this. A little less crude
than the first one!

sub compile {

    my $path = shift;
    my $first_compile = shift;
    my ($perl, $test);

    # make a unique temp file name so we don't accidentally do damage
    my $temp = "$path.temp";
    $temp = &make_unique_filename($temp) if -e $temp;

    print"Compile check $path\n";
    my @check_file = &get_script($path, 1);
    open (TEMP, ">", $temp) || die "Unable to open $temp:$!\n";
    print TEMP "print \"Syntax OK\";exit;\n";
    for (@check_file) {
        chomp;
        $_ =~ s/sub\s+AUTOLOAD/sub AUTOLOAD {} sub KILLED_OFF_OLD_AUTOLOAD/g; #
kill off autoload sub (cause hangs)
        print TEMP "$_\n";
        $perl.="$_\n";
    }
    eval '$test = `perl $temp`';
    close TEMP;
    unlink $temp || die "Unable to unlink $temp:$!\n";
    if($test =~ m/Syntax OK/) {
        #print "Compile ckeck OK!\n";
        return 0;
    } else {
          return 1;
    }
}

>
>
> Martien
> --
> Martien Verbruggen                      |
> Interactive Media Division              | "In a world without fences,
> Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
> NSW, Australia                          |



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

Date: 02 May 2001 09:18:22 -0700
From: John Salmon <jsalmon@thesalmons.org>
Subject: closing a hung pipe
Message-Id: <m3k83zsp0x.fsf@gw.thesalmons.org>


I would like to read from an "unreliable" pipe.  Unreliable means that
sometimes, at unpredictable times, the process writing to the pipe
hangs.  It does not send EOF.  It does not exit.  When this happens,
I'd like to re-open the pipe handle with a new process.  Here's an outline of
my first attempt:

$SIG{ALRM} = sub{
        close IN;
        open IN, "unreliable |";
}

open IN, "unreliable |";
alarm(10);
while(<IN>){
        alarm(0);
        # blah blah blah
}continue{
        alarm(10);
}

The problem is that close IN; hangs because perl helpfully waits for the
child process to exit when closing a pipe so it can set $?.  I'm not
interested in $?.  I have reason to believe that the process is hung and
will never die (of its own accord).  Leaving out the close doesn't
help.  open implicitly calls close if the handle is already open.

What can I do?
- Somehow tell close not to wait.  How??
- I could kill the 'unreliable' process.  How do I discover it's pid??
- Find a completely different approach?

Any help appreciated.

Thanks,
John Salmon



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

Date: 02 May 2001 18:09:41 +0100
From: nobull@mail.com
Subject: Re: closing a hung pipe
Message-Id: <u9d79rvfsa.fsf@wcl-l.bham.ac.uk>

John Salmon <jsalmon@thesalmons.org> writes:

> I would like to read from an "unreliable" pipe.  Unreliable means that
> sometimes, at unpredictable times, the process writing to the pipe
> hangs.  It does not send EOF.  It does not exit.  When this happens,
> I'd like to re-open the pipe handle with a new process.  Here's an outline of
> my first attempt:
> 
> $SIG{ALRM} = sub{
>         close IN;
>         open IN, "unreliable |";
> }
> 
> open IN, "unreliable |";
> alarm(10);
> while(<IN>){
>         alarm(0);
>         # blah blah blah
> }continue{
>         alarm(10);
> }
> 
> The problem is that close IN; hangs because perl helpfully waits for the
> child process to exit when closing a pipe so it can set $?.  I'm not
> interested in $?.  I have reason to believe that the process is hung and
> will never die (of its own accord).  Leaving out the close doesn't
> help.  open implicitly calls close if the handle is already open.

> What can I do?
> - Somehow tell close not to wait.  How??

AFAIK there's no way to prevent the wait on a close on a filehandle
that was opened as a pipe with open().

> - I could kill the 'unreliable' process. 

Maybe.

> How do I discover it's pid??

It is the return value from the open().

> - Find a completely different approach?

Send the output to a file as see FAQ: "How do I do a `tail -f' in
perl?"

Alternatively build a pipe out of primatives: pipe(), fork(), exec().

pipe(IN,OUT);
if (my $pid = fork) {
  # Parent
  close OUT;
} elsif (defined $pid) {
  # Child
  close IN;
  open STDOUT, ">&OUT";
  close OUT;
  exec "unreliable";
  die "exec unreliable: $!";
} else {
  # Failure
  die "fork: $!";
}

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 2 May 2001 07:28:11 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: FAQ 3.8:   Is there a ctags for Perl?
Message-Id: <FVTH6.99$kW6.1410@newsfeed.slurp.net>

>   Is there a ctags for Perl?
>
>     There's a simple one at
>     http://www.perl.com/CPAN/authors/id/TOMC/scripts/ptags.gz which may do
>     the trick. And if not, it's easy to hack into what you want.

http://ctags.sourceforge.net/

Exuberant Ctags 5.0.1 now offers Perl and Python support (and 21 other
languages)





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

Date: Wed, 02 May 2001 17:13:55 +0200
From: Philip Newton <pne-news-20010502@newton.digitalspace.net>
Subject: Re: Hacker Challenge. Can you break this script for me?
Message-Id: <6090ft0ch3p4hn968a1gv1d17mlmjp2mla@4ax.com>

On Wed, 02 May 2001 09:49:34 +1000, Jfreeman <jfreeman@tassie.net.au>
wrote:

> I have an essentially global package variable called my $found which is causing
                               ^^^^^^^
> this namespace issue.

'my' variables are not package variables.

Why not use real package variables inside your own package, then?

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Thu, 03 May 2001 02:29:54 +1000
From: Jfreeman <jfreeman@tassie.net.au>
Subject: Re: Hacker challenge. Can you break this script for me?
Message-Id: <3AF03602.48E10CCD@tassie.net.au>

Anno Siegel wrote:

> According to Jfreeman  <jfreeman@tassie.net.au>:
>
> [snipped, over-long lines reformatted]
>
> > Why this logically works.
> >
> > It is next to impossible to strip a # char and everything following it
> > until the end of that line (EOL) without causing a compilation error
> > unless the #....EOL is a real comment.
>
> This assumption is incredibly naive.  This bit
>
>     my $length = $#var;
>     $var = 456;
>
> will compile just fine after you cut off the "comment".  It will leave
> a nasty bug too, especially if $var happens to be a scalar ref at the
> time.  Except for the coexistence of $var with @var (yes, Uri, that's
> bad praxis :), this code is by no means remarkable.

Indeed it is not which is why the script leaves $# and $#var tokens alone.

Cheers

James

>
>
> Anno



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

Date: Thu, 03 May 2001 03:23:08 +1000
From: Jfreeman <jfreeman@tassie.net.au>
Subject: Re: Hacker challenge. Can you break this script for me?
Message-Id: <3AF0427C.5E3B07B6@tassie.net.au>



Uri Guttman wrote:

> >>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
>
>   AS> According to Jfreeman  <jfreeman@tassie.net.au>:
>
>   >> It is next to impossible to strip a # char and everything following it
>   >> until the end of that line (EOL) without causing a compilation error
>   >> unless the #....EOL is a real comment.
>
>   AS> This assumption is incredibly naive.  This bit
>
>   AS>     my $length = $#var;
>   AS>     $var = 456;
>
>   AS> will compile just fine after you cut off the "comment".  It will leave
>   AS> a nasty bug too, especially if $var happens to be a scalar ref at the
>   AS> time.  Except for the coexistence of $var with @var (yes, Uri, that's
>   AS> bad praxis :), this code is by no means remarkable.
>
> well, intentionally bad code that breaks a stupid program is good.

Intentionally bad code which does not break 'stupid programs' is however quite
pointless.
Here is some more difficult code, oh and I put the code above in to

C:\>type test.pl

#!usr/bin/perl

#your $# test?
my $length = $#var; #comment
$var = 456;         #comment

=head1 Striptest.pl

Gnarly perl that used to break stripcomments.pl. Now a test file.

=cut

print <<'drom"edary',<<"f#f",<<'=pod',<< ''; #comment
Just another Perl Hacker
drom"edary
#foo
f#f
#bar
=pod
#foo
    #too
        #you

$_ = "Just another Python# Hacker\n";
s {Python#}
  [Perl];
print;

$_=<<'=pod';
Just another Perl Hacker
=pod
print;

s[foo#]  #comment
[bar#];  #comment

m{  \#[#]   # comment
    \w+:    # comment
    [#]     # comment
    \#      # comment
    \}      # comment
    }x;
#

$_ = "Just another Perl Hacker\n";
{
    print if m\foo\#comment
}

$_ = "Just another Perl Hacker # No comment, no comment!
    # Yes, really!
    # I am really a Perl Hacker!
";print;

(1) ? print "foo#\n" : print "bar#\n";  # foobar

print "\"Goodnight I'm tired!\"
# No comment here\n"; # but one here
sleep 1;    # Because tired
print "Goodbye!\n";

C:\>perl stripcomments.pl test.pl
Compile check .\test.pl
Backup of original script written to .\test.pl.bak1
Processing...
Compile check .\test.pl
Done! Comment stripped file .\test.pl

C:\>type test.pl

#!usr/bin/perl
# Stripped by stripcomments.pl (c) Dr James Freeman jfreeman@tassie.net.au
my $length = $#var;
$var = 456;
print <<'drom"edary',<<"f#f",<<'=pod',<< '';
Just another Perl Hacker
drom"edary
#foo
f#f
#bar
=pod
#foo
    #too
        #you

$_ = "Just another Python# Hacker\n";
s {Python#}
  [Perl];
print;
$_=<<'=pod';
Just another Perl Hacker
=pod
print;
s[foo#]
[bar#];
m{  \#[#]
    \w+:
    [#]
    \#
    \}
    }x;
$_ = "Just another Perl Hacker\n";
{
    print if m\foo\
}
$_ = "Just another Perl Hacker # No comment, no comment!
    # Yes, really!
    # I am really a Perl Hacker!
";print;
(1) ? print "foo#\n" : print "bar#\n";
print "\"Goodnight I'm tired!\"
# No comment here\n";
sleep 1;
print "Goodbye!\n";

C:\>perl test.pl
Just another Perl Hacker
#foo
#bar
#foo
    #too
        #you
Just another Perl Hacker
Just another Perl Hacker
Just another Perl Hacker # No comment, no comment!
    # Yes, really!
    # I am really a Perl Hacker!
foo#
"Goodnight I'm tired!"
# No comment here
Goodbye!

C:\>perl stripcomments.pl test.pl 80
Compile check .\test.pl
Backup of original script written to .\test.pl.bak2
Processing...
Compile check .\test.pl
Done! Comment stripped file .\test.pl

C:\>type test.pl

#!usr/bin/perl
# Stripped by stripcomments.pl (c) Dr James Freeman jfreeman@tassie.net.au
my $length = $#var; $var = 456; print <<'drom"edary',<<"f#f",<<'=pod',<< '';
Just another Perl Hacker
drom"edary
#foo
f#f
#bar
=pod
#foo
    #too
        #you

$_ = "Just another Python# Hacker\n";
s {Python#} [Perl]; print; $_=<<'=pod';
Just another Perl Hacker
=pod
print; s[foo#] [bar#]; m{  \#[#] \w+: [#] \# \} }x;
$_ = "Just another Perl Hacker\n"; { print if m\foo\ } $_ = "Just another Perl
Hacker # No comment, no comment!
    # Yes, really!
    # I am really a Perl Hacker!
";print;
(1) ? print "foo#\n" : print "bar#\n"; print "\"Goodnight I'm tired!\"
# No comment here\n"; sleep 1;
print "Goodbye!\n";


> i see
> no reason for this thing and won't lift a finger to help.

It is a free world.

> a better way
> would be to run it through deparse but that is known to be broken in
> places.

Why better? New script uses B::Bytecode to verify output anyway

James

>
>
> uri
>
> --
> Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
> SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
> Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
> Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html



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

Date: Thu, 03 May 2001 03:30:45 +1000
From: Jfreeman <jfreeman@tassie.net.au>
Subject: Re: Hacker challenge. Can you break this script for me?
Message-Id: <3AF04445.6E2D1527@tassie.net.au>



"Godzilla!" wrote:

> Uri Guttman wrote:
>
> > Anno Siegel wrote:
> > >  Jfreeman  wrote:
>
> > > > It is next to impossible to strip a # char and everything following it
> > > > until the end of that line (EOL) without causing a compilation error
> > > > unless the #....EOL is a real comment.
>
> > > This assumption is incredibly naive.  This bit
>
> > >     my $length = $#var;
> > >     $var = 456;
>
> > > will compile just fine after you cut off the "comment".  It will leave
> > > a nasty bug too, especially if $var happens to be a scalar ref at the
> > > time.  Except for the coexistence of $var with @var (yes, Uri, that's
> > > bad praxis :), this code is by no means remarkable.
>
> > well, intentionally bad code that breaks a stupid program is good. i see
> > no reason for this thing and won't lift a finger to help. a better way
> > would be to run it through deparse but that is known to be broken in
> > places.
>
> Ahhh... come on Uri. You are a natural for this kind of stuff!
> Despite your bad disposition, you are a true Perl guru.
> Asking Perlies to hack a script is analogous to declaring
> open season on yourself. Lock and Load, Uri!
>
> I'll give you one to work with. Call for a module in a test
> script which cannot be loaded into INC and run his comment
> stripper. Wallah!
>
> Actually, his comment stripper does fairly much everything
> it should. However, I am not so sure his overall approach
> is all that logical. No need to compile a script in order
> to strip comments.

I use the compile as a check for strip integrity. New compile routine compiles
everyting the perl -c does, as I have found a way to capture the required
output. New today (from the revision history):

B<2 May 2001>

Rewrote compile checking routine to a much better one as Godzilla! was cross,
and we all know what happens when Godzilla! gets cross. Script will now compile
check 630 of 636 perl files in the standard distribution. None of the failures
pass perl -c.

    Stripcomments statistics for .\perl\
    Elapsed time: 129 seconds
    Total lines processed: 141,143
    Total comments stripped: 13,449
    Total files: 630
    Successful: 630 (100.00%)
    Failed:    0 (0.00%)

    C:\>


Added interactive supression of compile checking.

Changed the support for deprecated $foo'bar syntax to allow foo'bar as this
turned up in a test file with the next compile checker.

Added automatic unique filename seeking for backups and temp files.

Added a bytecode checking facility as suggested by Rudolf Polzer. Despite not
working in some trivial cases this proves that over 95% of the files stripped
by stripcomments.pl compile to the same source code with a perfect byte for
byte match.

For files which fail the byte code test a diff engine has been included to write

a diff of the pre and post stripping files. This is a 'Just the facts Jack'
diff, which makes it easy to see where the changes have been made.

Changed to v0.93


> Certainly needs to run separate processes
> or, write his programs as I do in my native tongue, Choctaw.
>
> Heh! Uri, don't even think about using my hacking method
> displayed today. It is way too ingenious and, too easy.
> Ain't I a stinker?
>
> Poor Freeman, probably feels like forty-thousand headmen
> whooped him with ugly sticks.
>
> Godzilla!
> --
> Forty-Thousand Headmen    ... and moi rocking on my cello!
>   http://la.znet.com/~callgirl5/headmen.mid



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

Date: Thu, 03 May 2001 03:43:32 +1000
From: Jfreeman <jfreeman@tassie.net.au>
Subject: Re: Hacker challenge. Can you break this script for me?
Message-Id: <3AF04744.7A286257@tassie.net.au>



Bart Lateur wrote:

> Jfreeman wrote:
>
> >It is next to impossible to strip a # char and everything following it until the
> >end of that line (EOL) without causing a compilation error unless the #....EOL
> >is a real comment.
>
> Oh yeah?
>
>         s#a#b#;
>         /a//m#b#;
>
> This is valid Perl.
>
>         s
>         /a//m
>
> So is this.

C:\>type test.pl

s#a#b#;    #comment
/a//m#b#;  #comment

# This is valid Perl.

s
/a//m   #comment

C:\>perl test.pl
Illegal division by zero at test.pl line 2.

C:\>perl -c test.pl
test.pl syntax OK

C:\>perl stripcomments.pl test.pl
Compile check .\test.pl
Backup of original script written to .\test.pl.bak3
Processing...
Compile check .\test.pl
Done! Comment stripped file .\test.pl


C:\>type test.pl

# Stripped by stripcomments.pl (c) Dr James Freeman jfreeman@tassie.net.au
s#a#b#;
/a//m#b#;
s
/a//m

C:\>

This is valid stripping.

>
>
> --
>         Bart.



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

Date: Thu, 03 May 2001 03:53:53 +1000
From: Jfreeman <jfreeman@tassie.net.au>
Subject: Re: Hacker challenge. Can you break this script for me?
Message-Id: <3AF049B1.1EA8D09F@tassie.net.au>



Gwyn Judd wrote:

> "mein Luftkissenfahrzeug ist voll von den Aalen"
> said Bart Lateur (bart.lateur@skynet.be) in
> <ugnuetcre9t5lq6l1pco7b3gpjs5cmeva7@4ax.com>:
> >Jfreeman wrote:
> >
> >>It is next to impossible to strip a # char and everything following it until the
> >>end of that line (EOL) without causing a compilation error unless the #....EOL
> >>is a real comment.
> >
> >Oh yeah?
> >
> >       s#a#b#;
> >       /a//m#b#;
> >
> >This is valid Perl.
> >
> >       s
> >       /a//m

This does not break the script, see demo

>
>
> Actually I like this example:

So do I. Very inventive.  This is the first one that actually does not parse.

Cheers

James

>
>
> #!/usr/bin/perl -w
> use strict;
> use Fcntl qw/:seek/;
>
> my $stripped = 1;
>
> # Is this a comment?
> # CODE
> # $stripped = 0
> # CODE
>
> seek DATA, 0, SEEK_SET;
>
> while (<DATA>)
> {
>     next unless /^# CODE/ ... /^# CODE/;
>
>     s/^#//;
>     eval;
> }
>
> if ($stripped)
> {
>     print "Hey, you stripped my comments!\n";
> }
>
> __END__
>
> --
> Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
> Reserve your abuse for your true friends.
>              -- Larry Wall in <199712041852.KAA19364@wall.org>



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

Date: Thu, 03 May 2001 04:04:55 +1000
From: Jfreeman <jfreeman@tassie.net.au>
Subject: Re: Hacker Challenge. Can you break this script for me?
Message-Id: <3AF04C47.DCE8B7B@tassie.net.au>



"Godzilla!" wrote:

> Jfreeman wrote:
>
> > "Godzilla!" wrote:
> > > Jfreeman wrote:
>
> > > > It has long been axiomatic that only (the Perl parser) can parse perl.
>
> > > (snipped)
>
> > > Randal sorely underestimates his abilities in his article
> > > relative to this thread. My belief is Randal has forgotten
> > > more about Perl than I have learned over a number of years.
>
> > > After unzipping your file, setting up a test directory,
> > > it took me less than three minutes to break your script.
>
> > You have not broken the script at all. As stated in the pod only scripts which
> > compile as a string under eval are processed. Clearly this script does not pass
> > the eval., so never gets processed. If you can show me how to capture the output
> > of perl -c this would not be an issue but that's another thread - see  thread
> > Capturing the output of perl -c myfile.pl
>
> So programmers must adhere to your rules for writing scripts
> in order to successfully use your program. This is illogical.

I agree it was sub optimal, however  it is also fixed. The new compile checker uses
`perl file` and
validates anything that perl -c will

>
> I tend to disagree and hold an opinion about your program
> which is quite different than yours. Evidence suggests
> otherwise, based on my exhaustive testing of your program.
> Perhaps others will invest time and effort in testing your
> program as I have, then add pertinent comments.
>
> Your program does ok, so far. I tested fifteen scripts,
> some mine own, others off-the-shelf generic scripts. I've
> encountered only two failures by your script out of those
> fifteen scripts tested. Comments are stripped as expected
> and I have noted no serious problems other than these
> two failures noted in my articles. This is not bad for
> beta stage development.

:-)

>
> Other problems I noted are insignificant and can be
> readily remedied by a programmer.
>
> You presented a challenge, I have met your challenge, twice.

Thank you. I have responded to your problem. If you check out the new script you
will find the new reliable compile checker, the optional bytecode checker,
the diff comparison file and a few misc bits and pieces.

Now compiles and parses 630/636 of 5.6.0 The missing 6 have dependecies and fail under
perl -c

James

[snip]



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

Date: Wed, 02 May 2001 16:30:25 +0200
From: Reiner Dassing <dassing@wettzell.ifag.de>
To: u518615722@spawnkill.ip-mobilphone.net
Subject: Re: Help: Time issue
Message-Id: <3AF01A01.E29A4947@wettzell.ifag.de>

Hello!
u518615722@spawnkill.ip-mobilphone.net wrote:
> 
> I have a string extracted from <STDIN>,
> 04/26/2001 15:03:46
> 
> how can i make it assigned as
> (my $sec,my $min, my $hour, my $mday, my $mon,
> my $year)=(46,3,15,4,26,2001)?
> 
> I tried
> (my $sec,my $min, my $hour, my $mday, my $mon,
> my $year, my $wday, my $yday,my $isdst)=
> timelocal(04/26/2001 15:03:46),
> but it is not working.
> 
> Thanks for your help.
> 
> 
I will give you the following test script for your problem:

use strict;

my ( $sec, $min, $hour, $day, $month, $year);

$_ = '04/26/2001 15:03:46';
($month,$day,$year,$hour,$min,$sec) = /^(\d+)\/(\d+)\/(\d+)
+(\d+):(\d+):(\d+)$/;

print "$day-$month-$year, $hour:$min:$sec\n";


--
Mit freundlichen Gruessen / With best regards
   Reiner Dassing


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

Date: Wed, 02 May 2001 18:19:21 +0200
From: Ulrich Ackermann <ack@ivu.de>
Subject: Re: Help: Time issue
Message-Id: <3AF03389.BA473C5C@ivu.de>

u518615722@spawnkill.ip-mobilphone.net wrote:

> I have a string extracted from <STDIN>,
> 04/26/2001 15:03:46
>
> I tried
> (my $sec,my $min, my $hour, my $mday, my $mon,
> my $year, my $wday, my $yday,my $isdst)=
> timelocal(04/26/2001 15:03:46),
> but it is not working.

I don't know if I got you right. Maybe the following is what you looked
for:
my $teststring = "04/26/2001 15:03:46";
my ($month, $day, $year, $hour, $min, $sec) =
    $teststring =~ m|(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+)|;

HTH, Ulrich




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

Date: Wed, 02 May 2001 13:28:45 GMT
From: "BarryK" <notmyrealemail@example.com>
Subject: Re: How to: Create Regex which extracts N number of words before target word
Message-Id: <hYTH6.49580$U4.11809094@news1.rdc1.tn.home.com>

"Richard J. Rauenzahn" <nospam@hairball.cup.hp.com> wrote in message
news:988747796.671523@hpvablab.cup.hp.com...
>
> Thanks -- and thanks for updating your munging!  One last request for
> now -- give up the habit of top posting.  It really annoys the locals,
> and you're likely to get more help when you don't annoy the locals.
>
> For a quoting guide:  http://www.netmeister.org/news/learn2quote2.html

Great tip! Thanks for the reference. Will do.

+++++++++++++++++++++++++++++++

Rich, I took your implicit suggestion to reverse the order of "\w\W", but
Bart pointed out a great counterexample which breaks the regex:

== START CODE ===

$string = "word1 word2 word3 cat word5 cat word7 word8 word9";

@matches = ($string =~ m |(\w+ \W+){2}cat(\W+ \w+){2} |xg);

print join ("\n", @matches);

== END CODE =====

THIS SHOULD RETURN:

word2 word3 cat word5 cat
cat word5 cat word7 word8

BUT INSTEAD RETURNS:

word3
 cat




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

Date: 02 May 2001 11:04:07 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: How to: Create Regex which extracts N number of words before target word
Message-Id: <m3pudrloug.fsf@dhcp9-172.support.tivoli.com>

On Wed, 02 May 2001, notmyrealemail@example.com wrote:

> $string = "word1 word2 word3 cat word5 cat word7 word8 word9";
> 
> @matches = ($string =~ m |(\w+ \W+){2}cat(\W+ \w+){2} |xg);
> 
> print join ("\n", @matches);
> 
> == END CODE =====
> 
> THIS SHOULD RETURN:
> 
> word2 word3 cat word5 cat
> cat word5 cat word7 word8

A single invocation of a regex cannot give overlapping matches.
You'll have to be more clever.

> BUT INSTEAD RETURNS:
> 
> word3
>  cat

This output is mostly a result of the capturing parens you have in the
regex, and their interaction with the {2}.  Change it to:

/ (?: \w+ \W+ ){2} cat (?: \W+ \w+ ){2} /gx

and you will at least get the first match that you expect.

As for handling overlapping matches, here's one way to do it:

$string =~ m{
             (                         # start saving match
              \b                       # needed to limit back-track
              (?:\w+\W+){2}            # match two words
              cat
              (?:\W+\w+){2}            # match two words
              \b                       # needed to limit back-track
             )                         # ok, that's a match
             (?{ push @matches, $1 })  # save the match so far
             (?!)                      # force back-track for other matches
            }x;

Aren't experimental regex features fun!

-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 02 May 2001 16:20:57 GMT
From: stefan kruger <stefan@inty.net>
Subject: IMAP server in perl?
Message-Id: <JtWH6.5482$X91.681712@news1.cableinet.net>


Hi all,

has anyone got a perl implementation of an IMAP mailserver?
It doesn't have to be 'production quality' or anything.

It's not on CPAN. Just thought I'd ask before I start writing
one myself.

cheers, stefan


-- 
Dr Stefan Kruger <stefan@inty.net> http://www.inty.net
Developer, Intelligent Network Technology, Ltd
1700 Park Avenue, Aztec West, Bristol BS32 4UA, UK



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

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


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