[24117] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6311 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 27 14:05:31 2004

Date: Sat, 27 Mar 2004 11:05:04 -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           Sat, 27 Mar 2004     Volume: 10 Number: 6311

Today's topics:
    Re: Choosing Perl/Python for my particular niche <catcher@linuxmail.org>
    Re: Choosing Perl/Python for my particular niche (Cameron Laird)
    Re: Choosing Perl/Python for my particular niche <tassilo.parseval@rwth-aachen.de>
        cpu use in threads <angshu31@hotmail.com>
    Re: Does anyone know what this switch does? <invalid-email@rochester.rr.com>
    Re: Does anyone know what this switch does? <vunderink@t-online.de>
    Re: Does anyone know what this switch does? <noreply@gunnar.cc>
    Re: Filehandles Referenced with a Variable <mikeflan@earthlink.net>
    Re: Filehandles Referenced with a Variable <mikeflan@earthlink.net>
    Re: Filehandles Referenced with a Variable <uri@stemsystems.com>
    Re: Filehandles Referenced with a Variable <mikeflan@earthlink.net>
    Re: Filehandles Referenced with a Variable <uri@stemsystems.com>
    Re: Loss of privledges in a perl app <perlcdr@mail.rumania>
    Re: Perl:  Generate registration code <arodland@eSntPerAmaMil.net>
    Re: SCALAR(0x82dea94) <todd@asgweb.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 27 Mar 2004 12:22:44 -0500
From: zatoichi <catcher@linuxmail.org>
Subject: Re: Choosing Perl/Python for my particular niche
Message-Id: <kJCdnZOwIr75JfjdRVn-gQ@adelphia.com>

Cameron Laird wrote:
> In article <40657D14.3FBE7E82@doe.carleton.ca>,

> My current instinct is that you'll be happiest with Perl--
> but it's a close choice, all around.  I'm most accomplished
> in Tcl, and would happily use it, or Perl, or Python.  It
> seems to me, though, that it's crucial that you be able
> to exploit libraries that pertain to your domain, and, in
> particular, optimized engines for linear algebra, graph
> theory, and linear and mathematical programming.  Tcl 
> lacks the weight that Perl and, to an increasing extent,
> Python can boast in their libraries.
Since you happily use Perl, Python or Tcl, I have a question. How do you 
decided which one to use?  :-)

Robert


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

Date: Sat, 27 Mar 2004 17:26:02 -0000
From: claird@lairds.com (Cameron Laird)
Subject: Re: Choosing Perl/Python for my particular niche
Message-Id: <106be9aroogdq77@corp.supernews.com>

In article <kJCdnZOwIr75JfjdRVn-gQ@adelphia.com>,
zatoichi  <catcher@linuxmail.org> wrote:
>Cameron Laird wrote:
>> In article <40657D14.3FBE7E82@doe.carleton.ca>,
>
>> My current instinct is that you'll be happiest with Perl--
>> but it's a close choice, all around.  I'm most accomplished
>> in Tcl, and would happily use it, or Perl, or Python.  It
>> seems to me, though, that it's crucial that you be able
>> to exploit libraries that pertain to your domain, and, in
>> particular, optimized engines for linear algebra, graph
>> theory, and linear and mathematical programming.  Tcl 
>> lacks the weight that Perl and, to an increasing extent,
>> Python can boast in their libraries.
>Since you happily use Perl, Python or Tcl, I have a question. How do you 
>decided which one to use?  :-)
>
>Robert

Most often, whatever is already at hand.  It'll be interesting
some day to come across an organization that doesn't already 
have a standard in place.
-- 

Cameron Laird <claird@phaseit.net>
Business:  http://www.Phaseit.net


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

Date: 27 Mar 2004 18:55:42 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Choosing Perl/Python for my particular niche
Message-Id: <c44ine$ad6$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Cameron Laird:

> I generally favor Python over Perl; in the absence of
> more details, I think there's mild evidence that those
> who don't specialize in programming are happier over the
> long term with the readability of the former.  They're
> very close, though.  The one most certain advantage 
> Python boasts is a dimension that I'd think important
> to you, although you haven't mentioned it:  Python's
> interfaces to C++ are MUCH easier to manage than Perl's.
> Perl6 will change this.  For now, though, it's FAR 
> easier to practice "dual-level programming" with Python
> and C++.  If you have a large existing library of C++
> work, I think that tips the balance toward Python.
> Understand, SWIG and other alternatives make Perl-to-C++
> links possible; with Python's facilities, though,
> including Pyrex, they're *fun*.

