[28510] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9874 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 21 00:06:13 2006

Date: Fri, 20 Oct 2006 21:05:06 -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           Fri, 20 Oct 2006     Volume: 10 Number: 9874

Today's topics:
        avoid multiple script startup overhead <inetquestion@hotmail.com>
    Re: avoid multiple script startup overhead usenet@DavidFilmer.com
    Re: avoid multiple script startup overhead xhoster@gmail.com
    Re: avoid multiple script startup overhead <veatchla@yahoo.com>
    Re: Efficient Searching xhoster@gmail.com
    Re: FAQ 4.4 Does Perl have a round() function? What abo usenet@DavidFilmer.com
    Re: Firefox Won't Execute My Perl Script robic0
    Re: FTP to a windows file share? <veatchla@yahoo.com>
    Re: Parsing and regex <d_toth@ltu.edu>
    Re: Perl ActiveX: A VBA string passed to my control is  robic0
    Re: Perl ActiveX: A VBA string passed to my control is  robic0
    Re: perlembed - how to get 'use constant' values <wahab@chemie.uni-halle.de>
    Re: perlembed - how to get 'use constant' values <sisyphus1@nomail.afraid.org>
        Sorting Data in Two Columns <alison@logicsaysNOSPAM.com>
    Re: Sorting Data in Two Columns <john@castleamber.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 20 Oct 2006 15:31:18 -0700
From: "inetquestion" <inetquestion@hotmail.com>
Subject: avoid multiple script startup overhead
Message-Id: <1161383478.260093.160410@i42g2000cwa.googlegroups.com>

I'd like to get some opinions on possible new solutions to handle a
problem we are seeing on our solaris servers due to various cron jobs
aligning at various times throughout the hour.  The obvious answer of
changing the times so they do not line up really isn't feasible and
wont really buy us much in the long term.  What we've see is the
spawning of new perl and ksh interpreters to run various scripts is
what is consuming the bulk of the cpu.  One idea I've been
contimplating for perl is
having one master script running to avoid starting the interpreter up
each minute.  What I'm unclear about is the ability to fork off entire
scripts from there.  Will this use an instance of the existing
interpreter, or just spawn another instance.  I'm not sure if this
approach even begins to address
the same concerns with ksh scripts.  Any suggestions along these lines
or completely new ideas altogether?

Regards,

-Inet



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

Date: 20 Oct 2006 15:44:05 -0700
From: usenet@DavidFilmer.com
Subject: Re: avoid multiple script startup overhead
Message-Id: <1161384245.062294.251820@f16g2000cwb.googlegroups.com>

inetquestion wrote:
> to avoid starting the interpreter up each minute.

Your cron runs at one-minute intervals?

Is it even necessary to stop the program?  Why not just let the program
run continuously in a loop, with a sleep() to slow it down?  Something
like this:

while (1) {
   print "Here we go\n";
   #do some stuff
   sleep 60;
}

You could put the program in your inittab to start automatically upon
system statup and respawn if it goes down for some reason.

--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



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

Date: 20 Oct 2006 23:37:34 GMT
From: xhoster@gmail.com
Subject: Re: avoid multiple script startup overhead
Message-Id: <20061020193906.162$Lf@newsreader.com>

"inetquestion" <inetquestion@hotmail.com> wrote:
> I'd like to get some opinions on possible new solutions to handle a
> problem we are seeing on our solaris servers due to various cron jobs
> aligning at various times throughout the hour.  The obvious answer of
> changing the times so they do not line up really isn't feasible and
> wont really buy us much in the long term.  What we've see is the
> spawning of new perl and ksh interpreters to run various scripts is
> what is consuming the bulk of the cpu.  One idea I've been
> contimplating for perl is
> having one master script running to avoid starting the interpreter up
> each minute.

I don't understand.  You must be starting the intepreter up dozens of times
a second, not once a minute, to be having a serious problem.


> What I'm unclear about is the ability to fork off entire
> scripts from there.  Will this use an instance of the existing
> interpreter, or just spawn another instance.

That depends on how you do it.  If you do:

my $pid = fork;
defined $pid or die "didn't fork $!";
$pid and exec "perl new_program.pl";

Then you will start up another interpreter, with all the resource hogging
that that implies (but also with the new, clean interpreter and namespace.)

If you do:

my $pid = fork;
defined $pid or die "didn't fork $!";
unless ($pid) {
  do "new_program.pl"; #error checking should be done, but isn't.
  exit;
};

Then it rapidly forks a new interpreter (rather than going through the
trouble of starting one from scratch), but that means the name space
doesn't get completely cleared out (but the lexicals do).  Also,
new_program.pl gets recompiled each time, which can be slow if it is big,
but probably not as slow as spawning an interpreter from scratch.  You need
to do something with $SIG{CHLD} or wait to avoid zombies.

Better yet would be to do:

use new_program.pm;
#...
my $pid=fork;
defined $pid or die "didn't fork $!";
unless ($pid) {
  exec_new_program_code();
  exit;
};

But then new_program needs to be designed to be used as a module not an
"entire script" as you specified.


> I'm not sure if this
> approach even begins to address
> the same concerns with ksh scripts.  Any suggestions along these lines
> or completely new ideas altogether?

You've already taken one step back to rethink whether you need to spawn
scripts from scratch at a huge rate, but fork them instead.  I think you
should take a step further back and ask if you need to fork them at a huge
rate, either.   Rather than having thousands of processes doing one thing
each, why not have 10 processes doing 100 things each, either sequentially
(if CPU bound) or using IO::Select (If not CPU bound)?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Fri, 20 Oct 2006 21:23:27 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: avoid multiple script startup overhead
Message-Id: <12jj14no9mdbfc7@news.supernews.com>

inetquestion wrote:
> I'd like to get some opinions on possible new solutions to handle a
> problem we are seeing on our solaris servers due to various cron jobs
> aligning at various times throughout the hour.  The obvious answer of
> changing the times so they do not line up really isn't feasible and
> wont really buy us much in the long term.  What we've see is the
> spawning of new perl and ksh interpreters to run various scripts is
> what is consuming the bulk of the cpu.  One idea I've been
> contimplating for perl is
> having one master script running to avoid starting the interpreter up
> each minute.  What I'm unclear about is the ability to fork off entire
> scripts from there.  Will this use an instance of the existing
> interpreter, or just spawn another instance.  I'm not sure if this
> approach even begins to address
> the same concerns with ksh scripts.  Any suggestions along these lines
> or completely new ideas altogether?
> 
> Regards,
> 
> -Inet
> 

Are you trying to prevent the same script from running multiple times? 
For example, script A is started every minute via cron but at times, 
script A executes for 2 minutes.

Can you modify the scripts?  If so, create a lock file containing it's 
pid and delete it when the script finishes.  Then when the script starts 
up, it checks if a lock files exists.   If it does exist, the script 
simply exits.  Or continue to execute if the pid contained in the lock 
file no longer exists on the system.  Obviously you would re-write the 
lock file with the updated pid.

I realize this could create a race condition in check for the lock file, 
but it is one option to consider.

-- 

Len


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

Date: 21 Oct 2006 01:13:46 GMT
From: xhoster@gmail.com
Subject: Re: Efficient Searching
Message-Id: <20061020211519.535$QA@newsreader.com>

HaroldWho <hlarons@yahoo.com> wrote:
> On Wed, 18 Oct 2006 18:40:11 -0000, HaroldWho wrote in
> comp.lang.perl.misc:
> > I have an 2.7 Mb, 75,000 line comma-separated ASCII file with each line
> > of the form: integer_1,integer_2,string_1,string_2
> >
> > Given a target integer, I need to search for the record for which
> >       target >= integer_1 && target <= integer_2.
>
> To answer some of the many questions posed by all the replies:
>
> 1. Ranges do not overlap.
 ...
> There seems to be two ideas here for me to followup on:
>
> a) A binary search (full disclosure: I'm not a CS person, so I'll need to
> learn more about this).

Assuming @x holds an array of records (each record being a 4-element
array, [start,end,string1,string2]) and that it is already sorted by
the starting point (which, since they are not overlapping, means they
must are automatically sorted by end point, to), then here is an example
binary search.  It works with fp, not integers, and it might not deal with
ties the way you would want it to:

### Don't use on an empty @x!
  my $low=0;
  my $high=$#x;
  while ($high>$low) {
    my $mid=int ( ($high+$low)/2);
    if ($x[$mid][1] >= $target) {
       $high=$mid;
    } else {
       $low=$mid+1;
    }
  };
