[30486] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1729 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 17 18:10:08 2008

Date: Thu, 17 Jul 2008 15:09:32 -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, 17 Jul 2008     Volume: 11 Number: 1729

Today's topics:
    Re: Bot::BasicBot's forkit() creating zombies <rcaputo@pobox.com>
    Re: C linked lists in Perl <smallpond@juno.com>
    Re: C linked lists in Perl <joost@zeekat.nl>
    Re: C linked lists in Perl <tzz@lifelogs.com>
    Re: FAQ 1.12 What's the difference between "perl" and " <jwkenne@attglobal.net>
        find which subgroups don't match in regex <sakradevanamindra@gmail.com>
    Re: find which subgroups don't match in regex <ben@morrow.me.uk>
    Re: find which subgroups don't match in regex <fawaka@gmail.com>
    Re: find which subgroups don't match in regex xhoster@gmail.com
    Re: How to identify a 32 or 64 bit OS? <nospam-abuse@ilyaz.org>
    Re: How to identify a 32 or 64 bit OS? <tzz@lifelogs.com>
    Re: How to identify a 32 or 64 bit OS? <tzz@lifelogs.com>
        Need recommendations on parsing an instruction matrix sln@netherlands.com
    Re: Need recommendations on parsing an instruction matr sln@netherlands.com
    Re: Need recommendations on parsing an instruction matr sln@netherlands.com
        Numerically sort a file on a given column where column  joemacbusiness@yahoo.com
    Re: Question in Perl Arrays xhoster@gmail.com
    Re: Question in Perl Arrays <uri@stemsystems.com>
    Re: remove previous lines of a log file <news@lawshouse.org>
        SOS...on system command cyrusgreats@gmail.com
    Re: SOS...on system command <glex_no-spam@qwest-spam-no.invalid>
    Re: SOS...on system command cyrusgreats@gmail.com
    Re: SOS...on system command <joost@zeekat.nl>
    Re: SOS...on system command xhoster@gmail.com
    Re: SOS...on system command (Jens Thoms Toerring)
    Re: SOS...on system command <fawaka@gmail.com>
    Re: SOS...on system command (Jens Thoms Toerring)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 17 Jul 2008 20:04:37 GMT
From: Rocco Caputo <rcaputo@pobox.com>
Subject: Re: Bot::BasicBot's forkit() creating zombies
Message-Id: <slrng7v9j9.1ao.rcaputo@eyrie.homenet>

On Sun, 06 Jul 2008 15:06:28 GMT, Marko Vihoma wrote:
>
> If anyone has any experience with Bot::BasicBot, I would be glad to hear
> how to run forkit() without creating zombies and if this is a bug in
> Bot::BasicBot.

It may be a bug in Bot::BasicBot.  POE's SIGCHLD handling changed not
too long ago, and I don't know if Bot::BasicBot follows the new
recommendations.

The folks in irc.perl.org #poe may have better and/or deeper answers.

-- 
Rocco Caputo - http://poe.perl.org/


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

Date: Thu, 17 Jul 2008 11:15:34 -0400
From: smallpond <smallpond@juno.com>
Subject: Re: C linked lists in Perl
Message-Id: <6bd15$487f6220$23951@news.teranews.com>

Ted Zlatanov wrote:
> On Wed, 16 Jul 2008 20:43:27 GMT Uri Guttman <uri@stemsystems.com> wrote: 
> 
> UG> as i said above no lang HAS linked lists
> 
> Java has them as part of the standard java.util libraries that come with
> the standard JRE.
> 
> Lisp pretty much is all about linked lists, they are built into
> everything.
> 
> I'm sure there are others.
> 
> Ted


In lisp a list can be built from cons cells.  It is not a data type in
lisp any more than in C.

--S
** Posted from http://www.teranews.com **


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

Date: Thu, 17 Jul 2008 21:47:37 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: C linked lists in Perl
Message-Id: <873am8uwbq.fsf@zeekat.nl>

smallpond <smallpond@juno.com> writes:

> In lisp a list can be built from cons cells.  It is not a data type in
> lisp any more than in C.

Te question isn't whether linked lists is a datatype in lisp (it
isn't), the question is if the language has supports for linked lists
"build in" which it clearly does - as a simple example, the (list)
function builds a linked list. Similarily the (first) (second) etc
functions act on linked lists.

It's fairly trivial to build this kind of support in C or perl, but
you still have to do it yourself (or use some non-standard library).

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


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

Date: Thu, 17 Jul 2008 15:48:36 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: C linked lists in Perl
Message-Id: <86lk00nsnv.fsf@lifelogs.com>

On Thu, 17 Jul 2008 17:26:58 GMT Uri Guttman <uri@stemsystems.com> wrote: 

>>>>>> "TZ" == Ted Zlatanov <tzz@lifelogs.com> writes:
TZ> Lisp pretty much is all about linked lists, they are built into
TZ> everything.

UG> sure but other than car and cdr (great names! and i know why) and dotted
UG> pair, it doesn't have any builtin support for linked lists. you still
UG> need to work at making them with primitives. 

