[29020] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 264 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Mar 25 16:09:58 2007

Date: Sun, 25 Mar 2007 13:09:08 -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           Sun, 25 Mar 2007     Volume: 11 Number: 264

Today's topics:
    Re: Executing awk from perl script <morty3e@gmail.com>
    Re: Executing awk from perl script <bik.mido@tiscalinet.it>
    Re: Executing awk from perl script <hjp-usenet2@hjp.at>
    Re: Executing awk from perl script <abigail@abigail.be>
    Re: Executing awk from perl script <bik.mido@tiscalinet.it>
        Perl Regexp that deals with variable parameter-string l asspenm@gmail.com
    Re: Perl Regexp that deals with variable parameter-stri <stoupa@practisoft.cz>
    Re: Perl Regexp that deals with variable parameter-stri <nobull67@gmail.com>
    Re: Perl Regexp that deals with variable parameter-stri <bik.mido@tiscalinet.it>
    Re: Perl Regexp that deals with variable parameter-stri <attn.steven.kuo@gmail.com>
    Re: Perl Regexp that deals with variable parameter-stri <nobull67@gmail.com>
    Re: time structure without shift <stoupa@practisoft.cz>
    Re: time structure without shift <bik.mido@tiscalinet.it>
    Re: time structure without shift <mjcarman@mchsi.com>
    Re: time structure without shift <jurgenex@hotmail.com>
    Re: time structure without shift <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 25 Mar 2007 06:15:21 -0700
From: "AyOut" <morty3e@gmail.com>
Subject: Re: Executing awk from perl script
Message-Id: <1174828520.916392.273220@p15g2000hsd.googlegroups.com>

On Mar 25, 5:24 am, Tintin <tin...@invalid.invalid> wrote:
> AyOut wrote:
> > I'm new to perl and have the following line that I try to execute:
>
> > ....
> > my $hm = `date +%H:%M --date "1 minute ago"`;
> > my $fname = `date +AppName_stats.log.%Y-%m-%d --date "1 days ago"`;
>
> > my $hits = `find /logs/server_name0?/dir/. -name "$fname*" -exec
> > gunzip -c {} ;\ | /grep SearchStr | /bin/awk -F","
> > '{if(substr($1,12,5)~hmpoint)print $3}' hmpoint=$hm | /bin/awk '{tot+=
> > $1}END{print tot}'`;
>
> > When I run this I get all kinds of complaints on the $hits line.  I've
> > tried various modifications, but can't seem to get it to work.  Any
> > idea of what's wrong here?
>
> Why bother writing in Perl, if you are essentially writing a shell script?
>
> --
> Posted via a free Usenet account fromhttp://www.teranews.com

I'm writing the data to rrdtool.



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

Date: Sun, 25 Mar 2007 16:47:54 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Executing awk from perl script
Message-Id: <nl2d03h4it24vgcmvfnk98e3rtg2ivcnip@4ax.com>

On 25 Mar 2007 06:15:21 -0700, "AyOut" <morty3e@gmail.com> wrote:

>> Why bother writing in Perl, if you are essentially writing a shell script?
>>
>> --
>> Posted via a free Usenet account fromhttp://www.teranews.com

Please don't quote the full message. Please don't quote .sig's.

>I'm writing the data to rrdtool.

So what? Do you know that it comes with an accompanying Perl module?
Do you know that there's also a RRDTool::OO module providing a
convenient OO interface to it?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 25 Mar 2007 17:13:52 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Executing awk from perl script
Message-Id: <slrnf0d4dg.6n1.hjp-usenet2@yoyo.hjp.at>

On 2007-03-25 14:47, Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On 25 Mar 2007 06:15:21 -0700, "AyOut" <morty3e@gmail.com> wrote:
>>> Why bother writing in Perl, if you are essentially writing a shell script?
>
>>I'm writing the data to rrdtool.
>
> So what? Do you know that it comes with an accompanying Perl module?