When it comes to embedding C/C++ into Perl, SWIG is the last thing that
I'd recommend. It may be capable of transforming such a library into a
Perl module on its own with no user intervention. However, C/C++ doesn't
map particularly well onto Perl from an interface point-of-view: A 1:1
translation of a C++ API doesn't look particularly good.

Those things should be done manually. How much work this is depends on
the library. Some only require a few lines of XS. XS' learning curve is
admittedly a bit steep. Not because it is difficult in itself but rather
because the documentation leaves a few things to be desired. There are
some actions on completing perlxstut.pod on its way right now, though.

There is also Inline::CPP, although I don't think it is as mature as
Inline::C. And since you have mentioned Tcl, even that can be inlined
with the help of Inline::Tcl.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Sat, 27 Mar 2004 13:48:43 -0500
From: "Angshuman Guin" <angshu31@hotmail.com>
Subject: cpu use in threads
Message-Id: <c44iai$6ee$1@news-int2.gatech.edu>

I am trying to use the capabilities of a multi(4) processor system to split
a task by using threads. But when I run the program I see only one cpu being
used although I have spawned 2 threads.

Am I doing anything wrong? Here is some relevant portion of my code:
__________________________________
use threads;
 ...
 ...
 ...
my $thr1 = threads->new(\&sub1, @det_files);
my $thr2 = threads->new(\&sub1, @det_files1);

$thr1->join;
$thr2->join;
 ...
 ...
__________________________________

And here is the output from perl -V


_______________________________

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.21-1.1931.2.382.entsmp,
archname=i386-linux-thread-multi
    uname='linux str'




config_args='-des -Doptimize=-O2 -g -pipe -march=i386 -mcpu=i686 -Dmyhostnam
e=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat,
Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix
=/usr -Dsiteprefix=/usr -Dotherlibdirs=/usr/lib/perl5/5.8.0 -Duseshrplib -Du
sethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -
Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallus
rbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef'
 useithreads=define usemultiplicity=
    useperlio= d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=un uselongdouble=
    usemymalloc=, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags
='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-ali
asing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr
/include/gdbm',
    optimize='',




cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-st
rict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.2.2 20030222 (Red Hat Linux 3.2.2-5)',
gccosandvers=''
gccversion='3.2.2 200302'
    intsize=r, longsize=r, ptrsize=5, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long'
k', ivsize=4'
ivtype='l, nvtype='double'
o_nonbl', nvsize=, Off_t='', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc'
l', ldflags =' -L/u'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libper
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so', d_dlsymun=undef,
ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi
/CORE'
    cccdlflags='-fPIC'
ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5', lddlflags='s
Unicode/Normalize XS/A'


Characteristics of this binary (from libperl):
  Compile-time options: DEBUGGING MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
PERL_IMPLICIT_CONTEXT
  Locally applied patches:
        MAINT18379
  Built under linux
  Compiled at Aug 13 2003 11:47:58
  @INC:
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0

__________________________________


Thanks in advance!
-AG-





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

Date: Sat, 27 Mar 2004 17:59:25 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Does anyone know what this switch does?
Message-Id: <4065C0D9.9020202@rochester.rr.com>

Rob Vunderink wrote:

 ...


> Check out this url:
> http://www.opstartpagina.nl/cgi-bin/ipadres.cgi
> 
> It works.
> 
> Now check out this url:
> http://angel.regioportals.nl/gelderlander/cgi-bin/ipadres.cgi
> 
> It does not work, although the scripts are the same in both cases:


"It does not work" doesn't convey much information.  What exactly does 
it do that you think it shouldn't do, or doesn't do that you think it 
should do?  (Yeah, I know, I could check out your links, but I'm lazy 
and more interested in what your server log says).


