[23713] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5919 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 10 00:10:44 2003

Date: Tue, 9 Dec 2003 21:10:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 9 Dec 2003     Volume: 10 Number: 5919

Today's topics:
    Re: Regex and multiples on same line <krahnj@acm.org>
    Re: Regex and multiples on same line (Tad McClellan)
        Retrieving then deleting elements of a list (references <apollock11@hotmail.com>
    Re: Retrieving then deleting elements of a list (refere <krahnj@acm.org>
    Re: Rounding up to 2 decimal places (at)FinancialDataCorp.com (Bob Mariotti)
    Re: Rounding up to 2 decimal places <waltman@pobox.com>
    Re: Scp files to another server help <me@privacy.net>
        Server-side script executed on page load or event, but  <henryn@zzzspacebbs.com>
    Re: What is '_' <krahnj@acm.org>
    Re: What is '_' <parv_@yahooWhereElse.com>
    Re: What is '_' (Sara)
    Re: What is '_' <uri@stemsystems.com>
    Re: Why does ne always work <me@privacy.net>
    Re: WIN32::Internet <ha_schwar@gmx.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 10 Dec 2003 00:46:46 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Regex and multiples on same line
Message-Id: <3FD66CF2.14A36BC6@acm.org>

Gary Mayor wrote:
> 
> Thanks for everyone in my earlier message. Now i've got a problem with
> regex. I've got a file with lines like this,
> 
> CATETITLE1 CATETITLE2 CATETITLE3 CATETITLE4
> CATETITLE5 CATETITLE6 CATETITLE7 CATETITLE8
> 
> while(<FILE>) {
>    if ($_=~ /CATETITLE/) {
>       $counter++;
>    }
> }
> 
> if I then run through the file and match each time there is a CATETITLE
> I only get a count of 2. How do I find out the total amount of CATETITLE?


while ( <FILE> ) {
   $counter += () = /CATETITLE/g;
}



John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 9 Dec 2003 21:58:47 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regex and multiples on same line
Message-Id: <slrnbtd6fn.tdf.tadmc@magna.augustmail.com>

Gary Mayor <gary@tgpmakers.com> wrote:

> while(<FILE>) {
>    if ($_=~ /CATETITLE/) {


   while ($_=~ /CATETITLE/g) {


>       $counter++;
>    }
> }

> if I then run through the file and match each time there is a CATETITLE 
> I only get a count of 2. How do I find out the total amount of CATETITLE?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 09 Dec 2003 15:25:28 -0800
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Retrieving then deleting elements of a list (references)
Message-Id: <br5lld$1o9j$1@agate.berkeley.edu>

Hello!

I have a list of data structures. Each struct has a number of
fields. I need to retrieve certain elements of the list based
on the value of one of its fields, then delete those elements.
The reason I need to do this is that after I treat these first
special cases, I need to go through and process all of the
remaining elements in a generic way. I don't want to process
those special elements twice, so I need to remove them the first
time I process them. Is that clear?

I imagine I could do something like popping unprocessed elements
to a new array but my attempts at this have been awkward and
I'm looking for something very efficient and elegant. Since it's
the type of thing I need to do frequently I figure it should be
something I can add to my bag of perl tools.

So I first want to process those elements that have a 'type'
field containing 'SERIES', i.e., $elt->{type} =~ /SERIES/:

my @series = grep ($_->{type} =~ /SERIES/, @{$data->{elements}});
foreach my $ser (@series) {
    etc...
}
my @items = grep ($_->{type} =~ /ITEM/, @{$data->{elements}});
foreach my $item (@items) {
    etc...
}
## Now process everything that's left over
foreach my $elt (@{$data->{elements}}) {
    etc...
}

Note, not every element has a 'type' field.

Except you can see in the above scenario, that last foreach
processes everything in $data->{elements}, not just anything
"left over."

Any elegant suggestions? Is this something map could do?



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

Date: Wed, 10 Dec 2003 01:08:48 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Retrieving then deleting elements of a list (references)
Message-Id: <3FD6721C.576134F7@acm.org>

Arvin Portlock wrote:
> 
> I have a list of data structures. Each struct has a number of
> fields. I need to retrieve certain elements of the list based
> on the value of one of its fields, then delete those elements.
> The reason I need to do this is that after I treat these first
> special cases, I need to go through and process all of the
> remaining elements in a generic way. I don't want to process
> those special elements twice, so I need to remove them the first
> time I process them. Is that clear?
> 
> I imagine I could do something like popping unprocessed elements
> to a new array but my attempts at this have been awkward and
> I'm looking for something very efficient and elegant. Since it's
> the type of thing I need to do frequently I figure it should be
> something I can add to my bag of perl tools.
> 
> So I first want to process those elements that have a 'type'
> field containing 'SERIES', i.e., $elt->{type} =~ /SERIES/:
> 
> my @series = grep ($_->{type} =~ /SERIES/, @{$data->{elements}});
> foreach my $ser (@series) {
>     etc...
> }
> my @items = grep ($_->{type} =~ /ITEM/, @{$data->{elements}});
> foreach my $item (@items) {
>     etc...
> }
> ## Now process everything that's left over
> foreach my $elt (@{$data->{elements}}) {
>     etc...
> }
> 
> Note, not every element has a 'type' field.
> 
> Except you can see in the above scenario, that last foreach
> processes everything in $data->{elements}, not just anything
> "left over."
> 
> Any elegant suggestions? Is this something map could do?


You could store the left-overs in another array.


my ( @series, @left_overs );
push @{ $_->{type} =~ /SERIES/ ? \@series : \@left_overs }, $_ for @{$data->{elements}};
foreach my $ser ( @series ) {
    etc...
}
my @items
push @{ $_->{type} =~ /ITEM/ ? \@items : \@left_overs }, $_ for splice @left_overs;
foreach my $item ( @items ) {
    etc...
}
## Now process everything that's left over
foreach my $elt ( @left_overs ) {
    etc...
}


John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 10 Dec 2003 01:36:24 GMT
From: R.Mariotti(at)FinancialDataCorp.com (Bob Mariotti)
Subject: Re: Rounding up to 2 decimal places
Message-Id: <3fd6785a.14065414@news.cshore.com>

On Tue, 09 Dec 2003 12:26:35 +0000, Gary Mayor <gary@abertron.co.uk>
wrote:

>Hi,
>What a nightmare i've been trawling deja all morning for a simple method 
>of rounding a number up to 2 decimal places. I've checked out the ceil 
>function which only rounds numbers up to no decimal places which is no 
>good. The printf function rounds numbers up and down.
>
>Let's take this number
>
>0.3325
>
>I need it to be,
>
>0.34
>
>How do i do that. Do I have to write a routine that checks if there is a 
>third digit or what. The number is calculated for the UK VAT system at 
>17.5% i need the number rounded up to only 2 decimal places. Yes I have 
>checked perlfaq4.
>
>Simple problem seems impossible answer.
>
>Any ideas
>
>Gary
>

You might want to try something as simple as this:

my $VALUE=0.3325;
$value=sprintf("%.2f",$VALUE);
print "value=$value\n";

Good luck.

Bob


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

Date: Tue, 9 Dec 2003 22:50:00 -0500
From: Walt Mankowski <waltman@pobox.com>
Subject: Re: Rounding up to 2 decimal places
Message-Id: <slrnbtd5v8.t3h.waltman@waltman.dnsalias.org>

On 2003-12-10, R.Mariotti(at)FinancialDataCorp.com (Bob Mariotti) <> wrote:
> On Tue, 09 Dec 2003 12:26:35 +0000, Gary Mayor <gary@abertron.co.uk>
> wrote:
>
>>Hi,
>>What a nightmare i've been trawling deja all morning for a simple method 
>>of rounding a number up to 2 decimal places. I've checked out the ceil 
>>function which only rounds numbers up to no decimal places which is no 
>>good. The printf function rounds numbers up and down.
>>
>>Let's take this number
>>
>>0.3325
>>
>>I need it to be,
>>
>>0.34
>>
>>How do i do that. Do I have to write a routine that checks if there is a 
>>third digit or what. The number is calculated for the UK VAT system at 
>>17.5% i need the number rounded up to only 2 decimal places. Yes I have 
>>checked perlfaq4.
>>
>>Simple problem seems impossible answer.
>>
>>Any ideas
>>
>>Gary
>>
>
> You might want to try something as simple as this:
>
> my $VALUE=0.3325;
> $value=sprintf("%.2f",$VALUE);
> print "value=$value\n";

Er, that doesn't work.  Gary said he always wants it to round *up*.
Your code rounds *down* and prints out 0.33.

The trick I've always used in situations like this is to add 0.005 to it
before passing it to printf.

Walt


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

Date: Wed, 10 Dec 2003 17:46:01 +1300
From: "Tintin" <me@privacy.net>
Subject: Re: Scp files to another server help
Message-Id: <br68g0$28enps$1@ID-172104.news.uni-berlin.de>


"JennAshton" <joel@tradersunited.com> wrote in message
news:c5b9b407.0312081805.19193fd1@posting.google.com...
> Hi,
>
> I wrote a simple scp script from my server to pacman server which
> copies all jpg files to /jennash/ directory.
>
> Now, I need help with this script. I would like it to pull not just
> *.jpg files but other file types as well. Also, is it possible to pull
> only files that is 3 minutes old? Please help.
>
> Thanks!
>
> JennAsh
>
> #!/usr/bin/perl
>
> system('scp /export/www/docs/*.jpg pacman:/export/www/jennash/');
>
> exit;

And the relevance to Perl is???

Here's a shell script to do it:

#!/bin/sh
scp `find /export/www/docs -type f -mmin 3` pacman:/export/www/jennash




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

Date: Wed, 10 Dec 2003 04:19:06 GMT
From: Henry <henryn@zzzspacebbs.com>
Subject: Server-side script executed on page load or event, but not SSI
Message-Id: <BBFB9198.18EB3%henryn@zzzspacebbs.com>

Folks:

I'm writing perl CGI scripts to do some database front-ends, no problem.

However, there's a couple of housekeeping chores to do occasionally: For
example, looking for database updates and downloading them if required.

Thus, on the entry page for my access system there might be a spot that
usually says "database consistent" but will occasionally --every couple of
months-- say "database updated mm/dd/yy" or something like that.

Behind the scenes is a script --perl, I hope-- that runs when the entry page
is loaded which checks to see if it's been run already that day. If not then
it checks the modification date opf the remote database, and ...you get the
picture. 

I see how to do this with SSIs, but I'm looking for alternatives.

Yes, I could tack it on to any of the existing cgi's but they already run a
bit long as it is.

Thanks,

Henry

henryn@zzzspacebbs.com  remove 'zzz'




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

Date: Wed, 10 Dec 2003 00:37:53 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: What is '_'
Message-Id: <3FD66ADD.9CAFC16B@acm.org>

"Randal L. Schwartz" wrote:
> 
> >>>>> "Richard" == Richard Gration <richard@zync.co.uk> writes:
> 
> Richard> When you get perl to stat a file (ie you ask perl for
> Richard> information about the file, eg is it a directory, how long is
> Richard> the file, what is its mod time, etc) perl uses a system
> Richard> function called stat, which returns a lot of information
> Richard> about the file. The results of the stat are cached. The '_'
> Richard> causes perl to consult the stored stat results instead of
> Richard> statting the file again.
> 
> Yup.  One of the few features of Perl I can claim to have invented.
> Two others that come to mind are the literal-slice notation and the
> use of arrow for dereferencing code refs.  And the JAPH. :)

Yes, but what have you done lately?   :-)


John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 09 Dec 2003 23:47:59 GMT
From: parv <parv_@yahooWhereElse.com>
Subject: Re: What is '_'
Message-Id: <slrnbtco1g.1fe.parv_@localhost.holy.cow>

in message <3fd6154c@news.victoria.tc.ca>,
wrote Malcolm Dew-Jones ...

> Perldoc -f -x  (-x is the function name eh?)
> 
> at the end, all the gory details, and examples.

The gory details are not too gory for me.  I want to know the
"scope" & lifetime of cached results.  If i have...

   sub routine
   {
     my $file = shift;

     if ( -e $file )
     {
       # do something
       return;
     }

     if ( -d $file )
     {
       # do something else
       return;
     }

     if ( function() )
     {
       # do something else
       return;
     }
   }

   sub function { return -f _; }


 ...can i replace the third "$file" w/ "_"?  Will function()
consistently give the result about $file in routine() (barring any
other file tests happening in the interim)?


  - parv

-- 
In order to reach me, do away w/ WhereElse in the address.



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

Date: 9 Dec 2003 19:42:47 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: What is '_'
Message-Id: <776e0325.0312091942.3832479e@posting.google.com>

merlyn@stonehenge.com (Randal L. Schwartz) wrote in message news:<b556d3741ef8606141a20a128ebf8529@news.teranews.com>...
> >>>>> "Richard" == Richard Gration <richard@zync.co.uk> writes:
> 
> Richard> When you get perl to stat a file (ie you ask perl for
> Richard> information about the file, eg is it a directory, how long is
> Richard> the file, what is its mod time, etc) perl uses a system
> Richard> function called stat, which returns a lot of information
> Richard> about the file. The results of the stat are cached. The '_'
> Richard> causes perl to consult the stored stat results instead of
> Richard> statting the file again.
> 
> Yup.  One of the few features of Perl I can claim to have invented.
> Two others that come to mind are the literal-slice notation and the
> use of arrow for dereferencing code refs.  And the JAPH. :)
> 
> print "Just another Perl hacker,"