On Thu, 17 Jul 2008 11:15:34 -0400 smallpond <smallpond@juno.com> wrote: 

s> In lisp a list can be built from cons cells.  It is not a data type in
s> lisp any more than in C.

I really don't know how much more "built-in" linked lists can be than
what you find in Lisp, considering that code and data both are lists and
treated as such by the language, and you can construct either
dynamically.  At this point you're arguing that with Lisp you have an
assembled band saw (vs. Perl's Swiss Army knife or Java's diesel-powered
hammer-screwdriver) but you can't use it until you plug it in.  Well,
yeah, but that is not an argument worth having.

Ted


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

Date: Thu, 17 Jul 2008 16:11:10 -0400
From: John W Kennedy <jwkenne@attglobal.net>
Subject: Re: FAQ 1.12 What's the difference between "perl" and "Perl"?
Message-Id: <487fa75e$0$20922$607ed4bc@cv.net>

Charlton Wilbur wrote:
>>>>>> "GCE" == Gordon Corbin Etly <cor@gmail.com> writes:
> 
>     GCE> Then why suppose this notion that people typing "PERL" is some
>     GCE> how inferior. It is little more than a stereotype, and there
>     GCE> are several people that push this and essentially tell the
>     GCE> person they are replying that "this is how to write it, conform
>     GCE> or else". It's this which I believe is just wrong. I have no
>     GCE> problems _what_ _so_ _ever_ with correcting people who are
>     GCE> doing something wrong. However, typing "PERL" is not a mistake
>     GCE> in and of itself; it's a perfectly valid compression and
>     GCE> telling random people it is wrong is misleading at best,
>     GCE> deceptive at worst.
> 
> I'm not telling you it's *wrong*, for the record.
> 
> I'm telling you that using it makes you look like someone who's
> inexperienced with Perl, like someone who's never read the FAQ, or who's
> too stubborn to conform to common usage. 
> 
> These are the three reasons that people commonly use PERL.
> Inexperience, ignorance, intransigence.
> 
> You may be a brilliant programmer, the best software developer ever, but
> if you use PERL on a resume, in a cover letter, or in an online forum,
> the safe bet is that you're one of the three.  It's not worth wasting
> time to figure out that you're just a free thinker.

For God's sake! He is provably nothing but a common, vulgar troll. Stop 
responding to him.
-- 
John W. Kennedy
  "Never try to take over the international economy based on a radical 
feminist agenda if you're not sure your leader isn't a transvestite."
   -- David Misch:  "She-Spies", "While You Were Out"


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

Date: Thu, 17 Jul 2008 12:39:58 -0700 (PDT)
From: Shoryuken <sakradevanamindra@gmail.com>
Subject: find which subgroups don't match in regex
Message-Id: <6b7240cd-06d4-4245-9ec9-48dab7100c61@z66g2000hsc.googlegroups.com>

Hello gents, here's the thing been confusing me for  a while:

$regex="(\w+)\s([0-9]+)";

$a="Tom 1990";  # it's a match
$b="Jack xyz"; # not a match, because of $2 doesn't match ... but
here's my question, exactly how to inform the users of this unmatched
subgroup? (i.e. $2 is the problem, $1 is fine, etc.)

For a regex matching, is there a way to find which subgroups don't
match?

thanks in advance.


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

Date: Thu, 17 Jul 2008 21:02:25 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: find which subgroups don't match in regex
Message-Id: <h3l4l5-ioh.ln1@osiris.mauzo.dyndns.org>


Quoth Shoryuken <sakradevanamindra@gmail.com>:
> Hello gents, here's the thing been confusing me for  a while:
> 
> $regex="(\w+)\s([0-9]+)";
> 
> $a="Tom 1990";  # it's a match
> $b="Jack xyz"; # not a match, because of $2 doesn't match ... but
> here's my question, exactly how to inform the users of this unmatched
> subgroup? (i.e. $2 is the problem, $1 is fine, etc.)
> 
> For a regex matching, is there a way to find which subgroups don't
> match?

You can use /gc and \G to match one piece at a time, without losing your
place; something like

    my @matches = qw/ \w+ \s [0-9]+ /;
    my $string = 'Jack xyz';

    for my $match (@matches) {
        $string =~ /\G$match/gc
            or print "$match failed at position " . pos $string;
    }

Ben

-- 
                Outside of a dog, a book is a man's best friend.
                Inside of a dog, it's too dark to read.
ben@morrow.me.uk                                                  Groucho Marx


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

Date: Thu, 17 Jul 2008 22:07:47 +0200
From: Leon Timmermans <fawaka@gmail.com>
Subject: Re: find which subgroups don't match in regex
Message-Id: <327d5$487fa693$89e0e08f$22247@news1.tudelft.nl>

On Thu, 17 Jul 2008 12:39:58 -0700, Shoryuken wrote:

> Hello gents, here's the thing been confusing me for  a while:
> 
> $regex="(\w+)\s([0-9]+)";
> 