> 
> = - = - = - = - = - = - = - = -
> #!/usr/bin/perl
> 
> print "Content-type: text/html\n\n";
> print "Uw IP-adres is: $ENV{REMOTE_ADDR}";
> = - = - = - = - = - = - = - = -
> 
> Now check out this url:
> http://angel.regioportals.nl/gelderlander/cgi-bin/ipadres2.cgi
> 
> It works. The script is:
> 
> = - = - = - = - = - = - = - = -
> #!/usr/bin/perl --
> 
> print "Content-type: text/html\n\n";
> print "Uw IP-adres is: $ENV{REMOTE_ADDR}";
> = - = - = - = - = - = - = - = -
> 
> Her comes the question.
> The difference is the " --" on the shebang line. What does this switch
> do? Why does it make a difference?
> 
 ...


> Rob Vunderink


The chances are pretty good that you have some garble in your "shebang" 
line.  On a Unix-type system, this line is initially processed by the 
kernel, and the kernel is not at all forgiving of possible stuff like a 
termination of CR NL, rather than the expected NL.  Check your shebang 
line out for extraneous characters and, if present, remove them.  This 
sort of thing happens if a source file is prepared on Windoze and run on 
some flavor of Unix without converting the line endings.  Perl doesn't 
care, and the kernel doesn't care once it finds the start of an argument 
list, but the kernel does care if the first thing following the filename 
of the executable is not a space character or a newline.  Specifically, 
a CR is not acceptable (there may be some flavors of Unix that don't 
care, but at least some do).

HTH.

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Sat, 27 Mar 2004 19:19:34 +0100
From: Rob Vunderink <vunderink@t-online.de>
Subject: Re: Does anyone know what this switch does?
Message-Id: <BC8B8446.1FB0%vunderink@t-online.de>

Thanks Bob,

There is not much I can do about the server. It belongs to my employer, I
can upload things but if I want to communicate I run into red tape. They'd
say (and they said): your script is wrong and we don't know Perl.

When I say it doesn't work, I mean that the corrupted url prompts my Mac (no
windoze) to download the file instead of carrying out the script.

Since I posted my first mail today I have tried something that worked: I
uploaded an empty cgi file to the "bad" server and typed the script on line,
using BBEdit. It worked.

When I downloaded and uploaded the script again, I ran into the old problem.

My conclusion: something happens with the line endings when I upload to that
particular server. I use Fetch on my Mac on use either automatic or text
(i.e. ASCII), but this appeared not to make a difference. When I upload to
the server of my own ISP these unpleasant things don't happen.

Fortunately, " --" solves the problem of the shebang line ending on my
employer's server, but I'd rather live without the hassle.

Best regards,
Rob Vunderink



in article 4065C0D9.9020202@rochester.rr.com, Bob Walton at
invalid-email@rochester.rr.com wrote on 27-03-2004 18:59:

> Rob Vunderink wrote:
> 
> ...
> 
> 
>> Check out this url:
>> http://www.opstartpagina.nl/cgi-bin/ipadres.cgi
>> 
>> It works.
>> 
>> Now check out this url:
>> http://angel.regioportals.nl/gelderlander/cgi-bin/ipadres.cgi
>> 
>> It does not work, although the scripts are the same in both cases:
> 
> 
> "It does not work" doesn't convey much information.  What exactly does
> it do that you think it shouldn't do, or doesn't do that you think it
> should do?  (Yeah, I know, I could check out your links, but I'm lazy
> and more interested in what your server log says).
> 
> 
>> 
>> = - = - = - = - = - = - = - = -
>> #!/usr/bin/perl
>> 
>> print "Content-type: text/html\n\n";
>> print "Uw IP-adres is: $ENV{REMOTE_ADDR}";
>> = - = - = - = - = - = - = - = -
>> 
>> Now check out this url:
>> http://angel.regioportals.nl/gelderlander/cgi-bin/ipadres2.cgi
>> 
>> It works. The script is:
>> 
>> = - = - = - = - = - = - = - = -
>> #!/usr/bin/perl --
>> 
>> print "Content-type: text/html\n\n";
>> print "Uw IP-adres is: $ENV{REMOTE_ADDR}";
>> = - = - = - = - = - = - = - = -
>> 
>> Her comes the question.
>> The difference is the " --" on the shebang line. What does this switch
>> do? Why does it make a difference?
>> 
> ...
> 
> 
>> Rob Vunderink
> 
> 
> The chances are pretty good that you have some garble in your "shebang"
> line.  On a Unix-type system, this line is initially processed by the
> kernel, and the kernel is not at all forgiving of possible stuff like a
> termination of CR NL, rather than the expected NL.  Check your shebang
> line out for extraneous characters and, if present, remove them.  This
> sort of thing happens if a source file is prepared on Windoze and run on
> some flavor of Unix without converting the line endings.  Perl doesn't
> care, and the kernel doesn't care once it finds the start of an argument
> list, but the kernel does care if the first thing following the filename
> of the executable is not a space character or a newline.  Specifically,
> a CR is not acceptable (there may be some flavors of Unix that don't
> care, but at least some do).
> 
> HTH.



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