### At this point, $low indexes the record which contains $target, if
### there is such a record.  (Otherwise, it indexes a record near where
### the right one would be, were it there.)
### So, do a final check to see if the record $x[$low] qualifies

  my $found = scalar grep +($_->[0]<$target and $_->[1]>$target), $x[$low];
  print $found? "found at $low\n" : "not found\n";

> b) The suggestion by Mirco Wahab. Particular thanks to you for trying to
> read my mind.

That was just an alternative way to parse the data.  It won't result in a
meaningful performance improvement.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 20 Oct 2006 15:10:37 -0700
From: usenet@DavidFilmer.com
Subject: Re: FAQ 4.4 Does Perl have a round() function? What about ceil() and floor()? Trig functions?
Message-Id: <1161382237.744368.148480@h48g2000cwc.googlegroups.com>

PerlFAQ Server wrote:
>             $floor  = floor(3.5);  # 3

I was wondering why on earth anyone would use a posix method to do what
the builtin int() function does  (besides folks who can't shake the C
habit).  I wondered what the difference was  (if any). So I read the
docs a bit and discovered:

> machine representations of floating point numbers can sometimes
> produce counterintuitive results.  For example, "int(-6.725/0.025)" produces
> -268 rather than the correct -269; that's because it's really more like
> -268.99999999999994315658 instead.  Usually, the "sprintf", "printf", or the
> "POSIX::floor" and "POSIX::ceil" functions will serve you better than will int().

I never realized that!

--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



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

Date: Fri, 20 Oct 2006 18:20:40 -0700
From: robic0
Subject: Re: Firefox Won't Execute My Perl Script
Message-Id: <k6tij2t53qu14o3drn2i88ifgkvmtav9k2@4ax.com>

On 11 Oct 2006 18:51:20 -0700, "Matt Garrish" <mgarrish@gmail.com> wrote:

>
>Mirco Wahab wrote:
>
>> Thus spoke Matt Garrish (on 2006-10-11 23:08):
>> > Mirco Wahab wrote:
>> >> Thus spoke Sherm Pendley (on 2006-10-11 16:36):
>> >> > "Matt Garrish" <mgarrish@gmail.com> writes:
>> >> >> Sherm Pendley wrote:
>> >> >>> robic0 writes:
>> >> >>> > Hey Jew there must be something that is Perl used heavily in page production.
>> >> >>> > Jeez what could it be. Oh well, it must be a fuckin secret........
>> >> >>> 'PerlScript' ne 'Perl'. Perl is used heavily. PerlScript - ActiveState's
>> >> >> True and not so true. ...
>> >> > 'very rarely' ne 'never'. :-)
>> >> > ...
>> >> > Robic0 took Jürgen's statement as saying that *Perl itself* is rarely used.
>> >> > I guess he just can't resist an opportunity to make a fool of himself in
>> >> > public.
>> >
>> >> [trust no one but this ... (from the "riddle of the steel")]
>> >> ...  like the swords in warfare died with the men who lived by them ...
>> >
>> > Sorry, are you trying to be prophetic? I haven't followed the group a
>> > lot lately, but you seem to have a thing for sword metaphors.
>>
>> IIRC did I do *one* another thing like that
>> where I tried to be funny or so ...
>>
>> > If you want to prophesy the demise of Perl get in line with
>> > everyone who's been predicting its doom since the advent of
>> > the web.
>>
>> Actually, the "advent of the web" was (afaik) in
>> coincidence with the advent of Perl5 and it's CGI
>> revolution of things.
>>
>> BTW, I always tell younger people to use Perl and
>> give them examples¹ for this and for that. When they
>> leave and go into some other context, they will never
>> do any Perl out there, they'd do Ruby or Python or
>> the like - if they don't get into Java in the first
>> place.
>>
>> Why is that? Am I wrong and short sighted? Don't
>> I see the whole thing? As much as I like to work
>> with Perl, as dark I foresee its perspectives.
>>
>
>I've never applied for a job where Perl was a primary requirement, and
>I've never had a job where Perl wasn't an intergral part of the system.
>What does that tell you?
>
>And really, so what if it dies off? If it does it will be because
>there's something ever better and simpler to use to accomplish the
>myriad of tasks Perl can, but that something hasn't come and your
>foretelling Perl's demise with nothing to back it up but perceived
>foresight isn't going to make that day come any sooner.
>
>So rather than lament something that I doubt is going to happen for a
>good long time, why don't you just enjoy using the language for what it
>makes simpler in your life.
>
>Matt