Regular expressions aren't strings in Perl, please don't make them 
strings. There is absolutely no reason to do so. Also, [0-9] can be 
better written as \d. Also, you could consider anchoring the regexp to 
the beginning and the end of the string.

> $a="Tom 1990";  # it's a match
> $b="Jack xyz"; # not a match, because of $2 doesn't match ... but here's
> my question, exactly how to inform the users of this unmatched subgroup?
> (i.e. $2 is the problem, $1 is fine, etc.)
> 

In this case, you could match for /\w+\s/. If that is present then the 
absence number is the problem.

> For a regex matching, is there a way to find which subgroups don't
> match?
> 

In the general case, no. That's because they fail all of the time, until 
they succeed. There is no definitive moment of failure.

Leon Timmermans


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

Date: 17 Jul 2008 20:15:51 GMT
From: xhoster@gmail.com
Subject: Re: find which subgroups don't match in regex
Message-Id: <20080717161553.697$p7@newsreader.com>

Shoryuken <sakradevanamindra@gmail.com> wrote:
> Hello gents, here's the thing been confusing me for  a while:
>
> $regex="(\w+)\s([0-9]+)";
>
> $a="Tom 1990";  # it's a match
> $b="Jack xyz"; # not a match, because of $2 doesn't match ... but
> here's my question, exactly how to inform the users of this unmatched
> subgroup? (i.e. $2 is the problem, $1 is fine, etc.)
>
> For a regex matching, is there a way to find which subgroups don't
> match?

There isn't a built-in way.  You'd have to build it yourself, and that
will probably be non-trivial, as it would pretty much have to be an expert
system in your exact context, not just some standard Perl feature.

For example, whose "fault" is it that this doesn't match:

"1990 Tom" =~ /(\w+)\s(\d+)/;

Both subgroups will match individually, just not when put together.

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, 17 Jul 2008 20:20:42 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: How to identify a 32 or 64 bit OS?
Message-Id: <g5o9iq$uel$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Ted Zlatanov 
<tzz@lifelogs.com>], who wrote in article <86fxq8pg6g.fsf@lifelogs.com>:
> >> (I mention this because recently I argued that the "q" template should
> >> not require 64-bit support, as it does now :)
> >> 
> 
> LT> Yeah, I also don't understand why "q" can't work on 32bit platforms. Most 
> LT> common 32 bit platforms support 64 bit integers these days. It has to be 
> LT> possible to make some kind of hack to include this support. Math::Int64 
> LT> seems to be able to do it, so I don't see why perl itself can't.
> 
> I asked on perl5-porters, let's see what they say.

The perl's I build support this for many years.  I submitted the patch
about 2003.

Hope this helps,
Ilya


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

Date: Thu, 17 Jul 2008 15:36:20 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to identify a 32 or 64 bit OS?
Message-Id: <86tzeont8b.fsf@lifelogs.com>

On Thu, 17 Jul 2008 10:41:00 -0700 (PDT) T <g4173c@motorola.com> wrote: 

T> On Jul 17, 11:09 am, Ted Zlatanov <t...@lifelogs.com> wrote:
>> On Wed, 16 Jul 2008 12:25:00 -0700 (PDT) T <g41...@motorola.com> wrote:
>> 
T> How could I identify if the OS is 32 bit or 64 bit? I need to find a
T> way to do this that will work on Windows as well as Linux. Thus even
T> if the processor is 64, you might be running just Windows XP or is it
T> running Windows XP 64? Same would be true for Linux, although I think
T> I can use "uname -a" for that. Yes/No?
>> 
>> Leon's suggestions is good, and you can also do
>> 
>> pack "q", 1;
>> 
>> If it fails, you don't have 64 bit support.
>> 
>> (I mention this because recently I argued that the "q" template should
>> not require 64-bit support, as it does now :)

T> I thought that was it, however when I try that I get:

T> 64 bit machine:

T> % test
T> Useless use of pack in void context at test line 4.
T> 1

I would recommend Leon's solution instead of mine, as I am arguing that
the "q" template SHOULD be provided in 32-bit Perl.

Ted


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

Date: Thu, 17 Jul 2008 15:38:46 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to identify a 32 or 64 bit OS?
Message-Id: <86prpcnt49.fsf@lifelogs.com>

On Thu, 17 Jul 2008 20:20:42 +0000 (UTC) Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote: 

IZ> [A complimentary Cc of this posting was sent to
IZ> Ted Zlatanov 
IZ> <tzz@lifelogs.com>], who wrote in article <86fxq8pg6g.fsf@lifelogs.com>:
>> >> (I mention this because recently I argued that the "q" template should
>> >> not require 64-bit support, as it does now :)
>> >> 
>> 
LT> Yeah, I also don't understand why "q" can't work on 32bit platforms. Most 
LT> common 32 bit platforms support 64 bit integers these days. It has to be 
LT> possible to make some kind of hack to include this support. Math::Int64 
LT> seems to be able to do it, so I don't see why perl itself can't.
>> 
>> I asked on perl5-porters, let's see what they say.

IZ> The perl's I build support this for many years.  I submitted the patch
IZ> about 2003.