I think, that, yes, he knows that, since he answered the question "Why
bother writing in Perl?" with "I'm writing the data to rrdtool". Maybe
he doesn't know that he doesn't have to use Perl for that?

	hp


-- 
   _  | Peter J. Holzer    | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR       | to write clearly is like blaming English for
| |   | hjp@hjp.at         | the circumlocutions of bureaucrats.
__/   | http://www.hjp.at/ |	-- Charlton Wilbur in clpm


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

Date: 25 Mar 2007 15:40:32 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Executing awk from perl script
Message-Id: <slrnf0d5uk.k6j.abigail@alexandra.abigail.be>

AyOut (morty3e@gmail.com) wrote on MMMMCMLIII September MCMXCIII in
<URL:news:1174755317.701337.79540@b75g2000hsg.googlegroups.com>:
??  I'm new to perl and have the following line that I try to execute:
??  
??  ...
??  my $hm = `date +%H:%M --date "1 minute ago"`;
??  my $fname = `date +AppName_stats.log.%Y-%m-%d --date "1 days ago"`;
??  
??  my $hits = `find /logs/server_name0?/dir/. -name "$fname*" -exec
??  gunzip -c {} ;\ | /grep SearchStr | /bin/awk -F","
??  '{if(substr($1,12,5)~hmpoint)print $3}' hmpoint=$hm | /bin/awk '{tot+=
??  $1}END{print tot}'`;
??  
??  When I run this I get all kinds of complaints on the $hits line.  I've
??  tried various modifications, but can't seem to get it to work.  Any
??  idea of what's wrong here?


Please, "all kinds of complaints" is not useful at all.

You get much better response if you actually include the error messages
and/or warnings.

But I give you one hint: `` is a double quoted context. So Perl will 
interpretate variables.



Abigail
-- 
END   {print "Hacker\n"}
CHECK {print "another "}
BEGIN {print "Just "   }
INIT  {print "Perl "   }


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

Date: Sun, 25 Mar 2007 18:29:22 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Executing awk from perl script
Message-Id: <gp8d035bj4t8f1m65bc4arvcrfpv4shkog@4ax.com>

On Sun, 25 Mar 2007 17:13:52 +0200, "Peter J. Holzer"
<hjp-usenet2@hjp.at> wrote:

>>>> Why bother writing in Perl, if you are essentially writing a shell script?
>>
>>>I'm writing the data to rrdtool.
>>
>> So what? Do you know that it comes with an accompanying Perl module?
>
>I think, that, yes, he knows that, since he answered the question "Why
>bother writing in Perl?" with "I'm writing the data to rrdtool". Maybe
>he doesn't know that he doesn't have to use Perl for that?

D'Oh! You're right, of course! (Actually, I couldn't make sense of the
comment...)


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 25 Mar 2007 07:36:15 -0700
From: asspenm@gmail.com
Subject: Perl Regexp that deals with variable parameter-string length.
Message-Id: <1174833375.833768.103120@p77g2000hsh.googlegroups.com>

Hello all,

I've been writing a perl script that requires dealing with a file
containing lines with strings in the form of:

XXX-YYY-ZZZ  (3 parameters pattern)

or

XXX-YYY-ZZZ-AAA (4 parameters pattern)

or

XXX-YYY-ZZZ-AAA-BBB.... (N parameters pattern)

While XXX, YYY, etc are strings (locations).

I need to calclulate a total distance between those locations:

$total_distance += $DISTANCE{$2} - $DISTANCE{$1} ;

In other words - i've got from 3 to N parameters per line, seperated
by a dash.

I've tried to think of a smart way to assign them to the back-
refference variables, lets say $1 to $N, but did not succeed.

Currently i'm just breaking up the pattern with split and running over
it with foreach, but this is ugly, i'm sure there's a way to include
them in a regexp that assigns all $1..$N accordingly.

Any ideas?
Thanks
Assaf



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

Date: Sun, 25 Mar 2007 16:48:37 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Perl Regexp that deals with variable parameter-string length.
Message-Id: <eu62r5$2gur$1@ns.felk.cvut.cz>