Curious, just consulted Camel v3, don't see this documented, or at
least if its there, it's not obvious. Is it a secret only revealed to
newsgroup readers? :) Nice to know though thanks!

G


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

Date: Wed, 10 Dec 2003 05:00:20 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: What is '_'
Message-Id: <x7r7zdgtcr.fsf@mail.sysarch.com>

>>>>> "p" == parv  <parv_@yahooWhereElse.com> writes:

  p> in message <3fd6154c@news.victoria.tc.ca>,
  p> wrote Malcolm Dew-Jones ...

  >> Perldoc -f -x  (-x is the function name eh?)
  >> 
  >> at the end, all the gory details, and examples.

  p> The gory details are not too gory for me.  I want to know the
  p> "scope" & lifetime of cached results.  If i have...

it is a simple rule. _ caches the MOST RECENT full stat made by the stat
or -X call. there is nothing else to know.


  p>    sub routine
  p>    {
  p>      my $file = shift;

  p>      if ( -e $file )
  p>      {
  p>        # do something
  p>        return;
  p>      }

  p>      if ( -d $file )

you can use _ there.

  p>      {
  p>        # do something else
  p>        return;
  p>      }

  p>      if ( function() )
  p>      {
  p>        # do something else
  p>        return;
  p>      }
  p>    }

  p>    sub function { return -f _; }

