[25069] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7319 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 27 09:05:46 2004

Date: Wed, 27 Oct 2004 06:05: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           Wed, 27 Oct 2004     Volume: 10 Number: 7319

Today's topics:
    Re: Common file operations <usenet@morrow.me.uk>
    Re: Compiling or Hiding Perl <peter@semantico.com>
    Re: Compiling or Hiding Perl (Anno Siegel)
    Re: Compiling or Hiding Perl <peter@semantico.com>
    Re: Compiling or Hiding Perl <phaylon@dunkelheit.at>
    Re: Finding the size of a rather complicated hash-struc (Anno Siegel)
    Re: Finding the size of a rather complicated hash-struc <wyzelli@yahoo.com>
    Re: Finding the size of a rather complicated hash-struc <kuujinbo@hotmail.com>
    Re: Get Win32 Total Physical Memory & Available Physica <ThomasKratz@REMOVEwebCAPS.de>
    Re: Get Win32 Total Physical Memory & Available Physica <kuujinbo@hotmail.com>
    Re: help in parsing xml messages <nobull@mail.com>
    Re: open-perl-ide qustion (Anno Siegel)
    Re: open-perl-ide qustion <iohihuh@INVALID.yahoo.com>
        Reducing amount of repetative code (Brad)
    Re: Reducing amount of repetative code <do-not-use@invalid.net>
    Re: Reducing amount of repetative code <josef.moellers@fujitsu-siemens.com>
    Re: Reducing amount of repetative code (Anno Siegel)
    Re: Verify a url form a perl script <dug@plusthree.com>
    Re: What's the seed? <usenet@morrow.me.uk>
    Re: Which is the best book for learning OO perl? <aha1@gmx.net>
    Re: Why does Perl use more resource than Php? <scampbel+usenet@cis.strath.ac.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 27 Oct 2004 10:28:41 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Common file operations
Message-Id: <9b6452-rl4.ln1@osiris.mauzo.dyndns.org>


Quoth "Shmuel (Seymour J.) Metz" <spamtrap@library.lspace.org.invalid>:
> In <ywffd.5216$LT1.3686@trnddc09>, on 10/25/2004
>    at 10:56 PM, "J  rgen Exner" <jurgenex@hotmail.com> said:
> 
> >Your question is not clear to me. Or maybe it is actually two
> >questions?
> 
> First, some background. In OS/2 there is no[1] concept of mounting a
> directory; instead, file systems are referred to by drive letter,
> there is a current dirve and each drive letter has an associated CWD.
> A file specification of the form[2] d:\name.ext is interpreted as
> d:\cwd\name.ext, a name of the form name.ext is interpreted as being
> in the cwd of the current drive and a name of the form \path\name.ext
> is interpreted as being in the specified directory on the current
> drive. I'd like to allow the user to specify any of the forms and
> convert them to d:\path\name.ext.

I happen to know that the Win32 modules allow you to retreive te current
drive and current dir separately; I'd be pretty confident that either
the OS/2 modules do or that the Win32 modules will run under OS/2.

OTOH, File::Spec::Win32->rel2abs will do what you want, AFAICT.

> >And the second part would be how to prepend the CWD to the file
> >names found.  That's a trivial job for the double quote operator or
> >the concatenation  operator ".".
> 
> Simple but not trivial, because I have to first test whether the drive
> is already their and whether the absolute path is already there.

Which File::Spec does for you.

> >Where did you find a function "canon"?
> 
> Sorry, that's a typo. It's the canonpath method of the File:Spec
> module. It's in the online Perl documentation and also in the
> Dromedary.

Yup; but canonpath is not the right function :). canonpath performs a
*logical* cleanup of the path: e.g. on Unix it remove /./ and /foo/../
sections, and double slashes; it performs equivalent cleanup on other
OSen, but never looks at the actual filesystem. As I said before, the
method you want is rel2abs, which will default to taking the path
relative to the cwd.

