[22827] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5048 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 27 18:06:09 2003

Date: Tue, 27 May 2003 15:05:09 -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           Tue, 27 May 2003     Volume: 10 Number: 5048

Today's topics:
        better way to do this than a hash? (david)
    Re: better way to do this than a hash? (Tad McClellan)
    Re: better way to do this than a hash? <usenet@dwall.fastmail.fm>
    Re: comparing 2 files using perl <usenet@dwall.fastmail.fm>
    Re: comparing 2 files using perl (James E Keenan)
        Doing substitutions in a while loop (while /.../g) <apollock11@hotmail.com>
    Re: Doing substitutions in a while loop (while /.../g) (Tad McClellan)
        Help: Graph Module Doesn't Detect Cycle..Any suggestion (entropy123)
    Re: how to not cause a file lock? <abigail@abigail.nl>
    Re: Module to decode MS Word documents? <henq _ replace 0 by o <hvtijen@h0tmail.c0m>>
        module WriteExcel formatting (Kenjis Kaan)
    Re: NEWBIE: Store and Access Arrays <nobody@dev.null>
    Re: Perl 5.6.1 and Oracle 8.1.7 <No_4@dsl.pipex.com>
    Re: Reverse Reference Question <usenet@dwall.fastmail.fm>
        Safe Eval <cf@<Nooooo spaaammm>phased.co.uk>
    Re: Safe Eval <henq _ replace 0 by o <hvtijen@h0tmail.c0m>>
    Re: scope of variable (James E Keenan)
    Re: scope of variable (James E Keenan)
    Re: scope of variable (Malcolm Dew-Jones)
    Re: scope of variable <jasonp@uq.net.au>
    Re: Sorting hash <uri@stemsystems.com>
    Re: Sorting hash (Gary E. Ansok)
    Re: Sorting hash <ddunham@redwood.taos.com>
    Re: Sorting hash <noreply@gunnar.cc>
    Re: Sorting hash <noreply@gunnar.cc>
    Re: Sorting hash <ddunham@redwood.taos.com>
    Re: STDOUT print not showing up <usenet@dwall.fastmail.fm>
    Re: STDOUT print not showing up <jasonp@uq.net.au>
        Tie module (Thomas)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 27 May 2003 12:53:28 -0700
From: dwlepage@yahoo.com (david)
Subject: better way to do this than a hash?
Message-Id: <b09a22ae.0305271153.7807264c@posting.google.com>

All -
I have a program that does some editing within an exported LDIF - it
works as I expect it to, but takes an awful long time to run on a
database of 50K users. Is there a faster way to do this or ways I can
tweak this to work faster?
Thanks,

if ( @ARGV ne 1 ) {
        print "Usage: fldif.pl <exportfile.ldif>";
        exit 0
        }

#Initialize variables
my $outfile = "fixedldif.ldif";
my ($keyname, $keyvalue, $search, $replace) = "";
my %uid = ();

open(IN, "<$ARGV[0]") or die "Could not open: \"$ARGV[0]\" $!";
flock (IN, 1);  #Shared lock

open(OUT, ">$outfile") or die "Could not open: $outfile $!";
flock (OUT, 2); #Exclusive lock

while (<IN>) {
	#Reset $keyname and $keyvalue for each new record
	if (/^dn: UserId=/) {
		$keyname = $keyvalue = "";
		#Set $keyname to "UserId".TOK.0
		if (/^dn: UserId=(\w+),/) {
			$keyname = $1 . ".TOK.0";
		}
	}
	#Set $keyvalue to true authenticator value
        if (/^sccComment:/) {
                if (/^sccComment: (DG-\w+)\s+/) {
                        $keyvalue = $1;
                }
                elsif (/^sccComment: (STII-\w+)\s+/) {
                        $keyvalue = $1;
                }
                elsif (/^sccComment: (S\/N\:\w+)\s+/) {
                        $keyvalue = $1;
                }
        }
        
	#Add values to hash
        if (!($keyname eq "") && !($keyvalue eq "")) {
                $uid{"$keyname"} = $keyvalue;
	}

	#If the line contains a token reference
	if (/\.TOK\.0/) {
		         foreach $key (keys(%uid)) {
#                        if (/$search/) {
                                $search = $key;
                                $replace = $uid{"$key"};
                                s/$search/$replace/g;
				#exit foreach once matched
                                next;
                }
                #Next comes here
                
                s/(DG\-)|(STII\-)|(S\/N\:)//g;
        }
        	#Send each line to new file
   print OUT $_;
}
close(IN);
close(OUT);


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