Do you know why the patch hasn't been accepted yet?  I couldn't find it
through Google or archive searches.

Ted


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

Date: Thu, 17 Jul 2008 20:59:39 GMT
From: sln@netherlands.com
Subject: Need recommendations on parsing an instruction matrix
Message-Id: <qjbv74d78q8k2k8fscor3bkfie115u2v0j@4ax.com>

Below is a range (Find/Action) of parameters that can be passed to a parsing function.
I am going to parse this as a matrix. This is a serialized instruction matrix that can
have duplicates. Not only do I wan't to parse and validate it, but I wan't to put it into
a form where the sequence can be easily accesable and tracked during processing.

There will be duplicates, so it is passed and read as an array. On the user side, LINK
has no parameter. Otherwise its a square matrix.

Any help would be appretiated.
(the below table will not show correct columns)


Event Instruction Sequence Matrix (EISM)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Find                |       Action
-------------~~~~   |  -----------------
                    |
<any N/A action>    |  REPLACE => 'data'
<any N/A action>    |  REMOVE  => ''
<any N/A action>    |  INSERT  => 'data'
<any N/A action>    |  CALL    => \&sub
<only Rx_ find>     |  Rx_REPLACE => 'data'
LINK     => 1       |  N/A
LINK     => 0       |  N/A
CMNT     => 'data'  |  <any valid action>
CDATA    => 'data'  |  <any valid action>
CONT     => 'data'  |  <any valid action>
TAG      => 'data'  |  <any valid action>
ATTR     => 'data'  |  <any valid action>
VALU     => 'data'  |  <any valid action>
XMLDCL   => 'data'  |  <any valid action>
XMLVER   => 'data'  |  <any valid action>
XMLENC   => 'data'  |  <any valid action>
XMLSTAND => 'data'  |  <any valid action>
PI       => 'data'  |  <any valid action>
DOCTYP   => 'data'  |  <any valid action>
ENTITY   => 'data'  |  <any valid action>
ENTGENR  => 'data'  |  <any valid action>
ENTPENR  => 'data'  |  <any valid action>
ATTLIST  => 'data'  |  <any valid action>
ELEMENT  => 'data'  |  <any valid action>
----
Rx_CMNT     => 'data'  |  <any valid action>
Rx_CDATA    => 'data'  |  <any valid action>
Rx_CONT     => 'data'  |  <any valid action>
Rx_TAG      => 'data'  |  <any valid action>
Rx_ATTR     => 'data'  |  <any valid action>
Rx_VALU     => 'data'  |  <any valid action>
Rx_XMLDCL   => 'data'  |  <any valid action>
Rx_XMLVER   => 'data'  |  <any valid action>
Rx_XMLENC   => 'data'  |  <any valid action>
Rx_XMLSTAND => 'data'  |  <any valid action>
Rx_PI       => 'data'  |  <any valid action>
Rx_DOCTYP   => 'data'  |  <any valid action>
Rx_ENTITY   => 'data'  |  <any valid action>
Rx_ENTGENR  => 'data'  |  <any valid action>
Rx_ENTPENR  => 'data'  |  <any valid action>
Rx_ATTLIST  => 'data'  |  <any valid action>
Rx_ELEMENT  => 'data'  |  <any valid action>

thanks
sln



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

Date: Thu, 17 Jul 2008 21:12:51 GMT
From: sln@netherlands.com
Subject: Re: Need recommendations on parsing an instruction matrix
Message-Id: <g3dv74dopk0kc56lpv64ukstvd02c6g6j0@4ax.com>

On Thu, 17 Jul 2008 20:59:39 GMT, sln@netherlands.com wrote:

One thing. The instruction sequence is atomic, no Action is done unless the
complete sequence of Find instructions is valididated during processing.

I forgot the most important Action, no action:

Find                |       Action
-------------~~~~   |  -----------------
                    |
<any N/A action>    |  NOACTION => ''


sln

