[22089] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4311 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 24 21:05:38 2002

Date: Tue, 24 Dec 2002 18: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           Tue, 24 Dec 2002     Volume: 10 Number: 4311

Today's topics:
    Re: File::Find module ; want to resume search from poin <bik.mido@tiscalinet.it>
    Re: File::Find module ; want to resume search from poin (Mitchell Laks)
        Hash sort <No_Mail_Address@cox.net>
    Re: Hash sort <steven.smolinski@sympatico.ca>
    Re: Hash sort <uri@stemsystems.com>
    Re: Hash sort <No_Mail_Address@cox.net>
        help missing module  <jaster@home.still>
    Re: How to begin a File Comparison btam01@ccsf.edu
    Re: How to begin a File Comparison <bwalton@rochester.rr.com>
    Re: Lotus Notes OLE: Help on avoiding undefined value a <eric.ehlers@btopenworld.com.spamoff>
    Re: Lotus Notes OLE: Help on avoiding undefined value a <goldbb2@earthlink.net>
    Re: missing Net/SMTP and PPM search shows nothing. <bwalton@rochester.rr.com>
        negation and or (R.Noory)
    Re: negation and or <bwalton@rochester.rr.com>
    Re: negation and or <mgjv@tradingpost.com.au>
        ppm vs. perl -MCPAN -e shell  <lou.moran@gellerandwind.com>
    Re: ppm vs. perl -MCPAN -e shell  <bwalton@rochester.rr.com>
    Re: Processing \0xx in nonliteral strings <goldbb2@earthlink.net>
    Re: Simple array problem <bwalton@rochester.rr.com>
        Small databases <bobx@linuxmail.org>
    Re: Small databases <bwalton@rochester.rr.com>
        Thanks -- Re: SOS: evaluate a string/function jg10@duke.edu
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 24 Dec 2002 20:59:30 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: File::Find module ; want to resume search from point of failure.
Message-Id: <6ceh0vcs7q2ucd5i24001m22gu22mklt98@4ax.com>

On 22 Dec 2002 13:47:54 -0800, mlaks2000@yahoo.com (Mitchell Laks)
wrote:

>Dear Perl Gurus

Well I'm not a "Perl Guru", but I feel like suggesting my 2 cents...

>I am using File::Find to execute a command on the files in a directory
>(i call the command &wanted for cultural reasons :) ).
>
>However if an exception  is raised, and my search gets aborted, and if
>i keep track of what file was acted upon when the search was
>cancelled, is there a way to resume the search and execution from the
>point of failure and avoid searching through all of the (530,000)
>files again from the beginning?

In addition to the excellent advices given to you by other posters and
keeping in mind their remarks, why don't you use the "postprocess" and
"preprocess" keys (see 'perldoc File::Find') to set, if possible, a
file (e.g. 'File_Find.dun') per directory to indicate that it has been
fully processed and respectively to stop searching it?

Or better you could store in such a file information about the files
that have already been processed and grep them out from the argument
list of the "preprocess" sub (be careful with directories!!).

Well, at least you could develop one of these ideas and adapt it to
your needs.


HTH,
Michele
-- 
>It's because the universe was programmed in C++.
No, no, it was programmed in Forth.  See Genesis 1:12:
"And the earth brought Forth ..."
- Robert Israel on sci.math, thread "Why numbers?"


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

Date: 24 Dec 2002 13:55:50 -0800
From: mlaks2000@yahoo.com (Mitchell Laks)
Subject: Re: File::Find module ; want to resume search from point of failure.
Message-Id: <ab3b13db.0212241355.3979f225@posting.google.com>

You guys are amazing!!!!!!
I am completely overwhelmed by your generosity and helpfulness. 
You have completely covered all the aspects that I needed to learn,
both the wonderful script from Benjamin - which was exactly what i
needed - and all it taught me ->
i learned about the _ operator the pseudo filehandle which keeps the
lstat and stat info that was exposed at the last call to stat! cool
(found a description in effective perl after wondering why you didnt
use teh default $_ ). cool. also thanks for the example of how the
prune function can be used!

To Anno and Bart - thanks very much to you now i understand the find
algorithm. I never would have guessed about how readdir() works - so
now that clarifies that too.
My deepest gratitude. By the way the first run crashed after copying
2800 some od directories, my fault - i shouldnt have played with the
machine after 4 days of hands off... I will now try the scripts and
use the knowledge!!!
thank you all.
mitchell


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