Matt, you can apply to Google Inc, in Santa Monica, CA.,
where they do massive Perl in page production, if thats
what you want to do. They will let you work off-site too.

I think Perl is as good as the meterred demand usage of such.
If Google gods do nothing but Perl (massive Perl OOP) for page
production, I don't think Perl is going away for many, many years!!!

Ahhhh, imo of course...

robic0


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

Date: Fri, 20 Oct 2006 21:12:30 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: FTP to a windows file share?
Message-Id: <12jj0g5o4edq133@news.supernews.com>

MattJ83 wrote:
>> C:\temp>type \\Violet\Infotop\UNC.txt
>> This is a text file on another PC
>>
> 
> ^^^ are you just creating a txt file here in temp? but with
> '\\Violet\Infotop\UNC.txt' as a filename?
> 
>> C:\temp>type test.pl
>> #!perl
>> use strict;
>> use warnings;
>> open my $fh, '<', '//Violet/Infotop/UNC.txt'
>>    or die "Unable to open file because $!";
>> while (<$fh>) { print; }
>> close $fh;
>>
>>
>> C:\temp>test.pl
>> This is a text file on another PC
> 
> This code is just creating a file called UNC.txt in temp and then
> running some code from temp to open the file isn't it?
> 
> Im trying to run the script from a unix server (bash shell) and trying
> to get the same result at the moment (ie - open a file from a windows
> file share in unix).
> Eventually - getting the data passed from unix to this windows file
> share.
> 

I just started to read this thread so I'm sorry if this was discussed 
and I just missed it.  I'm guessing that windows server ukbr1234 has a 
shared directory called 'shared' with a sub-directory called test.  This 
share is physically located on the server, for example, at d:\share\test 
on ukbr1234.  Correct?

You need to copy some unix files to \\ukbr1234\share\text.  Correct?

Is ftp installed on the windows server?
If not, can ftp be installed on this server?

If ftp is or can be installed, then you can create an virtual ftp 
directory pointing to d:\share\test.  The unix server can then ftp to 
the windows server just like you ftp to a unix server using Net::FTP. 
The windows share \\ukbr1234\share\test will contain the unix files when 
accessing from your desktop.  Is this what you are looking for?

-- 

Len


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

Date: 20 Oct 2006 19:35:30 -0700
From: "toof57" <d_toth@ltu.edu>
Subject: Re: Parsing and regex
Message-Id: <1161398130.871527.263200@i42g2000cwa.googlegroups.com>

John,
Yes you are absolutely right. If found a section on that in a search
and it worked like a charm. So now I am over hurdle #2 and heading down
the home stretch. I was just too tired last night, but this morning, it
all clicked. Perl is a really cool language and the more I program in
it, the more I enjoy it.

Thanks for your help!

David

John Bokma wrote:
> "toof57" <d_toth@ltu.edu> wrote:
>
> > Can you assign a regex to a variable
>
> perldoc perlop and check out qr// in section 'Regexp Quote-Like Operators'
>
>
> --
> John                Experienced Perl programmer: http://castleamber.com/
>
>           Perl help, tutorials, and examples: http://johnbokma.com/perl/



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

Date: Fri, 20 Oct 2006 18:56:46 -0700
From: robic0
Subject: Re: Perl ActiveX: A VBA string passed to my control is treated as a doubel-quoted string
Message-Id: <3fuij295hlcdj7evfsnf5pcpg06duc6bva@4ax.com>

On 10 Oct 2006 06:41:16 -0700, david.f.jenkins@usa.net wrote:

>
>robic0 wrote:
>> On 9 Oct 2006 16:29:02 -0700, david.f.jenkins@usa.net wrote:
>>
>> >
>> >david.f.jenkins@usa.net wrote:
>> >> Hi: I'm very new at all things Perl, so I may have my terminology
>> >> boogered up.  Here goes:
>> >>
>> >> I have written a Perl ActiveX control that's suppose to do some regular
>> >> expression operations on data and patterns sent from VBA (as VT_BSTR).
>> >> Everything seems to be working ok, except that it appears the pattern
>> >> arguments to Perl are being treated as double-quoted strings.
>> >>
>> >> Here is a string I'm passing in from VBA (and also using when testing
>> >> using a Perl call):
>> >>
>> >> "(\s)(-{1,2}|-)(\s)" (the character after the vertical bar is an en
>> >> dash.)
>> >>
>> >> When I use this string in VBA, I get erroneous resutls from my control.
>> >> If I write a call in Perl, using the same arguments as I use in VBA, I
>> >> also get erroneous results.  However, if I change the Perl argument
>> >> string to a single-quoted string, then I get correct results.  Alos, if
>> >> I change the \s's to blanks and use double quotes, it works ok.  If I
>> >> leave the \s's in and use single-quotes, it works ok.  But as is -
>> >> unh-unh.
>> >>
>> >> Do I have interpolative context problems?  The larger question I have,
>> >> is how can I coerce the control to treat the string that's being passed
>> >> in as single-quoted string?  Or is there perhaps some easier solution?
>> >
>> >I found this in a post to this group from 1996 - it pretty much sums up
>> >my problem, I think:
>> >
>> >"If a variable [function argument, in my case]  has a string which will
>> >be interpreted as a double-quoted string, is there a way to cause the
>> >variable to be interpreted as a single-quoted string?
>> >"
>>
>> So you are sending a regex string from VB embedded in Power Point to
>> a ActiveX (com object) control that has an embedded Perl regex lib.
>>
>> Hmm, interesting. Seems pretty high power stuff for someone who doesen't
>> know what single/double quoted (in-solution) strings are.
>>
>> Perl regex has its own set of escape characters like any other parser.
>> The reason the single '' quotes worked for you is that '\s' is \s
>> in any language. The \ is the universal escape character.
>>
>> To make '\s' come out the other end of the pipe you have to use "\\s"
>> double flavor. It then goes into solution as \s. In solution means after
>> the parser transforms it and its in memory and will never get changed
>> unless it comes out and posibly goes back in modified.
>>
>> Perl regex has a further set of escape characters. Using the universal '\'
>> character you should, on the VBA side, escape all of Perls regex escape
>> characters.
>>
>> Below is a sample Perl code to escape all regex from a perl string.
>> You need to extrapolate this to the VBA side.
>>
>> Good luck, you seem to be in total misery......
>> robic0
>>
>> ps. just escape everything..... literally!
>>
>> ------------------------------------
>>
>>
>> use strict;
>> use warnings;
>>
>> my ($pat_convert);
>>
>> $pat_convert  = convertPatternMeta ( 'Hello...?' );
>> showMatchResult ($pat_convert, 'Hello...? this is a big string x');
>> showMatchResult ($pat_convert, 'Oh Hello x');
>>
>> $pat_convert  = convertPatternMeta ( '*?+' );
>> showMatchResult ($pat_convert, 'Hello...? this (*?+) is a big string x');
>> showMatchResult ($pat_convert, '*?+ and so is this');
>>
>> ## ------------------------------------
>> ## Helpers
>> ##
>> sub convertPatternMeta
>> {
>>     my ($pattern) = shift;
>>     my @regx_esc_codes =
>>     (
>>     "\\", '/', '(', ')', '[', ']', '?', '|',
>>     '+', '.', '*', '$', '^', '{', '}', '@'
>>     );
>>     foreach my $tc (@regx_esc_codes) {
>>         # code template for regex
>>         my $xxx = "\$pattern =~ s/\\$tc/\\\\\\$tc/g;";
>>         eval $xxx;
>>         if ($@) {
>>             # the compiler will show the escape char, add
>>             # it char to @regx_esc_codes
>>             $@ =~ s/^[\s]+//s; $@ =~ s/[\s]+$//s;
>>             die "$@";
>>         }
>>     }
>>     return $pattern;
>> }
>> ##
>> sub showMatchResult
>> {
>>     my ($pattern, $string) = @_;
>>     my $result_txt = '';
>>     my ($result) = $string =~ /$pattern/;
>>     if ($result) { $result_txt = 'DOES match'}
>>     else { $result_txt = 'Does NOT match' }
>>     print "\nString:      $string\n$result_txt\nPattern:     $pattern\n";
>> }
>
>Thanks so very much.
>
>Over the evening, I discovered this:  I have unnecessarily compounded
>the problem by writing some Perl calls and using double-quoted strings.
> Because of interpolation, I was misled into thnking that the calls
>from VBA were being treated similarly.  On the VBA side, I'm using some
>symbols in both search and replacement strings and I need to do some
>back-flips to handle those properly in the Perl/ActiveX environment, as
>well as properly handling the escape considerations.
>
>At any rate, all is now well, and I very much appreciate the time you
>obviously expended in helping me out.