> >What is a file specification in your terminlogoy?
> 
> I'd probably want to support the OS/2 conventions, which use * and ?
> as wildcards, with ? matching a single component. I haven't decided
> whether to restrict the input a bit or to translate into a regular
> expression. d:\m?file.* would match, e.g., d:\cwd\mafile.cmd,
> d:\cwd\mbfile.exe, d:\cwd\mcfile.html.

In that case you want to use glob *after* rel2abs: rel2abs does not
check if the file exists, so it should correctly give you an absolute
glob pattern that will work. If that doesn't work, you could do

my @dirs = map { File::Spec->rel2abs($_) } glob $pattern;

You may also be interested in File::DosGlob, which may give you globbing
semantics you are more used to, I don't know.

Ben

-- 
   Although few may originate a policy, we are all able to judge it.
                                             - Pericles of Athens, c.430 B.C.
  ben@morrow.me.uk


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

Date: Wed, 27 Oct 2004 11:33:15 +0100
From: Peter Hickman <peter@semantico.com>
Subject: Re: Compiling or Hiding Perl
Message-Id: <417f796c$0$11938$afc38c87@news.easynet.co.uk>

daniel kaplan wrote:
>>(Yes, I'm being an ass, but I can't help it today. Don't take it
>>personally.)
> 
> 
> read all threads related to me, and you bet i'll take it personally....but
> on the off chance you really couldn't help it...sometimes, it's company
> policy, sometimes it's shareholders, etc. etc.
> 
> in the end you have  to research every possibilty....also as i said in an
> earlier post, when i researched this a year ago or so, i got my answer, but
> since am now looking into Perl i had to re-check.  afert all things change
> 
> 

When I started programming perl, around the time version 4 was released, there 
was talk of a tool to hide the Perl code. There has probably been talk of a tool 
to hide Perl code since version 1.

We are on the threshold of version 6 and it is still not here and to be honest I 
don't ever think it will exist. Lets face it this has never been a requirement 
of the language and never will be. There are many more productive things for the 
developers to undertake than hiding the code.

It will never happen.


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

Date: 27 Oct 2004 10:48:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Compiling or Hiding Perl
Message-Id: <clnuec$p1r$2@mamenchi.zrz.TU-Berlin.DE>

Peter Hickman  <peter@semantico.com> wrote in comp.lang.perl.misc:
> daniel kaplan wrote:
> >>(Yes, I'm being an ass, but I can't help it today. Don't take it
> >>personally.)
> > 
> > 
> > read all threads related to me, and you bet i'll take it personally....but
> > on the off chance you really couldn't help it...sometimes, it's company
> > policy, sometimes it's shareholders, etc. etc.
> > 
> > in the end you have  to research every possibilty....also as i said in an
> > earlier post, when i researched this a year ago or so, i got my answer, but
> > since am now looking into Perl i had to re-check.  afert all things change
> > 
> > 
> 
> When I started programming perl, around the time version 4 was released, there 
> was talk of a tool to hide the Perl code. There has probably been talk
> of a tool 
> to hide Perl code since version 1.
> 
> We are on the threshold of version 6 and it is still not here and to be
> honest I 
> don't ever think it will exist. Lets face it this has never been a requirement 
> of the language and never will be. There are many more productive things
> for the 
> developers to undertake than hiding the code.
> 
> It will never happen.

It may already have happened.  If it's proprietary software, how
would we know?  Neither the tool itself, nor the products treated
with it would be recognizable as Perl programs.

No, I don't really think such a product exists, but there is a
certain contradiction in expecting the open-source community to
provide the tools for hiding sources.

Anno


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

Date: Wed, 27 Oct 2004 11:56:32 +0100
From: Peter Hickman <peter@semantico.com>
Subject: Re: Compiling or Hiding Perl
Message-Id: <417f7ee1$0$505$afc38c87@news.easynet.co.uk>

Anno Siegel wrote:
> It may already have happened.  If it's proprietary software, how
> would we know?  Neither the tool itself, nor the products treated
> with it would be recognizable as Perl programs.
> 
> No, I don't really think such a product exists, but there is a
> certain contradiction in expecting the open-source community to
> provide the tools for hiding sources.
> 
> Anno