Date: Tue, 24 Dec 2002 22:15:19 GMT
From: Fred <No_Mail_Address@cox.net>
Subject: Hash sort
Message-Id: <3E08DCDF.CE4BEEC7@cox.net>

Hello there,

I have a hash: 
	 $mailrc{$name} = $address ;    

I know how to sort and print it with a foreach-loop:

	foreach (sort keys %mailrc) {
		print "$_ \t\t $mailrc{$_} \n" ;
	}

But I cannot find a way to sort and print it using a while loop:

	while ( ($name,$address) = each  %mailrc ) {	
		print "$name \t\t $address \n" ;
	}
	
Is it possible to sort and print a hash using a while loop?

---
Fred


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

Date: Wed, 25 Dec 2002 00:02:35 GMT
From: Steven Smolinski <steven.smolinski@sympatico.ca>
Subject: Re: Hash sort
Message-Id: <vA6O9.1852$Yo5.376214@news20.bellglobal.com>

Fred <No_Mail_Address@cox.net> wrote:
> I have a hash: 
> 	 $mailrc{$name} = $address ;    
> 
> I know how to sort and print it with a foreach-loop:
> 
> 	foreach (sort keys %mailrc) {
> 		print "$_ \t\t $mailrc{$_} \n" ;
> 	}

This for loop is also idiomatic, and has a better golf score:

    print "$_=$mailrc{$_}\n" for sort keys %mailrc;

> But I cannot find a way to sort and print it using a while loop:
> 
> 	while ( ($name,$address) = each  %mailrc ) {	
> 		print "$name \t\t $address \n" ;
> 	}
> 	
> Is it possible to sort and print a hash using a while loop?

Since you already know a good way, why try to cram the operation into
some other random control structure?  I'd hate to maintain code written
by someone who's trying to find a less apt control structure for
straightforward logic.

Anyway, here's a while loop that accomplishes the same thing, with a few
wasted cycles:

    while (1) {
        print "$_=$mailrc{$_}\n" for sort keys %mailrc;
        last;
    }

HTH. :-)

Steve
-- 
Steven Smolinski => http://arbiter.ca/
GnuPG Public Key => http://arbiter.ca/steves_public_key.txt
                 => or email me with 'auto-key' in the subject.
Key Fingerprint  => 08C8 6481 3A7B 2A1C 7C26  A5FC 1A1B 66AB F637 495D


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

Date: Wed, 25 Dec 2002 00:51:36 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Hash sort
Message-Id: <x7wulyapk8.fsf@mail.sysarch.com>

>>>>> "SS" == Steven Smolinski <steven.smolinski@sympatico.ca> writes:

  >> But I cannot find a way to sort and print it using a while loop:
  >> 
  >> while ( ($name,$address) = each  %mailrc ) {	
  >> print "$name \t\t $address \n" ;
  >> }
  >> 
  >> Is it possible to sort and print a hash using a while loop?

you still have to build up a list of stuff to sort so you don't gain
anything by using the each function.

  SS> Anyway, here's a while loop that accomplishes the same thing, with a few
  SS> wasted cycles:

  SS>     while (1) {
  SS>         print "$_=$mailrc{$_}\n" for 
  SS>         last;
  SS>     }

this is the more interesting one liner for printing a hash:

	print map "$_ \t\t $mailrc{$_}\n", sort keys %mailrc;

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: Wed, 25 Dec 2002 01:25:56 GMT
From: Fred <No_Mail_Address@cox.net>
Subject: Re: Hash sort
Message-Id: <3E09098C.653EB37F@cox.net>

 
>> "SS" == Steven Smolinski <steven.smolinski@sympatico.ca> writes:
(snip)
> Uri Guttman wrote:
> (snip)
> this is the more interesting one liner for printing a hash:
> 
>         print map "$_ \t\t $mailrc{$_}\n", sort keys %mailrc;
> 
> uri

But how would I sort the %hash and write it to a @array instead of
printing to a file?

---
Fred


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

Date: Tue, 24 Dec 2002 22:42:59 GMT
From: "jaster" <jaster@home.still>
Subject: help missing module 
Message-Id: <Tp5O9.714$2A1.312382561@newssvr11.news.prodigy.com>

Happy holiday to everyone.
I'm using RH7.2 w/ Perl 5.6.1 but now if I " use Digest::MD5 "  I get an
error module not found.   I installed perl-Digest-2.20 and my rpm -qa perl*
shows the module is installed.   Any idea what I need to do to fix this
problem?   Thanks for all help.




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