If you take out the "eval" and hardcode, you can pass dynamic created regex
strings from the VB(app) side, which is a feature you will use in the future.
A little extra time doing this will save you headaches in the long run.

Thanks but I didn't spend time on it, I posted it here over 2 years ago.
It fixes the meta quote option. Its now ripped off code, some call it
quotemeta() function. I cut it down and pasted it from a 12,000 line
Perl code I'd written for a major anti-virus company.

good luck, as my indian dentist says: "No pain", "No pain" !!!

robic0



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

Date: Fri, 20 Oct 2006 19:05:16 -0700
From: robic0
Subject: Re: Perl ActiveX: A VBA string passed to my control is treated as a doubel-quoted string
Message-Id: <l00jj2pqr3gumtc8a0k9ej6ctst22g316j@4ax.com>

On Fri, 20 Oct 2006 18:56:46 -0700, robic0 wrote:

>On 10 Oct 2006 06:41:16 -0700, david.f.jenkins@usa.net wrote:
>
>>
>>robic0 wrote:
>>> On 9 Oct 2006 16:29:02 -0700, david.f.jenkins@usa.net wrote:
>>>
>>> >
>>> >david.f.jenkins@usa.net wrote:
>>> >> Hi: I'm very new at all things Perl, so I may have my terminology
>>> >> boogered up.  Here goes:
>>> >>
>>> >> I have written a Perl ActiveX control that's suppose to do some regular
>>> >> expression operations on data and patterns sent from VBA (as VT_BSTR).
>>> >> Everything seems to be working ok, except that it appears the pattern
>>> >> arguments to Perl are being treated as double-quoted strings.
>>> >>
>>> >> Here is a string I'm passing in from VBA (and also using when testing
>>> >> using a Perl call):
>>> >>
>>> >> "(\s)(-{1,2}|-)(\s)" (the character after the vertical bar is an en
>>> >> dash.)
>>> >>
>>> >> When I use this string in VBA, I get erroneous resutls from my control.
>>> >> If I write a call in Perl, using the same arguments as I use in VBA, I
>>> >> also get erroneous results.  However, if I change the Perl argument
>>> >> string to a single-quoted string, then I get correct results.  Alos, if
>>> >> I change the \s's to blanks and use double quotes, it works ok.  If I
>>> >> leave the \s's in and use single-quotes, it works ok.  But as is -
>>> >> unh-unh.
>>> >>
>>> >> Do I have interpolative context problems?  The larger question I have,
>>> >> is how can I coerce the control to treat the string that's being passed
>>> >> in as single-quoted string?  Or is there perhaps some easier solution?
>>> >
>>> >I found this in a post to this group from 1996 - it pretty much sums up
>>> >my problem, I think:
>>> >
>>> >"If a variable [function argument, in my case]  has a string which will
>>> >be interpreted as a double-quoted string, is there a way to cause the
>>> >variable to be interpreted as a single-quoted string?
>>> >"
>>>
>>> So you are sending a regex string from VB embedded in Power Point to
>>> a ActiveX (com object) control that has an embedded Perl regex lib.
>>>
>>> Hmm, interesting. Seems pretty high power stuff for someone who doesen't
>>> know what single/double quoted (in-solution) strings are.
>>>
>>> Perl regex has its own set of escape characters like any other parser.
>>> The reason the single '' quotes worked for you is that '\s' is \s
>>> in any language. The \ is the universal escape character.
>>>
>>> To make '\s' come out the other end of the pipe you have to use "\\s"
>>> double flavor. It then goes into solution as \s. In solution means after
>>> the parser transforms it and its in memory and will never get changed
>>> unless it comes out and posibly goes back in modified.
>>>
>>> Perl regex has a further set of escape characters. Using the universal '\'
>>> character you should, on the VBA side, escape all of Perls regex escape
>>> characters.
>>>
>>> Below is a sample Perl code to escape all regex from a perl string.
>>> You need to extrapolate this to the VBA side.
>>>
>>> Good luck, you seem to be in total misery......
>>> robic0
>>>
>>> ps. just escape everything..... literally!
>>>
>>> ------------------------------------
>>>
>>>
>>> use strict;
>>> use warnings;
>>>
>>> my ($pat_convert);
>>>
>>> $pat_convert  = convertPatternMeta ( 'Hello...?' );
>>> showMatchResult ($pat_convert, 'Hello...? this is a big string x');
>>> showMatchResult ($pat_convert, 'Oh Hello x');
>>>
>>> $pat_convert  = convertPatternMeta ( '*?+' );
>>> showMatchResult ($pat_convert, 'Hello...? this (*?+) is a big string x');
>>> showMatchResult ($pat_convert, '*?+ and so is this');
>>>
>>> ## ------------------------------------
>>> ## Helpers
>>> ##
>>> sub convertPatternMeta
>>> {
>>>     my ($pattern) = shift;
>>>     my @regx_esc_codes =
>>>     (
>>>     "\\", '/', '(', ')', '[', ']', '?', '|',
>>>     '+', '.', '*', '$', '^', '{', '}', '@'
>>>     );
>>>     foreach my $tc (@regx_esc_codes) {
>>>         # code template for regex
>>>         my $xxx = "\$pattern =~ s/\\$tc/\\\\\\$tc/g;";
>>>         eval $xxx;
>>>         if ($@) {
>>>             # the compiler will show the escape char, add
>>>             # it char to @regx_esc_codes
>>>             $@ =~ s/^[\s]+//s; $@ =~ s/[\s]+$//s;
>>>             die "$@";
>>>         }
>>>     }
>>>     return $pattern;
>>> }
>>> ##
>>> sub showMatchResult
>>> {
>>>     my ($pattern, $string) = @_;
>>>     my $result_txt = '';
>>>     my ($result) = $string =~ /$pattern/;
>>>     if ($result) { $result_txt = 'DOES match'}
>>>     else { $result_txt = 'Does NOT match' }
>>>     print "\nString:      $string\n$result_txt\nPattern:     $pattern\n";
>>> }
>>
>>Thanks so very much.
>>
>>Over the evening, I discovered this:  I have unnecessarily compounded
>>the problem by writing some Perl calls and using double-quoted strings.
>> Because of interpolation, I was misled into thnking that the calls
>>from VBA were being treated similarly.  On the VBA side, I'm using some
>>symbols in both search and replacement strings and I need to do some
>>back-flips to handle those properly in the Perl/ActiveX environment, as
>>well as properly handling the escape considerations.
>>
>>At any rate, all is now well, and I very much appreciate the time you
>>obviously expended in helping me out.
>
>If you take out the "eval" and hardcode, you can pass dynamic created regex
>strings from the VB(app) side, which is a feature you will use in the future.
>A little extra time doing this will save you headaches in the long run.
>
>Thanks but I didn't spend time on it, I posted it here over 2 years ago.
>It fixes the meta quote option. Its now ripped off code, some call it
>quotemeta() function. I cut it down and pasted it from a 12,000 line
>Perl code I'd written for a major anti-virus company.
>
>good luck, as my indian dentist says: "No pain", "No pain" !!!
>
>robic0