Actually a thought just hit me about version 6. Maybe Perl could use the Python 
convention of compiling to byte code (py to pyc) and then distributing only the 
pyc files to run the program. Not ideal but makes things much harder to reverse 
engineer.

It would probably be too much to retrofit onto pre 6, but 6 could possibly take 
that path.

I will go off and post to perl6-internals.


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

Date: Wed, 27 Oct 2004 12:59:08 +0200
From: Robert Sedlacek <phaylon@dunkelheit.at>
Subject: Re: Compiling or Hiding Perl
Message-Id: <pan.2004.10.27.10.59.08.340183@dunkelheit.at>

daniel kaplan wrote:

> boy are you barking up the wrong tree...i tried to be free form here a few
> days ago and i have lost three pints of blood so far.  you either goose-step
> to the fuehrer...i mean FAQ, or you are wrong...
         ^^^^^^^
while (1) { *PLONK* }

g,
Robert

-- 
http://www.dunkelheit.at/

Ordinary morality is only for ordinary people.
                       -- Aleister Crowley



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

Date: 27 Oct 2004 10:37:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Finding the size of a rather complicated hash-structure
Message-Id: <clntq0$p1r$1@mamenchi.zrz.TU-Berlin.DE>

Fred  <na@na.no> wrote in comp.lang.perl.misc:
> Hi group
> 
> Ok, so I've got a rather complicated hash-structure that I'd like to find  
> the size of. Size in consumed bytes of memory. Just because I'm curious.  
> And I've done the obligatory searches for finding sizes of stuff, and I'm  
> not much the wiser. Exept I've come to understand that there isn't any  
> bult-in functionality to do this for such structures.

That is because the actual data structures perl uses depend on too
many things.  It's not only the Perl version and the platform, but
also which compiler was used to build perl and possibly with what
compile-time options.

> So here I am then. Needing help!
> 
> My hash-structure looks something like this:

Whatever it is, if you were to measure it exactly you'd get wildly
differing results depending on circumstances that will be hard to
control.

[...]

> I suppose I could loop through tree, pushing name and file to an array,  
> looping through the architectures for each element in tree, and pushing  
> name and file to the same array, and doing the same with the components.  
> And then just flattening the array and use length(). But...that's kinda  
> dirty.....

Use one of the linearizing modules to do that for you, Data::Dumper,
Storable or the like.  Use a non-compressing mode, then the length
of the resulting string should give reasonable comparisons between
similar data structures.  You will not catch any overhead Perl uses
to store the structure.

Anno


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

Date: Wed, 27 Oct 2004 11:52:27 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: Finding the size of a rather complicated hash-structure
Message-Id: <%ZLfd.663$K7.49@news-server.bigpond.net.au>

"Fred" <na@na.no> wrote in message news:opsgiu63tdzgaswl@frodepc...
> Hi group
>
> Ok, so I've got a rather complicated hash-structure that I'd like to find 
> the size of. Size in consumed bytes of memory. Just because I'm curious. 
> And I've done the obligatory searches for finding sizes of stuff, and I'm 
> not much the wiser. Exept I've come to understand that there isn't any 
> bult-in functionality to do this for such structures.
>
> So here I am then. Needing help!
>
> My hash-structure looks something like this:
>
> $tree = {
>   <key> => {
>     'name' => <str>,
>     'file' => <str>,
>     'architectures' => {
>       <key> => {
>         'name' => <str>,
>         'file' => <str>,
>         'components' => {
>           <key> = {
>             'name' => <str>,
>             'lib'  => <str>
>           }
>         }
>       }
>     }
>   }
> };
>

Use Storable

Write it to disk and look at the size of the file you create...

-- 
Wyzelli
print 'Just', 'another', 'Perl', 'Hacker'; 




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

Date: Wed, 27 Oct 2004 21:50:53 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: Finding the size of a rather complicated hash-structure
Message-Id: <2u9jtgF27peqtU1@uni-berlin.de>