Date: Tue, 24 Dec 2002 12:04:25 -0800
From: btam01@ccsf.edu
Subject: Re: How to begin a File Comparison
Message-Id: <Pine.HPX.4.44.0212241203170.15930-100000@hills.ccsf.cc.ca.us>

On Tue, 24 Dec 2002, Lou Moran wrote:

> The Story:
>
> There was a secretary who made a list of Names & Addresses.  These
> names and addresses are in no particular format and often deviate from
> even the most sensical envelope type format,  A new secretary was
> added to the mix.  She took a copy of the orginal file and began
> adding to it while the original secretary continued added to her
> original list.  They don't like each other and never speak.  Ever.
>
> The Idea:
>
> Get these massive files into some kind of format suitable for import
> into a database.
>
> The Task:
>
> 1 -- Do some sort of File Compare to weed out duplicates
>
> 2 -- Do some sort of Formatting to attempt to get these in some kind
> of order
>
> 3 -- Merge the files into one big, happy, database importable file
>
> (Perhaps 1 & 2 are backwards)
>
> I certainly do expect anyone to write anything (code wise) I just need
> some ideas on how to approach this project;  Modules, correct way to
> look at this, best practices type of stuff.  I should mention that we
> are actually talking about more than 2 files, but I plan to start on
> the big ones first.
>
> The originals are in Word Perfect and the only way to tell a file from
> the next is a Page Break.  I have the files in .txt with line breaks
> at the moment.
>
> All suggestions welcome (Please be nice it's the Holidays!)
>
> --
> There's more than one way to do it, but only some of them work

Maybe you can write a script to turn these files into a certain format.
From there, combine the files and do a unique sort?



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

Date: Tue, 24 Dec 2002 22:57:45 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: How to begin a File Comparison
Message-Id: <3E08E63F.80208@rochester.rr.com>

Lou Moran wrote:

> The Story:
> 
> There was a secretary who made a list of Names & Addresses.  These
> names and addresses are in no particular format and often deviate from
> even the most sensical envelope type format,  A new secretary was
> added to the mix.  She took a copy of the orginal file and began
> adding to it while the original secretary continued added to her
> original list.  They don't like each other and never speak.  Ever.
> 
> The Idea:
> 
> Get these massive files into some kind of format suitable for import
> into a database.
> 
> The Task:
> 
> 1 -- Do some sort of File Compare to weed out duplicates
> 
> 2 -- Do some sort of Formatting to attempt to get these in some kind
> of order
> 
> 3 -- Merge the files into one big, happy, database importable file
> 
> (Perhaps 1 & 2 are backwards)
> 
> I certainly do expect anyone to write anything (code wise) I just need
> some ideas on how to approach this project;  Modules, correct way to
> look at this, best practices type of stuff.  I should mention that we
> are actually talking about more than 2 files, but I plan to start on
> the big ones first.
> 
> The originals are in Word Perfect and the only way to tell a file from
> the next is a Page Break.  I have the files in .txt with line breaks
> at the moment.
> 
> All suggestions welcome (Please be nice it's the Holidays!)
 ...


You don't say if these are US address or otherwise.  I'll assume US -- 
the statements below may not apply to other countries.


The first step is certainly to get the two files into a standardized 
format.  There are some modules which might help with this, believe it 
or not:

Lingua::EN::AddressParse
Data::Address::Standardize

Then the two files can be concatenated and read in as hash keys.  Any 
exact duplicates will overwrite the second and subsequent times, so 
duplicates will be removed.  The code would go like [untested]:

open IN,"filename.ext" or die "Oops, couldn't open filename.txt, $!";
while(<IN>){
    chomp;
    $hash{$_}++;
}
close IN;
open OUT,">newfilename.ext" or
    die "Oops, couldn't open newfilename.ext for output, $!";
for(sort keys $hash){
    print OUT "$hash{$_}\n";
}
close OUT;

HTH.
-- 
Bob Walton



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

Date: Wed, 25 Dec 2002 00:36:59 +0000 (UTC)
From: "eric" <eric.ehlers@btopenworld.com.spamoff>
Subject: Re: Lotus Notes OLE: Help on avoiding undefined value as HASH reference.
Message-Id: <auaujb$61s$1@knossos.btinternet.com>

> > I read it in a Perl scalar as shown in this code:
> >         my $Product = $document->GetFirstItem('Product')->{Text};
> >
> >
> > All goes well but after looping trough 150 documents or so i suddenly
get
> an
> > error:
> >         "Can't use an undefined value as a HASH reference at line xx."

can you show us the code in "line xx"?  i believe that the line you have
shown above is not the line xx where the error is occurring.

> I found the problem but i still have no solution. It seems that at a
certain
> point the value in Product is:
>
>     'A&C Chemicals A`FilePlan'.
>
> There is a backtick in the product name! I read it into this:
>
>     >         my $Product = $document->GetFirstItem('Product')->{Text};
>

i think there is more to this problem than you have provided.  the presence
of a backtick in $Product would not prevent $Product from being used as a
hash reference, and would not cause the undefined error.  maybe you could
post a short snippet of standalone code which recreates the error - but more
likely by the time you get that far you'll find the answer yourself.

eric




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

Date: Tue, 24 Dec 2002 20:18:24 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Lotus Notes OLE: Help on avoiding undefined value as HASH reference.
Message-Id: <3E090760.E2D62727@earthlink.net>

smasr wrote:
> 
> Hi,
> 
> I am busy for several days now with a Perl script to extract views and
> attachements from a Lotus Notes database.
> 
> Finally the scripts runs but i have still a few problems. One problem
> i still have is:
> 
> explaination:
> "Product" is a Notes view name and contains a product name.
> 
> I read it in a Perl scalar as shown in this code:
>         my $Product = $document->GetFirstItem('Product')->{Text};
> 
> All goes well but after looping trough 150 documents or so i suddenly
> get an error:
>         "Can't use an undefined value as a HASH reference at line xx."
> 
> At some point there isn't a value in the 'Product' view and thats why
> i get the error. I think.. I have commented the line out and ran the
> script again. Then it stops after 170 documents with the same error
> but on the next line where i am reading another a View variable into a
> scalar.
> 
> Is there a way to avoid this error? I don't mind if there is no value
> but i don't want the script to stop.

   my $ProductThingy = $document->GetFirstItem('Product');
   if( !$ProductThingy ) {
      print "This document doesn't have a Product!\n";
      print ... information about $document ...;
      print ... such as its filename, etc.. ...;
      next DOCUMENT;
   }
   my $Product = $ProductThingy->{Text};



-- 
$..='(?:(?{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: Tue, 24 Dec 2002 23:11:43 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: missing Net/SMTP and PPM search shows nothing.
Message-Id: <3E08E985.5010104@rochester.rr.com>

R Solberg wrote:

 ...


> ppm search and nothing comes back.  How do I get NET::SMTP from PPM?
 ...


Try:

    ppm install libnet

at an OS command prompt.  But it seems that should have come with your 
original Perl installation?
-- 
Bob Walton



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

Date: 24 Dec 2002 12:04:49 -0800
From: rnoory@videotron.ca (R.Noory)
Subject: negation and or
Message-Id: <8fec9af1.0212241204.1d3886c8@posting.google.com>

Hello, 

What I want is to make one single rule out of rule (1) and (2); I
tried several syntax like (3), (4) (5) (6). Nothing seems to work.
Rule (3) does not exclude abacinate and rule (4)(5)(6) are not correct
from syntax point of view.

Input
exacinate
abacinate
deracinate

Rules
(w*?)(?<!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (1)
(w*?)(?<!x)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (2)

output
exacinate
abacinate
deracin(ate) - ation 

(w*?)(?!x|b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (3)
(w*?)(?<!x|!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (4)
(w*?)(?<!x|?<!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (5)
(w*?)(?<!x|!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (6)

Thanks


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

Date: Tue, 24 Dec 2002 22:28:20 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: negation and or
Message-Id: <3E08DF5B.1020803@rochester.rr.com>

R.Noory wrote:

 ...


> What I want is to make one single rule out of rule (1) and (2); I
> tried several syntax like (3), (4) (5) (6). Nothing seems to work.
> Rule (3) does not exclude abacinate and rule (4)(5)(6) are not correct
> from syntax point of view.
> 
> Input
> exacinate
> abacinate
> deracinate
> 
> Rules
> (w*?)(?<!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (1)
> (w*?)(?<!x)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (2)
> 
> output
> exacinate
> abacinate
> deracin(ate) - ation 
> 
> (w*?)(?!x|b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (3)
> (w*?)(?<!x|!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (4)
> (w*?)(?<!x|?<!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (5)
> (w*?)(?<!x|!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (6)

I don't know if I followed all of that, but, if I did, try:


while(<DATA>){
	chomp;
	s;(w*?)(?<!x)(?<!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation;;
	print "$_\n";
}
__DATA__
exacinate
abacinate
deracinate

That generates:

D:\junk>perl junk245.pl
exacinate
abacinate
deracin(ate)-ation

D:\junk>

which I gather is your desired output.
-- 
Bob Walton



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

Date: Wed, 25 Dec 2002 10:00:01 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: negation and or
Message-Id: <slrnb0hpnh.4tt.mgjv@martien.heliotrope.home>

On 24 Dec 2002 12:04:49 -0800,
	R.Noory <rnoory@videotron.ca> wrote:
> Hello, 
> 
> What I want is to make one single rule out of rule (1) and (2); I
> tried several syntax like (3), (4) (5) (6). Nothing seems to work.
> Rule (3) does not exclude abacinate and rule (4)(5)(6) are not correct
> from syntax point of view.
> 
> Input
> exacinate
> abacinate
> deracinate
> 
> Rules
> (w*?)(?<!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (1)
> (w*?)(?<!x)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (2)

That's not Perl. I suppose the bit before the ; is a pattern to match,
and the bit after the ; is the substitution pattern for s///?

> output
> exacinate
> abacinate
> deracin(ate) - ation 
> 
> (w*?)(?!x|b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (3)
> (w*?)(?<!x|!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (4)
> (w*?)(?<!x|?<!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (5)
> (w*?)(?<!x|!b)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation (6)

s;(w*?)(?<!b|x)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation;

(?<!) is a single grouping construction (fixed-width lookbehind). In
other words, it is not a combination of (?<) with a negation of ! for
each bit that follows.

Anything after the ! and before the ) is the pattern that needs to be
matched (and negated). As long as all possible matches of that pattern
are the same length, it'll work.

Alternatively, you can make use of the fact that these things are
zero-width matches:

s;(w*?)(?<!b)(?<!x)(acin)(w*?)(ate)\b;$1$2$3(ate)-ation;

Martien

PS. I wouldn't have chosen ; as the delimiter, but it was easiest to do
it that way, given your input.
-- 
                        | 
Martien Verbruggen      | Since light travels faster than sound, isn't
                        | that why some people appear bright until you
                        | hear them speak?


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

Date: Tue, 24 Dec 2002 14:51:46 -0500
From: Lou Moran <lou.moran@gellerandwind.com>
Subject: ppm vs. perl -MCPAN -e shell 
Message-Id: <79eh0v8r8h53fhmgisp95tsgm8d70n2amf@4ax.com>

At work I use Active State's distribution of Perl and mostly it comes
with anything I need module wise.

Sometimes while mucking about CPAN.org I see a Module that I think
would be useful.  Today's is File::Compare .

so:

C:\>ppm
PPM interactive shell (2.1.6) - type 'help' for available commands.
PPM> install File::Compare
Install package 'File-Compare?' (y/N): y
Installing package 'File-Compare'...
Error installing package 'File-Compare': Could not locate a PPD file
for package File-Compare

Now in hindsight I proabably already have File::Compare but that's not
the question:

The Question is does ppm use the same "repository" as CPAN or is it
totally different?

--
There's more than one way to do it, but only some of them work


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

Date: Tue, 24 Dec 2002 22:36:32 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: ppm vs. perl -MCPAN -e shell 
Message-Id: <3E08E147.8050107@rochester.rr.com>

Lou Moran wrote:

 ...
> PPM> install File::Compare


PPM would probably know this as File-Compare if it were there (which it 
isn't)


 ...


> The Question is does ppm use the same "repository" as CPAN or is it
> totally different?
 ...


They are similar, in that the PPM repository includes those 

modules which ActiveState has compiled, ported, tested and 

made into nice

little installation packets for their ActiveState Perl.  It does not 
include all the modules on CPAN, not by a long shot.  The PPM modules 
may not be the latest version, either.
-- 
Bob Walton



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

Date: Tue, 24 Dec 2002 19:13:36 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Processing \0xx in nonliteral strings
Message-Id: <3E08F830.4422F784@earthlink.net>

Moshe Jacobson wrote:
> 
> Hello all, I hope you can answer this somewhat difficult question:
> 
> I'm trying to take a user-provided format string, and provide an
> output string with various %-macros replaced with application-specific
> data, and also with \n, \r, \0xx, etc backslash escapes expanded as
> well.
> 
> Currently, I have the following code:
> 
> my $fmt = "user: %u\ndomain:%d\n"; # example
[snip]
> The problem with this is that I cannot use this method to expand \0xx
> (octal value) escape sequences, because I cannot express every
> possible value as a literal for the perl preprocessor to expand for me
> (as I'm doing in the top there).

That's because you're processing letters one-at-a-time, when you
actually need to process them in groups.

> How can I take a string provided to me in a variable and expand all
> backslash-escaped character sequences as if I were the perl
> preprocessor?

If *all* you want is to process backslash-escapes just as if you were
the perl preprocessor, then *use* the perl preprocessor.

   $string =~ s/\\(0x\d{1,2}|[0-7]{1,3}|.)/
      $1 ne '"' ? eval qq["\\$1"] : '"'/sge;

[untested]

But, since you also want to escape %-thingies, then try:

   my $fmt = 'user: %u\ndomain:%d\n'; # example
   my %percent = (
      'u' => $usr, 'd' => $dom, ....,
   );
   $string =~ s<(?=([\\%])(?sx:
      (?:\\(0x\d{1,2}|[0-7]{1,3}|.))
   |
      (?:%(.))
   )>{
      if( $1 eq "\\" ) {
         $2 eq '"' ? '"' : eval qq["\\$2"];
      } else {
          exists $percent{$3} ? $percent{$3} : "%$3";
      }
   }ge;
[untested]


-- 
$..='(?:(?{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: Tue, 24 Dec 2002 23:25:24 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Simple array problem
Message-Id: <3E08ECBA.8030308@rochester.rr.com>

Andrew Hamm wrote:

> Andrew Hamm wrote:
> 
>>Absolutely!!!
>>
>>    @new = @docarray[$i .. $f];
>>
>>
> 
> In fact, chew on this:
> 
> %hash = (a => 1, b => 2, c => 3);
> @arr = @hash{a,c};
> 
> Consufed? Delighted? Excited?
> 

Well, actually... @hash{a,c} doesn't pass muster with use strict, so 
that should be:

    @arr = @hash{'a','c'};

The bareword hash key bit only applies to strings which look like a 
variable name or a number, which a hash slice list of keys doesn't.
-- 
Bob Walton



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

Date: Tue, 24 Dec 2002 20:29:33 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Small databases
Message-Id: <Ns3O9.7430$uV4.3875075@news2.news.adelphia.net>

What are the options for a good small footprint database...on Windows (XP).

Bob




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

Date: Tue, 24 Dec 2002 22:10:32 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Small databases
Message-Id: <3E08DB30.7050805@rochester.rr.com>

Bob X wrote:

> What are the options for a good small footprint database...on Windows (XP).
> 
> Bob
 ...


Hmmmmm...that question leaves a *ton* of room open for interpretation. 
Since you're asking in a Perl newsgroup, I will assume you mean 
databases implemented in Perl, not databases like Access, mySQL, etc. 
Also, I'm not sure what you mean by "footprint"?  Disk size?  Size of 
the program?  If you want the least disk size, check out DBI with 
DBD::RAM.  The entire database is in RAM, so it doesn't take any disk 
space.  Unless you want it to.  There is also DBI with DBD::CSV, which 
makes comma-separated-value files behave like an SQL database.  Very low 
footprint if large size coupled with high performance is not desired.

Since you're on Windoze, you might check out DBI with DBD::Excel, 
although that probably won't win any footprint race.  And DBI with 
DBD::ODBC, which will let you access (sorry about the pun) other 
Micro$loth databases.

And finally, consider tie'ing a hash to a dbm-type file.  This gives a 
very nice interface to a key-value type database in the form of a Perl 
hash.  File types supported on Windoze are DB_File and SDBM.  DB_File is 
the general winner.  Note that binary compatibility of the resulting 
database files is not among the goals of these schemes.  Perhaps not 
even from computer to computer even with the same OS, or even on the 
same computer across different versions of the supporting software.

And, of course, you can roll your own.  If your info is fixed-length, 
you could open an ordinary file and, using the seek function, read and 
print information to the file.  And there are undoubtely many more 
scheme out there.  Consider checking CPAN.
-- 
Bob Walton



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

Date: Tue, 24 Dec 2002 14:49:36 -0500
From: jg10@duke.edu
Subject: Thanks -- Re: SOS: evaluate a string/function
Message-Id: <Pine.GSO.4.50.0212241446130.9674-100000@teer4.acpub.duke.edu>


Thanks Jay !

> Getting excited about it won't help.

Exactly, actually I was more desperate than excited after sitting
there for many hours.

> : my $str="sin(2)";
> : print "sin(2) again = ",eval{$str},"\n";
>
> That's a block eval.  You want a string eval.

Will remember the difference from now on.

> print "sin(2) again = ", eval($str), "\n";
>



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

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


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