[30303] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1546 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 15 18:14:35 2008

Date: Thu, 15 May 2008 15:14:26 -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           Thu, 15 May 2008     Volume: 11 Number: 1546

Today's topics:
        Questions on scalar references in general, substr and r sln@netherlands.co
    Re: Questions on scalar references in general, substr a sln@netherlands.co
        regular expression question <moleskyca1@yahoo.com>
    Re: regular expression question <jimsgibson@gmail.com>
    Re: regular expression question <noreply@gunnar.cc>
    Re: regular expression question <moleskyca1@yahoo.com>
    Re: regular expression question <abigail@abigail.be>
    Re: regular expression question sln@netherlands.co
    Re: URGENT: SENIOR SAP PP/MM ANALYST - San Jose, CA <dha@panix.com>
    Re: URGENT: SENIOR SAP PP/MM ANALYST - San Jose, CA <sbour@niaid.nih.gov>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 15 May 2008 12:40:06 -0700
From: sln@netherlands.co
Subject: Questions on scalar references in general, substr and regular expression engine in particular
Message-Id: <i71p24tfctm1k27uq9pmc4hk4du90tkrlp@4ax.com>

ActiveState perl guidelines state its better to pass by reference for best performance.

Does this apply in the case of SCALARS?

It would seem that dereferencing a SCALAR reference would create a temporary of the original
and I think this is the case.

Perl seems to know array and hash references pretty well and, internally, dereferencing them does
not seem to incur overhead of making a temporary copy of the original array or hash, the element is
directly accessed, as if the reference were a pointer.

Thats fine, I have no problem at all with this. I am only interrested in SCALAR.

I was curious about the function 'substr'. The first parameter is EXPRESSION. It seems to be an
EXPRESSION evaluator. On its face, it will not take a reference, but it will take a dereferenced SCALAR.
But I wonder if, based on the EXPRESSION, if it knows it is dereferencing a SCALAR, and does not make a temporary copy.

In the case of the regular expression engine, I wonder the same thing, although with this there may be other properties
that would cause the discrepancies shown below.

For example 'pos()=' and '= pos()' might incur much overhead, and that may explain it as it could produce unknown temporaries
in the engine.

If I run this code segment 100 times, the substr is averaging 10 times faster than the regex. I can't explain it.

Thanks!


// substr
return substr($$refscalar, 20, 30);

// regex		
$savpos = pos($$refscalar);
pos($$refscalar) = 20;
while ($$refscalar =~ /(.{10})/gs) {
	pos($$refscalar) = $savpos;
	return $1;
}





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

Date: Thu, 15 May 2008 12:54:34 -0700
From: sln@netherlands.co
Subject: Re: Questions on scalar references in general, substr and regular expression engine in particular
Message-Id: <g65p24tss27fiqfo1m6urhfg8qtv86o96e@4ax.com>

On Thu, 15 May 2008 12:40:06 -0700, sln@netherlands.co wrote:

>ActiveState perl guidelines state its better to pass by reference for best performance.
>
>Does this apply in the case of SCALARS?
>
>It would seem that dereferencing a SCALAR reference would create a temporary of the original
>and I think this is the case.
>
>Perl seems to know array and hash references pretty well and, internally, dereferencing them does
>not seem to incur overhead of making a temporary copy of the original array or hash, the element is
>directly accessed, as if the reference were a pointer.
>
>Thats fine, I have no problem at all with this. I am only interrested in SCALAR.
>
>I was curious about the function 'substr'. The first parameter is EXPRESSION. It seems to be an
>EXPRESSION evaluator. On its face, it will not take a reference, but it will take a dereferenced SCALAR.
>But I wonder if, based on the EXPRESSION, if it knows it is dereferencing a SCALAR, and does not make a temporary copy.
>
>In the case of the regular expression engine, I wonder the same thing, although with this there may be other properties
>that would cause the discrepancies shown below.
>
>For example 'pos()=' and '= pos()' might incur much overhead, and that may explain it as it could produce unknown temporaries
>in the engine.
>
>If I run this code segment 100 times, the substr is averaging 10 times faster than the regex. I can't explain it.
>
>Thanks!
>
>
>// substr
>return substr($$refscalar, 20, 30);
I'm sorry, this should be       ^10
>
>// regex		
>$savpos = pos($$refscalar);
>pos($$refscalar) = 20;
>while ($$refscalar =~ /(.{10})/gs) {
>	pos($$refscalar) = $savpos;
>	return $1;
>}
>
>



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

Date: Thu, 15 May 2008 11:48:26 -0700 (PDT)
From: Orson <moleskyca1@yahoo.com>
Subject: regular expression question
Message-Id: <1abd8794-b762-400e-9079-4876c603e5e2@d77g2000hsb.googlegroups.com>