if nothing has done a stat or -X since the previous one on $file, then
you are ok. but i wouldn't trust your code to not do that. _ is
basically an operator but it acts like a global variable with no
scoping. i would never use it outside the immediate area which had the
original stat call.

  p> ...can i replace the third "$file" w/ "_"?  Will function()
  p> consistently give the result about $file in routine() (barring any
  p> other file tests happening in the interim)?

the key is what you said, barring any other file tests. assuming that is
true when making sub calls is just not good coding IMO.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 10 Dec 2003 17:54:38 +1300
From: "Tintin" <me@privacy.net>
Subject: Re: Why does ne always work
Message-Id: <br694v$2a4sc6$1@ID-172104.news.uni-berlin.de>


"Gary Mayor" <gary@tgpmakers.com> wrote in message
news:br4f7d$q6s$1@news6.svr.pol.co.uk...
> Hi,
> Whilst i'm here i might as well see if anyone else has noticed strange
> things with if ($blah ne $blah) sometimes it works sometimes it doesn't.
> I always end up doing it a different way as i start pulling my hair out
> because everything is correct it just doesn't work.
>
> Anyone else had that problem.

I'm going to take a stab in the dark here and suggest you are comparing
values from a file without chomping it.




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

Date: Wed, 10 Dec 2003 00:38:59 +0100
From: "Harald" <ha_schwar@gmx.de>
Subject: Re: WIN32::Internet
Message-Id: <br5med$q90$05$1@news.t-online.com>

Have you ever thought about NTLM authentication?
Win32::Internet is the easiest (and only ?) module to do this...

-- 

Harald
 ... to respond to my email-address remove <_>.

> Why Win32::Internet?  I glanced through the docs for it, and offhand I
> don't see anything that you can't do just as easily with other modules
> which don't have the disadvantage of only working on one operating
> system.
>
> -- 
> David Wall




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

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.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5919
***************************************


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