Date: Tue, 27 May 2003 15:23:57 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: better way to do this than a hash?
Message-Id: <slrnbd7iat.330.tadmc@magna.augustmail.com>

david <dwlepage@yahoo.com> wrote:

> if ( @ARGV ne 1 ) {


You are using the wrong operator.

ne compares _strings_, you want to compare _numbers_:

   if (@ARGV != 1) {

(that sounds familiar...)


>         exit 0


You should exit with a NON-zero value when an error is detected.

(so does that...)


> flock (IN, 1);  #Shared lock


Just because you asked for it does not mean you actually
got what you asked for. It's best to check and see:

   flock(IN, LOCK_SH) or die "could not get lock $!";

You should import the constants rather than hardcode them.


>         if (!($keyname eq "") && !($keyvalue eq "")) {


Negative logic can make your head hurt, help to avoid the pain:

   if ($keyname ne "" and $keyvalue ne "") {
or
   if (length $keyname and length $keyvalue) {


>                 $uid{"$keyname"} = $keyvalue;
                       ^        ^

A useless use of double quotes.

   $uid{$keyname} = $keyvalue;


>                 s/(DG\-)|(STII\-)|(S\/N\:)//g;
                       ^        ^        ^
                       ^        ^        ^

Useless use of backslashes.

You only need to backslash regex metacharacters.


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


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

Date: Tue, 27 May 2003 21:41:58 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: better way to do this than a hash?
Message-Id: <Xns9388B40C475EFdkwwashere@216.168.3.30>

david <dwlepage@yahoo.com> wrote:

>      #Reset $keyname and $keyvalue for each new record
>      if (/^dn: UserId=/) {
>           $keyname = $keyvalue = "";
>           #Set $keyname to "UserId".TOK.0
>           if (/^dn: UserId=(\w+),/) {
>                $keyname = $1 . ".TOK.0";
>          }
>     }

No need to match twice:

       #Set $keyname to "UserId".TOK.0
       if (/^dn: UserId=(?:(\w+),)?/) {
           $keyname = length $1 > 0 ?  "$1.TOK.0" : '';
           $keyvalue = '';
       }



>      #Set $keyvalue to true authenticator value
>         if (/^sccComment:/) {
>                 if (/^sccComment: (DG-\w+)\s+/) {
>                         $keyvalue = $1;
>                 }
>                 elsif (/^sccComment: (STII-\w+)\s+/) {
>                         $keyvalue = $1;
>                 }
>                 elsif (/^sccComment: (S\/N\:\w+)\s+/) {
>                         $keyvalue = $1;
>                 }
>         }

Similarly here:

    #Set $keyvalue to true authenticator value
    if (/^sccComment: ((?:DG-|STII-|S\/N:)\w+)\s+/) {
        $keyvalue = $1;
    }




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

Date: Tue, 27 May 2003 19:30:26 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: comparing 2 files using perl
Message-Id: <Xns93889DBFD81D0dkwwashere@216.168.3.30>

P. Egan <poko_e@yahoo.com> wrote:

> I have 2 files that I'm comparing...if there is no match in a
> string from file1 to file2, I want to write file1.  I know this
> sounds like grep, but grep isn't giving me what I'm looking for. 
> I am reformatting file2 to look like file1(just the date portion
> is the string that I'm comparing).
> 
> File1 looks like:
> ./home1/filenet/images/000004/00000410051998.log
> ./home1/filenet/images/000004/00000401011901.log
> ./home1/filenet/images/000016/00001601011901.log
> ./home1/filenet/images/000016/00001601211991.log
> ./home1/filenet/images/000016/00001605161986.log
> ./home1/filenet/images/000016/00001601021996.log
> 
> File2 looks like:
> ./00/00/16/1990_01_16.pdf
> ./00/00/16/1991_01_21.pdf
> ./00/00/16/1996_01_02.pdf
> ./00/00/16/1998_01_02.pdf
> ./00/00/16/1999_12_31.pdf

It's not clear to me what you want to do.  A more detailed 
explanation would help, especially if you have code that even 
partially does what you want.

Here's a piece of code that (I think) may do something like what you 
want.

    use strict;
    use warnings;
    
    my @file1 = qw{
        ./home1/filenet/images/000004/00000410051998.log
        ./home1/filenet/images/000004/00000401011901.log
        ./home1/filenet/images/000016/00001601011901.log
        ./home1/filenet/images/000016/00001601211991.log
        ./home1/filenet/images/000016/00001605161986.log
        ./home1/filenet/images/000016/00001601021996.log  
    };
    
    my @file2 = qw{
        ./00/00/16/1990_01_16.pdf
        ./00/00/16/1991_01_21.pdf
        ./00/00/16/1996_01_02.pdf
        ./00/00/16/1998_01_02.pdf
        ./00/00/16/1999_12_31.pdf
    };
    
    my %file2_entry;
    foreach my $path (@file2) {
        my @part = grep length, split /[\/_.]/, $path;
         # use $" to avoid saying join('',@array) over and over
        local $"  = '';
        my $f2 = "@part[0,1,2]/@part[0,1,2]@part[4,5,3]";
        $file2_entry{"./home1/filenet/images/$f2.log"} = 1;
    }
    foreach my $path (@file1) {
        next if exists $file2_entry{$path};
        print "$path\n";
    }

Of course you'll be reading from files instead of looping over 
arrays, but that's easily modified.



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

Date: 27 May 2003 13:07:51 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: comparing 2 files using perl
Message-Id: <b955da04.0305271207.7e58776a@posting.google.com>

poko_e@yahoo.com (P. Egan) wrote in message news:<d5c97a1c.0305270618.218fb654@posting.google.com>...
> I have 2 files that I'm comparing...if there is no match in a string
> from file1 to file2, I want to write file1.  I know this sounds like
> grep, but grep isn't giving me what I'm looking for.  I am
> reformatting file2 to look like file1(just the date portion is the
> string that I'm comparing).
> 
Assuming that you're comparing _just_ the date portion, try something like this:

	my @log = qw(
	./home1/filenet/images/000004/00000410051998.log
	./home1/filenet/images/000004/00000401011901.log
	./home1/filenet/images/000016/00001601011901.log
	./home1/filenet/images/000016/00001601211991.log
	./home1/filenet/images/000016/00001605161986.log
	./home1/filenet/images/000016/00001601021996.log
	);
	
	my @pdf = qw(
	./00/00/16/1990_01_16.pdf
	./00/00/16/1991_01_21.pdf
	./00/00/16/1996_01_02.pdf
	./00/00/16/1998_01_02.pdf
	./00/00/16/1999_12_31.pdf
	);
	
	my (%seenlog, %seenpdf);
	
	foreach (@log) {
	        next unless (m|\/\d{14}\.log$|);
		my ($year, $month, $day, $key);
	        if (m|\/\d{6}(\d{2})(\d{2})(\d{4})\.log$|) {
			($month, $day, $year) = ($1, $2, $3);
		}
	        $key = $year . '_'. $month . '_'. $day;
		$seenlog{$key}++;
	}
	
	foreach (@pdf) {
	        next unless (m|\d{4}_\d{2}_\d{2}\.pdf$|);
		my ($year, $month, $day, $key);
	        if (m|(\d{4})_(\d{2})_(\d{2})\.pdf$|) {
			($year, $month, $day) = ($1, $2, $3);
		}
	        $key = $year . '_'. $month . '_'. $day;
		$seenpdf{$key}++;
	}
	
	foreach (sort keys %seenpdf) {
	        if (! $seenlog{$_}) {
	                print "Do something with unmatched pdf $_\n";
		}
}

Cf perlfaq4.pod
How can I tell whether a certain element is in a list or array?


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

Date: Tue, 27 May 2003 12:22:06 -0700
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Doing substitutions in a while loop (while /.../g)
Message-Id: <bb0e38$2e4m$1@agate.berkeley.edu>

What is the most elegant way of performing substitutions if
you're matching patterns in a while loop running through a
big old block of slurped text?

For example suppose I have a bunch of values in an array
I want to swap in for markers in an HTML file (which can
span multiple lines). This is not the actual application
I want to do but hopefully describes what I want more
clearly.

local $/ = undef;
my $text = <>;
while ($text =~ /<!-- ([^<>]+) -->/g) {
    my $subst_val = pop @array;
    ## Here, somehow replace $1 with $subst_val
}
## Write $text to a new file

I find myself wanting to do this all the time for a
variety of applications. Can somebody tell me a fast,
elegant way to do it?



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

Date: Tue, 27 May 2003 16:08:43 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Doing substitutions in a while loop (while /.../g)
Message-Id: <slrnbd7kur.34o.tadmc@magna.augustmail.com>

Arvin Portlock <apollock11@hotmail.com> wrote:

> What is the most elegant way of performing substitutions if
> you're matching patterns in a while loop running through a
> big old block of slurped text?


> while ($text =~ /<!-- ([^<>]+) -->/g) {
>     my $subst_val = pop @array;
>     ## Here, somehow replace $1 with $subst_val
> }


   $text =~ s/<!-- ([^<>]+) -->/ '<!-- ' . pop(@array) . ' -->' /ge;


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


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

Date: 27 May 2003 12:11:20 -0700
From: email_entropy123@yahoo.com (entropy123)
Subject: Help: Graph Module Doesn't Detect Cycle..Any suggestions?
Message-Id: <90cdce37.0305271111.33a0ed50@posting.google.com>

I'm writing a piece of code which requires some cycle detection and
can't seem to get the graph module to work. Here is the
problem...cycle needs me to input the values I believe to be in a
cycle I put the vertices in @C and all the edges in @E = qw/a b a c a
e e f f g g h h a/; #which essentially say a-b, a-c, a-e-f-g-h-a (this
is the cycle). now if @C= qw/a e f g h/ then the cycle will be
detected, if @C = qw/a f e g h/ (same elements, different order) the
cycle will not be detected.

Is there a workaround for this or do I need to tell the module
something else about my system?

Thanks!

entropy

#!/usr/bin/perl -w

use strict;

use diagnostics;

use Graph;
#use Graph::Directed;
use Graph::Undirected;

my $G;
my $E;
my $Q;
my $d = 1;


my @V = qw/a b c d e f g h/;
my @E = qw/a b a c a e e f f g g h h a/;
my @C = qw/a f e g h/;


$G = Graph->new(@V);

print "Graph->new(@V): $G\n";

$b = $G->undirected($d);

print "undirected($d): $b\n";

$E = $G->add_edges(@E);

print "add_edges(@E): $G\n";

$Q =$G->has_cycle(@C);

print"has_cycle: $Q\n";


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

Date: 27 May 2003 18:30:39 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: how to not cause a file lock?
Message-Id: <slrnbd7bmf.co.abigail@alexandra.abigail.nl>

peder (peder@stickomdeintpassa.com) wrote on MMMDLVI September MCMXCIII
in <URL:news:3d4fb39f.0305270951.5d458cec@posting.google.com>:
-:  hi
-:  
-:  i'm working on a project where i will read a text file from a network
-:  share (win32). it is crucial that this file doesn't get locked by the
-:  perl script since the file is business critical.
-:  
-:  how can i prevent this? 

The same way as you prevent it from being deleted by Perl: just don't do it.


Now, if your OS does some automated locking, then you should turn
your attention to the OS, not Perl.



Abigail
-- 
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'


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

Date: Tue, 27 May 2003 23:38:22 +0200
From: "henq" <henq _ replace 0 by o <hvtijen@h0tmail.c0m>>
Subject: Re: Module to decode MS Word documents?
Message-Id: <3ed3dacf$0$45377$1b62eedf@news.wanadoo.nl>

Stuart,

Use wvWare to concert Word to html, pipe through lynx to convert html to
plain text.

~henq

"Stuart Moore" <stjm2@cam.ac.uk> schreef in bericht
news:bb068p$mdc$1@pegasus.csx.cam.ac.uk...
> Are there any modules that'd help me grab text from a word document?
Doesn't
> matter if it looses all formatting etc but it'll need to get text from
> inside tables, preferably leaving some mark where the table boundaries are
> but not essential. A quick browse of CPAN revealied nothing.
>
> If not, any suggestions for other languages (preferably ones that are
easily
> used for cgi)
>
> Stuart
>
>




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

Date: 27 May 2003 13:44:04 -0700
From: tivolinewbie@canada.com (Kenjis Kaan)
Subject: module WriteExcel formatting
Message-Id: <6a8ba9f8.0305271244.4a5e944a@posting.google.com>

re:     use Spreadsheet::WriteExcel;

Hello gurus, I am trying to write a spreadsheet but need to have
certain formatting.  The problem I see is that after perl has write a
XLS file, when I open it, all the columns seems to partially cover the
one before it.  So even if
in one column a string "THIS_ISA_VERY_LONG_TeXT", you will get
"THIS_ISA_VER"
displayed because the column next to it covers the rest of the text. 
So is there a way you can instruct the formatting so that you can
arbitrary describe how wide you want the column, or even to set it to
be as long as the longest string in the column??  Any taker?

The other thing I am trying to do is to set the foreground/background
colour to
a very specific colour based on RGB notation, so 'red','brown' just
isn't good
enough, I would like to specify it as "FF0000" for red, and "0000FF"
for blue and anywhere in between, "CCAAFF", or "D3F8AA" etc.  How can
you enter this
so that the module will accept it.  My attempt  so far has been
ignored and the resulting colour defaults to black.
ThanksinAdvance.


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

Date: Tue, 27 May 2003 19:46:55 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: NEWBIE: Store and Access Arrays
Message-Id: <3ED3C090.2040506@dev.null>



Sylvie Stone wrote:

> [...]
> I have a web form that pulls data from a datbase on submit, then
> prints it to screen. I'd like to give the user an option to have the
> data emailed to them.
> 
> This is what I have. I can print to screen, but I can't *store* the
> array to be used later on in the script to build the email body. It's
> on the Intranet, otherwise I'd post a URL.
> [...]


Sending e-mail is really a special case of printing if you open a pipe 
to sendmail. See the example shown in the perlfaq9 "How do I send mail?"

If you really want to store an array (on disk) then use the Storable module.



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

Date: Tue, 27 May 2003 20:41:28 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Perl 5.6.1 and Oracle 8.1.7
Message-Id: <3ed3bf67$0$11377$cc9e4d1f@news.dial.pipex.com>

 >Tomasz wrote:

> I've got a perl 5.6.1. I would like to connect to Oracle Database
> 8.1.7 on the remote machine, without installing Oracle Client on my
> machine. I've installed DBI package, but there are problems with
> DBD-Oracle - installation cannot find the ORACLE_HOME structure. I've
> copied some folders to my machine (network, rdbms, lib) and it worked
> till 'make test'. How can I connect with the remote machine?

    AFAIR the ORACLE_HOME setting in such cases is only used for looking 
up error messages and NLS info.

    All you need to do is set it:

$ENV{'ORACLE_HOME'} = '/no/such/dir';

(but you then will only get error message as numbers...).



-- 
      -*-    Just because I've written it here doesn't    -*-
      -*-    mean that you should, or I do, believe it.   -*-



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

Date: Tue, 27 May 2003 20:15:39 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Reverse Reference Question
Message-Id: <Xns9388A56A496ACdkwwashere@216.168.3.30>

Moose <mooseshoes@gmx.net> wrote:

> I'm a Perl beginner and I would like to create a structure that
> includes a hash of masterkeywords (eg. %masterkeywords), the keys
> of which get referenced by a set of subscriber ID's.  In this way
> I can keep track of which subscriber ID's are referencing the same
> masterkeywords.  I would also like to be able to do a reverse
> reference and by submitting a key to the hash, generate the list
> of subscriber ID's that are referenced. 
> 
> Please suggest a Perl technique for accomplishing this.

Please read

    perldoc perlreftut
    perldoc perldsc

These will get you started on creating data structures.

-- 
David Wall


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

Date: Tue, 27 May 2003 20:11:36 +0100
From: CitFish <cf@<Nooooo spaaammm>phased.co.uk>
Subject: Safe Eval
Message-Id: <9jd7dvs54bjp5fnbkqbakv6s72i6p8g4ve@4ax.com>

I have a CGI process that receives data and acts upon it.

The process is usually straightforward and goes as follows:-

-check data integrity
-make a database entry
-send  an email
-provide a HTML page back

The whole process is driven by a series of parameter files that hold
the parameters for each transaction type.

However, increasingly I need to add more complex rules to some of
these processes, for example:-

"For process NEW if the email address is domain name X then add
attachment Y and don't bother with database entry"

Managing these rules has become increasingly difficult as I have to
keep changing a perl module that contains each of the process
handlers.

So, I was thinking that I could make this more manageable by using the
"eval" statement and running code that was embedded within a parameter
file.

Thus my code would look like:-

IF parameter file for process NEW has key "emailCode" THEN
eval($parameterFile{'emailcode'} else send email as normal

My questions are:-

1) does this make sense or is there a better solution
2) how can I restrict the scope of the eval statement to prevent
malicious code (ie. s/system//g; etc....) or only access a subset of
program variables

Any pointers greately appreciated
CF


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

Date: Tue, 27 May 2003 23:06:52 +0200
From: "henq" <henq _ replace 0 by o <hvtijen@h0tmail.c0m>>
Subject: Re: Safe Eval
Message-Id: <3ed3d36c$0$45383$1b62eedf@news.wanadoo.nl>

You could consider a rule-based solution.
A set of conditions (the rules) transform a set of values (like current
customer, date, mode and so one) into a set of other values (send_mail
(yes/no) and so forth).

The rules are stored and edited outside your program (in a config file or
mysql db). They are eval-ed, but you have a standard framework instead of ad
hoc coding.

I can send you a piece of sample code I wrote, (but never finished).

~henq



"CitFish phased.co.uk>" <cf@<Nooooo spaaammm> schreef in bericht
news:9jd7dvs54bjp5fnbkqbakv6s72i6p8g4ve@4ax.com...
> I have a CGI process that receives data and acts upon it.
>
> The process is usually straightforward and goes as follows:-
>
> -check data integrity
> -make a database entry
> -send  an email
> -provide a HTML page back
>
> The whole process is driven by a series of parameter files that hold
> the parameters for each transaction type.
>
> However, increasingly I need to add more complex rules to some of
> these processes, for example:-
>
> "For process NEW if the email address is domain name X then add
> attachment Y and don't bother with database entry"
>
> Managing these rules has become increasingly difficult as I have to
> keep changing a perl module that contains each of the process
> handlers.
>
> So, I was thinking that I could make this more manageable by using the
> "eval" statement and running code that was embedded within a parameter
> file.
>
> Thus my code would look like:-
>
> IF parameter file for process NEW has key "emailCode" THEN
> eval($parameterFile{'emailcode'} else send email as normal
>
> My questions are:-
>
> 1) does this make sense or is there a better solution
> 2) how can I restrict the scope of the eval statement to prevent
> malicious code (ie. s/system//g; etc....) or only access a subset of
> program variables
>
> Any pointers greately appreciated
> CF




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

Date: 27 May 2003 12:21:02 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: scope of variable
Message-Id: <b955da04.0305271121.20f7d533@posting.google.com>

fatted@yahoo.com (fatted) wrote in message news:<4eb7646d.0305270116.665b04ab@posting.google.com>...
> Consider code:
> 
> use warnings;
> use strict;
> 
> open(OUT,'>>','program.log');
> 
> while(1)
> {
>         sleep(3);
>         print OUT "Hello\n";
> }
> 
Try:
	open(OUT,">>program.log") or die "Couldn't open: $!";
	select OUT;
	$|++;
	select STDOUT;
	while(1) {
	       sleep(3);
	       print OUT "Hello, world again\n";
	       print "Hello, world again\n";
	}
	close OUT or die "Couldn't close: $!";

Adapted from a posting by Dave Cross:
http://groups.google.com/groups?q=sleep+filehandle+open+group:comp.lang.perl.misc&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=pan.2002.06.17.19.51.01.822470.1447%40dave.org.uk&rnum=5

Which in turned made reference to: 
http://perl.plover.com/FAQs/Buffering.html>


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

Date: 27 May 2003 12:21:03 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: scope of variable
Message-Id: <b955da04.0305271121.7b8fb9fd@posting.google.com>

fatted@yahoo.com (fatted) wrote in message news:<4eb7646d.0305270116.665b04ab@posting.google.com>...
> Consider code:
> 
> use warnings;
> use strict;
> 
> open(OUT,'>>','program.log');
> 
> while(1)
> {
>         sleep(3);
>         print OUT "Hello\n";
> }
> 
Try:
	open(OUT,">>program.log") or die "Couldn't open: $!";
	select OUT;
	$|++;
	select STDOUT;
	while(1) {
	       sleep(3);
	       print OUT "Hello, world again\n";
	       print "Hello, world again\n";
	}
	close OUT or die "Couldn't close: $!";

Adapted from a posting by Dave Cross:
http://groups.google.com/groups?q=sleep+filehandle+open+group:comp.lang.perl.misc&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=pan.2002.06.17.19.51.01.822470.1447%40dave.org.uk&rnum=5

Which in turned made reference to: 
http://perl.plover.com/FAQs/Buffering.html>


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

Date: 27 May 2003 12:43:07 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: scope of variable
Message-Id: <3ed3bfcb@news.victoria.tc.ca>

Jason Parker-Burlingham (jasonp@uq.net.au) wrote:
: Malte Ubl <ubl@schaffhausen.de> writes:

: > fatted wrote:
: >> With the strict pragma, the filehandle OUT is not available in the
: >> while block
: > The strict pragma does not change the scope of a variable.

: Right.  To elaborate a bit:  Variable scoping rules don't apply to
: filehandles.  This code works:

Sure they do.  A plain old file handle is a global variable, and has the
same scope as every other global variable. 



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

Date: Tue, 27 May 2003 16:23:07 -0400
From: Jason Parker-Burlingham <jasonp@uq.net.au>
Subject: Re: scope of variable
Message-Id: <878yssb0lw.fsf@freezer.burling>

yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) writes:

> Jason Parker-Burlingham (jasonp@uq.net.au) wrote:
> : Right.  To elaborate a bit:  Variable scoping rules don't apply to
> : filehandles.  This code works:
> Sure they do.  A plain old file handle is a global variable, and has the
> same scope as every other global variable. 

Hmm, yes.  That's a much better way of saying what I was trying to get
across.  Thanks.
-- 
``Oooh!  A gingerbread house!  Hansel and Gretel are set for life!''


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

Date: Tue, 27 May 2003 18:45:58 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Sorting hash
Message-Id: <x7of1ons7t.fsf@mail.sysarch.com>

>>>>> "DD" == Darren Dunham <ddunham@redwood.taos.com> writes:

  DD> I read the post as saying that a specific requirement was based on the
  DD> fact that %hash did not change.  If it didn't change, then the sort
  DD> didn't need to be rerun, and his concern about changing key order
  DD> appears to vanish.

having reread the OP, i have no idea what he really wants. your answer
sounds possible but he needs to clarify what he wants and with an
example. i bet it is a premature optimization error or an XY problem.

uri

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


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

Date: Tue, 27 May 2003 19:55:58 +0000 (UTC)
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Sorting hash
Message-Id: <bb0fse$h06$1@naig.caltech.edu>

In article <bavafl$3tkgm$1@ID-184292.news.dfncis.de>,
Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote:
>I'm sorting the keys of a hash by (part of) the hash values like this:
>
>     @sortedkeys = sort {
>         ($hash{$b} =~ /^([\d.-]+)\|/)[0]
>                        <=>
>         ($hash{$a} =~ /^([\d.-]+)\|/)[0]
>     } keys %hash;
>
>This is about what happens if two values would be identical. Basically 
>I don't care in _which_ order the corresponding keys are stored in the 
>array, but the sort will be done many times, and I want the keys to be 
>stored in _the same_ order each time as long as the hash isn't changed.

One possibility is to use the hash key as a secondary sort -- since
the hash keys can never have the same value, the order is predictable
and stable.

     @sortedkeys = sort {
         ($hash{$b} =~ /^([\d.-]+)\|/)[0]
                        <=>
         ($hash{$a} =~ /^([\d.-]+)\|/)[0])
         or $a cmp $b
     } keys %hash;

Gary
-- 
Thank you for calling.... To use our automated payment information
system, say Payment.  If you have questions about your bill or
charges you do not understand, say Pinhead.  To hear these options
again, say Attention Span of a Gnat.


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

Date: Tue, 27 May 2003 20:20:14 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Sorting hash
Message-Id: <2MPAa.5066$uv.100974791@newssvr21.news.prodigy.com>

Darren Dunham <ddunham@redwood.taos.com> wrote:

> Sure.  I was just pointing out that the OPs post did not seem to
> specifically require a stable sort, so that if 5.8 just wasn't
> available, he might not be out of luck.

Never mind.  I reread the original post for the third time and finally
found what I was unable to understand about the requirements the first
two times.

Yes, a stable sort would be needed.  Ignore the rest of what I was
talking about.  :-)

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


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

Date: Tue, 27 May 2003 23:02:33 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Sorting hash
Message-Id: <bb0kdr$4hvmv$1@ID-184292.news.dfncis.de>

Darren Dunham wrote:
>> Gunnar Hjalmarsson wrote:
>>> This is about what happens if two values would be identical.
>>> Basically I don't care in _which_ order the corresponding keys
>>> are stored in the array, but the sort will be done many times,
>>> and I want the keys to be stored in _the same_ order each time
>>> as long as the hash isn't changed.
>>> 
>>> My question is: Can I trust that the keys will appear in
>>> @sortedkeys in _the same_ order, even if there would be
>>> occurrences of identical hash values, or do I need to add
>>> another sort criterion to be sure?

OP here, noting that clarifications were requested. (And I who thought
I was crystal clear... :) ). Let me clarify by responding to Darren's
post:

> I believe the OP doesn't mind if the order of identical keys
> changes from the keys list to the sort output, only that the order
> remain identical if repeated.

Confirmed.

> I'm pretty certain that even the quicksort algorithm will do that.

If that's the case, I don't need to alter the code.

> Of course I'm not sure I understand why a sort on the same elements
> would be repeated many times instead of simply stored.

Simplified explanation to give context: I'm storing data in a DBM
(SDBM) database, from which I print some data via CGI as a sorted
list. The reason for my concern about the order, would there be
identical values, is that if the number of keys is large, only a
portion of the list is printed, and if you want to view another
portion, it's a new CGI request.

So, I suppose that using 'stable', as suggested by Tassilo, would give
me a satisfying result when the program is run under Perl 5.8.0. And
Gary's suggestion, i.e. using the hash key as a secondary sort, would
give me a satisfying result irrespective of Perl version, since I
don't care about preserving any original order (which I don't control
anyway since it's a stored hash, right?).

However, since
1) I care about portability, and
2) adding a secondary sort key wouldn't improve efficiency,
not changing anything seems to be an interesting option. This
presupposes, of course, that Darren is right, and not just "pretty
certain" ;-), about how the quicksort algorithm works.

