[17228] in Perl-Users-Digest
Perl-Users Digest, Issue: 4650 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 18 09:10:28 2000
Date: Wed, 18 Oct 2000 06:10:15 -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: <971874615-v9-i4650@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 18 Oct 2000 Volume: 9 Number: 4650
Today's topics:
Re: Regex and end of line wierdness (Bernard El-Hagin)
Re: Regex and end of line wierdness <anthony@notsoevil.com>
Re: Regex substitution question... <bart.lateur@skynet.be>
Software and Automation Technology Search Engine <oliviermoron@iname.com>
Re: Sort Help Needed <godzilla@stomp.stomp.tokyo>
Re: Sort Help Needed <uri@sysarch.com>
Re: Sort Help Needed <godzilla@stomp.stomp.tokyo>
Re: Sort <jihad.battikha@sharewire.com>
split on comma except when embedded inside quotes <jalford12@yahoo.co.uk>
Re: split on comma except when embedded inside quotes <Rainer.Matzke@gmx.de>
Re: Why '12 13 14' =~ /1./g match only 12 ? (Jari Aalto+mail.emacs)
Re: Why doesn't PERL like Gunnar <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Oct 2000 07:17:02 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Regex and end of line wierdness
Message-Id: <slrn8uqjlb.28m.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 18 Oct 2000 17:44:56 +1000, jason <elephant@squirrelgroup.com>
wrote:
>Matthew Enger wrote ..
>> I am trying to match an IP address using the following:
>>
>>$ip = "202.77.181.194\n";
>>
>>print CheckIP($ip);
>>
>>
>>sub CheckIP {
>>
>> my $ip = $_[0];
>>
>> if ($ip =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) {
>> return 1;
>> }
>> else {
>> return 0;
>> }
>>
>>}
>>
>> I have noticed that the value in $ip is getting through and this is
>>returning 0. Should this be happening?
>
>your code 'returns' 1 for me
Maybe the OP was confused by the fact that the regex matches in spite of
the anchoring of the last digit to $ and there being a newline in the
input string after it. I think he just typoed the return code.
Mathew, if that's the case then the explanation is that the newline
character comes *after* $ so the regex happily matches $ip. If you don't
want the regex to match $ip with a newline character at the end try:
/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$(?!\n)/;
Cheers,
Bernard
--
perl -le'
($B,$e,$r,$n,$a,$r,$d)=q=$B$e$r$n$a$r$d==~m;
\$(.);xg;print$B.$e.$r.$n.$a.$r.$d;'
------------------------------
Date: Wed, 18 Oct 2000 12:39:48 GMT
From: Anthony Bouvier <anthony@notsoevil.com>
Subject: Re: Regex and end of line wierdness
Message-Id: <393E41D6.86E335B3@notsoevil.com>
i ran your exact script, no changes, and 1 was returned.
--
anthony bouvier
notsoevil philosopher
--
------------------------------
Date: Wed, 18 Oct 2000 07:30:32 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regex substitution question...
Message-Id: <aujqusojgjjffhsl9r6cs33taimokp9k71@4ax.com>
Colin Tucker wrote:
>[Display("[Value("foobar")]")]
>At the moment, I have it scanning for occurrences of square brackets with
>anything between them, which it then evaluates as a function, and
>substitutes the function's return value into the HTML, but the problem is
>illustrated above - I want to be able to substitute "nested" commands.
I think that is what the module Text::Balanced is for. It's part of the
package for Parse::RecDescent.
use Text::Balanced 'extract_bracketed';
$text = <<'##';
[Display("[Value("foobar")]")]
...
</html>
##
my($extracted, $remainder) = extract_bracketed($text,'[');
print "Extracted: '$extracted'\n";
print "Remainder: '$remainder'\n";
-->
Extracted: '[Display("[Value("foobar")]")]'
Remainder: '
...
</html>
'
As you can see, it's your task to find the opening bracket.
--
Bart.
------------------------------
Date: Wed, 18 Oct 2000 11:10:12 +0200
From: "Olivier Moron" <oliviermoron@iname.com>
Subject: Software and Automation Technology Search Engine
Message-Id: <8sjpds$1uu$1@s1.read.news.oleane.net>
I'm proud of announcing the creation of a site that groups in one search
engine a lot of links to valuable resources on Software and Automation
Technologies.
http://saatse.tripod.com
Abstract from the site:
"This personal web site provides you with a large collection of links (more
than 220) to technical sites (internet technologies, software languages,
operating systems, automation field, fieldbuses, ...), see 'Topic list' to
have an idea of the different subjects.
The purpose of this site is to help you finding technical information. Some
links are in French, but most are in English."
Regards,
Olivier Moron
------------------------------
Date: Wed, 18 Oct 2000 00:45:47 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sort Help Needed
Message-Id: <39ED552B.4A01D107@stomp.stomp.tokyo>
Ralph Freshour wrote:
> I am having some trouble getting 2 sorts on some data.
> I have a report that, in part, lools like this:
> warrenh 10/17/2000 warren hal
> udontquit 10/17/2000 todd gar
> tim.glaze 10/17/2000 tim gla
> teamesteem 10/17/2000 andy bee
> ellenm 10/17/2000 ellen mur
> stetson 10/17/2000 jeffry ste
> scoping 10/17/2000 judy bar
> customcoat 10/17/2000 carl pen
> crusaderra 10/17/2000 j.e. mac
> What I am trying to do is to sort on the first col
> first, then sort on the second col -
> but it is not working.
I have modified your input data into a
format which is usable and easy with
which to work, as you should have done.
Two changes will be noted. First change
is to add a proper delimiter for a split
and, a critical change which you also
should have done, format your dates as
numbers by removing right slashes.
This is the easy part. Most of my substitutions
at script's end, are cosmetic in nature.
* smiles at Randall *
Told you I am becoming dangerous, Randal.
Godzilla!
--
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class
TEST SCRIPT:
____________
#!/usr/local/bin/perl
print "Content-type: text/plain\n\n";
$input = "warrenh ¦10202000 warren hal
udontquit ¦10112000 todd gar
tim.glaze ¦10172000 tim gla
teamesteem ¦10252000 andy bee
ellenm ¦10162000 ellen mur
stetson ¦10152000 jeffry ste
scoping ¦10302000 judy bar
customcoat ¦10012000 carl pen
crusaderra ¦10182000 j.e. mac";
@Array = split (/\n/, $input);
@New_Array = map { $_ -> [0] } sort { $a -> [1] <=> $b -> [1] }
map { [$_, (split /¦/) [1]] } @Array;
foreach $element (@New_Array)
{
$element =~ s/^\s+//;
$element =~ s/¦//;
$element =~ s¡(\d\d)(\d\d)(\d\d)¡$1/$2/$3¡;
print "$element\n";
}
exit;
PRINTED RESULTS:
________________
customcoat 10/01/2000 carl pen
udontquit 10/11/2000 todd gar
stetson 10/15/2000 jeffry ste
ellenm 10/16/2000 ellen mur
tim.glaze 10/17/2000 tim gla
crusaderra 10/18/2000 j.e. mac
warrenh 10/20/2000 warren hal
teamesteem 10/25/2000 andy bee
scoping 10/30/2000 judy bar
------------------------------
Date: Wed, 18 Oct 2000 07:51:51 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sort Help Needed
Message-Id: <x7bswisi20.fsf@home.sysarch.com>
>>>>> "G" == Godzilla! <godzilla@stomp.stomp.tokyo> writes:
G> I have modified your input data into a
G> format which is usable and easy with
G> which to work, as you should have done.
typical moronzilla approach. disregard the user's request and wander off
down some psychotic path.
G> Two changes will be noted. First change
G> is to add a proper delimiter for a split
G> and, a critical change which you also
G> should have done, format your dates as
G> numbers by removing right slashes.
the white space is perfectly fine for a delimiter. your stupid use of
high binary chars is pathetic and worthless.
how about you writing the code to actually mung his data? editing it by
hand it useless. here, i have 4 million records, can you edit them for me?
G> Told you I am becoming dangerous, Randal.
you have always been dangerous, which is why so many of us protect others
from being infected by your ebola code.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Wed, 18 Oct 2000 01:16:46 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sort Help Needed
Message-Id: <39ED5C6E.FB42526A@stomp.stomp.tokyo>
Uri Guttman seething with envy hissed:
> > Godzilla! wrote code beyond Guttman's ability:
(snipped his verbal diarrhea)
> you have always been dangerous, which is why so many of
> us protect others from being infected by your ebola code.
Ebola Code? EBOLA CODE?
* winks at Randall and laughs *
Godzilla!
--
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class
------------------------------
Date: Wed, 18 Oct 2000 04:51:15 -0400
From: Jihad Battikha <jihad.battikha@sharewire.com>
Subject: Re: Sort
Message-Id: <39ED6483.C9B34FED@sharewire.com>
jtjohnston wrote:
> I'm using this to sort the lines in a db file. The problem is
> each line begins with a number.
> ....
> foreach $key (sort keys %DB){
> ....
foreach $key (sort { $a <=> $b } keys %DB) {
Perl's documentation also has plenty of info to get you started on
different types of sorting scenarios...
--
Jihad Battikha <jihad.battikha@sharewire.com>
Sharewire, Inc. --- http://www.sharewire.com/
- Free forms, programs, and content for web sites.
- No assembly required.
Disclaimer:
Before sending me commercial e-mail, the sender must first agree
to my LEGAL NOTICE located at: http://www.highsynth.com/sig.html
------------------------------
Date: Wed, 18 Oct 2000 13:25:18 +0100
From: "JA" <jalford12@yahoo.co.uk>
Subject: split on comma except when embedded inside quotes
Message-Id: <xHgH5.34047$Kx.2547781@e420r-sjo1.usenetserver.com>
I'm sure I've seen this somewhere but I can't find it.
I've got a CSV file that contains comma delimited data that includes quoted
strings with an embedded comma.
for example:-
8 Alexandra Road,"Wimbledon, London",SW19 7JZ,020 8273 5057
I need to be able to split the line on the comma, ignoring any quote embedded
commas.
Is there a way to do this ? or do I have to strip out quote embedded commas
first before the split. I'd rather like to be able to print the value on the
screen as it is held on the file.
J.
------------------------------
Date: Wed, 18 Oct 2000 15:08:12 +0200
From: "Rainer Matzke" <Rainer.Matzke@gmx.de>
Subject: Re: split on comma except when embedded inside quotes
Message-Id: <39ed9fe2$0$27969@businessnews.de.uu.net>
hi j!
you could try to write a complex regular expression
(yes it exists)
or better
use the Text::ParseWords module
function is quoteword
e. g.
use Text::ParseWords;
# $line contains the actual csv-line
@fields = quoteword(",", 0, $line);
you can find discussion and solutions of such problems in the perl cookbook
(look for the regular expression there)!
------------------------------
Date: 18 Oct 2000 14:52:55 +0300
From: jari.aalto@poboxes.com (Jari Aalto+mail.emacs)
Subject: Re: Why '12 13 14' =~ /1./g match only 12 ?
Message-Id: <wk66mqjrhk.fsf@blue.sea.net>
Keywords: context,match,jari
* 2000-10-15 ilya@math.ohio-state.edu (Ilya Zakharevich)
* <http://search.dejanews.com/msgid.xp?MID=%3C8sd4dr$rk6$1@charm.magnus.acs.ohio-state.edu%3E&format=threaded>
| [A complimentary Cc of this posting was sent to Jari Aalto+mail
| <jari.aalto@poboxes.com>],
| who wrote :
| > Isn't /g is supposed to scan the whole line? Why then the $1
| > only contains the first match?
|
| What do you want it to contain, the last one?
Yes, I expected the last match to "move" to the end, due to /g
| > $_ = "12 13 14";
| > /(1.)/g;
| > print "Match: $1\n";
|
| Is it a list context, or a scalar context? [I do not know, and do not
| care...]
In scalar context as if I had written
print "Matched: $1\n" if "12 13 14" =~ /(1.)/g;
Now the /g has no effect in the regexps? If this is correct, please
state in the documents that the /g is applied only in list context.
Jari
------------------------------
Date: Wed, 18 Oct 2000 07:31:52 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why doesn't PERL like Gunnar
Message-Id: <ffkqus4gosc05jc2voou83ca9bo9c675l1@4ax.com>
Peter Prinz wrote:
>If the problem is caused by the fact that '\G' is a special caracter for
>regular expressions,
>how can I match the string "\\Gunnar" ??
quotemeta().
$B =~ /\Q$B/
--
Bart.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4650
**************************************