[31270] in Perl-Users-Digest
Perl-Users Digest, Issue: 2515 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 12 03:09:43 2009
Date: Sun, 12 Jul 2009 00:09: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 Sun, 12 Jul 2009 Volume: 11 Number: 2515
Today's topics:
[OT] Re: formatting a number of elsif statements <m@rtij.nl.invlalid>
Re: [OT] Re: formatting a number of elsif statements sln@netherlands.com
Re: Calling 'C' routines from perl. <ralph.malph@altavista.com>
Re: FAQ 4.28 How do I change the Nth occurrence of some <brian.d.foy@gmail.com>
ImageShack Hacked - Popular Image Hosting Website Vanda <reid@tardis-db.co.uk>
Re: Perl Fails To List All The Multiple Matches In The <m@rtij.nl.invlalid>
Re: Perl Fails To List All The Multiple Matches In The <jurgenex@hotmail.com>
Re: To extract file name only from a file sln@netherlands.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 10 Jul 2009 22:32:35 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: [OT] Re: formatting a number of elsif statements
Message-Id: <34lki6-9mn.ln1@news.rtij.nl>
On Thu, 09 Jul 2009 15:18:50 -0700, sln wrote:
> On Thu, 09 Jul 2009 14:39:54 -0700, sln@netherlands.com wrote:
>
>>On Thu, 9 Jul 2009 07:18:09 +0200, Martijn Lievaart <m@rtij.nl.invlalid>
>>wrote:
>>
>>>On Mon, 06 Jul 2009 13:32:51 -0700, sln wrote:
>>>
>>>>>Another reason is that it can often be implemented using a branch
>>>>>table.
> <snip>
>
> It cannot be! Comparisons on each case must be made, there is no single
> leaf.
It's rather simple, something like:
switch (x) {
case 1:
f1();
break;
case 2:
f2();
break;
.
.
.
case <n>:
f<n>;
break;
}
might be implemented (in pseudo assembler)
.data
label branchtable
Lcont
L1
L2
.
.
.
L<n>
.code
; value is in accumulator X
CMP X,<n>
JGT Lcont
JMP branchtable[x]
L1:
call f1
JMP Lcont
L2:
call f2
JMP Lcont
.
.
.
L<n>:
CALL f<n>
Lcont:
Again, this is pretty basic stuff, consult a good book on compilers.
M4
------------------------------
Date: Sat, 11 Jul 2009 16:29:59 -0700
From: sln@netherlands.com
Subject: Re: [OT] Re: formatting a number of elsif statements
Message-Id: <b16i5517m6rb7t08so6vm73u14dct0iqg8@4ax.com>
On Fri, 10 Jul 2009 22:32:35 +0200, Martijn Lievaart <m@rtij.nl.invlalid> wrote:
>On Thu, 09 Jul 2009 15:18:50 -0700, sln wrote:
>
>> On Thu, 09 Jul 2009 14:39:54 -0700, sln@netherlands.com wrote:
>>
>>>On Thu, 9 Jul 2009 07:18:09 +0200, Martijn Lievaart <m@rtij.nl.invlalid>
>>>wrote:
>>>
>>>>On Mon, 06 Jul 2009 13:32:51 -0700, sln wrote:
>>>>
>>>>>>Another reason is that it can often be implemented using a branch
>>>>>>table.
>> <snip>
>>
>> It cannot be! Comparisons on each case must be made, there is no single
>> leaf.
>
>It's rather simple, something like:
>
>switch (x) {
> case 1:
> f1();
> break;
> case 2:
> f2();
> break;
>.
>.
>.
> case <n>:
> f<n>;
> break;
>}
>
>might be implemented (in pseudo assembler)
>
>.data
>label branchtable
>Lcont
>L1
>L2
>.
>.
>.
>L<n>
>
>.code
>
>; value is in accumulator X
>
>CMP X,<n>
>JGT Lcont
>JMP branchtable[x]
>L1:
>call f1
>JMP Lcont
>L2:
>call f2
>JMP Lcont
>.
>.
>.
>L<n>:
>CALL f<n>
>Lcont:
>
>Again, this is pretty basic stuff, consult a good book on compilers.
>
>M4
Looks pretty basic. A single comparison of a value in a range (seemingly continuous)
that is the offset into a table (data) that hold the absolute jump addresses.
Its the going from here:
CMP X,<n>
to here:
JMP branchtable[x]
thats got me. I haven't done assembly in a long time, if I were paid to do it I would.
I do remember doing thousands and thousands of hand written machine code lines before assemblers.
Mostly 8-bit. Then some stuff with Masm 5.1 and eproms for a while. Mostly frogotten.
Thats why I look at your pseudo assembler and wonder if there is a hidden meaning in CMP X,<n>
the '<n>' especially. It might be benificial to view dissasembly (preferably after c2 pass)
to see if they actually invented some new 'op' code or something that would be a miracle and
shorten your assembly down to what appears to be really only a very few machine cycles.
So that this:
if (x == 1)
f1();
else
CMP X,1
JRNE 16
call f1
JMP Lcont
if (x == 2)
f2();
else
CMP X,2
JRNE 16
call f2
JMP Lcont
...
Lcont:
will forever be looked on as bad code as will this:
switch (x) {
case 1:
f1();
case 2:
case 109827:
fall();
break;
}
-sln
------------------------------
Date: Sat, 11 Jul 2009 00:03:12 -0400
From: Ralph Malph <ralph.malph@altavista.com>
Subject: Re: Calling 'C' routines from perl.
Message-Id: <h392uc$c9j$1@aioe.org>
Prathap wrote:
> Hi All:
>
>
> Can someone let me know how to invoke a 'C' routine from perl. I
> have to develop an application
> that requires Perl and C interactions. I need to know this in
> detail. Please provide me with exmples or referances where I can learn
> this.
>
> Thanks for the help in advance.
>
> Regards,
> Prathap
Sorry shitskin...no aid to the enemy.
------------------------------
Date: Fri, 10 Jul 2009 22:33:35 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.28 How do I change the Nth occurrence of something?
Message-Id: <100720092233356302%brian.d.foy@gmail.com>
In article
<937440cb-1d0a-4d4d-9496-f99769d2b3ed@x5g2000prf.googlegroups.com>,
C.DeRykus <derykus@gmail.com> wrote:
> On Jul 9, 10:48 am, anno4...@radom.zrz.tu-berlin.de wrote:
> Or, use /gc and stop one short of the match count:
>
> my $n = 5;
> my $re = qr/(whom?)ever/;
>
> $str =~ /$re/gc} for 1 .. $n-1; # position at match-1
> $str =~ s/\G(.*?)$re/$1${2}soever/ # replace next if any
ah, very tricky. After the for(), the pos ends up either after any
possible matches in the failure case, or right before the next possible
one.
------------------------------
Date: Fri, 10 Jul 2009 22:18:20 -0700
From: "Reid Tardis" <reid@tardis-db.co.uk>
Subject: ImageShack Hacked - Popular Image Hosting Website Vandalized
Message-Id: <zgV5m.423$dW5.324@newsfe04.iad>
Hacked
http://www.kevinkatovic.com/2009/07/imageshack-hacked-popular-image-hosting.html -
ImageShack.us Hacked check out what it looked like!
------------------------------
Date: Fri, 10 Jul 2009 22:34:13 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Perl Fails To List All The Multiple Matches In The Same Line?
Message-Id: <57lki6-9mn.ln1@news.rtij.nl>
On Thu, 09 Jul 2009 14:09:13 -0700, sln wrote:
> Why can't windows do unix?
In this case, it can. Install cygwin.
HTH,
M4
------------------------------
Date: Fri, 10 Jul 2009 14:34:52 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Perl Fails To List All The Multiple Matches In The Same Line?
Message-Id: <2qcf55dgibgfr5ha060n7f8egsffg2nd22@4ax.com>
Martijn Lievaart <m@rtij.nl.invlalid> wrote:
>On Thu, 09 Jul 2009 14:09:13 -0700, sln wrote:
>
>> Why can't windows do unix?
"Why can't a Ford do a Chevy?"
>In this case, it can. Install cygwin.
That doesn't "do Unix" (whatever that is supposed to mean).
It merely provides the typical Unix utilities in the Windows
environment.
jue
------------------------------
Date: Sat, 11 Jul 2009 14:18:10 -0700
From: sln@netherlands.com
Subject: Re: To extract file name only from a file
Message-Id: <povh55h6v44hdd0ij8nlhtrcua610bjbvb@4ax.com>
On Thu, 9 Jul 2009 08:00:03 -0700 (PDT), Rider <clearguy02@yahoo.com> wrote:
>
>Hi experts,
>
>I have this file, inut.txt (listed below). each line in the file has
>more than 10 fields, but I am just listing a sample format here.
>
>I need to print out only the filenames that are ending with .txt in
>the output..
>
>The output should be:
>===============
>unixFile1.txt
>unixFile2.txt
>unixFile3.txt
>...
>..
>===============
>
>I am looking out for a shorter form of a reg exp to extract only the
>file names in to the output here. I do the basic perl coding on an
>occasional basis, but don't know the right reg exp to do it.
>
>Thanks in advance,
>J
>
>
>Here is the input file.
>===================
>1, bob, usr/tst/unixFile1.txt, boston, text1, text2, text3
>2, bob, usr/tst/unixFile2.txt, boston, text1, text2, text3
>3, bob, usr/tst/unixFile3.txt, boston, text1, text2, text3
>.....
>....
>===================
This might help. Its a construct your own recipe. How you use it
is up to you. Certainly not a 1-liner (or short) but neither is real
file name parsing. There might be a module you could invoke.
Or you could use something like:
/(?:(\/\s*[.-]+.*?)|([a-z0-9_][a-z0-9_ .-]*\.txt))[\s,]+/i and defined $2
-sln
----------------------------
## parse_fname_unix.pl
## (some rudimentary regex construction)
##
use strict;
use warnings;
use constant debug => 1;
my $start_char = "a-z0-9_";
my $body_chars = "$start_char .-";
my $field_seps = "\\s,";
my $fname = "[$start_char][$body_chars]*";
my $ext = "txt";
my $bad_fname = "\/\\s*[.-]+.*?";
my $qualified_name = qr/(?:($bad_fname)|($fname\.$ext))[$field_seps]+/i;
print "\n$qualified_name\n";
while (<DATA>)
{
next if (/^\s*$/);
if (debug) {
print "\n$_";
while (/$qualified_name/g)
{
print "\tBAD: $1\n" if defined $1;
print "\tOK: $2\n" if defined $2;
}
} else {
while (/$qualified_name/g and defined $2) {
print "$2\n";
}
}
}
__DATA__
-4, bob, unix/ .txt/File_-4.txt, boston, text1, unix/tst.txt/File_-4a.txt
-3, bob, unix .txt/File_-3.txt, boston, text1, text2, text3
-2, bob, unix .txt/.-File_-2.txt, boston, text1, text2, text3
-1, bob, unix .txt.-File_-1.txt, boston, text1, text2, text3
0, bob, unixFile0.txt, boston, text1, text2, text3
1, bob, usr/tst/unixFile1.txt, boston, text1, text2, text3
2, bob, usr/tst/unixFile2.txt, boston, text1, text2, text3
3, bob, usr/tst/unix.some.txt.File3.txt, boston, text1, text2, text3
4, bob, usr/tst.txt/unixFile4.Txt, boston, text1, text2, text3
--------------------
output:
(?i-xsm:(?:(/\s*[.-]+.*?)|([a-z0-9_][a-z0-9_ .-]*\.txt))[\s,]+)
-4, bob, unix/ .txt/File_-4.txt, boston, text1, unix/tst.txt/File_-4a.txt
BAD: / .txt/File_-4.txt
OK: File_-4a.txt
-3, bob, unix .txt/File_-3.txt, boston, text1, text2, text3
OK: File_-3.txt
-2, bob, unix .txt/.-File_-2.txt, boston, text1, text2, text3
BAD: /.-File_-2.txt
-1, bob, unix .txt.-File_-1.txt, boston, text1, text2, text3
OK: unix .txt.-File_-1.txt
0, bob, unixFile0.txt, boston, text1, text2, text3
OK: unixFile0.txt
1, bob, usr/tst/unixFile1.txt, boston, text1, text2, text3
OK: unixFile1.txt
2, bob, usr/tst/unixFile2.txt, boston, text1, text2, text3
OK: unixFile2.txt
3, bob, usr/tst/unix.some.txt.File3.txt, boston, text1, text2, text3
OK: unix.some.txt.File3.txt
4, bob, usr/tst.txt/unixFile4.Txt, boston, text1, text2, text3
OK: unixFile4.Txt
------------------------------
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 V11 Issue 2515
***************************************