Hope this clarifies my question.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 27 May 2003 23:07:55 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Sorting hash
Message-Id: <bb0knu$4gk0q$1@ID-184292.news.dfncis.de>

Darren Dunham wrote:
> Darren Dunham <ddunham@redwood.taos.com> wrote:
>> Sure.  I was just pointing out that the OPs post did not seem to 
>> specifically require a stable sort, so that if 5.8 just wasn't 
>> available, he might not be out of luck.
> 
> Never mind.  I reread the original post for the third time and
> finally found what I was unable to understand about the
> requirements the first two times.

What did you find? :) Actually, I would say that you caught the
requirements quite well in your first reply.

> Yes, a stable sort would be needed.  Ignore the rest of what I was 
> talking about.  :-)

Why?

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 27 May 2003 22:03:07 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Sorting hash
Message-Id: <vgRAa.828$La1.321@newssvr19.news.prodigy.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> What did you find? :) Actually, I would say that you caught the
> requirements quite well in your first reply.

I'm thinking it depends on what the OP meant from this sentence.

"I want the keys to be stored in _the same_ order each time as long as
the hash isn't changed."

It seems to me that if "hash isn't changed" means that no changes to
keys or values are made, then it's rather silly to do another sort.
You've got one sort, so keeping a copy of it is the way to go.  Much
faster, and you're guaranteed of the same order.  That was how I read it
originally.