Fred wrote:
> Hi group
> 
> Ok, so I've got a rather complicated hash-structure that I'd like to 
> find  the size of. Size in consumed bytes of memory. Just because I'm 
> curious.  And I've done the obligatory searches for finding sizes of 
> stuff, and I'm  not much the wiser. Exept I've come to understand that 
> there isn't any  bult-in functionality to do this for such structures.
> 
> So here I am then. Needing help!
> 
> My hash-structure looks something like this:
> 
> $tree = {
>   <key> => {
>     'name' => <str>,
>     'file' => <str>,
>     'architectures' => {
>       <key> => {
>         'name' => <str>,
>         'file' => <str>,
>         'components' => {
>           <key> = {
>             'name' => <str>,
>             'lib'  => <str>
>           }
>         }
>       }
>     }
>   }
> };
> 

Have a look at Devel::Size

HTH - keith


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

Date: Wed, 27 Oct 2004 13:32:26 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Get Win32 Total Physical Memory & Available Physical Memory stats
Message-Id: <417f8748$0$17098$bb690d87@news.main-rheiner.de>

Karim Wall wrote:
> Hello. I've checked CPAN and have searched the net as well and have not been 
> able to find a Perl script or module that will get me the Total Physical 
> Memory and Available Physical Memory stats for a remote system, much less an 
> NT utility. The one utility I found, SYSTEMINFO.EXE can't be used to get 
> info on an NT4 system and I have plenty of them.  I've found some scripts 
> that provide task mgr types of info but that's too much.
> 
> Any ideas?
> 
> Thanks,
> Karim 
> 
> 

An example how to get at WMI information with Win32::OLE can be found here:

    http://tinyurl.com/5f2tn

You have to use Win32::OLE as

  use Win32::OLE qw/in/;

and change the object creation to

    my $wmi = Win32::OLE->GetObject(
       "winmgmts:{impersonationLevel=impersonate,(security)}\\\\<machine>"
    );

Thomas

-- 
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-


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

Date: Wed, 27 Oct 2004 20:45:29 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: Get Win32 Total Physical Memory & Available Physical Memory stats
Message-Id: <2u9g2sF27lsdpU1@uni-berlin.de>

Karim Wall wrote:
> Hello. I've checked CPAN and have searched the net as well and have not been 
> able to find a Perl script or module that will get me the Total Physical 
> Memory and Available Physical Memory stats for a remote system, much less an 
> NT utility. The one utility I found, SYSTEMINFO.EXE can't be used to get 
> info on an NT4 system and I have plenty of them.  I've found some scripts 
> that provide task mgr types of info but that's too much.
> 
> Any ideas?
> 
> Thanks,
> Karim 
> 
> 

Try Perl's Win32::OLE and MS's WMI:

use strict;
use warnings;
use Win32::OLE qw[in];

my $host  = $ARGV[0] || '.';
my $wmi   = Win32::OLE->GetObject( "winmgmts://$host/root/cimv2" )
             or die Win32::FormatMessage( Win32::OLE::LastError() );

my %instances = (
   Win32_PhysicalMemory  => \&get_pmem,
   Win32_PerfRawData_PerfOS_Memory => \&get_amem,
);

my $out;
foreach ( keys %instances ) {
   my $class = $wmi->InstancesOf( $_ );
   $out .= $instances{ $_ }->( $class );
}
print $out;

sub get_pmem {
   my $class = shift;
   my $total;
   $total +=  $_->{Capacity} foreach in($class);
   return "Physical Memory: $total\n";
}

sub get_amem {
   my $class = shift;
   my $amem;
   $amem .= join ' ', $_->{AvailableBytes} foreach in($class);
   return "Available Memory: $amem\n";
}


Good resources:

Basics of using Win32:OLE & WMI:
http://www.ntmag.com/WindowsScripting/Article/ArticleID/19828/19828.html

WMI Win32 clases:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_classes.asp

HTH - keith


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