<asspenm@gmail.com> píse v diskusním príspevku 
news:1174833375.833768.103120@p77g2000hsh.googlegroups.com...
> Hello all,
>
> I've been writing a perl script that requires dealing with a file
> containing lines with strings in the form of:
>
> XXX-YYY-ZZZ  (3 parameters pattern)
>
> or
>
> XXX-YYY-ZZZ-AAA (4 parameters pattern)
>
> or
>
> XXX-YYY-ZZZ-AAA-BBB.... (N parameters pattern)
>
> While XXX, YYY, etc are strings (locations).
>
> I need to calclulate a total distance between those locations:
>
> $total_distance += $DISTANCE{$2} - $DISTANCE{$1} ;
>
> In other words - i've got from 3 to N parameters per line, seperated
> by a dash.
>
> I've tried to think of a smart way to assign them to the back-
> refference variables, lets say $1 to $N, but did not succeed.
>
maybe:

$total_distance = 0;
@locations = split(/\-/, $string);
foreach my $i (0 .. $#locations -1)
    {
    $total_distance += $locations[$i + 1] - $locations[$i];
    }

-- 

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail 
from another non-spammer site please.)




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

Date: 25 Mar 2007 09:03:47 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Perl Regexp that deals with variable parameter-string length.
Message-Id: <1174838627.318989.206580@d57g2000hsg.googlegroups.com>

On 25 Mar, 15:36, assp...@gmail.com wrote:
> Hello all,
>
> I've been writing a perl script that requires dealing with a file
> containing lines with strings in the form of:
>
> XXX-YYY-ZZZ  (3 parameters pattern)
>
> or
>
> XXX-YYY-ZZZ-AAA (4 parameters pattern)
>
> or
>
> XXX-YYY-ZZZ-AAA-BBB.... (N parameters pattern)
>
> While XXX, YYY, etc are strings (locations).
>
> I need to calclulate a total distance between those locations:
>
> $total_distance += $DISTANCE{$2} - $DISTANCE{$1} ;

There is no obvious way in which that can be extended to more than 2
items.

> In other words - i've got from 3 to N parameters per
> line,seperated by a dash.
>
> I've tried to think of a smart way to assign them to the back-
> refference variables, lets say $1 to $N, but did not succeed.
>
> Currently i'm just breaking up the pattern with split and
> running over it with foreach, but this is ugly, i'm sure
> there's a way to
> include them in a regexp that assigns all $1..$N accordingly.

You need to update your aesthetic metric. The natural representation
storing a for a list of values in Perl is an array not several named
variables. The $1 etc variables are not an array because in general
the 1st,2nd,3rd capture in a regex is not semantically related as
members of a list.

> Any ideas?

>From what we can guess about your real problem and the solution you
are trying (using split) you are doing it right.

Of course without seeing what you are actually doing or what you are
actually trying to achieve it's hard to be sure.



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

Date: Sun, 25 Mar 2007 18:33:28 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl Regexp that deals with variable parameter-string length.
Message-Id: <b19d035n15gmo0df13q3u5n64g72fn6c0n@4ax.com>

On 25 Mar 2007 07:36:15 -0700, asspenm@gmail.com wrote:

>$total_distance += $DISTANCE{$2} - $DISTANCE{$1} ;
>
>In other words - i've got from 3 to N parameters per line, seperated
>by a dash.

And how do you want to generalize the above expression when more than
two parameters are involved?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 25 Mar 2007 10:41:30 -0700
From: "attn.steven.kuo@gmail.com" <attn.steven.kuo@gmail.com>
Subject: Re: Perl Regexp that deals with variable parameter-string length.
Message-Id: <1174844490.279081.168050@b75g2000hsg.googlegroups.com>