Date: Sat, 27 Mar 2004 19:45:55 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Does anyone know what this switch does?
Message-Id: <c44i4f$2ec5fo$1@ID-184292.news.uni-berlin.de>

Rob Vunderink wrote:
> The difference is the " --" on the shebang line. What does this
> switch do? Why does it make a difference?

I don't think it does.

When you say "it does not work", you probably mean that you are
prompted to open or download the script. That has nothing to do with
the code, but it rather indicates that you haven't set the execute bit
(chmod 755) and/or that you didn't upload the script in ASCII transfer
mode.

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



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

Date: Sat, 27 Mar 2004 18:03:15 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Filehandles Referenced with a Variable
Message-Id: <4065C1FE.B018725B@earthlink.net>



> choosing names are the most important decisions you ever make in
> coding. most coders don't spend nearly enough time on good names.

I know you are right there, and I am guilty.  I am trying to reform.


>
> there is an FAQ on that. read it.

Found it - thanks:

What's wrong with always quoting ``$vars''?

The problem is that those double-quotes force stringification-- coercing numbers
and references into strings--even when you don't want them to be strings. Think
of it this way: double-quote expansion is used to produce new strings. If you
already have a string, why do you need more?

If you get used to writing odd things like these:

    print "$var";       # BAD
    $new = "$old";      # BAD
    somefunc("$var");   # BAD

You'll be in trouble. Those should (in 99.8% of the cases) be the simpler and
more direct:

    print $var;
    $new = $old;
    somefunc($var);

Otherwise, besides slowing you down, you're going to break code when the thing
in the scalar is actually neither a string nor a number, but a reference:

    func(\@array);
    sub func {
        my $aref = shift;
        my $oref = "$aref";  # WRONG
    }

You can also get into subtle problems on those few operations in Perl that
actually do care about the difference between a string and a number, such as the
magical ++ autoincrement operator or the syscall() function.

Stringification also destroys arrays.

    @lines = `command`;
    print "@lines";             # WRONG - extra blanks
    print @lines;               # right


> declare vars when you first use them.

Yeah, I am doing that right now.  I need to get into that
habit.


>
> gack!! that is the whole problem. use IO::Handle or my $st and save the
> handle in a hash indexed by the state name.

I read the IO::Handle documentation and gave it a try.  The error
I get is "Can't call method "fdopen" on an undefined value at
line 16.

I have
use IO::Handle;

 . . .

foreach $st (@states) {
    $io->fdopen ( $st , '>' );
}


I also tried:
$io->fdopen ( @states , '>' );
outside the loop, but get the same error.


I was surprised to find the IO::Handle module used in
only one script in my library of scripts, and it doesn't help
much:

use strict;
use warnings;
use IO::Handle;

autoflush STDOUT;
autoflush STDERR;

print "Before\n";
sleep 5;
print "After\n";

__END__


I went through perldoc perlopentut twice.  It's quite long.

I'll go out to the web to find more examples of IO::Handle
in use.



> no need to close them by hand. exiting the program will do it for you.

OK, thanks.
Feels kinda odd, but I have removed all close statements.





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

Date: Sat, 27 Mar 2004 18:06:44 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Filehandles Referenced with a Variable
Message-Id: <4065C2CD.BE34837@earthlink.net>


Myron Turner wrote:

> I know this topic has been gone over, but this is based on
> "Programming Perl", page 249,  which I've known about but have never
> used:
>
> my %handles;
>
> for my $file(@names) {
>     my $fh;
>     $handles{$file} = $fh;
> }

This confuses me.  It's seems like $fh would not
be defined as anything useful, but I'll give it a try.



