[22202] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4423 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 17 18:05:54 2003

Date: Fri, 17 Jan 2003 15:05:08 -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           Fri, 17 Jan 2003     Volume: 10 Number: 4423

Today's topics:
    Re: APL's relation to perl (Sara)
    Re: APL's relation to perl <uri@stemsystems.com>
    Re: Equivalent of /g for unpack? <goldbb2@earthlink.net>
    Re: Extraction from variable (Tad McClellan)
    Re: Extraction from variable <NO.koos.JUNK.pol.MAIL@raketnet.nl>
    Re: How do I calculate today minus any given number <eric.schwartz@hp.com>
    Re: How do I calculate today minus any given number <eric.schwartz@hp.com>
    Re: howto specify maybe 1+ space regexp Andrew Lee
    Re: more problems with storable. (Ben Morrow)
    Re: more problems with storable. <bongie@gmx.net>
    Re: most popular unix scripting language Andrew Lee
    Re: perl hashes seems to slow down <goldbb2@earthlink.net>
    Re: perl hashes seems to slow down (Andrew Allaire)
        Recompile Perl with CPAN? <vhg@byu.edu>
    Re: Recompile Perl with CPAN? (Anno Siegel)
    Re: Recreating a MIME::Lite object <goldbb2@earthlink.net>
    Re: Recreating a MIME::Lite object <me@privacy.net>
        regex help plse <penny1482@attbi.com>
    Re: regex help plse <skuo@mtwhitney.nsc.com>
    Re: regex help plse (Anno Siegel)
    Re: Storable.pm (Ben Morrow)
    Re: Uninitialised value in join or string issue (Ben Morrow)
    Re: Uninitialised value in join or string issue <NO.koos.JUNK.pol.MAIL@raketnet.nl>
    Re: ~ Urgently require a Webpage Hit counter script !!? (Sara)
    Re: ~ Urgently require a Webpage Hit counter script !!? <dha@panix2.panix.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 17 Jan 2003 11:07:57 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: APL's relation to perl
Message-Id: <776e0325.0301171107.e303d1a@posting.google.com>

"J\(ust\) a\(nother\) phet" <japhet@hushhushmail.com> wrote in message news:<rCRV9.24893$ZE1.524843@news1.nokia.com>...
> Long lost cousins?
> Has perl herited anything from APL?
> If not should it?!

I WISH! APL is (was) one of the best linear variable programming
languages in existence. Imagine a primitive function (domino) to
invert an arbitry matrix (of ANY number of dimensions even!). How many
lines of Perl code would that be?

Also APL had primitives to reverse vectors, rotate columns or rows or
other tuples in a matrix, sorting, indexing (iota), rearranging rows
or cols ([n m]), shape and reshape (rho), unravel (,), take, drop etc
etc etc. It even had primtives (encode decode) to find roots of linear
equations!

I probably spend 1/4 of my time writing Perl subs to do these kinds of
things which APL had in its toolbag out of the box. Regexes take up a
lot of the slack and many of the functions are easily realized, but in
fact for a 60's vintage language, APL was WAY ahead of its time.
That's probably why it failed to gain much of a following. Well that,
and its lack of objectivity.

There ARE similarties- neither is strongly typed, there are no nested
subroutines, and they are both interpreted. APL of course had its own
APL/OS (the workspace) in which to develop which was powerful as well.

Would I consider APL as a contemporary alternative to Perl? No way.
Once you taste the power of the regex you can never go back. But could
Perl learn a few more things about the power of primitive functions? I
think so. As a "reporting language", some common reporting tasks are
seemingly missing, and their inclusion would make Perl a more
versatile tool. Sure you can probably find a lot of those functions in
CPAN, but the core, in my opinion, could be a lot more powerful.

Gx


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

Date: Fri, 17 Jan 2003 19:11:54 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: APL's relation to perl
Message-Id: <x7d6mv7fr9.fsf@mail.sysarch.com>

>>>>> "S" == Sara  <genericax@hotmail.com> writes:

  S> Would I consider APL as a contemporary alternative to Perl? No way.
  S> Once you taste the power of the regex you can never go back. But could
  S> Perl learn a few more things about the power of primitive functions? I
  S> think so. As a "reporting language", some common reporting tasks are
  S> seemingly missing, and their inclusion would make Perl a more
  S> versatile tool. Sure you can probably find a lot of those functions in
  S> CPAN, but the core, in my opinion, could be a lot more powerful.