On Mar 25, 7:36 am, assp...@gmail.com wrote:
> Hello all,
>
> I've been writing a perl script that requires dealing with a file
> containing lines with strings in the form of:
>
> XXX-YYY-ZZZ  (3 parameters pattern)
>
> or
>
> XXX-YYY-ZZZ-AAA (4 parameters pattern)
>
> or
>
> XXX-YYY-ZZZ-AAA-BBB.... (N parameters pattern)
>
> While XXX, YYY, etc are strings (locations).
>
> I need to calclulate a total distance between those locations:
>
> $total_distance += $DISTANCE{$2} - $DISTANCE{$1} ;
>


Does that mean you want the sum of differences
between overlapping, adjacent "locations"?

while (<DATA>) {
    my $total = 0;
    $total += ($2 - $1) while /\G(\d{3})-(?=(\d{3}))/gc;
    print $total, "\n";
}

__DATA__
111-222-333
111-222-333-444
000-123-246-369

--
Hope this helps,
Steven



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

Date: 25 Mar 2007 11:58:41 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Perl Regexp that deals with variable parameter-string length.
Message-Id: <1174849121.103380.20160@y66g2000hsf.googlegroups.com>

On 25 Mar, 18:41, "attn.steven....@gmail.com"

> Does that mean you want the sum of differences
> between overlapping, adjacent "locations"?

Er, the sum of differences between overlapping adjacent pairs of
elements in a list is just the difference between the first and last
elements in the list.

This, of course, has nothing to do with Perl.



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

Date: Sun, 25 Mar 2007 16:12:42 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: time structure without shift
Message-Id: <eu6073$2fse$1@ns.felk.cvut.cz>

"Dr.Ruud" <rvtol+news@isolution.nl> pí¨e v diskusním príspevku 
news:eu5mgi.1hc.1@news.isolution.nl...
> Petr Vileta schreef:
>> Michael Carman:
>>> Petr Vileta:
>
>>>> I have time in seconds and want to get time structure
>>>> of this time but without shift to local time.
>>>
>>> perldoc -f gmtime
>>
>> gmtime can't help me.
>
> Just read the advised documentation again. And again.
>
>
>> gmtime() suppose time value in local time
>
> Huh? From that doc: "not locale dependent".
>
From the doc: "Converts a time as returned by the time function to a 
8-element list with the time localized for the standard Greenwich time 
zone."
Can you say that gmtime(1174831209) return the same value in USA and in 
Germany too? If yes, then where is "time localized for the standard 
Greenwich time zone" ???
-- 

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail 
from another non-spammer site please.)




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

Date: Sun, 25 Mar 2007 16:43:40 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: time structure without shift
Message-Id: <2b2d03l7gkidnra15e818n3hq2hc6vg99l@4ax.com>

On Sun, 25 Mar 2007 16:12:42 +0200, "Petr Vileta"
<stoupa@practisoft.cz> wrote:

>>> gmtime() suppose time value in local time
>>
>> Huh? From that doc: "not locale dependent".
>>
>From the doc: "Converts a time as returned by the time function to a 
>8-element list with the time localized for the standard Greenwich time 
>zone."
>Can you say that gmtime(1174831209) return the same value in USA and in 

Does Greenwich's locatication change as you move to USA or Germany?

>Germany too? If yes, then where is "time localized for the standard 
>Greenwich time zone" ???

What is where?!?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 25 Mar 2007 16:17:44 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: time structure without shift
Message-Id: <IgxNh.9038$oV.982@attbi_s21>

On 3/25/2007 9:12 AM, Petr Vileta wrote:
> "Dr.Ruud" <rvtol+news@isolution.nl>
>> Petr Vileta schreef:
>>> Michael Carman:
>>>> Petr Vileta:
>>>>> I have time in seconds and want to get time structure of this time 
>>>>> but without shift to local time.
>>>> 
>>>> perldoc -f gmtime
>>> 
>>> gmtime() suppose time value in local time
>> 
>> Huh? From that doc: "not locale dependent".
> 
> From the doc: "Converts a time as returned by the time function to a 
> 8-element list with the time localized for the standard Greenwich time zone."