Date: Wed, 27 Oct 2004 12:55:36 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: help in parsing xml messages
Message-Id: <clo230$15h$1@sun3.bham.ac.uk>



Julie wrote:

> <q path="bugs/bug/bugs/@bug_id=3" match="endswith" true="true" op="and">
>   <q path="bugs/bug/reports/@id=57" match="binary" true="true" op="and">
>     <q path="bugs/bug/reports/@id=21" match="partial" true="true" op="or"/>
>   </q>
> </q>
> 
> I want to parse it so that I can then 
> create a query via
> reading the innermost loop and then the outer loop and then the outer loop,
> and creating sql queries with each pass.
> 
> 
> like.....
> 
> SELECT * from reports r,bugs b where r.id=21 and r.id= 57 and b.bug_id = 3;
> 
> how do I parse the xml to do this ?

If you want to parse XML I'd suggest using an XML parser module from the 
XML::* hierachy on CPAN.

The most popular two (AFAIK) XML::Parser and XML::LibXML are based on 
external XML parser libraries (expat and the GNOME libxml2).

I've never programmed XML::Parser but have used XML::LibXML.  This is 
because I'm doing stuff with XSLT using XML::LibXSTL.  If I wasn't using 
XSLT I'd probably have gone for XML::Parser.



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

Date: 27 Oct 2004 10:13:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: open-perl-ide qustion
Message-Id: <clnsc5$n7i$1@mamenchi.zrz.TU-Berlin.DE>

daniel kaplan <nospam@nospam.com> wrote in comp.lang.perl.misc:
> > hehehe ... I had mastered vi long before I ever heard of an IDE. Alas,
> > the great unwashed masses have forced me to write m$ windoze
> > applications for a living.
> 
> gotta right for the masses, or you don't eat.   1 month ago i would have
> flatout defended MS period.  And in a way I still, lots of what IS today,
> woudln't be if it weren't for them.  However, what they did to me, one month
> ago...ooooh.  words cannot describe.  and this isn't the place for it
> anyways.....

Then why did you post it?  It has zero informative content.

Anno


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

Date: Wed, 27 Oct 2004 10:55:49 GMT
From: "I H H" <iohihuh@INVALID.yahoo.com>
Subject: Re: open-perl-ide qustion
Message-Id: <V8Lfd.28766$k4.555431@news1.nokia.com>


"Charlton Wilbur" <cwilbur@mithril.chromatico.net> wrote in message
news:87lldshpbx.fsf@mithril.chromatico.net...
> >>>>> "SP" == Sherm Pendley <spamtrap@dot-app.org> writes:
>
>     SP> The same applies to Perl docs in general, actually. Trying to
>     SP> memorize them all would be a Herculean task. But it *is* a
>     SP> pretty good idea to familiarize yourself with "perldoc perl",
>     SP> so you'll know what docs are available.
>
> Hell, I've been using Perl for 10 years, and I *still* consult the FAQ
> when I'm trying something I haven't done before.
>
> For a while I got the FAQ-a-day mailings, and that was a pretty
> convenient way to digest it.
>
> Charlton
>
>
> -- 
> cwilbur at chromatico dot net
> cwilbur at mac dot com

The most important thing: Do NOT ask question here! It might disturb the
perlunixemcsvivimfuckinggods in their daydreams.




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

Date: 27 Oct 2004 03:54:10 -0700
From: szpara_ga@o2.pl (Brad)
Subject: Reducing amount of repetative code
Message-Id: <723549b9.0410270254.7d8fbd4d@posting.google.com>

Hello,

  I'm trying to reduce some code which repeats itself
in my program, but I can't find a clever way to do it.
I'm parsing a file which looks like this:

____
;   Key1: Value1
;   Key2: Value2 22:33
;   Key3: Value3

 and so on
____

  The "\d\d:\d\d" with Key2 will always appear.

  I'm parsing this file by using this loop:

_____
while (<>)
{
  if (/^;\s+Key1: (.*)/)
  {
    $object->method('a string connect with Key1' => $1);
  }

  if (/^;\s+Key2: (.*) \d\d:\d\d/)
  {
    $object->method('a string connect with Key2' => $1);
  }

  if (/^;\s+Key3: (.*)/)
  {
    $object->method('a string connect with Key3' => $1);
  }
}
_____


  Each time I find a line which matches the regex I call a method
on an object (neither of which are relevant) with two arguments
based on the result of the match.

  Can anyone think of a way to reduce the amount of code here?
An awful lot of it is repeated.


Thanks very much,
Brad


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

Date: 27 Oct 2004 13:14:10 +0200
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Reducing amount of repetative code
Message-Id: <yzd4qkg4dml.fsf@invalid.net>


szpara_ga@o2.pl (Brad) writes:
> 
>   I'm trying to reduce some code which repeats itself
> in my program, but I can't find a clever way to do it.
> I'm parsing a file which looks like this:

One way which comes to mind is to write some code that generates
the stereotypical code. A good programming language to use for
program-generating programs is of course Perl.

(If you have any reason to modify the generated code by hand after
it's been generated, discrepancies will appear between the true source
and the modified generated code, but that's a subject for another
discussion forum.)



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

Date: Wed, 27 Oct 2004 13:29:21 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Reducing amount of repetative code
Message-Id: <clo0jj$dad$1@nntp.fujitsu-siemens.com>

Brad wrote:
> Hello,
>=20
>   I'm trying to reduce some code which repeats itself
> in my program, but I can't find a clever way to do it.
> I'm parsing a file which looks like this:
>=20
> ____
> ;   Key1: Value1
> ;   Key2: Value2 22:33
> ;   Key3: Value3
>=20
>  and so on
> ____
>=20
>   The "\d\d:\d\d" with Key2 will always appear.
>=20
>   I'm parsing this file by using this loop:
>=20
> _____
> while (<>)
> {
>   if (/^;\s+Key1: (.*)/)
>   {
>     $object->method('a string connect with Key1' =3D> $1);
>   }
>=20
>   if (/^;\s+Key2: (.*) \d\d:\d\d/)
>   {
>     $object->method('a string connect with Key2' =3D> $1);
>   }
>=20
>   if (/^;\s+Key3: (.*)/)
>   {
>     $object->method('a string connect with Key3' =3D> $1);
>   }
> }
> _____
>=20
>=20
>   Each time I find a line which matches the regex I call a method
> on an object (neither of which are relevant) with two arguments
> based on the result of the match.
>=20
>   Can anyone think of a way to reduce the amount of code here?
> An awful lot of it is repeated.

Use an array of hashes:

my @table =3D (
     { Key =3D> "Key1", Postfix =3D> '' },
     { Key =3D> "Key2", Postfix =3D> ' \d\d:\d\d' },
     { Key =3D> "Key3", Postfix =3D> '' }
);
while (my $l =3D <>) {
     foreach (@table) {
         my $key =3D ${$_}{Key};
         my $postfix =3D ${$_}{Postfix};
         if ($l =3D~ m/^;\s+$key: (.*)$postfix/) {
	    $object->method("a string connect with $key" =3D> $1);
	    last;
	}
     }
}

Not much less code, but little repetition and easily expandable.

--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: 27 Oct 2004 11:57:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reducing amount of repetative code
Message-Id: <clo2g2$s35$2@mamenchi.zrz.TU-Berlin.DE>

Brad <szpara_ga@o2.pl> wrote in comp.lang.perl.misc:
> Hello,
> 
>   I'm trying to reduce some code which repeats itself
> in my program, but I can't find a clever way to do it.
> I'm parsing a file which looks like this:
> 
> ____
> ;   Key1: Value1
> ;   Key2: Value2 22:33
> ;   Key3: Value3
> 
>  and so on
> ____
> 
>   The "\d\d:\d\d" with Key2 will always appear.
>
>   I'm parsing this file by using this loop:
> 
> _____
> while (<>)
> {
>   if (/^;\s+Key1: (.*)/)
>   {
>     $object->method('a string connect with Key1' => $1);
>   }
> 
>   if (/^;\s+Key2: (.*) \d\d:\d\d/)
>   {
>     $object->method('a string connect with Key2' => $1);
>   }
> 
>   if (/^;\s+Key3: (.*)/)
>   {
>     $object->method('a string connect with Key3' => $1);
>   }
> }
> _____
> 
> 
>   Each time I find a line which matches the regex I call a method
> on an object (neither of which are relevant) with two arguments
> based on the result of the match.
> 
>   Can anyone think of a way to reduce the amount of code here?
> An awful lot of it is repeated.