>Below is a range (Find/Action) of parameters that can be passed to a parsing function.
>I am going to parse this as a matrix. This is a serialized instruction matrix that can
>have duplicates. Not only do I wan't to parse and validate it, but I wan't to put it into
>a form where the sequence can be easily accesable and tracked during processing.
>
>There will be duplicates, so it is passed and read as an array. On the user side, LINK
>has no parameter. Otherwise its a square matrix.
>
>Any help would be appretiated.
>(the below table will not show correct columns)
>
>
>Event Instruction Sequence Matrix (EISM)
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>Find                |       Action
>-------------~~~~   |  -----------------
>                    |
><any N/A action>    |  REPLACE => 'data'
><any N/A action>    |  REMOVE  => ''
><any N/A action>    |  INSERT  => 'data'
><any N/A action>    |  CALL    => \&sub
><only Rx_ find>     |  Rx_REPLACE => 'data'
>LINK     => 1       |  N/A
>LINK     => 0       |  N/A
>CMNT     => 'data'  |  <any valid action>
>CDATA    => 'data'  |  <any valid action>
>CONT     => 'data'  |  <any valid action>
>TAG      => 'data'  |  <any valid action>
>ATTR     => 'data'  |  <any valid action>
>VALU     => 'data'  |  <any valid action>
>XMLDCL   => 'data'  |  <any valid action>
>XMLVER   => 'data'  |  <any valid action>
>XMLENC   => 'data'  |  <any valid action>
>XMLSTAND => 'data'  |  <any valid action>
>PI       => 'data'  |  <any valid action>
>DOCTYP   => 'data'  |  <any valid action>
>ENTITY   => 'data'  |  <any valid action>
>ENTGENR  => 'data'  |  <any valid action>
>ENTPENR  => 'data'  |  <any valid action>
>ATTLIST  => 'data'  |  <any valid action>
>ELEMENT  => 'data'  |  <any valid action>
>----
>Rx_CMNT     => 'data'  |  <any valid action>
>Rx_CDATA    => 'data'  |  <any valid action>
>Rx_CONT     => 'data'  |  <any valid action>
>Rx_TAG      => 'data'  |  <any valid action>
>Rx_ATTR     => 'data'  |  <any valid action>
>Rx_VALU     => 'data'  |  <any valid action>
>Rx_XMLDCL   => 'data'  |  <any valid action>
>Rx_XMLVER   => 'data'  |  <any valid action>
>Rx_XMLENC   => 'data'  |  <any valid action>
>Rx_XMLSTAND => 'data'  |  <any valid action>
>Rx_PI       => 'data'  |  <any valid action>
>Rx_DOCTYP   => 'data'  |  <any valid action>
>Rx_ENTITY   => 'data'  |  <any valid action>
>Rx_ENTGENR  => 'data'  |  <any valid action>
>Rx_ENTPENR  => 'data'  |  <any valid action>
>Rx_ATTLIST  => 'data'  |  <any valid action>
>Rx_ELEMENT  => 'data'  |  <any valid action>
>
>thanks
>sln



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

Date: Thu, 17 Jul 2008 21:26:29 GMT
From: sln@netherlands.com
Subject: Re: Need recommendations on parsing an instruction matrix
Message-Id: <9rdv749jan286oanul3l4ehoa2la4tmars@4ax.com>

On Thu, 17 Jul 2008 20:59:39 GMT, sln@netherlands.com wrote:

Also, let me say that the implementation is pretty ambitous here given the permutations
the posible input represents. If you have comments about that handling, it is welcome
as well. In fact any constructive help is always welcome, no matter how trivial.

thank you
sln

>Below is a range (Find/Action) of parameters that can be passed to a parsing function.
>I am going to parse this as a matrix. This is a serialized instruction matrix that can
>have duplicates. Not only do I wan't to parse and validate it, but I wan't to put it into
>a form where the sequence can be easily accesable and tracked during processing.
>
>There will be duplicates, so it is passed and read as an array. On the user side, LINK
>has no parameter. Otherwise its a square matrix.
>



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

Date: Thu, 17 Jul 2008 14:29:52 -0700 (PDT)
From: joemacbusiness@yahoo.com
Subject: Numerically sort a file on a given column where column is a $var
Message-Id: <ec5af98b-68e9-4d0a-9ee6-f9df1c0f5400@k30g2000hse.googlegroups.com>

Hi All,

I want a subroutine that will sort a file on any given column.
So I have a file like this:

300 400 500 600 700
33 2337483 482 78374 4567
10 20 30 40 50
1000 1001 1002 1003 1004
9  8  7  6  5

And I run my numericSortCol() routine on it sorting on
column 1 and should get this:

9  8  7  6  5
10 20 30 40 50
300 400 500 600 700
1000 1001 1002 1003 1004
33 2337483 482 78374 4567

The problem is that I cannot get the bynum() to accept 2 args.
The code will work if I hard-code the $col in bynum, and
tweek the "problem line" a bit but that defeats the purpose of the
"sort on column" feature.

Does anyone have a solution for this?

Thanks, --Joe M.

######################### Here's the code I have so far:
[joe@localhost work]$ cat test18.pl
#!/usr/bin/perl

my $infile = "test18.in";
open(F,"$infile") || print "cannot open $infile $!";
my @array = <F>;
close(F);

numericSortCol(1,\@array);

sub numericSortCol {
    my $col = shift;
    my $aref = shift;
    foreach my $item (sort bynum($col,@{ $aref })){     # <<<< problem
line??
        print "item: $item\n";
    }
}

sub bynum {
    my $col = shift;
    @a = split(/\s+/,$a);
    @b = split(/\s+/,$b);
    $a[$col] <=> $b[$col];
#    $a[1] <=> $b[1];
}
[joe@localhost work]$
[joe@localhost work]$
######################### Here's the input file
[joe@localhost work]$ cat test18.in
300 400 500 600 700
33 2337483 482 78374 4567
10 20 30 40 50
1000 1001 1002 1003 1004
9  8  7  6  5
[joe@localhost work]$
[joe@localhost work]$
######################### Here's the runtime:
[joe@localhost work]$ perl test18.pl
item: 1
item: 9  8  7  6  5