you should take a peek at the perl 6 world. many of the apl vector
flavored ops are getting into perl. you will be able to convert most
common ops to a vector form, e.g. a scalar can be added to all elements
of an array or two arrays can be compared element by element. there are
too many other improvements to even list here. go to dev.perl.org and
read the apocalyse and related docs.

uri

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


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

Date: Fri, 17 Jan 2003 14:39:59 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Equivalent of /g for unpack?
Message-Id: <3E285C0F.7E11B28@earthlink.net>

jtd wrote:
> 
> Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:
> > Reading from a file, then performing substr() on the data sounds
> > rather innefficient.
> >
> > You probably want something like this:
> 
> Thanks, can I do something similar with strings in memory? I need to
> separate unpacking from file access for a number of reasons.

Hmm, how about the '@' template?

   my $pos = 0;
   my $fmt = ....;
   while( $pos < length($packed_str) ) {
      my @struct = unpack( '@'.$pos.$fmt, $packed_str );

      $pos += length( pack($fmt, @struct) );

      $fmt = ... format for next data structure to unpack ...;
   }

But I'm not sure how efficient this is compared to substr.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Fri, 17 Jan 2003 12:51:39 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Extraction from variable
Message-Id: <slrnb2gk5r.588.tadmc@magna.augustmail.com>


[ Please learn how to properly format followups. Text rearranged.

  Please provide an attributions when you quote someone.
]


Jon Rogers <jon@rogers.tv> wrote:

>>    $var =~ s/[^a-zA-Z0-9]+//g;


> Would this mean that $var now is untainted if I use -T mode?


What happened when you tried it?


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


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

Date: Fri, 17 Jan 2003 21:23:38 +0100
From: Koos Pol <NO.koos.JUNK.pol.MAIL@raketnet.nl>
Subject: Re: Extraction from variable
Message-Id: <b09oob$nh0vg$1@ID-171888.news.dfncis.de>

On vrijdag 17 januari 2003 18:01 Tad McClellan wrote:

> From the "Version 8 Regular Expressions" section in perlre.pod
> 
>    If the first character after the "[" is "^", the class matches
>    any character not in the list.


Yep. Found it. Thanks.
So much to learn and so little time... :-)

-- 
KP
koos _ pol @ raketnet nl


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

Date: 17 Jan 2003 13:19:29 -0700
From: Eric Schwartz <eric.schwartz@hp.com>
Subject: Re: How do I calculate today minus any given number
Message-Id: <eto3cnril66.fsf@wormtongue.emschwar>

"David" <perl-dvd@darklaser.com> writes:
> There's really no need to use an external module, Perl does all this for
> you with a combination of time() and localtime().

But the module will do it correctly.  Your code will fail if daylight
savings time rears its ugly head-- you can be off by a day in that
case.

> ##############################################
> my $daysago = 30;
> my @date = localtime(time() - ($daysago * 86400));

Not all days are 86400 seconds long.  In most countries with some form
of DST, it can vary between 82800 and 90000 seconds.

Just use Date::Calc instead; it's simpler, and it will always give you
the right answer.  It's also much shorter:

use Date::Calc qw/Add_Delta_Days/;

my ($day, $month, $year) = (localtime(time))[3,4,5];
$month++; $year += 1900;
my ($lastday, $lastmonth, $lastyear) =
       Add_Delta_Days($year,$month,$day,-30);
print "30 days ago was: $lastyear-$lastmonth-$lastday\n";

(tested)

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: 17 Jan 2003 13:21:20 -0700
From: Eric Schwartz <eric.schwartz@hp.com>
Subject: Re: How do I calculate today minus any given number
Message-Id: <etoy95jh6in.fsf@wormtongue.emschwar>

Andrew Lee writes:
> You can use localtime().

But it'll be wrong at least twice a year.

> my $cur_time = time();	# utime 
> my $prev_time = $cur_time - 60*60*24*30;	  # 30 days ago

Not necessarily.  See my other post.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Fri, 17 Jan 2003 14:31:26 -0500
From: Andrew Lee
Subject: Re: howto specify maybe 1+ space regexp
Message-Id: <m2mg2v4bv6tc9dhcak5s0p441bd6njkehb@4ax.com>

On Thu, 16 Jan 2003 11:20:13 -0600, Lance Hoffmeyer
<lance@augustmail.com> wrote:

>I am having problems on specifying a regexp.
>I want to include 0 or more spaces.
>
>Here is what works but not as efficient as what I want:
>
>$text =~ s/($base1.*?\=.*?)[\d]{2,3}/$1$b4r4/g;

Why are you escaping '=' ?
>
>Here is what doesn't work but is what I want:
>
>$text =~ s/($base1\s+?\=\s+?)[\d]{2,3}/$1$b4r4/g;

If it doesn't work, why do you want it?

>
>What have I misspecified?
>

What is $text?


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

Date: Fri, 17 Jan 2003 19:06:03 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: more problems with storable.
Message-Id: <b09k6r$nlf$1@wisteria.csv.warwick.ac.uk>

"Harald H.-J. Bongartz" <bongie@gmx.net> wrote:
>Richard S Beckett wrote:
>> I'm still having trouble with storable...
>
>Didn't you read Ben's response?
>(Message-ID: <b06qfe$gkm$1@wisteria.csv.warwick.ac.uk>)

:)

>[...]
>> # Load saved variables, or use default values.
>> my $ref = retrieve 'saved.dat' if -e 'saved.dat';
>
>I would prefer
>        ... if -f 'saved.dat' && -r _;
>to check if it's a plain file and readable.

And I would _much_ prefer 
my $ref = retrieve 'saved.dat';
because it doesn't have a race condition.

Ben


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

Date: Fri, 17 Jan 2003 21:51:56 +0100
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: more problems with storable.
Message-Id: <2318691.APjIJtOEB9@nyoga.dubu.de>

Ben Morrow wrote:
> "Harald H.-J. Bongartz" <bongie@gmx.net> wrote:
>>I would prefer
>>        ... if -f 'saved.dat' && -r _;
>>to check if it's a plain file and readable.
> 
> And I would _much_ prefer
> my $ref = retrieve 'saved.dat';
> because it doesn't have a race condition.

Right you are. :-)

So the best approach would really be to encapsulate the call in an eval,
like you wrote in the other thread.

At least unless the problem with retrieve() aborting on errors is
solved.

Ciao,
        Harald
-- 
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
That's our advantage at Microsoft; we set the standards and we can 
change them.            -- Karen Hargrove, Microsoft, Feb 1993



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

Date: Fri, 17 Jan 2003 14:04:04 -0500
From: Andrew Lee
Subject: Re: most popular unix scripting language
Message-Id: <jrjg2vo9vqfmr05fmhbi4td4ldtj12i3os@4ax.com>

On 17 Jan 2003 05:44:57 -0800, genericax@hotmail.com (Sara) wrote:

>claird@lairds.com (Cameron Laird) wrote in message news:<v2ekbhldaj4mf0@corp.supernews.com>...
>> In article <f51c02db.0301161617.3622cfaa@posting.google.com>,
>> dambalaMaster <dorli@hotmail.com> wrote:
>> >does anyone know which is the most popular unix scripting language?
>> >
>> >xp829
>> 
>> Yes.  Several hundreds of thousands of people know, and,
>> between them, they only come up with about two dozen
>> different answers.
>
>
>Accordind to DICE/monster, Perl IS the hands-down winner. Larry gets
>the prize haha.. Although javascript is frightenly close. Take heart
>though Perlistas- now that the DOJ ordered Mickeysoft to support java,
>it'll be worthless to 90% of the technical community. The
>business-geeks will love it though...
 

[snip stats]

<off topic rant>

And what the heck is business logic anyway?  Sun acts like it invented
a new idea by promoting that oxymoron.  Does business logic only apply
to enterprise computing?  Is enterprise computing computing that only
runs on SPARC architecture?  Does J2EE technology better encapsulate
-- in a component based model sense -- enterprise business logic?
Suppose I wanted to develop a multi-tier enterprise application that
utilizes core Web services in an enterprise application integration
platform ... will that many buzzwords make me a better programmer?

Does it come with an IDE?

</off topic rant>
    ^^^^^^^^^

Like how encapsulated that?  That's going on my resume!


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

Date: Fri, 17 Jan 2003 14:35:26 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: perl hashes seems to slow down
Message-Id: <3E285AFE.DDB2B300@earthlink.net>