The key here is "as returned by the time function". perldoc -f time says:

  Returns the number of non-leap seconds since whatever time the system
  considers to be the epoch, suitable for feeding to "gmtime" and
  "localtime". On most systems the epoch is 00:00:00 UTC...
                                                     ^^^
UTC is another name for GMT.

> Can you say that gmtime(1174831209) return the same value in USA and in 
> Germany too?

Yes, because time() returns a value in GMT, which means that localtime() and
time() both expect their input to be expressed in GMT.

> If yes, then where is "time localized for the standard Greenwich time zone"?

The value returned will be for what the local time would be in Greenwich.

-mjc


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

Date: Sun, 25 Mar 2007 16:50:39 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: time structure without shift
Message-Id: <zLxNh.617$Rp2.247@trndny04>

Michael Carman wrote:
> UTC is another name for GMT.
>
>> If yes, then where is "time localized for the standard Greenwich
>> time zone"?
>
> The value returned will be for what the local time would be in
> Greenwich.

That is exactly why I hate the term "GMT". Greenwich in England does 
observer Daylight Saving Time aka Summer Time while UTC does not. Now, is 
GMT the same as UTC or is GMT the local time in Greenwich? It can be either 
or but not both. And depending on who you are talking to you will get either 
answer.

Therefore I strongly, strongly advise against using the term "GMT" when 
actually you are meaning "UTC".

jue 




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

Date: Sun, 25 Mar 2007 19:06:19 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: time structure without shift
Message-Id: <slrnf0db0b.8tn.hjp-usenet2@yoyo.hjp.at>

On 2007-03-25 16:17, Michael Carman <mjcarman@mchsi.com> wrote:
> On 3/25/2007 9:12 AM, Petr Vileta wrote:
>> "Dr.Ruud" <rvtol+news@isolution.nl>
>>> Petr Vileta schreef:
>>>> Michael Carman:
>>>>> Petr Vileta:
>>>>>> I have time in seconds and want to get time structure of this time 
>>>>>> but without shift to local time.
>>>>> 
>>>>> perldoc -f gmtime
>>>> 
>>>> gmtime() suppose time value in local time
>>> 
>>> Huh? From that doc: "not locale dependent".
>> 
>> From the doc: "Converts a time as returned by the time function to a 
>> 8-element list with the time localized for the standard Greenwich time zone."
>
> The key here is "as returned by the time function". perldoc -f time says:
>
>   Returns the number of non-leap seconds since whatever time the system
>   considers to be the epoch, suitable for feeding to "gmtime" and
>   "localtime". On most systems the epoch is 00:00:00 UTC...
>                                                      ^^^
> UTC is another name for GMT.
>
>> Can you say that gmtime(1174831209) return the same value in USA and in 
>> Germany too?
>
> Yes,

Yes, but

> because time() returns a value in GMT,

the reason you give is false. time() returns the time difference between
"now" and an arbitrary point in time in the past (the "epoch"). That
time difference is of course the same in every time zone, so that value
is neither in GMT nor in any other time zone. That that point in time
was chosen to be midnight in the GMT time zone makes no difference. You
can also say it was chosen to be noon in Kamchatka.

> which means that localtime() and time() both expect their input to be
> expressed in GMT.

You mean gmtime(). time() has no input.

Both expect their input to be in seconds since the epoch.


>> If yes, then where is "time localized for the standard Greenwich time zone"?
>
> The value returned will be for what the local time would be in Greenwich.

Again, no. The local time for Greenwich is currently +0100 (they have
DST in the UK, too). But UTC is always +0000. So "time localized for the
standard Greenwich time zone" is at least ambiguous. (I guess that's the
reason why the term "GMT" is deprecated in favour of "UTC". It's kind of
illogical if Greenwich doesn't use Greenwich Mean time ...)

	hp


-- 
   _  | Peter J. Holzer    | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR       | to write clearly is like blaming English for
| |   | hjp@hjp.at         | the circumlocutions of bureaucrats.
__/   | http://www.hjp.at/ |	-- Charlton Wilbur in clpm


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

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


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