item: 10 20 30 40 50

item: 33 2337483 482 78374 4567

item: 300 400 500 600 700

item: 1000 1001 1002 1003 1004

[joe@localhost work]$



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

Date: 17 Jul 2008 19:17:46 GMT
From: xhoster@gmail.com
Subject: Re: Question in Perl Arrays
Message-Id: <20080717151748.757$Ng@newsreader.com>

Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth xhoster@gmail.com:
> >
> > On the first point, I'm somewhat confused myself.  I've never fully
> > understand what the flip-flop mode does, but I understand enough to
> > avoid accidentally using it, so my confusion is safely sequestered.
>
> It's designed for use with -n. Something like
>
>     perl -ne'/foo/../bar/ and print'
>
> will print all the lines from 'foo' to 'bar', and

Oh yeah, I vaguely know what its purpose is, but all the things about
when each test is executed, and .. versus ..., and $. vs $_, and whether
the state is attached to one particular line of code or is global, it all
just made my eyes glaze over.  So I decided I'd punt, and come back and
read the docs in more depth when/if I ever decided I actually needed to use
it.

Recently I wanted exactly the 3rd line after a given line (say, the one
containing "foo") over thousands of files.

I thought this would work:
fgrep -A3 -B-3 foo *.txt

Except fgrep stubbornly refuses to accept negative arguments to -B.
That almost tempted me to go back and read up on flip-flop again, but I
found another string that I could filter on (one that was unique to the
desired line out of the four lines returned by fgrep -A3 foo, but not
globally unique) before I actually bit the bullet.

Now that I have gone back and reread, I think this would work:

perl -lne '(/foo/../bar/) == 4 and print "$ARGV\t$_"' *.txt

But only because I found a string ("bar", here) that always occurs later
in each file to turn off the flip-flop, preparing it for the next file.

Hmm.

perl -lne '(/foo/..eof(ARGV)) == 4 and print "$ARGV\t$_"' *.txt

That seems to do it.  Well, now I know.

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, 17 Jul 2008 19:26:17 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Question in Perl Arrays
Message-Id: <x7prpcmhwn.fsf@mail.sysarch.com>

>>>>> "x" == xhoster  <xhoster@gmail.com> writes:

  x> Ben Morrow <ben@morrow.me.uk> wrote:
  >> Quoth xhoster@gmail.com:
  >> >
  >> > On the first point, I'm somewhat confused myself.  I've never fully
  >> > understand what the flip-flop mode does, but I understand enough to
  >> > avoid accidentally using it, so my confusion is safely sequestered.
  >> 
  >> It's designed for use with -n. Something like
  >> 
  >> perl -ne'/foo/../bar/ and print'
  >> 
  >> will print all the lines from 'foo' to 'bar', and

  x> Oh yeah, I vaguely know what its purpose is, but all the things about
  x> when each test is executed, and .. versus ..., and $. vs $_, and whether
  x> the state is attached to one particular line of code or is global, it all
  x> just made my eyes glaze over.  So I decided I'd punt, and come back and
  x> read the docs in more depth when/if I ever decided I actually needed to use
  x> it.

$_ has nothing to do with .. (it does matter if you use // as an
expression in your ..). the state of .. has to be local to the instance
of the op (not even the line of code). otherwise all hell would break
loose if two modules used .. at the same time. as for when the test
expressions are executed, it is easy to remember. left until true, then
right until true. all ... does is also test right immediately when left
becomes true so you can work on a range of one line. 

  x> Recently I wanted exactly the 3rd line after a given line (say, the one
  x> containing "foo") over thousands of files.

  x> I thought this would work:
  x> fgrep -A3 -B-3 foo *.txt

  x> Except fgrep stubbornly refuses to accept negative arguments to -B.
  x> That almost tempted me to go back and read up on flip-flop again, but I
  x> found another string that I could filter on (one that was unique to the
  x> desired line out of the four lines returned by fgrep -A3 foo, but not
  x> globally unique) before I actually bit the bullet.

  x> Now that I have gone back and reread, I think this would work:

  x> perl -lne '(/foo/../bar/) == 4 and print "$ARGV\t$_"' *.txt

  x> But only because I found a string ("bar", here) that always occurs later
  x> in each file to turn off the flip-flop, preparing it for the next file.

  x> Hmm.

  x> perl -lne '(/foo/..eof(ARGV)) == 4 and print "$ARGV\t$_"' *.txt

  x> That seems to do it.  Well, now I know.

look into ack, a perl version of grep with many perlish and developer
features. it may support that and if not, patches welcome! in fact
boston.pm is working on a rewrite of the ack main loop to make it faster
and cleaner.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Thu, 17 Jul 2008 22:04:08 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: remove previous lines of a log file
Message-Id: <1216328646.3497.0@proxy02.news.clara.net>

rajesh wrote:
> Hi,
>        I am unable to use this script. It gives the output file with
> the lines until the keyword is found. after the first occurance of the
> keyword, starting from there all lines are getting deleted.

Well did you try to fix it?  Or did you just pop back here?