I now suppose instead that it was meant that the *keys* of the hash
haven't changed, even though the values might.  If that's the case, then
a changing value could cause a set of keys with the same value to sort
in a different order (since they are otherwise unconstrained).  If that
is what was intended, then some constraints are necessary.  Either
another key or a stable sort would work, since the order of keys()
should be the same.

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


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

Date: Tue, 27 May 2003 20:31:23 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: STDOUT print not showing up
Message-Id: <Xns9388A81504594dkwwashere@216.168.3.30>

Jan <jan_buys@hotmail.com> wrote:

> I have a problem when printing to a default STDOUT command-line
> window.  What I basically do is print a bunch of info to STDOUT
> and in the end I ask a question to the user of the script.  (I use
> the normal print command and some HERE documents for that).
> 
> Problem is : the text is not showing up in the console (normal
> cmd.exe console) and the script just waits for an answer to the
> question (which, of course, is not visible).  Only when I answer
> it, all text output that should have been printed prior to waiting
> for answer is printed.  Not quite userfriendly, unless you're
> clairvoyant, which most common users are not.

We're not clairvoyant either.  How is anyone supposed to help you if 
you don't post any code?

Try reducing your code to the shortest snippet you can that still 
demonstrates the problem.  If you do this, there's a good chance you 
might discover the problem for yourself.  If not, post that snippet 
(don't re-type, use copy-and-paste) and maybe someone will be able to 
help you.  ("Maybe" because, well, this *is* usenet.)

Be sure to enable strict and warnings:

    use strict;
    use warnings;

Enabling these pragmas will catch many errors for you.  Think of them 
as essential safety equipment.

WAG:  maybe you're running the program from an editor that opens a 
command-line window (such as Crimson Editor or Ultraedit).  
'cmd.exe' suggests you're using Windows NT/2000/XP.  Try opening a 
command prompt by itself (not from the editor) and running the 
program from there.

-- 
David Wall


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

Date: Tue, 27 May 2003 16:31:09 -0400
From: Jason Parker-Burlingham <jasonp@uq.net.au>
Subject: Re: STDOUT print not showing up
Message-Id: <87wugc9lo2.fsf@freezer.burling>

jan_buys@hotmail.com (Jan) writes:

> I have a problem when printing to a default STDOUT command-line
> window.  What I basically do is print a bunch of info to STDOUT and in
> the end I ask a question to the user of the script.  (I use the normal
> print command and some HERE documents for that).
>
> Problem is : the text is not showing up in the console (normal cmd.exe
> console) and the script just waits for an answer to the question
> (which, of course, is not visible). 

You might have a problem with buffering.  Without seeing the code it's
hard to say for sure (and I'm no expert on I/O buffering).
-- 
``Oooh!  A gingerbread house!  Hansel and Gretel are set for life!''


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

Date: 27 May 2003 14:36:35 -0700
From: cfa532@hotmail.com (Thomas)
Subject: Tie module
Message-Id: <530f730d.0305271336.3b011d6f@posting.google.com>

Can someone explain the concept of Tie in plain English. I am too dumb
to figure it out by reading the manual. It sounds like a powerful tool
though.

Thanks in advance


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

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


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