BTW, not being very VB enthusiastic, I could write the C++ equivalent
in 5 minutes if you need it.....

robic0


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

Date: Sat, 21 Oct 2006 00:12:56 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: perlembed - how to get 'use constant' values
Message-Id: <ehbur8$4na$1@mlucom4.urz.uni-halle.de>

Thus spoke Mirco Wahab (on 2006-10-20 14:57):

> But, what I didn't manage is to access
> some "Variables" defined by the
> "use constant" pragma.
> 
> 
> --- Perl ----
>    ...
>    use constant R_Q => 2.5;
>    ...
> 
> 
> --- C -------
>    ...
>    if( (sv=get_sv("main::R_Q", FALSE)) != 0 )
>       ...
>    ...

Uhh, a 'constant' is just a sub and returns everything
written behind the '=>',

   use constant WTF => qw' the good the bad and the ugly ';
   print join "\n", WTF;

prints:

   the
   good
   the
   bad
   and
   the
   ugly


there is even an accessor (cv_const_sv) for that,
so the solution  was straightforward as
long as I figured correctly (not sure):

--- Perl ----
   ...
   use constant R_Q => 2.5;


--- C ---------
   CV *cv;
   SV *sv;
   double r_q;
   ...
   if( (cv = get_cv("main::R_Q", FALSE)) != 0 )
      if( (sv = cv_const_sv(cv)) != 0 )
         r_q = SvNV( sv );
   ...


