[30371] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1614 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 5 16:09:52 2008

Date: Thu, 5 Jun 2008 13:09:13 -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, 5 Jun 2008     Volume: 11 Number: 1614

Today's topics:
    Re: Counting lines in big number of files - in parallel <allergic-to-spam@no-spam-allowed.org>
    Re: eperl help: multi-pass processing <glex_no-spam@qwest-spam-no.invalid>
    Re: How to get the output from an ICQ clent <szrRE@szromanMO.comVE>
        perl command line help <muforo@gmail.com>
    Re: perl command line help <jurgenex@hotmail.com>
    Re: perl command line help <tzz@lifelogs.com>
    Re: Perl grep and Perl 4 <szrRE@szromanMO.comVE>
    Re: Perl grep and Perl 4 <cwilbur@chromatico.net>
        perl_parse free some resource. <xydinesh@gmail.com>
    Re: Prevent kill signals to childs xhoster@gmail.com
    Re: regex back matching <jimsgibson@gmail.com>
    Re: regex back matching <jurgenex@hotmail.com>
    Re: regex back matching <glex_no-spam@qwest-spam-no.invalid>
    Re: regex back matching <noreply@gunnar.cc>
    Re: regex back matching <jurgenex@hotmail.com>
    Re: regex back matching <noreply@gunnar.cc>
    Re: regex back matching <tzz@lifelogs.com>
    Re: regex back matching <muforo@gmail.com>
    Re: regex back matching <noreply@gunnar.cc>
    Re: regex back matching <tzz@lifelogs.com>
        select and filehandle <xiaoxia2005a@yahoo.com>
    Re: select and filehandle <mritty@gmail.com>
    Re: select and filehandle xhoster@gmail.com
    Re: Stopping a File::Find on first find <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 05 Jun 2008 18:34:02 GMT
From: Jim Cochrane <allergic-to-spam@no-spam-allowed.org>
Subject: Re: Counting lines in big number of files - in parallel. <c4857a09-1348-4b5c-8b42-affc273f949d@k37g2000hsf.googlegroups.com> <48452891$0$10631$fa0fcedb@news.zen.co.uk> <75c7fc7a-c0c9-4b39-afb1-5a0e42149446@x35g2000hsb.googlegroups.com> <RLc1k.835$Gn.687@edtnps92>
Message-Id: <4848319a$0$30636$834e42db@reader.greatnowhere.com>

On 2008-06-03, John W. Krahn <someone@example.com> wrote:
> hadzio@gmail.com wrote:
>> Hi,
>> 
>> Thank you for these remarks:
>> 
>>> 1) Useless use of cat
>>> "cat $file_to_read | wc -l |" starts two processes (plus shell etc)
>>> I'd use "wc -l $file_to_be read"
>> 
>> My command returns a value in a format easier to process ;)
>
> Still a UUOC.  Instead of "cat $file_to_read | wc -l |" use "wc -l < 
> $file_to_read |" or just:
>
> chomp( my $file_number_of_lines = `wc -l < $file_to_read` );

You can drop the '<':

chomp( my $file_number_of_lines = `wc -l $file_to_read` );


-- 



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

Date: Thu, 05 Jun 2008 10:25:09 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: eperl help: multi-pass processing
Message-Id: <48480556$0$48226$815e3792@news.qwest.net>