Sure.  The price is a more complex regex, because it now has to
cover all the alternatives.  Untested:

    /^;\s+Key(\d): (.*?)(?: \d\d:\d\d)?$/ and
        print "a string connected with Key$1 => $2\n" while <>;

Anno





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

Date: Wed, 27 Oct 2004 07:29:01 -0400
From: Douglas Hunter <dug@plusthree.com>
Subject: Re: Verify a url form a perl script
Message-Id: <clo0or$nkd$0@pita.alt.net>

joe wrote:
> I have been asked to write a perl script that will deploy a web page
> to one of our servers, I was able to do this. But now I want to be
> able to make sure that web page comes up and that we can navagate
> around the pages. Is there some built in functions that will let me do
> this? Can someone point me in the right direction to get started.

WWW::Mechanize is available from the CPAN and is very useful for this 
type of work.

> Thanks,
> Zim

-- Douglas Hunter


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

Date: Wed, 27 Oct 2004 10:36:55 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: What's the seed?
Message-Id: <nq6452-rl4.ln1@osiris.mauzo.dyndns.org>


Quoth ctcgag@hotmail.com:
> Ben Morrow <usenet@morrow.me.uk> wrote:
> > Quoth ctcgag@hotmail.com:
> > > Derek Fountain <nospam@example.com> wrote:
> > > >
> > > > single, steps. I have my suspicions about the quality of my seed!
> > >
> > > my $x=int rand(~0);      #Cause srand to be invoked "naturally"
> > > srand($x);
> > > warn "using $x as seed"; #record seed
> >
> > I think this is incorrect: the seed contains *more* entropy than any
> > given return value from rand(), so this will give you less random
> > numbers than not setting the seed at all.
> 
> But the primary purpose wasn't to create a seed with more entropy
> than perl's default seed, but rather to know what the seed was so it could
> be re-used in the future.

Yes, but (I think) that your method will give a seed with substantially
*less* entropy than the perl default, which given the OP's comments
about the quality of his seed I would take to be a Bad Thing.

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Wed, 27 Oct 2004 13:09:08 +0200
From: aha <aha1@gmx.net>
Subject: Re: Which is the best book for learning OO perl?
Message-Id: <2u9dukF251tq1U1@uni-berlin.de>

Mark Day wrote:

> Any [good] suggestions appreciated.

i found simon cozens' chapter on oop a pretty good entry point:

http://learn.perl.org/library/beginning_perl/3145_Chap11.pdf

a.


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

Date: Wed, 27 Oct 2004 13:37:23 +0100
From: Stewart Campbell CS2002 <scampbel+usenet@cis.strath.ac.uk>
Subject: Re: Why does Perl use more resource than Php?
Message-Id: <417f967f$1@nntphost.cis.strath.ac.uk>

I Report, You Decide wrote:
> A hosting service lungcapage has banned yabb, because it takes too much
> CPU/memory, but phpBB is fine. Is that perl/php or the script itself? why
> perl sucks more resource of a server than php? i thought only mod-perl will
> suck not regular perl.
> 

The major difference there is YABB is flat file, phpBB uses a database.

YABB is older generation software, YABBSe and now SMF replace that, in 
PHP with a database backend.  Many message boards which use flat file 
are banned on a large number of hosts, including UBB, YABB, etc.

Anything with a database backend, is (normaly) going to be much quicker 
and less resource intensive than a flat file version.

Stewart


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

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 V10 Issue 7319
***************************************


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