It's interesting how most people who post in this group asking for 
someone to write their program for them get short shrift, yet this guy 
gets a draft and some immediate corrections, and then comes back for 
debugging help.  Twice.

-- 

Henry Law            Manchester, England


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

Date: Thu, 17 Jul 2008 13:35:30 -0700 (PDT)
From: cyrusgreats@gmail.com
Subject: SOS...on system command
Message-Id: <553f9d55-2fd2-4587-b8b8-27a79da001fd@w9g2000prd.googlegroups.com>

I'm trying to store out put into the array the search for string in
this case truncating, but when I run the following command it prints
all the output before going to the foreach loop, it was my
understanding that the out put of the of the command will be saved
into @output then it can be searched, can some tell me where I go
wrong on this..thanks in advance...


my $sys = "dude";
my @output= `snmpwalk -c public -v 1 $sys  .1 |grep \"truncating\"`;

foreach my $el (@output) {
  next if ($el !=m~ ^\truncating\);
 print " .................$el\n";
}


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

Date: Thu, 17 Jul 2008 15:45:38 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: SOS...on system command
Message-Id: <487faf72$0$48216$815e3792@news.qwest.net>

cyrusgreats@gmail.com wrote:

Next time please post a helpful subject.

> I'm trying to store out put into the array the search for string in
> this case truncating, but when I run the following command it prints
> all the output before going to the foreach loop, it was my
> understanding that the out put of the of the command will be saved
> into @output then it can be searched, can some tell me where I go
> wrong on this..thanks in advance...
> 
> 
> my $sys = "dude";
> my @output= `snmpwalk -c public -v 1 $sys  .1 |grep \"truncating\"`;
> 
> foreach my $el (@output) {
>   next if ($el !=m~ ^\truncating\);
                  ^^^^^^.. first, what do you expect that to do?
>  print " .................$el\n";
> }


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

Date: Thu, 17 Jul 2008 13:57:24 -0700 (PDT)
From: cyrusgreats@gmail.com
Subject: Re: SOS...on system command
Message-Id: <d7229ef0-25d1-4ee5-b89a-2c066fa5da4f@u36g2000pro.googlegroups.com>

On Jul 17, 1:45 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
wrote:
> cyrusgre...@gmail.com wrote:
>
> Next time please post a helpful subject.
>
> > I'm trying to store out put into the array the search for string in
> > this case truncating, but when I run the following command it prints
> > all the output before going to the foreach loop, it was my
> > understanding that the out put of the of the command will be saved
> > into @output then it can be searched, can some tell me where I go
> > wrong on this..thanks in advance...
>
> > my $sys = "dude";
> > my @output= `snmpwalk -c public -v 1 $sys  .1 |grep \"truncating\"`;
>
> > foreach my $el (@output) {
> >   next if ($el !=m~ ^\truncating\);
>
>                   ^^^^^^.. first, what do you expect that to do?
>
> >  print " .................$el\n";
> > }

My questions are:
1. why it print everything right after this "my @output= `snmpwalk -c
public -v 1 $sys  .1 |grep \"truncating\"`; " instead of storing it
into @output array
2. Why the @output is empty?

Sorry for bad subject, next time I'll try do better ;-)


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

Date: Thu, 17 Jul 2008 23:00:27 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: SOS...on system command
Message-Id: <87r69stedw.fsf@zeekat.nl>

cyrusgreats@gmail.com writes:

> On Jul 17, 1:45 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
>> cyrusgre...@gmail.com wrote:
>>
>> Next time please post a helpful subject.
>>
>> > I'm trying to store out put into the array the search for string in
>> > this case truncating, but when I run the following command it prints
>> > all the output before going to the foreach loop, it was my
>> > understanding that the out put of the of the command will be saved
>> > into @output then it can be searched, can some tell me where I go
>> > wrong on this..thanks in advance...
>>
>> > my $sys = "dude";
>> > my @output= `snmpwalk -c public -v 1 $sys  .1 |grep \"truncating\"`;
>>
>> > foreach my $el (@output) {
>> >   next if ($el !=m~ ^\truncating\);
>>
>>                   ^^^^^^.. first, what do you expect that to do?
>>
>> >  print " .................$el\n";
>> > }
>
> My questions are:
> 1. why it print everything right after this "my @output= `snmpwalk -c
> public -v 1 $sys  .1 |grep \"truncating\"`; " instead of storing it
> into @output array

Because your check is incorrect. I'm VERY surprised that code even
compiles. Please enable warnings and strict. Anyway, you probably want something like

  next if ($el =~ /^truncating/);

> 2. Why the @output is empty?

I'm sure it isn't.


-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


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

Date: 17 Jul 2008 21:02:58 GMT
From: xhoster@gmail.com
Subject: Re: SOS...on system command
Message-Id: <20080717170300.996$QY@newsreader.com>