> for my $file(@names) {
>    print "$file\n";
>    my $fh = $handles{$file};
>    open($fh, $file) || die "$!: $file\n";
>    print  <$fh>;
>    close $fh;
> }
>
> I'm not sure why, but in the second loop, you have to first assign the
> hash to a variable:
>             my $fh = $handles{$file};
> You can open and close the file with using the hash directly but you
> can't simply say;
>          print   < $handles{$file}>;
> If you do it prints the value of the GLOB.
>

Interesting.



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

Date: Sat, 27 Mar 2004 18:10:18 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Filehandles Referenced with a Variable
Message-Id: <x74qsaw48l.fsf@mail.sysarch.com>

>>>>> "MF" == Mike Flannigan <mikeflan@earthlink.net> writes:

  >> there is an FAQ on that. read it.

  MF> Found it - thanks:

why did you quote the FAQ here? we all have copies already.

<snip of full FAQ entry>

  MF> I read the IO::Handle documentation and gave it a try.  The error
  MF> I get is "Can't call method "fdopen" on an undefined value at
  MF> line 16.

you didn't read it well.

  MF> I have
  MF> use IO::Handle;

  MF> . . .

  MF> foreach $st (@states) {
  MF>     $io->fdopen ( $st , '>' );
  MF> }

where is $io created? why are you calling fdopen? it has no place here
as you don't have an fd anywhere. 

look at IO::File for file opening. i said IO::Handle is to get a HANDLE
not to open a file. i also said it is inherited by other IO:: modules.

  MF> I went through perldoc perlopentut twice.  It's quite long.

so go over it several more times. look for the parts on lexical file handle.

  MF> I'll go out to the web to find more examples of IO::Handle
  MF> in use.

look at IO::File instead. i thought my original comments would have led
you to that.

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: Sat, 27 Mar 2004 18:25:36 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Filehandles Referenced with a Variable
Message-Id: <4065C73C.73FAE1BD@earthlink.net>



> This should do the trick:
>
> for my $st (@states)
> {
>   open(my $fh, ">", "$st.txt") or die "Cannot open $st.txt: $!";
>   $type{$st} = $fh;
> }
>
> As others pointed out, %type is not a good name.

Obviously I'm must incapable of figuring out what you guys
are saying.  It did not work for me at all, and I'm kinda
glad it didn't, cause it makes more sense to me if it doesn't
work.  I'm not using a hash here, but the same structure
that you suggest:

foreach $st (@states) {
    open my $fh, ">$st.txt" or die "Cannot open $st.txt: $!";
    $st = $fh;
}



What I finally settled on is:
foreach my $st (@states) {
    open $st, ">$st.txt" or die "Cannot open $st.txt: $!";
}

It works find as long as 'use strict' is not invoked.

Perhaps I was wrong about me being promoted from
newbie to novice  :-)


Thanks for the help.  I really appreciate it.



Mike




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

Date: Sat, 27 Mar 2004 18:32:45 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Filehandles Referenced with a Variable
Message-Id: <x7y8pmuomr.fsf@mail.sysarch.com>

>>>>> "MF" == Mike Flannigan <mikeflan@earthlink.net> writes:

  >> for my $st (@states)
  >> {
  >> open(my $fh, ">", "$st.txt") or die "Cannot open $st.txt: $!";
  >> $type{$st} = $fh;
  >> }
  >> 

  MF> Obviously I'm must incapable of figuring out what you guys
  MF> are saying.  It did not work for me at all, and I'm kinda
  MF> glad it didn't, cause it makes more sense to me if it doesn't
  MF> work.  I'm not using a hash here, but the same structure
  MF> that you suggest:

what does 'It did not work for me at all' mean? that is a useless
statement. did it cause your computer to burst into flames? did it empty
your bank account? what didn't work? 

and the poor name %type has nothing to do with it working or not. it is
an issue of better coding style.

  MF> foreach $st (@states) {
  MF>     open my $fh, ">$st.txt" or die "Cannot open $st.txt: $!";
  MF>     $st = $fh;
  MF> }