Sara wrote:
> Benjamin Goldberg wrote:
[snip]
> > In addition, I would suggest profiling your code, using
> > Devel::DProf, and finding out which parts actually *need*
> > optomization, due to your program spending lots of time in them,
> > rather than guessing what needs to be sped up.
> 
> tied hashes sure do- try a GDBM with like 50,000 values.
> Talk about SLOW!

Sure, but the OP never suggested that any of his hashes were tied, so
one assumes that they aren't.

Given the slowness of tie()d variables, I've occasionally bypassed
tieing altogether, and done:

   my $db = SDBM_File->TIEHASH('filename', O_RDWR|O_CREAT, 0666);
   my $x = $db->FETCH($key);
   $db->STORE($key, $value);
   undef $db;

This is generally much faster, with the only drawback being that you
can't use $db in places where a hashref is expected... you can only use
it in places that "know" that it's an object.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: 17 Jan 2003 13:19:16 -0800
From: Andrew.Allaire@na.teleatlas.com (Andrew Allaire)
Subject: Re: perl hashes seems to slow down
Message-Id: <6bdb91de.0301171319.4580b0a6@posting.google.com>

nayeem@ntlworld.com (nayeem) wrote in message news:<50e1bf38.0301161133.1af1539e@posting.google.com>...
> fellow japhs,
> ive been using perl hashes for a recent project

 ...
> 
> any comments/suggestions/ideas/criticisms would be most appreciated.
> 
> nayeem

  I have a hunch that your performance is related to the number of
hashes or arrays you have constructed in this structure. I have
noticed a slow down in my own programs when I have created large
numbers of of seperate arrays or hashes. Note it wasn't the size of
any hash or array that seemed to be causing the slow down, but the
fact that there were too many little hashes or arrays. You might try
putting your sub records into scalars, and split them up with split or
unpack. Or even put the raw data into bufferish packages in a binary
file where and store the offset and size of these buffers in %$rs.
These approaches have worked for me.


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

Date: Fri, 17 Jan 2003 13:47:53 -0700
From: Vaughn Gardner <vhg@byu.edu>
Subject: Recompile Perl with CPAN?
Message-Id: <3E286BF9.8040206@byu.edu>

I'm having trouble installing some modules (Bundle::DBI, etc.) that 
depend on Thread.pm because my Perl build (a binary depot package) was 
built with pthread support.  I'd like to rebuild it (Perl, that is). 
Since I'm using the interactive CPAN mode (perl -MCPAN) to install the 
modules, how appropriate would it be to do a "force install perl-5.6.1"?

Thanks in advance,
Vaughn Gardner
BYU



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

Date: 17 Jan 2003 22:41:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Recompile Perl with CPAN?
Message-Id: <b0a0r5$14e$2@mamenchi.zrz.TU-Berlin.DE>

Vaughn Gardner  <vhg@byu.edu> wrote in comp.lang.perl.misc:
> I'm having trouble installing some modules (Bundle::DBI, etc.) that 
> depend on Thread.pm because my Perl build (a binary depot package) was 
> built with pthread support.  I'd like to rebuild it (Perl, that is). 
> Since I'm using the interactive CPAN mode (perl -MCPAN) to install the 
> modules, how appropriate would it be to do a "force install perl-5.6.1"?

Normally you don't have to force installation of a newly built Perl.
Install it regularly.  And, while you're at it, why not 5.8.0?

Anno


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

Date: Fri, 17 Jan 2003 14:23:31 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Recreating a MIME::Lite object
Message-Id: <3E285833.43A5727C@earthlink.net>

Ben Morrow wrote:
[snip demonstration of problem with Storable.pm]
> Is there any other knowledge would help work out what's wrong?

The best knowledge for working out what's wrong with a module is knowing
who the author is, especially their the email address, so that you can
demonstrate the problem for him and ask for a solution.  In the case of
Storable, the author is Abhijit Menon-Sen, whose email address is
ams@wiw.org.

But before you do that, I would like to point out that you've got
Storable version 2.04, and the CPAN version of Storable is 2.06.  It's
entirely possible that the problem you've run into has already been
fixed.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Fri, 17 Jan 2003 20:52:07 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Recreating a MIME::Lite object
Message-Id: <b09o98$nhb0b$1@ID-172104.news.dfncis.de>


"Ben Morrow" <mauzo@mimosa.csv.warwick.ac.uk> wrote in message
news:b07okd$srl$1@wisteria.csv.warwick.ac.uk...
> Can I ask the OP: do you really need the MIME::Lite object back? Do you
wish to
> do more with the message than send it? If you don't, then you can just
write it
> out to a text file and then read it back in and use some other mailing
module
> (Mail::Sendmail?) to send the complete message.