cyrusgreats@gmail.com wrote:
> I'm trying to store out put into the array the search for string in
> this case truncating, but when I run the following command it prints
> all the output before going to the foreach loop, it was my
> understanding that the out put of the of the command will be saved
> into @output then it can be searched, can some tell me where I go
> wrong on this..thanks in advance...
>
> my $sys = "dude";
> my @output= `snmpwalk -c public -v 1 $sys  .1 |grep \"truncating\"`;

I can't reproduce your problem.  Things for me work as expected, once I
replace snmpwalk with a command I trust to run on my computer which still
generates output containing "truncating" on some lines.

Are you sure your real code uses backticks, as shown above, and not system,
as your subject line would seem to suggest?


> foreach my $el (@output) {
>   next if ($el !=m~ ^\truncating\);

What the heck is that supposed to be?  It doesn't compile, whatever it
is.


>  print " .................$el\n";
> }

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: 17 Jul 2008 21:12:07 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: SOS...on system command
Message-Id: <6e9qt7F64q05U1@mid.uni-berlin.de>

cyrusgreats@gmail.com wrote:
> On Jul 17, 1:45 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
> > cyrusgre...@gmail.com wrote:
> >
> > Next time please post a helpful subject.
> >
> > > I'm trying to store out put into the array the search for string in
> > > this case truncating, but when I run the following command it prints
> > > all the output before going to the foreach loop, it was my
> > > understanding that the out put of the of the command will be saved
> > > into @output then it can be searched, can some tell me where I go
> > > wrong on this..thanks in advance...
> >
> > > my $sys = "dude";
> > > my @output= `snmpwalk -c public -v 1 $sys  .1 |grep \"truncating\"`;
> >
> > > foreach my $el (@output) {
> > >   next if ($el !=m~ ^\truncating\);
> >
> >                   ^^^^^^.. first, what do you expect that to do?
> >
> > >  print " .................$el\n";
> > > }

> My questions are:
> 1. why it print everything right after this "my @output= `snmpwalk -c
> public -v 1 $sys  .1 |grep \"truncating\"`; " instead of storing it
> into @output array
> 2. Why the @output is empty?

with the backticks you create a new process that starts a shell
to run the command. the output of this command is printed to
the stdout of that shell and is not passed back to your script.
That's what you're seeing when you run your script, the output
of the command goes to the terminal and not your script. All
your script receives is the return value of the last command
that got executed. If you want the output of a command then
don't use backticks but use open with the output of the com-
mand redirected to a file handle that your script can read
from:

open my $f, '|-', 'my_command' or die "Can't execute my_command\n";

Then read in what the command outputs just like it would be a
normal file:

my @output = <$f>;

and finally close this "file":

close $f;

Now '@output' contains all the lines output by the command.

                             Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de


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

Date: Thu, 17 Jul 2008 23:18:50 +0200
From: Leon Timmermans <fawaka@gmail.com>
Subject: Re: SOS...on system command
Message-Id: <95a69$487fb73a$89e0e08f$22247@news1.tudelft.nl>

On Thu, 17 Jul 2008 21:12:07 +0000, Jens Thoms Toerring wrote:
> with the backticks you create a new process that starts a shell to run
> the command. the output of this command is printed to the stdout of that
> shell and is not passed back to your script. That's what you're seeing
> when you run your script, the output of the command goes to the terminal
> and not your script.

That's not correct! Read the perlop entry for qx//. You're confusing 
backticks with system().

> open my $f, '|-', 'my_command' or die "Can't execute my_command\n";
 
That creates a process to write to, not to read from!

Leon Timmermans


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

Date: 17 Jul 2008 21:22:59 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: SOS...on system command
Message-Id: <6e9rhjF64q05U2@mid.uni-berlin.de>

Jens Thoms Toerring <jt@toerring.de> wrote:
> cyrusgreats@gmail.com wrote:
> > On Jul 17, 1:45 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> > wrote:
> > > cyrusgre...@gmail.com wrote:
> > >
> > > Next time please post a helpful subject.
> > >
> > > > I'm trying to store out put into the array the search for string in
> > > > this case truncating, but when I run the following command it prints
> > > > all the output before going to the foreach loop, it was my
> > > > understanding that the out put of the of the command will be saved
> > > > into @output then it can be searched, can some tell me where I go
> > > > wrong on this..thanks in advance...
> > >
> > > > my $sys = "dude";
> > > > my @output= `snmpwalk -c public -v 1 $sys  .1 |grep \"truncating\"`;
> > >
> > > > foreach my $el (@output) {
> > > >   next if ($el !=m~ ^\truncating\);
> > >
> > >                   ^^^^^^.. first, what do you expect that to do?
> > >
> > > >  print " .................$el\n";
> > > > }

> > My questions are:
> > 1. why it print everything right after this "my @output= `snmpwalk -c
> > public -v 1 $sys  .1 |grep \"truncating\"`; " instead of storing it
> > into @output array
> > 2. Why the @output is empty?

> with the backticks you create a new process that starts a shell
> to run the command. the output of this command is printed to
> the stdout of that shell and is not passed back to your script.

Sorry, forget about that. Got things mixed up with the system()
function you were refering to in the subject line. Things are
different with backticks.
                               Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de


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

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


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