Sorry, this is probably silly question, but I cannot find right
answer.

I am trying to use grep -P (for perl regular expressions). I want to
match lines that do not contain the chars "sync".

I thought I could do:

grep -P "[^(sync)]" mytextfile

I understand [] matches any char in the brackets and (sync) groups
those chars together, so I would negate to mean should not match those
chars.

This is return all lines in the file. I am doing something wrong, just
do not know what. Can someone explain, please?


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

Date: Thu, 15 May 2008 12:12:49 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: regular expression question
Message-Id: <150520081212497026%jimsgibson@gmail.com>

In article
<1abd8794-b762-400e-9079-4876c603e5e2@d77g2000hsb.googlegroups.com>,
Orson <moleskyca1@yahoo.com> wrote:

> Sorry, this is probably silly question, but I cannot find right
> answer.
> 
> I am trying to use grep -P (for perl regular expressions). I want to
> match lines that do not contain the chars "sync".

Does your grep have the '-v' switch ('--invert-match'):

  grep -v sync 

> 
> I thought I could do:
> 
> grep -P "[^(sync)]" mytextfile
> 
> I understand [] matches any char in the brackets and (sync) groups
> those chars together, so I would negate to mean should not match those
> chars.

Parentheses group, but not inside brackets. "[^(sync)]" will match any
character other than the 6 listed. In Perl, you would negate the test:

  $string !~ /sync/;

but that won't work as an option for grep. My grep doesn't have a '-P'
switch, so I can't tell how to use it. However, the -v switch seems to
do what you want.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
                http://www.usenet.com


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

Date: Thu, 15 May 2008 21:22:24 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regular expression question
Message-Id: <693gtjF304ejrU1@mid.individual.net>

Orson wrote:
> I am trying to use grep -P (for perl regular expressions). I want to
> match lines that do not contain the chars "sync".
> 
> I thought I could do:
> 
> grep -P "[^(sync)]" mytextfile
> 
> I understand [] matches any char in the brackets and (sync) groups
> those chars together, so I would negate to mean should not match those
> chars.

The parens don't group within brackets, so you match every line with any 
character other than
     ( s y n c )

Try using the -v option instead.

     grep -Pv "sync" mytextfile

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 15 May 2008 13:33:10 -0700 (PDT)
From: Orson <moleskyca1@yahoo.com>
Subject: Re: regular expression question
Message-Id: <6d9b9ded-ae91-49c0-bd0e-b82df4592a51@y21g2000hsf.googlegroups.com>

On May 15, 3:12=A0pm, Jim Gibson <jimsgib...@gmail.com> wrote:
> In article
> <1abd8794-b762-400e-9079-4876c603e...@d77g2000hsb.googlegroups.com>,
>
> Orson <molesky...@yahoo.com> wrote:
> > Sorry, this is probably silly question, but I cannot find right
> > answer.
>
> > I am trying to use grep -P (for perl regular expressions). I want to
> > match lines that do not contain the chars "sync".
>
> Does your grep have the '-v' switch ('--invert-match'):
>
> =A0 grep -v sync
>
>
>
> > I thought I could do:
>
> > grep -P "[^(sync)]" mytextfile
>
> > I understand [] matches any char in the brackets and (sync) groups
> > those chars together, so I would negate to mean should not match those
> > chars.
>
> Parentheses group, but not inside brackets. "[^(sync)]" will match any
> character other than the 6 listed. In Perl, you would negate the test:
>
> =A0 $string !~ /sync/;
>
> but that won't work as an option for grep. My grep doesn't have a '-P'
> switch, so I can't tell how to use it. However, the -v switch seems to
> do what you want.
>
> --
> Jim Gibson
>
> =A0Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0http://www.usenet.com

Yes, this is interesting and it works. I was trying to get the same
you get in perl when you do $string !~ /sync/ as you mentioned. I have
a solution to problem and I thank you for that. Out of curiosity how
would you negate a word with regex with grep if you didn't have the -v
option or anything like it ? I am not sure I know because my way as
just matching characters, but you want to say lines that do NOT have
the word "sync". Perhaps there is no way using regex.


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

Date: 15 May 2008 20:55:46 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: regular expression question
Message-Id: <slrng2p8qi.vjv.abigail@alexandra.abigail.be>

                                      _
Orson (moleskyca1@yahoo.com) wrote on VCCCLXXI September MCMXCIII in
<URL:news:1abd8794-b762-400e-9079-4876c603e5e2@d77g2000hsb.googlegroups.com>:
,,  Sorry, this is probably silly question, but I cannot find right
,,  answer.
,,  
,,  I am trying to use grep -P (for perl regular expressions). I want to
,,  match lines that do not contain the chars "sync".
,,  
,,  I thought I could do:
,,  
,,  grep -P "[^(sync)]" mytextfile
,,  
,,  I understand [] matches any char in the brackets

