[25759] in Perl-Users-Digest
Perl-Users Digest, Issue: 7998 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 20 18:10:28 2005
Date: Wed, 20 Apr 2005 15: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)
Perl-Users Digest Wed, 20 Apr 2005 Volume: 10 Number: 7998
Today's topics:
Re: regex showdown <smcbutler@hotmail.com>
Re: regex showdown <smcbutler@hotmail.com>
Re: regex showdown <mark.clementsREMOVETHIS@wanadoo.fr>
Re: regex showdown <skuo@mtwhitney.nsc.com>
Re: regex showdown <tadmc@augustmail.com>
Set a variable from a substring of another variable usi <t_carbon@yahoo.com>
Re: Set a variable from a substring of another variable <mark.clementsREMOVETHIS@wanadoo.fr>
Re: VIRUS W32.Goldun.M (Re: hotmail password request to <idmwarpzone_NOSPAM_@yahoo.com>
Re: VIRUS W32.Goldun.M (Re: hotmail password request to <Ilgaz@spamcop.net>
Re: VIRUS W32.Goldun.M (Re: hotmail password request to <u.hobelmann@web.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Apr 2005 11:14:21 -0700
From: "si" <smcbutler@hotmail.com>
Subject: Re: regex showdown
Message-Id: <1114020861.398127.33020@z14g2000cwz.googlegroups.com>
sorry guys, i have tried a few things but they didn't work out so i
didn't post them... here's my latest attempt
i'm kind of a newbie with regexp so don't laugh
/^(?<name>\w+)(*(?<pins>\w+)\s*)*(?<masterNm>\w)\s*(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/
$name = $1;
@friends = $2;
$alias = $3
%pairs ....
i was trying to avoid a while loop to populate @friends and %pairs but
i couldn't figure this out from my Friedl book
just trying to get a handle with this stuff...
thx
------------------------------
Date: 20 Apr 2005 11:18:12 -0700
From: "si" <smcbutler@hotmail.com>
Subject: Re: regex showdown
Message-Id: <1114021092.162159.310680@g14g2000cwa.googlegroups.com>
sorry that should have read
/^(?\w+)(*(?\w+)\s=AD*)*(?\w)\s*(?\w=AD+)\s*=3D\s*(?\w+)/=20
thx
------------------------------
Date: Wed, 20 Apr 2005 20:50:55 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: regex showdown
Message-Id: <4266a48f$0$25053$8fcfb975@news.wanadoo.fr>
si wrote:
> sorry guys, i have tried a few things but they didn't work out so i
> didn't post them... here's my latest attempt
>
> i'm kind of a newbie with regexp so don't laugh
>
>
> /^(?<name>\w+)(*(?<pins>\w+)\s*)*(?<masterNm>\w)\s*(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/
>
> $name = $1;
> @friends = $2;
> $alias = $3
> %pairs ....
>
> i was trying to avoid a while loop to populate @friends and %pairs but
> i couldn't figure this out from my Friedl book
>
> just trying to get a handle with this stuff...
>
> thx
>
> sorry that should have read
> /^(?\w+)(*(?\w+)\s*)*(?\w)\s*(?\w+)\s*=\s*(?\w+)/
OK - you are misunderstanding what ? and * do, and when () need to be
escaped (and when they don't). You need to read man perlre carefully.
Also have a look at man re - there are debug options that can be turned
on for regular expressions that may help you.
/(\w+)\s+\(((?:\w\s?)*)\)\s+(\w+)\s(.*)/);
*seems* to work for me. Make sure you understand what the regex is doing.
You can then use split and map to populate @friends and %pairs. Look at
perldoc -f split
perldoc -f map
regards,
Mark
------------------------------
Date: Wed, 20 Apr 2005 12:26:41 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: regex showdown
Message-Id: <Pine.GSO.4.21.0504201217130.27872-100000@mtwhitney.nsc.com>
On 20 Apr 2005, si wrote:
> sorry guys, i have tried a few things but they didn't work out so i
> didn't post them... here's my latest attempt
>
> i'm kind of a newbie with regexp so don't laugh
>
>
> /^(?<name>\w+)(*(?<pins>\w+)\s*)*(?<masterNm>\w)\s*(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/
>
> $name = $1;
> @friends = $2;
> $alias = $3
> %pairs ....
>
> i was trying to avoid a while loop to populate @friends and %pairs but
> i couldn't figure this out from my Friedl book
>
> just trying to get a handle with this stuff...
Assuming you can reliably use space, the equal sign, and parentheses
as delimiters, you can try:
use Data::Dumper;
$_ = 'aa (b c d) ee ff=1.7e-006 gg=4.1 hh=1 ii=on';
my $count_hash_elements = 0;
@_ = $_ =~ /([^ ()=]+)(?==(?{++$count_hash_elements}))?/g;
my ($alias, %hash) = splice(@_, -1 - 2 * $count_hash_elements);
my ($name, @friends) = @_;
print <<"__QED__";
NAME => $name
FRIENDS => @{[ Dumper \@friends]}
ALIAS => $alias
HASH => @{[ Dumper \%hash ]}
__QED__
What's wrong with using a while loop? If well written, it's much
easier to read and understand than what I've written. Take,
for example, the code here:
http://www.stonehenge.com/merlyn/UnixReview/col55.html
courtesy of Randal.
--
Hope this helps,
Steven
------------------------------
Date: Wed, 20 Apr 2005 16:12:50 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: regex showdown
Message-Id: <slrnd6dhei.5fu.tadmc@magna.augustmail.com>
si <smcbutler@hotmail.com> wrote:
> str = "aa (b c d) ee ff=1.7e-006 gg=4.1 hh=1 ii=on"
> what would be regex that would return the below?
>
> $name = 'aa'
>
> @friends = ('b', 'c', 'd')
>
> $alias = 'ee'
>
> %pairs = ( 'ff', 1.7e-006,
> 'gg', 4.1,
> 'hh', 1, etc .. )
if ($str =~ s/(\S+)\s+\(([^)]+)\)\s+(\S+)\s+// ) {
$name = $1;
$alias = $3;
@friends = split /\s+/, $2;
%pairs = split /[ =]+/, $str;
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 20 Apr 2005 12:09:18 -0700
From: "Tony" <t_carbon@yahoo.com>
Subject: Set a variable from a substring of another variable using Regular Expression
Message-Id: <1114024158.534906.160320@z14g2000cwz.googlegroups.com>
Howdy,
Here's my problem, I am reading in a file which contains lines of
different lengths. I need to set the last word on lines which match a
pattern (contain 'dogs') as the value of another variable.
# My file contains some lines that do not have the word
# dogs in them; and I am only interested here in lines
# that contain the word "dogs"
$START="dogs are:";
# I have opened my file, and now each instance of $_
# represents an entire line in sequence.
# So long as there is a line - repeat this loop.
while( $_=<FILE> ) {
$CURRENT_LINE=$_;
$CURRENT_LINE_DUPE=$CURRENT_LINE;
# Above I have setup two variables to hold the value
# of the current line.
#
# If and only if the current line contains the phrase "dogs Are:"
# do I continue to work on this line.
if ($CURRENT_LINE = /$START/) {
# What I want to do next is set the variable DOGSARE to the
# last word in this line.
$DOGSARE=~ m|(\w$)|;
print "$RDOGSARE";
}
}
In short - this doesn't work. The problem is setting the DOGSARE
variable value; I cannot seem to get it to set.
Any help would be greatly appreciated.
Thanks in advance,
TC
------------------------------
Date: Wed, 20 Apr 2005 21:32:18 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Set a variable from a substring of another variable using Regular Expression
Message-Id: <4266ae43$0$840$8fcfb975@news.wanadoo.fr>
Tony wrote:
> Howdy,
You have a fair few issues here...
First up:
always run with
use warnings;
use strict;
which will catch a lot of potential errors for you.
> Here's my problem, I am reading in a file which contains lines of
> different lengths. I need to set the last word on lines which match a
> pattern (contain 'dogs') as the value of another variable.
>
>
> # My file contains some lines that do not have the word
> # dogs in them; and I am only interested here in lines
> # that contain the word "dogs"
>
> $START="dogs are:";
Traditionally, variables tend not to be all uppercase, but anyway:
you have specified that you are interested in lines that contain the
word dogs, but you are using $START to generate a regex. Why set $START
to "dogs are:"?
>
> # I have opened my file, and now each instance of $_
> # represents an entire line in sequence.
> # So long as there is a line - repeat this loop.
>
> while( $_=<FILE> ) {
> $CURRENT_LINE=$_;
> $CURRENT_LINE_DUPE=$CURRENT_LINE;
How about:
while( my $currentLine = <FILE> ){
chomp $currentLine;
I'll assume that you are testing the call to
open FILE,....
for its return value and FILE is a valid filehandle. read
perldoc -f chomp
>
> # Above I have setup two variables to hold the value
> # of the current line.
> #
> # If and only if the current line contains the phrase "dogs Are:"
> # do I continue to work on this line.
>
> if ($CURRENT_LINE = /$START/) {
You are *not* using the match operator here on $CURRENT_LINE here: you
are assigning the return value of /$START/ (matching on $_ by default
)to $CURRENT_LINE, so $CURRENT_LINE will now contain true if the match
has succeeded.
Try:
if( $currentLine =~ /$START/o ){
read man perlre. Make sure you understand what the /o flag does (it
isn't necessary, but may give you some performance benefit, but note
that if $START changes for any reason then this regex will *not* be
recompiled and will continue to match against the old value). Read on....
>
> # What I want to do next is set the variable DOGSARE to the
> # last word in this line.
>
> $DOGSARE=~ m|(\w$)|;
> print "$RDOGSARE";
> }
> }
The regex is wrong, and you aren't pulling out the matched field
correctly. You can combine this with the previous test:
if( $currentLine =~ /$START(?:.*)\b(\w+)$/o ){
my $dogsAre = $1;
print "$1\n";
}
You need to read man perlre, and look at some regex examples. You seem
to be missing quite a lot...
regards,
Mark
------------------------------
Date: Wed, 20 Apr 2005 20:18:11 +0200
From: "Matthias Hoys" <idmwarpzone_NOSPAM_@yahoo.com>
Subject: Re: VIRUS W32.Goldun.M (Re: hotmail password request tool (intranet usage)
Message-Id: <42669ce5$0$25985$ba620e4c@news.skynet.be>
"Ilgaz" <Ilgaz@spamcop.net> wrote in message
news:3cl5mfF6nr9c4U5@individual.net...
> On 2005-04-18 15:11:55 +0300, updateserver28@hotmail.com said:
>
>> I found this on our intranet (i work at microsoft), and as im not
>> working there anymore soon i thought it would be nice for all you guys
>> and girls to get your hands on it. Ive put it on
>> http://matweb.info/~hotmail/hotmail.rar
>>
>> Have fun!
>
> W32.Goldun.M virus, Intego virus barrier reports.
>
> I saved a lots of people from checking the file I bet ;)
>
> Yay, so I have a anti virus in fact :P
>
> Ilgaz
>
Strange ... my up-to-date AVG freeware anti-virus didn't detect any virus in
the rar file. What anti-virus software do you use ?
Matthias
------------------------------
Date: Thu, 21 Apr 2005 00:28:30 +0300
From: Ilgaz <Ilgaz@spamcop.net>
Subject: Re: VIRUS W32.Goldun.M (Re: hotmail password request tool (intranet usage)
Message-Id: <3cnvruF6rll2pU1@individual.net>
On 2005-04-20 21:18:11 +0300, "Matthias Hoys"
<idmwarpzone_NOSPAM_@yahoo.com> said:
>
> "Ilgaz" <Ilgaz@spamcop.net> wrote in message
> news:3cl5mfF6nr9c4U5@individual.net...
>> On 2005-04-18 15:11:55 +0300, updateserver28@hotmail.com said:
>>
>>> I found this on our intranet (i work at microsoft), and as im not
>>> working there anymore soon i thought it would be nice for all you guys
>>> and girls to get your hands on it. Ive put it on
>>> http://matweb.info/~hotmail/hotmail.rar
>>>
>>> Have fun!
>>
>> W32.Goldun.M virus, Intego virus barrier reports.
>>
>> I saved a lots of people from checking the file I bet ;)
>>
>> Yay, so I have a anti virus in fact :P
>>
>> Ilgaz
>>
>
> Strange ... my up-to-date AVG freeware anti-virus didn't detect any
> virus in the rar file. What anti-virus software do you use ?
>
> Matthias
Its a mac antivirus, Intego Virusbarrier for OS X. Interesting really.
But don't expect anything good from stuff like that (password crack)
Ilgaz
------------------------------
Date: Wed, 20 Apr 2005 16:46:54 -0500
From: Ulrich Hobelmann <u.hobelmann@web.de>
Subject: Re: VIRUS W32.Goldun.M (Re: hotmail password request tool (intranet usage)
Message-Id: <3co0udF6mvfdpU1@individual.net>
Ilgaz wrote:
> Its a mac antivirus, Intego Virusbarrier for OS X. Interesting really.
>
> But don't expect anything good from stuff like that (password crack)
WTH do you run an antivirus on your Mac??
I've heard that in some cases they even do harm (was it Norton?),
and they definitely don't do any good. Where should you get a Mac
virus from (except by running a script that wipes your home
directory...)?
My Mac stays clean :)
--
No man is good enough to govern another man without that other's
consent. -- Abraham Lincoln
------------------------------
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 7998
***************************************