I need to access various attributes, hence the reason it would be easier if
I could recreate the object.

>
> I reckon the only other thing you can do (unless you investigate other
> Storable-alikes and find one which will store blessed refs) is to read the
> message back in using MIME::Tools, and deal with rebuilding the MIME::Lite
> object if you have to... could get messy.

I'll try the storable option first.





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

Date: Fri, 17 Jan 2003 20:50:47 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: regex help plse
Message-Id: <H0_V9.717718$%m4.3408106@rwcrnsc52.ops.asp.att.net>

I had a regex number extractor/formatter that worked fine (w the help of
this group). Now I am trying to modify it to handle embeded periods and/or
leading minus signs. I copied $rgx2 from Perl docs, it works fine for
decimal points, but will not emitt (output) the minus sign. I thought the
enclosing ( ...) in $rgx2 might be wrong, so I tried $rgx2a, still no good.

Suggestions appreciated.
--------snippet begin
my $rgx1 = '\d+';  #original
my $rgx2 = '[+-]?(\d+\.\d+|\d+\.|\.\d+|\d+)';  # num w or w/o decimal
my $rgx2a = '([+-]?\d+\.\d+|\d+\.|\.\d+|\d+)';  # num w or w/o decimal
#test data follows
my $lines = [
  '>>SPM::   0111350  0113550  0111270  0111425  4173  12150',
  '>>SPH::   0111200  0113350  0111050  0113280  -36540  37978',#bad output
  '>>SPM::   0113635  0115750  0112810  0113640  4657  8310',
  '>>SPH::   0113400  0115490  0112570  0113400  39.383  39419' ];#OK output
#input/output mappings
my @numbrs = map { [ map { s/(\d{4})(\d\d)$/$1.$2/; $_ } /$rgx2/go ] }
    grep{/SPH/} @$lines;
--------snippet end

Thanks again.
--
Dick Penny




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

Date: Fri, 17 Jan 2003 13:35:37 -0800
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: regex help plse
Message-Id: <Pine.GSO.4.21.0301171329550.17186-100000@mtwhitney.nsc.com>

On Fri, 17 Jan 2003, Dick Penny wrote:

> I had a regex number extractor/formatter that worked fine (w the help of
> this group). Now I am trying to modify it to handle embeded periods and/or
> leading minus signs. I copied $rgx2 from Perl docs, it works fine for
> decimal points, but will not emitt (output) the minus sign. I thought the
> enclosing ( ...) in $rgx2 might be wrong, so I tried $rgx2a, still no good.
> 
> Suggestions appreciated.
> --------snippet begin
> my $rgx1 = '\d+';  #original
> my $rgx2 = '[+-]?(\d+\.\d+|\d+\.|\.\d+|\d+)';  # num w or w/o decimal
> my $rgx2a = '([+-]?\d+\.\d+|\d+\.|\.\d+|\d+)';  # num w or w/o decimal



Only the first of the four alternative patterns contains the optional
'+' or '-'.  Try grouping as such (and use the qr operator):

my $rgx2a =
 qr'([+-]?(?:\d+\.\d+|\d+\.|\.\d+|\d+))'; 


> #test data follows
> my $lines = [
>   '>>SPM::   0111350  0113550  0111270  0111425  4173  12150',
>   '>>SPH::   0111200  0113350  0111050  0113280  -36540  37978',#bad output
>   '>>SPM::   0113635  0115750  0112810  0113640  4657  8310',
>   '>>SPH::   0113400  0115490  0112570  0113400  39.383  39419' ];#OK output
> #input/output mappings
> my @numbrs = map { [ map { s/(\d{4})(\d\d)$/$1.$2/; $_ } /$rgx2/go ] }
>     grep{/SPH/} @$lines;
> --------snippet end



The /o pattern modifier is unnecessary.

Thus:

use Data::Dumper;

my $rgx2a =
 qr'([+-]?(?:\d+\.\d+|\d+\.|\.\d+|\d+))'; 

my $lines = [
  '>>SPM::   0111350  0113550  0111270  0111425  4173  12150',
  '>>SPH::   0111200  0113350  0111050  0113280  -36540  37978',
  '>>SPM::   0113635  0115750  0112810  0113640  4657  8310',
  '>>SPH::   0113400  0115490  0112570  0113400  39.383  39419' ];