bukzor wrote:
> I'm sorry this is about eperl. If you know a better place to post,
> please let me know.
> 
> One of our systems uses a set of eperl files to hold our configuration
> parameters. Multiple passes are done on the configuration file to make
> sure that all eperl is interpolated. The problem is that sometimes the
> printout of a variable gets moved to before the assignment of the
> variable (don't ask why). For example:
> 
> [code]
> 
> PARAM1 = <:=$some_variable:>
> 
> <:
> $some_variable="some_value"
> :>
> 
> [/code]
> 
> Let's assume this can't be helped. On the first pass, the first line
> is left alone because that variable has no value, but the second block
> of eperl is deleted (since it doesn't print anything). We *do* have
> the variable with the correct value in memory, but it doesn't help
> much since we're past the point where it's used.
> 
> Two possible solutions (that I don't know how to implement):
> 1. Print out the values of all variables in memory into a file and
> load them before starting the next pass of eperl
> 2. Somehow make eperl go back and interpolate the file again without
> exiting.

Does eperl support BEGIN blocks?  If so, possibly something like this 
will work:


BEGIN {
   $some_variable='some_value';
}


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

Date: Thu, 5 Jun 2008 12:38:47 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: How to get the output from an ICQ clent
Message-Id: <g29fc702491@news4.newsguy.com>

Ted Zlatanov wrote:
> On Wed, 4 Jun 2008 13:30:50 -0700 (PDT) potrebitel
> <tvachkov@googlemail.com> wrote:
[...]
> p> Actually when I'm redirecting the output via ysm > output.txt, I'm
> p> getting an empty text file too... Is it perhaps not possible at
> all to
> p> catch the output somehow?
>
> If ysm is hung waiting for your input, it won't print anything out.  I
> don't know the particulars of how ysm works, sorry.
>
> Ted

Try using, instead of >, 2>&1 outall.txt, or 1> stdout.txt 2> stderr.txt

-- 
szr 




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

Date: Thu, 5 Jun 2008 09:09:12 -0700 (PDT)
From: Ray Muforosky <muforo@gmail.com>
Subject: perl command line help
Message-Id: <946e76e8-e068-4bba-9eb2-183d5f437844@k30g2000hse.googlegroups.com>

assuming fileA contain the data below could help with this

perl -lane '$l=$_, ($a,$b,$c,$d)= split(/\./,$F[0]),print $d' fileA

fileA
===
 192.68.45.718        daskjaskjf     asdfjkasjf asfkasfklh
 192.68.34.62      ADKDAK      Dkkslaslk  jjsdkdldj
 192.68.23           INEED             HELP PLEASE
 192.68.67.4      dkasdfkl       kasfkasfkakf
 192.68.4.97        flaskfk asfkfafv    asf

How do I modify the command line code above to get this below : print
lines where the last quadrant is even

123.68.45.718        daskjaskjf     asdfjkasjf asfkasfklh
192.68.34.62      ADKDAK      Dkkslaslk  jjsdkdldj
192.68.67.4      dkasdfkl       kasfkasfkakf


Thanks
Any other ideas will be appreciated.


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

Date: Thu, 05 Jun 2008 16:17:53 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: perl command line help
Message-Id: <e84g449uqeb7f7r79j53n9c9p58ggj8d6e@4ax.com>

Ray Muforosky <muforo@gmail.com> wrote:
>How do I modify the command line code above to get this below : print
>lines where the last quadrant is even
>
>123.68.45.718        daskjaskjf     asdfjkasjf asfkasfklh
>192.68.34.62      ADKDAK      Dkkslaslk  jjsdkdldj
>192.68.67.4      dkasdfkl       kasfkasfkakf

Exactly the same way as is currently being discussed in the thread
"regex back matching" which _YOU_ started. 
Why are you kicking off another thread with the identical topic while
there are still open question in the first one? Do you want to
re-discuss the same old questions again?

jue


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

Date: Thu, 05 Jun 2008 12:29:07 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: perl command line help
Message-Id: <86bq2f23ks.fsf@lifelogs.com>

On Thu, 05 Jun 2008 16:17:53 GMT Jürgen Exner <jurgenex@hotmail.com> wrote: 

JE> Ray Muforosky <muforo@gmail.com> wrote:
>> How do I modify the command line code above to get this below : print
>> lines where the last quadrant is even
>> 
>> 123.68.45.718        daskjaskjf     asdfjkasjf asfkasfklh
>> 192.68.34.62      ADKDAK      Dkkslaslk  jjsdkdldj
>> 192.68.67.4      dkasdfkl       kasfkasfkakf

JE> Exactly the same way as is currently being discussed in the thread
JE> "regex back matching" which _YOU_ started. 
JE> Why are you kicking off another thread with the identical topic while
JE> there are still open question in the first one? Do you want to
JE> re-discuss the same old questions again?

Obviously the IPs in this thread are in SI units, the other one was for
Americans ;)

Ted


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

Date: Thu, 5 Jun 2008 09:54:50 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Perl grep and Perl 4
Message-Id: <g295or01nnf@news4.newsguy.com>

Charlton Wilbur wrote:
>>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:
>
>>>>>> "Charlton" == Charlton Wilbur <cwilbur@chromatico.net> writes:
>>>>>> "f" == fourfour2  <fourfour2@gmail.com> writes:
>
>    f> Yep - this works when using Perl 5.  Unfortunately not in Perl
>    f> 4.035 though.
>
>    Charlton> Why are you using Perl 4?  Why are you using a version of
>    Charlton> Perl 4 that isn't the latest version?
>
>> The difference between 4.035 and 4.036 was a very trivial
>> patch, although I think it was a security patch.  I'm not good
>> at recalling things from a decade ago, though. :)
>
> Oh, right, but there's something pathological here - using Perl 4
> instead of Perl 5, and then, in this day and age, where you have to go
> through extra effort to get Perl 4 in the first place, not using the
> latest version, trivial patch or no.

That's assuming that he wasn't stuck with a server that had only Perl 4 
on it (and insufficient privileges to install a newer one.)

-- 
szr 




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

Date: Thu, 05 Jun 2008 14:12:14 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Perl grep and Perl 4
Message-Id: <86r6bbeoox.fsf@mithril.chromatico.net>

>>>>> "szr" == szr  <szrRE@szromanMO.comVE> writes:

    >> Oh, right, but there's something pathological here - using Perl 4
    >> instead of Perl 5, and then, in this day and age, where you have
    >> to go through extra effort to get Perl 4 in the first place, not
    >> using the latest version, trivial patch or no.

    szr> That's assuming that he wasn't stuck with a server that had
    szr> only Perl 4 on it (and insufficient privileges to install a
    szr> newer one.)

Right, which is a bizarre choice, verging on a pathology, on the part of
the host.  

Perl 4 was superseded by Perl 5 a decade and a half ago.  

Charlton



-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Thu, 5 Jun 2008 13:07:01 -0700 (PDT)
From: Din <xydinesh@gmail.com>
Subject: perl_parse free some resource.
Message-Id: <d9ba0528-1994-44f7-87e3-0c30fd0b0de2@x35g2000hsb.googlegroups.com>

  I'm using modperl2 with PerlRun to invoke my cgi script. My server
configuration is as follows

Apache/2.2.6 (Unix) Axis2C/1.3.1 mod_perl/2.0.4 Perl/v5.10.0

script I invoke via mod_perl2 (say echo_service.pl) call to some other
C program. In that c program going to invoke a perl function. However
when I call perl function from C ,perl_parse method seems freeing some
resources that mod_perl2 using.

Here is the valgrind trace.
-----------------------------------------
==21847== Invalid read of size 4
==21847==    at 0x4A0A7C8: Perl_save_clearsv (scope.c:490)
==21847==    by 0x4975B53: Perl_pp_padsv (pp_hot.c:309)
==21847==    by 0x492DB39: Perl_runops_debug (dump.c:1931)
==21847==    by 0x4969A2B: Perl_call_sv (perl.c:2646)
==21847==    by 0x481A593: modperl_callback (modperl_callback.c:101)
==21847==    by 0x481B8C4: modperl_callback_run_handlers
(modperl_callback.c:262)
==21847==    by 0x481C458: modperl_callback_per_dir
(modperl_callback.c:369)
==21847==    by 0x4814668: modperl_response_handler_run (mod_perl.c:
1000)
==21847==    by 0x4814940: modperl_response_handler_cgi (mod_perl.c:
1100)
==21847==    by 0x807D864: ap_run_handler (in /usr/local/apache2/bin/
httpd)
==21847==    by 0x807DFB4: ap_invoke_handler (in /usr/local/apache2/
bin/httpd)
==21847==    by 0x809BC1F: ap_process_request (in /usr/local/apache2/
bin/httpd)
==21847==  Address 0x51cf5cc is 8 bytes after a block of size 28
free'd
==21847==    at 0x402265C: free (vg_replace_malloc.c:323)
==21847==    by 0x48CCD1D: S_op_destroy (op.c:417)
==21847==    by 0x48D2EBC: Perl_append_list (op.c:2588)
==21847==    by 0x48C98BC: Perl_yyparse (perly.y:189)
==21847==    by 0x4967A5D: S_parse_body (perl.c:2230)
==21847==    by 0x4965FD3: perl_parse (perl.c:1650)
==21847==    by 0x4CFDA29: wsf_xml_msg_recv_invoke_other
(wsf_xml_msg_recv.c:429)
==21847==    by 0x4CFD329: wsf_xml_msg_recv_invoke_business_logic_sync
(wsf_xml_msg_recv.c:207)
==21847==    by 0x46F899E: axis2_msg_recv_invoke_business_logic
(msg_recv.c:392)
==21847==    by 0x46F877C: axis2_msg_recv_receive_impl (msg_recv.c:
319)
==21847==    by 0x46F89FA: axis2_msg_recv_receive (msg_recv.c:431)
==21847==    by 0x46E9F34: axis2_engine_receive (engine.c:315)


Any idea on fixing this segmentation fault would be a great help.

thanks,
Dinesh


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

Date: 05 Jun 2008 16:09:04 GMT
From: xhoster@gmail.com
Subject: Re: Prevent kill signals to childs
Message-Id: <20080605120905.902$UC@newsreader.com>

Felipe Alcacibar B <falcacibar@gmail.com> wrote:
> Hi, i have the this problem, i have process opened with open3, and i
> use waitpid in threads to determine if ends, but when i send a SIGINT
> (Control-C) the signal propagates to the childs, i need control this
> signal and prevent the propagation of the signal to childs, how i can
> do that???

When you press Control-C in most shells, the shell will send SIGINT to
everyone the "process group", or something like that.  If the child uses
POSIX::setsid() to remove itself from the parent's process group, then it
shouldn't receive the signal.

If that doesn't work, you could use a sig handler in the child to trap and
ignore the signal.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Thu, 05 Jun 2008 08:59:21 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: regex back matching
Message-Id: <050620080859211725%jimsgibson@gmail.com>

In article <Xns9AB467348BD9Fasu1cornelledu@127.0.0.1>, A. Sinan Unur
<1usa@llenroc.ude.invalid> wrote:

> Ray Muforosky <muforo@gmail.com> wrote in news:8566add6-1bfc-4231-8242-
> ba9790cf376f@r66g2000hsg.googlegroups.com:
> 
> > On Jun 5, 8:14 am, Dan Rumney <danrum...@77617270mail.net> wrote:
> >> Ray Muforosky wrote:
> >> > Hello
> >>
> >> > I need to match on lines where the 4 quadrant of the ip is even with
> >> > one line regex.
> >>
> >>   [snip]
> >>
> >> What do you have so far? There are plenty of pages outlinging regexps
> >> for matching IP addresses... that should prove a good start for you
> > 
> > egrep  '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.([stock here])\s*'
> > filename
> 
> What is egrep?

egrep is a version of the Unix grep program that does regular
expressions.

$ man egrep

"GREP(1)                                                                
NAME
 grep, egrep, fgrep - print lines matching a pattern

SYNOPSIS
 grep [options] PATTERN [FILE...]
 grep [options] [-e PATTERN | -f FILE] [FILE...]

DESCRIPTION
 Grep  searches the named input FILEs (or standard input if no files are
 named, or the file name - is given) for lines containing a match to the
 given PATTERN.  By default, grep prints the matching lines.

 In addition, two variant programs egrep and fgrep are available.  Egrep
 is the same as grep -E.  Fgrep is the same as grep -F."


So the OP is asking a question about a Unix utility in a Perl group.

-- 
Jim Gibson


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

Date: Thu, 05 Jun 2008 16:13:14 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: regex back matching
Message-Id: <uq3g44l150vahekgtulplqhl1v5po3omd1@4ax.com>

Ray Muforosky <muforo@gmail.com> wrote:
>On Jun 5, 9:11 am, Ted Zlatanov <t...@lifelogs.com> wrote:
>> On Thu, 5 Jun 2008 05:53:13 -0700 (PDT) Ray Muforosky <muf...@gmail.com> wrote:
>>
>> RM> I need to match on lines where the 4 quadrant of the ip is even with
>> RM> one line regex.
>>
>> RM> For example, if I have
>>
>> RM> 192.68.45.78        daskjaskjf     asdfjkasjf asfkasfklh
>> RM> 192.68.34.62      ADKDAK      Dkkslaslk  jjsdkdldj
>> RM> 192.68.23           INEED             HELP PLEASE
>> RM> 192.68.67.34      dkasdfkl       kasfkasfkakf
>> RM> 192.68.4.97        flaskfk asfkfafv    asf
>>
>> RM> I should only get:
>> RM> 123.68.45.78        daskjaskjf     asdfjkasjf asfkasfklh
>> RM> 192.68.34.62      ADKDAK      Dkkslaslk  jjsdkdldj
>> RM> 192.68.67.34      dkasdfkl       kasfkasfkakf
>>
>>  print if m/^[\d\.]+[02468]\s/;
>
>If I have the data below, the script will not totally work. 

"Will not work" is a very useless characterization. Unless you tell us
_why_ Ted's script doesn't meet your requirements I doubt if anyone will
be able to improve it. I was about to suggest a very similar approach
	    print if (/[02468] /);
which appears to do exactly what you asked for, just like -for all I can
tell- Ted's script..

jue


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

Date: Thu, 05 Jun 2008 11:44:39 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: regex back matching
Message-Id: <484817f7$0$89395$815e3792@news.qwest.net>

Ray Muforosky wrote:
> On Jun 5, 9:11 am, Ted Zlatanov <t...@lifelogs.com> wrote:
>> On Thu, 5 Jun 2008 05:53:13 -0700 (PDT) Ray Muforosky <muf...@gmail.com> wrote:
>>
>> RM> I need to match on lines where the 4 quadrant of the ip is even with
>> RM> one line regex.
>>
>> RM> For example, if I have
>>
>> RM> 192.68.45.78        daskjaskjf     asdfjkasjf asfkasfklh
>> RM> 192.68.34.62      ADKDAK      Dkkslaslk  jjsdkdldj
>> RM> 192.68.23           INEED             HELP PLEASE
>> RM> 192.68.67.34      dkasdfkl       kasfkasfkakf
>> RM> 192.68.4.97        flaskfk asfkfafv    asf
>>
>> RM> I should only get:
>> RM> 123.68.45.78        daskjaskjf     asdfjkasjf asfkasfklh
>> RM> 192.68.34.62      ADKDAK      Dkkslaslk  jjsdkdldj
>> RM> 192.68.67.34      dkasdfkl       kasfkasfkakf
>>
>> Even digits are [02468] in the decimal system.  A number is even if it
>> ends with an even digit.  So, assuming no malformed lines:
>>
>> #!/usr/bin/perl
>>
>> use warnings;
>> use strict;
>>
>> while (<DATA>)
>> {
>>  print if m/^[\d\.]+[02468]\s/;
>>
>> }
>>
>> __DATA__
>> 192.68.45.78        daskjaskjf     asdfjkasjf asfkasfklh
>> 192.68.34.62      ADKDAK      Dkkslaslk  jjsdkdldj
>> 192.68.23           INEED             HELP PLEASE
>> 192.68.67.34      dkasdfkl       kasfkasfkakf
>> 192.68.4.97        flaskfk asfkfafv    asf
>>
>> If you want, use Regexp::Common to grab the IP address before you check
>> its last digit.  This script will accept 1.2.3.4.5.6.7.8 and .2 as
>> valid, for example.
>>
>> Ted
> 
> If I have the data below, the script will not totally work. I want to
> get those lines where the last quadrant is even.
> 
> 192.68.45.718        daskjaskjf     asdfjkasjf asfkasfklh
> 192.68.34.6          ADKDAK      Dkkslaslk  jjsdkdldj
> 192.68.23            INEED             HELP PLEASE
> 192.68.67.34         dkasdfkl       kasfkasfkakf
> 192.68.4.97          flaskfk asfkfafv    asf

You have to tell us more than 'will not totally work'. What EXACTLY
doesn't work?

How does the above script that Ted proviced not work?  It seems
to do exactly what you're asking.

It'll print:

192.68.45.718        daskjaskjf     asdfjkasjf asfkasfklh
192.68.34.6          ADKDAK      Dkkslaslk  jjsdkdldj
192.68.67.34         dkasdfkl       kasfkasfkakf

What is wrong with the lines that it matched?


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

Date: Thu, 05 Jun 2008 18:53:02 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regex back matching
Message-Id: <6aqju4F390i87U1@mid.individual.net>

Jürgen Exner wrote:
> Ray Muforosky <muforo@gmail.com> wrote:
>> On Jun 5, 9:11 am, Ted Zlatanov <t...@lifelogs.com> wrote:
>>>
>>>  print if m/^[\d\.]+[02468]\s/;
>>
>> If I have the data below, the script will not totally work. 
> 
> "Will not work" is a very useless characterization.

Yes, stand-alone it is. But the OP's next sentence, which you chose to 
snip, is pretty clear IMO:

"I want to get those lines where the last quadrant is even."

> Unless you tell us 
> _why_ Ted's script doesn't meet your requirements I doubt if anyone will 
> be able to improve it.

Bla, bla...

Seems as if he wants something like

     print if /^(?:\d+\.){3}\d*[02468]\s/;

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


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

Date: Thu, 05 Jun 2008 17:00:52 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: regex back matching
Message-Id: <6q6g449r72e17ataqti55cbrqf312m8pv7@4ax.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>Jürgen Exner wrote:
>> Ray Muforosky <muforo@gmail.com> wrote:
>>> On Jun 5, 9:11 am, Ted Zlatanov <t...@lifelogs.com> wrote:
>>>>
>>>>  print if m/^[\d\.]+[02468]\s/;
>>>
>>> If I have the data below, the script will not totally work. 
>> 
>> "Will not work" is a very useless characterization.
>
>Yes, stand-alone it is. But the OP's next sentence, which you chose to 
>snip, is pretty clear IMO:
>
>"I want to get those lines where the last quadrant is even."

-v, please. 

Obviously you can deduce something that I fail to see (wouldnt' be the
first time). Mind to explain, please?

jue


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

Date: Thu, 05 Jun 2008 19:08:16 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regex back matching
Message-Id: <6aqkqjF399rjiU1@mid.individual.net>

Jürgen Exner wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>> Jürgen Exner wrote:
>>> Ray Muforosky <muforo@gmail.com> wrote:
>>>> On Jun 5, 9:11 am, Ted Zlatanov <t...@lifelogs.com> wrote:
>>>>>  print if m/^[\d\.]+[02468]\s/;
>>>> If I have the data below, the script will not totally work. 
>>> "Will not work" is a very useless characterization.
>> Yes, stand-alone it is. But the OP's next sentence, which you chose to 
>> snip, is pretty clear IMO:
>>
>> "I want to get those lines where the last quadrant is even."
> 
> -v, please. 
> 
> Obviously you can deduce something that I fail to see (wouldnt' be the
> first time). Mind to explain, please?

Well, maybe I pushed the send button a little too fast. Apologies for that.

What I had in mind was the first sentence in the first message in this 
thread:

"I need to match on lines where the 4 quadrant of the ip is even with
one line regex."

So I still think that I'm on the right track. :)

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


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

Date: Thu, 05 Jun 2008 12:27:53 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: regex back matching
Message-Id: <86fxrr23mu.fsf@lifelogs.com>

On Thu, 05 Jun 2008 18:53:02 +0200 Gunnar Hjalmarsson <noreply@gunnar.cc> wrote: 

GH> Jürgen Exner wrote:
>> Ray Muforosky <muforo@gmail.com> wrote:
>>> On Jun 5, 9:11 am, Ted Zlatanov <t...@lifelogs.com> wrote:
>>>> 
>>>> print if m/^[\d\.]+[02468]\s/;

GH> Seems as if he wants something like
GH>     print if /^(?:\d+\.){3}\d*[02468]\s/;

Gunnar, please test your regex against mine next time.  Same output, the
same that the OP requested in fact.

Ted


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

Date: Thu, 5 Jun 2008 10:45:53 -0700 (PDT)
From: Ray Muforosky <muforo@gmail.com>
Subject: Re: regex back matching
Message-Id: <44c0804a-dd99-4690-bff0-b81a61113f7f@k30g2000hse.googlegroups.com>

On Jun 5, 12:08=A0pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> J=FCrgen Exner wrote:
> > Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> >> J=FCrgen Exner wrote:
> >>> Ray Muforosky <muf...@gmail.com> wrote:
> >>>> On Jun 5, 9:11 am, Ted Zlatanov <t...@lifelogs.com> wrote:
> >>>>> =A0print if m/^[\d\.]+[02468]\s/;
> >>>> If I have the data below, the script will not totally work.
> >>> "Will not work" is a very useless characterization.
> >> Yes, stand-alone it is. But the OP's next sentence, which you chose to
> >> snip, is pretty clear IMO:
>
> >> "I want to get those lines where the last quadrant is even."
>
> > -v, please.
>
> > Obviously you can deduce something that I fail to see (wouldnt' be the
> > first time). Mind to explain, please?
>
> Well, maybe I pushed the send button a little too fast. Apologies for that=
 .
>
> What I had in mind was the first sentence in the first message in this
> thread:
>
> "I need to match on lines where the 4 quadrant of the ip is even with
> one line regex."
>
> So I still think that I'm on the right track. :)
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl- Hide quoted text -
>
> - Show quoted text -

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
My apologies to everyone. It's a typo on my end. Both commands worked.
print if m/^[\d\.]+[02468]\s/ and print if /^(?:\d+\.)
{3}\d*[02468]\s/;
- Ray
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


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

Date: Thu, 05 Jun 2008 20:50:21 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regex back matching
Message-Id: <6aqqpiF37f535U1@mid.individual.net>

Ted Zlatanov wrote:
> On Thu, 05 Jun 2008 18:53:02 +0200 Gunnar Hjalmarsson <noreply@gunnar.cc> wrote: 
> 
> GH> Jürgen Exner wrote:
>>> Ray Muforosky <muforo@gmail.com> wrote:
>>>> On Jun 5, 9:11 am, Ted Zlatanov <t...@lifelogs.com> wrote:
>>>>> print if m/^[\d\.]+[02468]\s/;
> 
> GH> Seems as if he wants something like
> GH>     print if /^(?:\d+\.){3}\d*[02468]\s/;
> 
> Gunnar, please test your regex against mine next time.  Same output, the
> same that the OP requested in fact.

Yes, they produce the same output when applied to the OP's sample data. 
But assume that the last digit on the third line is replaced with the 
digit 4:

192.68.24           INEED             HELP PLEASE

Your regex will print that line, while mine won't, since the IP address 
does not have any 4:th quadrant.

Nevertheless, after the OP's latest message I'm not sure about my 
interpretation any longer...

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


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

Date: Thu, 05 Jun 2008 14:51:05 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: regex back matching
Message-Id: <86tzg7zmmu.fsf@lifelogs.com>

On Thu, 05 Jun 2008 20:50:21 +0200 Gunnar Hjalmarsson <noreply@gunnar.cc> wrote: 

GH> Ted Zlatanov wrote:
>> On Thu, 05 Jun 2008 18:53:02 +0200 Gunnar Hjalmarsson <noreply@gunnar.cc> wrote: 
>> 
GH> Jürgen Exner wrote:
>>>> Ray Muforosky <muforo@gmail.com> wrote:
>>>>> On Jun 5, 9:11 am, Ted Zlatanov <t...@lifelogs.com> wrote:
>>>>>> print if m/^[\d\.]+[02468]\s/;
>> 
GH> Seems as if he wants something like
GH> print if /^(?:\d+\.){3}\d*[02468]\s/;
>> 
>> Gunnar, please test your regex against mine next time.  Same output, the
>> same that the OP requested in fact.

GH> Yes, they produce the same output when applied to the OP's sample data. But assume that the last digit on the third line is replaced with the digit 4:

GH> 192.68.24           INEED             HELP PLEASE

GH> Your regex will print that line, while mine won't, since the IP address does not have any 4:th quadrant.

As I mentioned, Regexp::Common should be used if the IP addresses need
to be checked for validity.  Your regex will accept 2000.2000.2000.2000
as a valid IP address, for example, and that's no better than 192.68.24
as far as IPs go.  I probably should have just posted a Regexp::Common
solution to avoid this discussion anyhow...

Ted

#!/usr/bin/perl

use warnings;
use strict;
use Regexp::Common qw/net/;

while (<DATA>)
{
 # look for an even last digit
 print if /$RE{net}{IPv4}{-keep}/ && $5 =~ m/[02468]$/;
 # or use the modulo 2 operation
 print if /$RE{net}{IPv4}{-keep}/ && $5 % 2 == 0;
 # checking if the lowest bit is off is left as an exercise for the reader
}

__DATA__
192.68.45.78        daskjaskjf     asdfjkasjf asfkasfklh
192.68.34.62      ADKDAK      Dkkslaslk  jjsdkdldj
192.68.23           INEED             HELP PLEASE
192.68.67.34      dkasdfkl       kasfkasfkakf
192.68.4.97        flaskfk asfkfafv    asf
2000.2000.2000.20000 3033ss


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

Date: Thu, 5 Jun 2008 12:08:01 -0700 (PDT)
From: April <xiaoxia2005a@yahoo.com>
Subject: select and filehandle
Message-Id: <3abd05ad-0d59-400f-9882-f70061e8f851@m45g2000hsb.googlegroups.com>

I found the following demo in a book regarding usage of "select" ...

1  select(FH1);
2  print "goes to FH1.\n";
3
4  $TempHandle = select(FH2);
5  print "goes to FH2.\n";
6
7  select ($TempHandle);
8  print "goes to FH1.\n"

This is in Perl for Dummies, 4th ed, p182.

My questions are:

It seems if I need to verify this, would need to add the following in
the pl file?

open(FH1, '>print1.txt');
open(FH2, '>print2.txt');

Line 5 would still uses FH1 and goes into print1.txt, as FH2 has not
been selected; and line eight will uses $TempHandle or FH2 and goes
into print2.txt, as FH2 is is now selected through $TempHandle
assignment?

However, my understanding contradicts to the suggestions in the book,
such as line 5 would goes in print2.txt, and line 8 would goes in
print1.txt.  My verification also says the author is correct.


What's wrong with me?



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

Date: Thu, 5 Jun 2008 12:35:50 -0700 (PDT)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: select and filehandle
Message-Id: <16757be3-6f65-4d5e-9042-87e3deeb6441@w7g2000hsa.googlegroups.com>

On Jun 5, 3:08=A0pm, April <xiaoxia20...@yahoo.com> wrote:
> I found the following demo in a book regarding usage of "select" ...
>
> 1 =A0select(FH1);
> 2 =A0print "goes to FH1.\n";
> 3
> 4 =A0$TempHandle =3D select(FH2);
> 5 =A0print "goes to FH2.\n";
> 6
> 7 =A0select ($TempHandle);
> 8 =A0print "goes to FH1.\n"
>
> This is in Perl for Dummies, 4th ed, p182.
>
> My questions are:
>
> It seems if I need to verify this, would need to add the following in
> the pl file?
>
> open(FH1, '>print1.txt');
> open(FH2, '>print2.txt');

Yes, but you should get into the habbit of writing open statements
like this instead:
open my $FH1, '>', 'print1.txt' or die "Could not open print1.txt:
$!";

> Line 5 would still uses FH1 and goes into print1.txt, as FH2 has not
> been selected;

I don't understand why you're saying that.  Line 4 pretty clearly
says:
$TempHandle =3D select(FH2);

That makes FH2 the selected filehandle, and stores whatever *was* the
selected filehandle (which in this case was FH1) in $TempHandle.

> and line eight will uses $TempHandle or FH2 and goes
> into print2.txt, as FH2 is is now selected through $TempHandle
> assignment?
>
> What's wrong with me?

I think you have a misunderstanding of the return value of select().

select() takes one argument, the filehandle you wish to select.   It
returns whatever filehandle was selected immediately prior to this
line.

Line 1 makes FH1 the selected filehandle.  The program ignores the
return value of select() in this case.

Line 4 makes FH2 the selected filehandle, and stores FH1 in
$TempHandle (because FH1 was selected prior to this line)

Line 7 makes $TempHandle (which is FH1) the selected filehandle again,
and again ignores the return value of select().

Paul Lalli


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

Date: 05 Jun 2008 19:38:20 GMT
From: xhoster@gmail.com
Subject: Re: select and filehandle
Message-Id: <20080605153823.114$aP@newsreader.com>

April <xiaoxia2005a@yahoo.com> wrote:
> I found the following demo in a book regarding usage of "select" ...
>
> 1  select(FH1);
> 2  print "goes to FH1.\n";
> 3
> 4  $TempHandle = select(FH2);
> 5  print "goes to FH2.\n";
> 6
> 7  select ($TempHandle);
> 8  print "goes to FH1.\n"
>
> This is in Perl for Dummies, 4th ed, p182.
>
> My questions are:
>
> It seems if I need to verify this, would need to add the following in
> the pl file?
>
> open(FH1, '>print1.txt');
> open(FH2, '>print2.txt');

Yes, and you should check those opens for failure.
>
> Line 5 would still uses FH1 and goes into print1.txt, as FH2 has not
> been selected;

Hunh?  The selection of FH2 is in line 4, so why hasn't it been executed?
Unless you are refering to line 5 of some hypothetical program which has
its lines renumbered because of the insertion of the open statements, in
which case you would have to show us that program.


> and line eight will uses $TempHandle or FH2 and goes
> into print2.txt, as FH2 is is now selected through $TempHandle
> assignment?

$TempHandle holds FH1, not FH2.  single-argument select selects the new
file handle (FH2 on line 4) and returns the old, previously selected, file
handle (FH1 on line 4, into $TempHandle)

> However, my understanding contradicts to the suggestions in the book,
> such as line 5 would goes in print2.txt, and line 8 would goes in
> print1.txt.  My verification also says the author is correct.
>
> What's wrong with me?

I think you understand the select backwards.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Thu, 05 Jun 2008 17:56:25 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Stopping a File::Find on first find
Message-Id: <a4ag44lbut7nb35ea54hcppktqasubv076@4ax.com>

Mason.Guy@gmail.com wrote:
>I've got a script that searches for a file in a dir heirarchy that
>contains a lot of files (using find of File::Find).
>
>The problem is, find searches through the entire dir tree to find all
>possible matches.  This takes a considerable amount of time.
>
>Is there a way to get find to exit early?

Haven't tried it but maybe File::Find::prune is what you are looking
for:
"The function may set "$File::Find::prune" to prune the tree [...]"

jue


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

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


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