why do you copy the HANDLE INTO THE LOOP VARIABLE???!!! you overwrite it
each time destroying the previous handle.


  MF> What I finally settled on is:
  MF> foreach my $st (@states) {
  MF>     open $st, ">$st.txt" or die "Cannot open $st.txt: $!";
  MF> }

  MF> It works find as long as 'use strict' is not invoked.

  MF> Perhaps I was wrong about me being promoted from
  MF> newbie to novice  :-)

yep.

it is SO easy. i don't know why you seem to have this mental block on
it.

a NAMED handle is a symbolic reference so it doesn't work under
strict. creating anonymous handle references is EASY.

  MF> Thanks for the help.  I really appreciate it.

but you aren't listening to the advice. you need a FRESH DYNAMICALLY
created ANONYMOUS HANDLE for each state STORED in a HASH indexed by the
STATE name. what more do you need to be told? 

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: Sat, 27 Mar 2004 16:23:28 GMT
From: perl coder <perlcdr@mail.rumania>
Subject: Re: Loss of privledges in a perl app
Message-Id: <4Uh9c.17187$gZ3.12772@bignews3.bellsouth.net>

Sherm Pendley said:
> BTW, there's no need to call an external program like "id" to get the
> currently euid - there are Perl variables that already hold that info. $<
> and $> hold the real and effective user id, and $( and $) the real and
> effective group id. The English.pm equivalents are $REAL_USER_ID, $UID,
> $EFFECTIVE_USER_ID, $EUID, $REAL_GROUP_ID, $GID, $EFFECTIVE_GROUP_ID, and
> $EGID.

Getting slightly off-topic here, but I was wondering what exact
procedure others use to switch privileges in a running program.  I've
been using this code for a while, and I think it's fairly safe, but
maybe something is missing.

sub drop_privs {
        my ($uid, $gid) = @_;

        # clean up environment
        foreach (keys %ENV) { delete $ENV{$_} }
        $ENV{'PATH'} = '/bin:/usr/bin';

        # go hang out somewhere safe
        chdir ('/var/run') or die "chdir: $!";

        $) = $gid;  # effective gid
        $( = $gid;  # real gid
        $> = $uid;  # effective uid
        $< = $uid;  # real uid

        if ($> != $uid || $< != $uid || $) != $gid || $( != $gid) {
                die "Can't drop root privs to UID $uid, GID $gid :(\n";
        }
}

I read somewhere that it's also necessary to call fork and exit for the
switch to happen correctly.  Why is that?


-- 
No crazy stuff in my email. ;-)


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

Date: Sat, 27 Mar 2004 17:23:18 GMT
From: Andrew Rodland <arodland@eSntPerAmaMil.net>
Subject: Re: Perl:  Generate registration code
Message-Id: <aMi9c.157$y4.89084@newshog.newsread.com>


> To get better help, you should probably also explain what the & operator
> does in VB, just to help the people out who have ever been able to bring
> themselves to touch that environment.

It's just the "." operator with an incredibly confusing name.


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

Date: Sat, 27 Mar 2004 09:22:36 -0700
From: Todd Anderson <todd@asgweb.net>
Subject: Re: SCALAR(0x82dea94)
Message-Id: <4065A9BE.9FEC9320@asgweb.net>

thanks for the help. even though i have to wade through a pile of rectal
discharge, i always get what i need. by the way, i make over $100k a year
from my site and i have not had one minute of formal programming training.
touche'
also, tad... i always apply advice that is posted in a coherent, cogent,
reasonable, and intelligent manner. your comments will fix my problem.
thank you very much.
Todd Anderson wrote:

> Hello,
> I posted this before and respondents wanted more code to help decipher
> it. So I'm posting again with code below.
> I have a script that is run by crontab. It Opens $user_file (flat file)
> and checks for accounts with current date and charges the users card if
> it's 30 days old. It also sends a reminder to those who are on the 30
> day free trial. Sometimes it puts this... SCALAR(0x82dea94)   or
> something similar at the beginning of the a line in the $user_file. The
> scipt only processes 20 lines at a time to avoid server time out.
> Thanks in advance for your help.
>
> sub billing_engine {
>
> $e_number = "-1";
>   open (USERS, "$user_file") || &billerror
>         ("$user_file Billing Notice" );
>             flock(USERS, 2);
>   while (<USERS>)
>     {
>     $line = $_;
>     chomp $line;
>     @fields = split (/\|/, $line);
>
> @line =$line;
> foreach $jiggy(@line){
> $e_number++;
>
> if (($start eq "$e_number")..($end eq "$e_number")){
> $namelist .="$fields[1]\n";
> $yes_row_count++;
>
> ($dbmonth,$dbday,$dbyear) = split (/\//, $fields[$field_for_update]);
> $julian_day = &jday($dbmonth,$dbday,$dbyear);
> ($today_month,$today_day,$today_year) = split (/\//, &get_date);
> $today = &jday($today_month,$today_day,$today_year);
> $updated_days_ago = ($today - $julian_day);
>
> if($fields[$field_for_account_status] eq "Ok"){
> $current_row .= "$line";
> @chargerow = $current_row;
>
> foreach $customer (@chargerow){
>
> if ($updated_days_ago >= "30"){
> $auth_count++;
>
> &auto_send_to_authorizenet;
>
> if($declined){
> $fields[$field_for_account_status] = "Ten_Days_Left";
> $new_current_row .= join('|' => @fields) . "\n";
> $email_user = $fields[$field_for_email];
> &declined_email;
> &admin_declined_email;
> $email_user = "";
> }
> else{    #not declined
> $fields[$field_for_account_status] = "Ok";
> $fields[$field_for_update] = "$current_date";
> $new_current_row .= join('|' => @fields) . "\n";
> $email_user = $fields[$field_for_email];
> &write_log;
> &account_paid_email;
> &admin_account_paid_email;
> $email_user = "";
> }#else not declined
>
> }# if 30 days old
>
> #save all the ones not 30 days old yet
> else{ $new_current_row .=  "$line\n";}
>
> }# foreach chargerow
>
> $new_current_row = "$new_current_row";
> }#status Ok
>
> ###########################################
>
> else {#not Ok
> $bill_row .= "$line";
> @bill_row = $bill_row;
>
> foreach $bill (@bill_row ){
> #This is what we do with all the people on 30 day trial
>
> $bill_row_count++;
>
> ################
> if($fields[$field_for_account_status] eq "One_Day_Left"){
> $One_bill_row_count++;
> $Thirty_bill_row_count++;
> $fields[$field_for_account_status] = "Delete";
> $Thirty_bill_row .= join('|' => @fields) . "\n";
> }
>
> #################
> elsif($fields[$field_for_account_status] eq "Two_Days_Left"){
> $Thirty_bill_row_count++;
> $fields[$field_for_account_status] = "One_Day_Left";
> $Thirty_bill_row .= join('|' => @fields) . "\n";
> $email_user = $fields[$field_for_email];
> &thirty_day_email;
> $email_user = "";
> }
>
>  #etc to 30-day-trial
>
> #################
> elsif($fields[$field_for_account_status] eq "30-Day-Trial"){
> $Thirty_bill_row_count++;
> $fields[$field_for_account_status] = "TwentyNine_Days_Left";
> $Thirty_bill_row .= join('|' => @fields) . "\n";
> $email_user = $fields[$field_for_email];
> &thirty_day_email;
> $email_user = "";
> }
>
> #################
> elsif($fields[$field_for_account_status] eq "Donated"){
> $Thirty_bill_row_count++;
> $fields[$field_for_account_status] = "Donated";
> $Thirty_bill_row .= join('|' => @fields) . "\n";
> $email_user = $fields[$field_for_email];
> $email_user = "";
> }
>
> #################
>
> else{
> $Leftover_bill_row_count++;
> $Thirty_bill_row_count++;
> $fields[$field_for_account_status] = "LeftOver";
> $Thirty_bill_row .= join('|' => @fields) . "\n";
>  }
>
> #################
>
>              }#foreach $bill
>          }#else
>
>  }#@billingnumber
> else{ $hold_row_count++;
>  $hold_row .="$line\n"; }
>
>   }#jiggy
> }#while
>  flock(USERS, 8);
>   close (USERS);
>
> open (USERS, ">$user_file") || &billerror("$user_file Billing Notice");
>             flock(USERS, 2);
> print USERS "$hold_row";
> print USERS "$new_current_row";
> print USERS "$Thirty_bill_row";
>
>  flock(USERS, 8);
>     close (USERS);
>
> ############
>
> }#billing engine



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

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


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