[25795] in Perl-Users-Digest
Perl-Users Digest, Issue: 8034 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 30 21:05:27 2005
Date: Sat, 30 Apr 2005 18:05:05 -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 Sat, 30 Apr 2005 Volume: 10 Number: 8034
Today's topics:
Re: a regex question .. <noreply@gunnar.cc>
Re: a regex question .. <geoff.cox@notquitecorrectfreeuk.com>
Re: a regex question .. <geoff.cox@notquitecorrectfreeuk.com>
Re: a regex question .. <someone@example.com>
Re: a regex question .. <geoff.cox@notquitecorrectfreeuk.com>
Re: a regex question .. <someone@example.com>
Re: a regex question .. <pilkowsk@informatik.uni-marburg.de>
Re: Can this be rewritten better? <tintin@invalid.invalid>
Re: Looking for Perl Grammar <khamis@wellcode.com>
Re: Looking for Perl Grammar <someone@example.com>
Re: Looking for Perl Grammar <pilkowsk@informatik.uni-marburg.de>
Re: Looking for Perl Grammar <tassilo.von.parseval@rwth-aachen.de>
Re: missing the boat <1usa@llenroc.ude.invalid>
Re: missing the boat <tadmc@augustmail.com>
Re: multiples ifs <john@castleamber.com>
Re: using CGI::Carp <noreply@gunnar.cc>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 30 Apr 2005 20:10:59 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: a regex question ..
Message-Id: <3dhvu9F6ub06uU1@individual.net>
Elvis Cehajic wrote:
> Fabian Pilkowski wrote:
>>
>> my $name = 'aaa2bbb3';
>> ( my $newname = $name ) =~ s/(\d)/0$1/g;
>> # results in: $newname = 'aaa02bbb03'
>
> Just keep in mind that this will change 'aaa11bbb12' to 'aaa0101bbb0102'
> which is probably not what the OP wants.
That's my interpretation as well. How about:
(my $newname = $name) =~ s/(^|\D)(\d)(?=\D|$)/${1}0$2/g;
rename $name, "new-$newname";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 30 Apr 2005 18:58:39 GMT
From: Geoff Cox <geoff.cox@notquitecorrectfreeuk.com>
Subject: Re: a regex question ..
Message-Id: <t8l771p6mv4nui5el1l5vn2i63ofmnc536@4ax.com>
On Sat, 30 Apr 2005 20:10:59 +0200, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:
>> Just keep in mind that this will change 'aaa11bbb12' to 'aaa0101bbb0102'
>> which is probably not what the OP wants.
>
>That's my interpretation as well. How about:
>
> (my $newname = $name) =~ s/(^|\D)(\d)(?=\D|$)/${1}0$2/g;
> rename $name, "new-$newname";
Gunnar,
Thanks - that was problem I was trying to sort ! Your code works fine.
Cheers all
Geoff
------------------------------
Date: Sat, 30 Apr 2005 19:00:25 GMT
From: Geoff Cox <geoff.cox@notquitecorrectfreeuk.com>
Subject: Re: a regex question ..
Message-Id: <7cl771td0596km503b27fctq3nrp1j9ij4@4ax.com>
On Sat, 30 Apr 2005 20:10:59 +0200, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:
>That's my interpretation as well. How about:
>
> (my $newname = $name) =~ s/(^|\D)(\d)(?=\D|$)/${1}0$2/g;
> rename $name, "new-$newname";
Gunnar,
wonder if you could just talk me through your code?! not sure what
parts of it mean ....
Geoff
------------------------------
Date: Sat, 30 Apr 2005 19:22:31 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: a regex question ..
Message-Id: <XVQce.16623$3V3.5787@edtnps89>
Geoff Cox wrote:
>
> I am trying to rename a list of files by changing any single digits in
> the names to a zero and the digit, eg 7 -> 07.
>
> Problem is there may be 2 instances in the name and the code below
> only works for the first single digit - how can I deal with both
> instances?
>
>
> if ($name =~ /^(.*?)\-(\d{1})\D(.*?)$/ ) {
> my $num = $2;
>
> rename ($name, "new-" . $1 . "-" . "0" . $num . "-" . $3);
>
> I have tried using tr/// but cannot see how to do it.
>
> My guess would be that the above is not the best way to go about this!
( my $newname = "new-$name" ) =~ s/(?<!\d)(\d)(?!\d)/0$1/g;
if ( -e $newname ) {
warn "Cannot rename $name because $newname exists.\n";
}
else {
rename $name, $newname or warn "Cannot rename $name to $newname: $!";
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 30 Apr 2005 20:34:59 GMT
From: Geoff Cox <geoff.cox@notquitecorrectfreeuk.com>
Subject: Re: a regex question ..
Message-Id: <ulq771dagne1pqennfru1kra9eqbkbp0d6@4ax.com>
On Sat, 30 Apr 2005 19:22:31 GMT, "John W. Krahn"
<someone@example.com> wrote:
>( my $newname = "new-$name" ) =~ s/(?<!\d)(\d)(?!\d)/0$1/g;
John,
Thanks for the above - I can see from a book I have that
(?!\d)
means that there must not be a single digit ahead of the the single
digit, (\d), but does
(?<!\d)
mean there must not be a single digit in front of the (\d) digit?
I didn't know about the look ahead etc so thanks for that ....
Cheers
Geoff
------------------------------
Date: Sat, 30 Apr 2005 21:29:18 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: a regex question ..
Message-Id: <OMSce.17990$3V3.16418@edtnps89>
Geoff Cox wrote:
> On Sat, 30 Apr 2005 19:22:31 GMT, "John W. Krahn"
> <someone@example.com> wrote:
>
>>( my $newname = "new-$name" ) =~ s/(?<!\d)(\d)(?!\d)/0$1/g;
>
> Thanks for the above - I can see from a book I have that
>
> (?!\d)
>
> means that there must not be a single digit ahead of the the single
> digit, (\d), but does
>
> (?<!\d)
>
> mean there must not be a single digit in front of the (\d) digit?
Yes.
> I didn't know about the look ahead etc so thanks for that ....
The information about those should be on your hard drive in the perlre.pod
document.
perldoc perlre
Or on the web at: http://perldoc.perl.org/perlre.html
Of course TMTOWTDI. :-)
my $newname = join '', 'new-', map /\A\d\z/ ? "0$_" : $_, split /(\d+)/, $name;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sun, 1 May 2005 00:49:07 +0200
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: a regex question ..
Message-Id: <3dig8lF6t4s9dU1@individual.net>
* Gunnar Hjalmarsson schrieb:
> Elvis Cehajic wrote:
>> Fabian Pilkowski wrote:
>>>
>>> my $name = 'aaa2bbb3';
>>> ( my $newname = $name ) =~ s/(\d)/0$1/g;
>>> # results in: $newname = 'aaa02bbb03'
>>
>> Just keep in mind that this will change 'aaa11bbb12' to 'aaa0101bbb0102'
>> which is probably not what the OP wants.
I know. I just mentioned the s/// operator for substitute the values. I
didn't proposed a solution to this special problem. For me, it seemed
Geoff hadn't problems to bulding up a regex rather than knowing about
s///.
>
> That's my interpretation as well. How about:
>
> (my $newname = $name) =~ s/(^|\D)(\d)(?=\D|$)/${1}0$2/g;
> rename $name, "new-$newname";
If someone came here with a question about "how adding leading zeros to
numbers", *we* would clue to sprintf(). Considering this, I suggest to
use something like
(my $newname = $name) =~ s/(\d+)/sprintf '%02u', $1/eg;
IMHO, this is more intuitive than searching for enclosing non-digits *by
hand* ;-)
regards,
fabian
------------------------------
Date: Sun, 1 May 2005 10:27:46 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Can this be rewritten better?
Message-Id: <wDTce.2447$Od6.389043@news.xtra.co.nz>
"Nikos" <hackeras@gmail.com> wrote in message
news:d4vpin$k36$1@nic.grnet.gr...
> Joe Smith wrote:
>> Henry Law wrote:
>>
>>>> if( param('select') and param('select') !~ /\.\./ )
>>>
>>>
>>> I don't know what this is doing but it looks odd to me. I can't
>>> imagine what the two calls to "param" are returning which when anded
>>> together could ever look like ".."
>>
>>
>> They're not anded together. To perform an AND operation on two
>> integers require using & not && or 'and'. The quoted line translates
>> to "if param('select') is true (not undef, not '', not 0, not '0')
>> and the value does not contain two consecutive periods ...".
>>
>> It probably makes more sense to write it as
>> if (defined param('select') and param('select') ~= /\.\./) { ... }
>>
>> -Joe
>
> I wrote it like this to avoid getting hackers pass cgi parameters to open
> files from the adress bar like:
>
> http://www.nikolas.tk/cgi-bin/index.pl?select='../../somepath/somefile')
> :-)
So obviously you don't mind things like:
http://www.nikolas.tk/cgi-bin/index.pl?select=/etc/passwd
------------------------------
Date: Sat, 30 Apr 2005 20:18:08 +0200
From: Khamis Abuelkomboz <khamis@wellcode.com>
Subject: Re: Looking for Perl Grammar
Message-Id: <d50i4q$vj6$05$1@news.t-online.com>
Joe Smith wrote:
> Khamis Abuelkomboz wrote:
>
>> I'm writing a Perl parser and I'm looking for a pure perl grammar.
>
>
> You won't find it.
>
> My favorite example is this:
>
> #!/usr/bin/perl -l
> print time / 2 ; #/; die 'This die() is not executed';
> print cos / 2 ; #/; warn 'But this warn() is!';
>
> To resolve the ambiguity of / as numerator/denominator versus m//
> requires knowledge of which functions require arguments and which
> do not. And if the program has 'use Module;', to determine which
> user-defined functions take arguments and which do not requires
> actually parsing the Module. You can't do that with pure grammar.
> -Joe
you got the problem, there is no clear way, when to figure out, using "/", if it is a numeric
operator or a string match clause.
However I'm really not writing grammar for perl, but use similar way, how perl parse itself. my
parsing gools is reporting functions, classes and variables plus cross-referencing.
I have resolved the most problems I have, however a 99% rate for "correct" interpreting the perl
files is enough for me.
However I still find clauses like
if ( s{foo}{bar} ) ...
if ( s[foo][var] ) ...
if ( s<foo><bar> ) ...
I still don't figure out what could be used as "brackets" for the s|tr|m commands???? So I'm looking
as example for grammar descriping how the (s, tr, qq) could be built, something like
S: s OP1 expr OP2 expr OP3
OP1: '/' | '{' | '[' | ':' | ...
OP2: '/' | '}{' | '][' | ...
OP3: '/' | '}' | ']' | ':' | ...
I'm still guissing :-)
regards
khamis
--
Try Code-Navigator on http://www.codenav.com
a source code navigating, analysis and developing tool.
It supports following languages:
* C/C++
* Java
* .NET (including CSharp, VB.Net and other .NET components)
* Classic Visual Basic
* PHP, HTML, XML, ASP, CSS
* Tcl/Tk,
* Perl
* Python
* SQL,
* m4 Preprocessor
* Cobol
------------------------------
Date: Sat, 30 Apr 2005 18:34:28 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Looking for Perl Grammar
Message-Id: <UcQce.16613$3V3.4360@edtnps89>
Khamis Abuelkomboz wrote:
> Joe Smith wrote:
>
>> Khamis Abuelkomboz wrote:
>>
>>> I'm writing a Perl parser and I'm looking for a pure perl grammar.
>>
>> You won't find it.
>>
>> My favorite example is this:
>>
>> #!/usr/bin/perl -l
>> print time / 2 ; #/; die 'This die() is not executed';
>> print cos / 2 ; #/; warn 'But this warn() is!';
>>
>> To resolve the ambiguity of / as numerator/denominator versus m//
>> requires knowledge of which functions require arguments and which
>> do not. And if the program has 'use Module;', to determine which
>> user-defined functions take arguments and which do not requires
>> actually parsing the Module. You can't do that with pure grammar.
>
> you got the problem, there is no clear way, when to figure out, using
> "/", if it is a numeric operator or a string match clause.
> However I'm really not writing grammar for perl, but use similar way,
> how perl parse itself. my parsing gools is reporting functions, classes
> and variables plus cross-referencing.
> I have resolved the most problems I have, however a 99% rate for
> "correct" interpreting the perl files is enough for me.
>
> However I still find clauses like
>
> if ( s{foo}{bar} ) ...
> if ( s[foo][var] ) ...
> if ( s<foo><bar> ) ...
If you like those how about:
if ( s{foo} <bar> ) ...
if ( s[foo] /bar/ ) ...
if ( s<foo>
^bar^ ) ...
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 30 Apr 2005 22:13:17 +0200
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Looking for Perl Grammar
Message-Id: <3di75nF6s4eq7U1@individual.net>
* Khamis Abuelkomboz schrieb:
>
> However I still find clauses like
>
> if ( s{foo}{bar} ) ...
> if ( s[foo][var] ) ...
> if ( s<foo><bar> ) ...
>
> I still don't figure out what could be used as "brackets" for the
> s|tr|m commands???? So I'm looking as example for grammar descriping
> how the (s, tr, qq) could be built, something like
>
> S: s OP1 expr OP2 expr OP3
> OP1: '/' | '{' | '[' | ':' | ...
> OP2: '/' | '}{' | '][' | ...
> OP3: '/' | '}' | ']' | ':' | ...
>
> I'm still guissing :-)
This is mentioned in `perldoc perlop` in the section named "Quote and
Quote-like Operators".
Non-bracketing delimiters use the same character fore and aft, but
the four sorts of brackets (round, angle, square, curly) will all
nest, which means that
q{foo{bar}baz}
is the same as
'foo{bar}baz'
[...]
There can be whitespace between the operator and the quoting
characters, except when # is being used as the quoting character.
q#foo# is parsed as the string foo, while q #foo# is the operator q
followed by a comment. Its argument will be taken from the next
line. This allows you to write:
s {foo} # Replace foo
{bar} # with bar.
So, for s/// you could start with a grammar similar to
S: s WS BRACKETED WS BRACKETED | s WS DELIM expr DELIM expr DELIM
BRACKETED: '(' expr ')' | '<' expr '>' | '[' expr ']' | '{' expr '}'
WS: WHITE-SPACES *
DELIM: '/' | '!' | ':' | '^'
I'm not deeply familiar with grammar descriptions. Is there a way to
ensure that each DELIM is the same char?
Don't forget to add the special behavior of »#« to your grammar. And of
course, do you want to allow comments between the BRACKETED parts as in
the example above? ;-)
regards,
fabian
------------------------------
Date: Sun, 1 May 2005 01:47:22 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Looking for Perl Grammar
Message-Id: <slrnd7868a.1sl.tassilo.von.parseval@localhost.localdomain>
Also sprach Khamis Abuelkomboz:
> However I'm really not writing grammar for perl, but use similar way, how perl parse itself. my
> parsing gools is reporting functions, classes and variables plus cross-referencing.
> I have resolved the most problems I have, however a 99% rate for "correct" interpreting the perl
> files is enough for me.
>
> However I still find clauses like
>
> if ( s{foo}{bar} ) ...
> if ( s[foo][var] ) ...
> if ( s<foo><bar> ) ...
>
> I still don't figure out what could be used as "brackets" for the s|tr|m commands???? So I'm looking
> as example for grammar descriping how the (s, tr, qq) could be built, something like
>
> S: s OP1 expr OP2 expr OP3
> OP1: '/' | '{' | '[' | ':' | ...
> OP2: '/' | '}{' | '][' | ...
> OP3: '/' | '}' | ']' | ':' | ...
You wont find it in the grammar because these things are done by the
Perl lexer. Perl's lexer is not defined in terms of a flex input-file.
It's hand-written so there is not much to gain for you there.
Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
------------------------------
Date: Sat, 30 Apr 2005 20:12:59 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: missing the boat
Message-Id: <Xns9648A4DD39B48asu1cornelledu@127.0.0.1>
"Michael De Tomaso" <mdetomaso@bak.rr.com> wrote in news:9zPce.15457
$R46.3867@tornado.socal.rr.com:
>
> Q: given a text file: "arp.txt" as follows:
...
> D:\study\perl\WIP>type arp.txt
>
> Interface: 192.168.1.100 --- 0x2
> Internet Address Physical Address Type
>
> 192.168.1.107 00-01-02-7c-94-47 dynamic
> 192.168.1.109 00-50-ba-a2-90-86 dynamic
...
> #!perl -w
>
> print "where is mdtFRIENDS:\n";
> print `grep "00\-50\-ba\-a2\-90\-86" arp.txt`;
>
> print "test over\n";
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>
> Q: why don't get the line with the mac address on the screen?
I don't know. It works on my system, although I do not see the point of
the exercise. If you are just going to use perl to spawn grep, why not
just grep in the first place?
> D:\study\perl\WIP>grep "00\-50\-ba\-a2\-90\-86" arp.txt
> 192.168.1.109 00-50-ba-a2-90-86 dynamic
Good for you.
> Q: where am I missing the boat???
By mispelling the word tomato, doing it in a particularly gaudy way, and
not using a proper sig separator so my newsreader can automatically snip
the stupid eyesore.
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Sat, 30 Apr 2005 19:48:49 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: missing the boat
Message-Id: <slrnd789rh.kcm.tadmc@magna.augustmail.com>
Michael De Tomaso <mdetomaso@bak.rr.com> wrote:
> print `grep "00\-50\-ba\-a2\-90\-86" arp.txt`;
Hyphens are not special in regexes, there is no need to backslash them.
> Q: where am I missing the boat???
By "shelling out" to do something that is easily done in native Perl.
[ snip onerous .sig ]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 1 May 2005 00:30:50 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: multiples ifs
Message-Id: <Xns9648C67ECFE41castleamber@130.133.1.4>
Nikos wrote:
> John Bokma wrote:
>
>> There is no need to introduce a span.
>>
>> You can also decide to make the class you use the most the default of
>> td.
>
> I hope you mean something like the following i was trying at the
> moment:
> ps. Scott tole me not to post formating issued here but since you
> answered lets finish it please.
Scott is right, but I thought a short answer to help you on your way
wouldn't be a big issue. But "trying"... did it work? I also recommend to
read the other excellent advice you got: look at the output of your script,
e.g. the HTML page itself. If it doesn't work as expected: read
http://www.w3.org/TR/CSS1. If you are new to this, try to make a simple
HTML page work first, and then code it in Perl.
If you can put the HTML page on line, more people in HTML or CSS related
groups are able to help you out. But again: do first some reading, learning
by "ask & copy" is a long and tiresome way, not only for you :-D.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Sun, 01 May 2005 00:47:24 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: using CGI::Carp
Message-Id: <3dig59F6sdtrmU1@individual.net>
Joe Smith wrote:
> Moritz Karbach wrote:
>>
>> printt "<h1>Hello World</h1>"; # typo in print
>
> 'fatalsToBrowser' displays errors that come after perl script
> has been compiled successfully and starts execution.
Compilation errors that come after CGI::Carp has been loaded via a use()
statement are also captured and displayed by 'fatalsToBrowser'.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
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 8034
***************************************