Yes, it does.

,,                                                   and (sync) groups
,,  those chars together

Why do you think you need to group things? Apparently, you think there
is a difference between:

    [ab]

and

    [(ab)]

and I am very interested to know what kind of difference you thing that
can be.

With a few extreme exceptions, [ ... ] matches a *SINGLE* character.
Regardless of the number of characters it lists inside the brackets.

I'm curious, if you think that /[sync]/ matches any string that contains
the substring "sync" (an no string that doesn't contain it), what do you
think that /sync/ matches?


,,                        so I would negate to mean should not match those
,,  chars.

Right, but not as you think it does. /[^(sync)]/ matches any string that
doesn't consists of just '(', 's', 'y', 'n', 'c' and ')' characters.

,,  This is return all lines in the file. I am doing something wrong, just
,,  do not know what. Can someone explain, please?


First, if you are using grep, use the -v option to negate.

If you're looking for a perl regex that matches any string that doesn't
contain 'sync', use:

    /^(?:(?!sync).)*$/s

Or, after some loop unrolling:

    /^[^s]*(?:s(?!ync)[^s]*)*$/


Abigail
-- 
package Z;use overload'""'=>sub{$b++?Hacker:Another};
sub TIESCALAR{bless\my$y=>Z}sub FETCH{$a++?Perl:Just}
$,=$";my$x=tie+my$y=>Z;print$y,$x,$y,$x,"\n";#Abigail


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

Date: Thu, 15 May 2008 14:21:25 -0700
From: sln@netherlands.co
Subject: Re: regular expression question
Message-Id: <55ap24l9cjb5fkcttr5cl1fg5l9qh7kicu@4ax.com>

On 15 May 2008 20:55:46 GMT, Abigail <abigail@abigail.be> wrote:

?! does not work
>    /^(?:(?!sync).)*$/s
      ^           ^  ^
and whats are these? "." ??????

>
>Or, after some loop unrolling:
>
>    /^[^s]*(?:s(?!ync)[^s]*)*$/
>
>
>Abigail



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

Date: Thu, 15 May 2008 15:44:10 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: URGENT: SENIOR SAP PP/MM ANALYST - San Jose, CA
Message-Id: <slrng2omib.ku2.dha@panix2.panix.com>

On 2008-05-14, khan.aadilrasheed@gmail.com <khan.aadilrasheed@gmail.com> wrote:
>
> Please respond me ASAP with

You have posted a job posting or a resume in a technical group.

Longstanding Usenet tradition dictates that such postings go into
groups with names that contain "jobs", like "misc.jobs.offered", not
technical discussion groups like the ones to which you posted.

Had you read and understood the Usenet user manual posted frequently to
"news.announce.newusers", you might have already known this. :)  (If
n.a.n is quieter than it should be, the relevent FAQs are available at
http://www.faqs.org/faqs/by-newsgroup/news/news.announce.newusers.html)
Another good source of information on how Usenet functions is
news.newusers.questions (information from which is also available at
http://www.geocities.com/nnqweb/).

Please do not explain your posting by saying "but I saw other job
postings here".  Just because one person jumps off a bridge, doesn't
mean everyone does.  Those postings are also in error, and I've
probably already notified them as well.

If you have questions about this policy, take it up with the news
administrators in the newsgroup news.admin.misc.

http://jobs.perl.org may be of more use to you

Yours for a better usenet,

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
The perversity of the Universe tends towards a maximum.


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

Date: Thu, 15 May 2008 10:57:48 -0700
From: "Stephan Bour" <sbour@niaid.nih.gov>
Subject: Re: URGENT: SENIOR SAP PP/MM ANALYST - San Jose, CA
Message-Id: <yQ_Wj.1538$l97.1244@flpi144.ffdc.sbc.com>

Uri Guttman wrote:
} khan aadilrasheed <khan.aadilrasheed@gmail.com> writes:
}  ka> 1) Your latest word formatted resume.
}
} i don't send resumes in perl

I have no love for these sort of postings, but he did say "word", not 
"perl"..

}  ka> 5) Visa Status
}
} i use mastercard.

"What's in your wallet?" :)

} no perl skills needed? then why are you spamming a perl group? this
} shows that you are too dumb to work for.

Technically, a spam is more than one message, and this was just one message. 
It's unwanted, granted, but not really spam in the strict sense of the term 
imho.

}  ka> Regards,
}
} nope. spammers never send regards.

True, an neither does the OP I'm sure. But please use more correct insults 
next time :P 




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

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


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