my @numbrs = map { [ map { s/(\d{4})(\d\d)$/$1.$2/; $_ } /$rgx2a/g ] }
    grep{/SPH/} @$lines;

print Dumper \@numbrs;

produces:

$VAR1 = [
          [
            '01112.00',
            '01133.50',
            '01110.50',
            '01132.80',
            '-36540',
            '37978'
          ],
          [
            '01134.00',
            '01154.90',
            '01125.70',
            '01134.00',
            '39.383',
            '39419'
          ]
        ];


-- 
HTH, 
Steven



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

Date: 17 Jan 2003 22:32:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regex help plse
Message-Id: <b0a0af$14e$1@mamenchi.zrz.TU-Berlin.DE>

Dick Penny <penny1482@attbi.com> wrote in comp.lang.perl.misc:
> I had a regex number extractor/formatter that worked fine (w the help of
> this group). Now I am trying to modify it to handle embeded periods and/or
> leading minus signs. I copied $rgx2 from Perl docs, it works fine for
> decimal points, but will not emitt (output) the minus sign. I thought the
> enclosing ( ...) in $rgx2 might be wrong, so I tried $rgx2a, still no good.
> 
> Suggestions appreciated.
> --------snippet begin
> my $rgx1 = '\d+';  #original
> my $rgx2 = '[+-]?(\d+\.\d+|\d+\.|\.\d+|\d+)';  # num w or w/o decimal
                   ^                        ^
These parentheses are needed for the regex to work.

> my $rgx2a = '([+-]?\d+\.\d+|\d+\.|\.\d+|\d+)';  # num w or w/o decimal
               ^                             ^
You have moved the first parenthesis.  Now the optional [+-] only belongs
to the first of the four alternatives.  If a later one matches, it matches
without [+-].  Use

    my $rgx2a = qr/([+-]?(?:\d+\.\d+|\d+\.|\.\d+|\d+))/;

Note that I have replaced the second pair of parens with the non-capturing
variant.

> #test data follows
> my $lines = [
>   '>>SPM::   0111350  0113550  0111270  0111425  4173  12150',
>   '>>SPH::   0111200  0113350  0111050  0113280  -36540  37978',#bad output
>   '>>SPM::   0113635  0115750  0112810  0113640  4657  8310',
>   '>>SPH::   0113400  0115490  0112570  0113400  39.383  39419' ];#OK output
> #input/output mappings
> my @numbrs = map { [ map { s/(\d{4})(\d\d)$/$1.$2/; $_ } /$rgx2/go ] }
                                                            ^^^^^
You want $rgx2a here.  $rgx2 doesn't work, but you knew that.

>     grep{/SPH/} @$lines;
> --------snippet end

It is nice to find some code, for a change, that runs blamelessly under
strict and warnings.

It is a useful technique to keep (parts of) regexes in variables the
way you do.  You might as well use the regex-quoting mechanism qr//
for the purpose.

However, you should try to keep *capturing* parentheses out of the
fixed parts as far as possible.  You must count opening parentheses
to know which parts are captured, so hiding them in a variable is
a bad idea.  This would have been better:

    my $rgx2a = qr/[+-]?(?:\d+\.\d+|\d+\.|\.\d+|\d+)/;

 ...and later

    map { s/(\d{4})(\d\d)$/$1.$2/; $_ } /($rgx2)/go

Anno


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

Date: Fri, 17 Jan 2003 19:21:49 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Storable.pm
Message-Id: <b09l4d$o4u$1@wisteria.csv.warwick.ac.uk>

"Richard S Beckett" <spikey-wan@bigfoot.com> wrote:
>
>"Ben Morrow" <mauzo@ux-ma160-16.csv.warwick.ac.uk> wrote
>> #!/usr/bin/perl
>> use warnings;
>> use strict;
>> use Storable;
>> my (%vars, $ref);
>>
>> $ref = retrieve 'saved.dat'; # avoid race: just try to retrieve and then
>see
>>                              # if it failed.
>
>There's a problem here. If saved.dat doesn't exixt the script exits with:
>can't open saved.dat: No such file or directory at save-vars1.pl line 8

<slap> Test code before posting, Ben...
Sorry.

/me is now confused. perldoc Storable:
: In case an I/O error occurs while
: reading, "undef" is returned instead.