Is there anything else one has to think about here?


Regards & thanks

Mirco


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

Date: Sat, 21 Oct 2006 12:34:21 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: perlembed - how to get 'use constant' values
Message-Id: <45398846$0$2917$afc38c87@news.optusnet.com.au>


"Mirco Wahab" <wahab@chemie.uni-halle.de> wrote in message
 .
 .
>
> Uhh, a 'constant' is just a sub
 .
 .
>    CV *cv;
>    SV *sv;
>    double r_q;
>    ...
>    if( (cv = get_cv("main::R_Q", FALSE)) != 0 )
>       if( (sv = cv_const_sv(cv)) != 0 )
>          r_q = SvNV( sv );
 .
 .

Fwiw (probably not a lot) you can also access the value with 'call_pv'. (See
perldoc perlcall):

     dSP;
     int count;
     double r_q;
     PUSHMARK(SP);
     count = call_pv("main::R_Q", G_SCALAR|G_NOARGS);

     if (count != 1)
        croak("Big trouble\n");

     SPAGAIN;

     r_q = POPn;

Cheers,
Rob




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

Date: Sat, 21 Oct 2006 01:41:04 +0100
From: "Alison" <alison@logicsaysNOSPAM.com>
Subject: Sorting Data in Two Columns
Message-Id: <g-SdnVW7W8zi8aTYnZ2dneKdnZydnZ2d@bt.com>

Hello,

I'm having a bit of difficulty in the following and hoping for a solution.
Have Googled over the last few days on and off.

Two columns of data; Referrers && Hits.  Rows are Referrer followed by total
number of hits from the referrer.

Data is stored in an array with two elements per record.

$pointer = record_number * 2;

$current_referrer = $array[$pointer];
$current_hits = $array[pointer+1];

Please may I ask how I would sort the rows based on the hits, in numerical
order?  Or alternatively, sorting the rows alphabetically based on the
referrers.

It's the keeping the two elements together as they are sorted where I'm
getting really confused.  I can easily sort a single column of strings or
numbers, but not two columns.

Perl/cgi/'C isn't my first language, microcontroller assembly language is.
So my method would otherwise result in ALOT of manual coding.  I'm hoping
this will only take just a couple of lines high level and be processor usage
friendly.

Many thanks,

Alison




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

Date: 21 Oct 2006 01:24:10 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Sorting Data in Two Columns
Message-Id: <Xns9862CF8A3589Bcastleamber@130.133.1.4>

"Alison" <alison@logicsaysNOSPAM.com> wrote:

> Hello,
> 
> I'm having a bit of difficulty in the following and hoping for a
> solution. Have Googled over the last few days on and off.
> 
> Two columns of data; Referrers && Hits.  Rows are Referrer followed by
> total number of hits from the referrer.
> 
> Data is stored in an array with two elements per record.
> 
> $pointer = record_number * 2;
> 
> $current_referrer = $array[$pointer];
> $current_hits = $array[pointer+1];

I recommend to use a different structure. If you want to know the number 
of hits per referer [sic], use a hash with the referer the key, and the 
hits the value.



my %referer_hits;

open my $fh, ....    	# open access_log for reading

while ( my $line = <$fh> ) {

   ... # extract referer

   $referer_hits{ $referer }++
}

close $fh ...

# Sorting on hits high -> low
for my $referer ( sort { $referer_hits{ $b } <=> $referer_hits{ $a } }
    	keys %referer_hit ) {

    	printf "%6d %s\n", $referer_hits{ $referer }, $referer;
}

untested, and you have to fill in the blanks.



If you're analyzing log files:

http://johnbokma.com/perl/google-search-cloud.html

and

http://johnbokma.com/perl/googlebot-statistics.html

might give you some additional ideas.


-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

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


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