Hmmm.

>What about...
>
>$ref = retrieve 'saved.dat' if -e saved.dat;
>
>Will that still give me a race problem?

Yes, but I guess you'll have to live with it (you probably don't care anyway :)
unless you want to do the ultra-careful

eval {
  $ref = retrieve 'saved.dat';
}
die $@ if $@ and $@ !~ /No such file or directory/;

I apologise for my post in the other thread concerning this subject...

>>    store \%vars, 'saved.dat' or die "store failed: $!";
>
>So I _do_ use "store \%vars" to store %vars?

No, you use C<store \%vars> to store \%vars :).
Later on (in time, not in the script) you retrieve (something equivalent to the
old value of) \%vars into $ref and copy the old values of %vars into the new
%vars (this is a different invocation of the script, remember) using
%vars = %$ref;
 . You can't store %vars directly, which is why you have to do this.

Ben


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

Date: Fri, 17 Jan 2003 19:28:22 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Uninitialised value in join or string issue
Message-Id: <b09lgm$o9c$1@wisteria.csv.warwick.ac.uk>

Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote:
>henrik nilsson wrote (Friday 17 January 2003 12:13):
>
>> When I run these lines from a CLI window, everything works fine.
>> 
>> (it is a cgi script. $authorcode is normally specified by the user)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> 
>> my $authorcode = 333;
>                   ^^^
>
>(Hey, the value for $authorcode is hardcoded. Hmmm... lets see what goes 
>on...)

Err, I take it you read the line above... ? :)

<snip perfectly correct comments on the dif. between "" and undef>

>> shouldn't the (!$authorcode) test be true?
>
>
>No. You can only check for a "not" value it there is a value. If there isn't 
>a value at all (read: undef) there is no value to check against. So your 
>statement should be rewritten to:
>
>    if ( defined $authorcode ) {print "...some html...\n"; exit; }
>
>Read "perldoc -f undef" for the nitty gritty.

No. undef is a perfectly acceptable false value.

~% perl -le'$a = undef; if (!$a) { print "yes" } else { print "no" }'
yes

Ben


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

Date: Fri, 17 Jan 2003 21:14:23 +0100
From: Koos Pol <NO.koos.JUNK.pol.MAIL@raketnet.nl>
Subject: Re: Uninitialised value in join or string issue
Message-Id: <b09o6v$nco8b$1@ID-171888.news.dfncis.de>

On vrijdag 17 januari 2003 20:28 Ben Morrow wrote:

> Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote:

>>No. You can only check for a "not" value it there is a value. If there
>>isn't a value at all (read: undef) there is no value to check against.

> No. undef is a perfectly acceptable false value.
> 
> ~% perl -le'$a = undef; if (!$a) { print "yes" } else { print "no" }'
> yes
> 
> Ben


You are --ofcourse-- absolutely right. ("Must check before send...")

-- 
KP
koos _ pol @ raketnet nl


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

Date: 17 Jan 2003 11:49:09 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: ~ Urgently require a Webpage Hit counter script !!??~
Message-Id: <776e0325.0301171149.a3913f3@posting.google.com>

inderjit S Gabrie <i.gabrie@mis.gla.ac.uk> wrote in message news:<3E282127.978DD144@mis.gla.ac.uk>...
> Hi all
> 
> 
> I am looking for a simple text webpage hit counter that would  keep
> track of hits
> into a file or possible email them to me with e.g. date/time of hit,
> webpage
> accessed,users Ip no etc etc can this be done or does anyone have a
> script...thanks
> in advnace...indy

and the reason this request would be made of a group discussing the
intracacies and features of The Perl Programming langauge is..?


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

Date: Fri, 17 Jan 2003 21:46:45 +0000 (UTC)
From: "David H. Adler" <dha@panix2.panix.com>
Subject: Re: ~ Urgently require a Webpage Hit counter script !!??~
Message-Id: <slrnb2gue5.2lc.dha@panix2.panix.com>

In article <newscache$un9v8h$wfb$1@news.emea.compuware.com>, Koos Pol wrote:

> And if it is so very urgent, how much are willing to pay? I would be more 
> than happy to give you a quote.

But you wouldn't actually do that here, since it would trigger one of my
infamous job posting messages.  Right?  :-)

dha
-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
New Songs/New Members/New CD/Same rotten attitude
    - Raving Noah press release


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

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


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