[19013] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1208 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 28 03:06:39 2001

Date: Thu, 28 Jun 2001 00:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993711912-v10-i1208@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 28 Jun 2001     Volume: 10 Number: 1208

Today's topics:
    Re: Calling package subroutines <goldbb2@earthlink.net>
    Re: Calling package subroutines (^CooL^)
    Re: cant modify $_[x] ???? <patelnavin@icenet.net>
    Re: Checking for duplicates before appending to file <goldbb2@earthlink.net>
    Re: command line news posting tools <sun_tong@users.sourceforge.net>
    Re: Compile perl on Solaris <djberg96@hotmail.com>
        Good perl web board w/image upload (OJ)
    Re: How to Build a Perl with Tk Package (Clinton A. Pierce)
        how to setup exit routine using eval  <j.vazapully@worldnet.att.net>
    Re: is there a way to look ahead/behind in a foreach (@ (Tony L. Svanstrom)
    Re: is there a way to look ahead/behind in a foreach (@ (Tony L. Svanstrom)
    Re: is there a way to look ahead/behind in a foreach (@ <goldbb2@earthlink.net>
    Re: is there a way to look ahead/behind in a foreach (@ (Jay Tilton)
    Re: is there a way to look ahead/behind in a foreach (@ (Craig Berry)
    Re: New to perl (Clinton A. Pierce)
    Re: New to perl <james@zephyr.org.uk>
    Re: newbie question-- need to do a search and replace o <james@zephyr.org.uk>
    Re: Newbie question: What's the opposite of chop? <krahnj@acm.org>
    Re: Newbie question: What's the opposite of chop? <jurgenex@hotmail.com>
        opposite of chop <eng80956@nus.edu.sg>
    Re: passing variables the 'right' way (Abigail)
    Re: Perl *is* strongly typed (was Re: Perl description) <johnlin@chttl.com.tw>
        Perl on AS/400 <coberbeck@hotmail.com>
    Re: Perl request <goldbb2@earthlink.net>
    Re: PostgreSQL/Perl error <cshannon@data2design.com>
        Process Errors <smichae@ilstu.edu>
    Re: range operator in scalar context - how to make it t <johnlin@chttl.com.tw>
    Re: range operator in scalar context - how to make it t (Charles DeRykus)
    Re: Reading binary data (method and style)? <goldbb2@earthlink.net>
    Re: Selling Scripts <sun_tong@users.sourceforge.net>
    Re: shell command <goldbb2@earthlink.net>
    Re: using System() and exec() <goldbb2@earthlink.net>
    Re: weird hash behaviour. <johnlin@chttl.com.tw>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 28 Jun 2001 01:36:21 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Calling package subroutines
Message-Id: <3B3AC255.41F9440C@earthlink.net>

^CooL^ wrote:
[snip]
> Here is an extract of the code in Conf.pm
> 
> package Dir::Conf;
[snip]
> *config = \%Conf::config;
[snip]

Your package is named Dir::Conf, but you are trying to use things from
package Conf.  %Dir::Conf::config exists, but %Conf::config does not.

Also, you seem to misunderstand when to use "use lib ..." and are [I
think] putting it where you should simply do "use packagename;"  In
addition, your BEGIN in Dir::Conf is extraneous.

The way I would write all this code might be something like:

In file Dir/Conf.pm:
#! perl
package Dir::Conf;
use Exporter;
use strict;
use warnings;

use base qw(Exporter);
use vars qw(@EXPORT_OK %config @connectionPool);
@EXPORT_OK = qw(%config %connectionpool);

sub initialize {
  ....
}
 .....

in somefile.pl, which uses Dir::Conf, have the following code:
#! perl
use strict;
use warnings;
use Dir::Conf qw(%config @connectionPool);

Dir::Conf::initialize();


-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: 27 Jun 2001 23:50:48 -0700
From: cool133@hotmail.com (^CooL^)
Subject: Re: Calling package subroutines
Message-Id: <211c8e3f.0106272250.24045d96@posting.google.com>

Thanks everyone for your kind help.
I got it to work thanks to you. :-)

Clyde.

Philip Newton <pne-news-20010627@newton.digitalspace.net> wrote in message news:<3dujjt4ncee60302jc2grqavqesl6gkhtu@4ax.com>...
> On 27 Jun 2001 08:16:00 -0700, cool133@hotmail.com (^CooL^) wrote:
> > I have created a package called Conf.pm
> 
> I doubt it. Looks like you have a *file* called Conf.pm which declares a
> *package* called Dir::Conf. See:
> 
> > package Dir::Conf;
> 
> [snip]
> > On running this script, I get the following error message:
> >   Undefined subroutine &Conf::initialise called at ./start.cgi
> > 
> > How on earth could this be??
> 
> I didn't see you 'use Dir::Conf;', so the subroutine never got defined.
> 
> Also, you shouldn't have to do this:
> 
> > # Import Global Variables
> > use vars qw(%config @connectionPool);
> > *config = \%Conf::config;
> > *connectionPool = \%Conf::connectionPool;
> 
> , as Dir::Conf will export those variables for you if you ask nicely,
> thanks to Exporter:
> 
> >   @Dir::Conf::EXPORT_OK = qw(%config @connectionPool);
> 
> So 'use Dir::Conf qw(%config @connectionPool);' should work.
> 
> You'll probably also have to change "use lib qw(..)" to "use lib
> qw(../..)" since "use Dir::Conf" will look for "Dir/Conf.pm" not just
> "Conf.pm".
> 
> But even then, Conf.pm declared the package Dir::Conf and not Conf, so
> the subroutine will be Dir::Conf::initialise.
> 
> Cheers,
> Philip
> 
> Cheers,
> Philip


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

Date: Thu, 28 Jun 2001 10:25:26 +0530
From: "Aman Patel" <patelnavin@icenet.net>
Subject: Re: cant modify $_[x] ????
Message-Id: <9hedb0$dd43v$1@ID-93885.news.dfncis.de>

> e.g.
> &doRemovePipes( my $modifyable_copy_of_text = $text );
>
> Now, what is it you really wanted to know?

Thanks!!!, i am sorry I am not conforming to the normal posting rules of
this news-group. It happens, I am experienced with perl, but have been here
for only 1 week.

I will learn from people like you, thanks for your help. Next time I will
copy paste my actual code and not 'made-up' couter-parts of the original.

And I am glad of the other solution which might be faster:

      $_[0] =~ tr/|//d;

And I have 1 more question:


why is e.g.
&doRemovePipes( my $modifyable_copy_of_text = $text );

why can $text be modifiable to begin with, What I mean to ask is what makes
a variable modifyable/non-modifyable... apparently the following are
read-only (i want to know why, perhaps a manpage would help but which man
page!)

$text = \'read-only text';
&pass_to_function( 'read-only text?' );

any other examples if you have...




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

Date: Thu, 28 Jun 2001 01:10:59 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Checking for duplicates before appending to file
Message-Id: <3B3ABC63.13ECBFF@earthlink.net>

David Soming wrote:
[snip]
> > > open(EMAILS,"address.txt");
> > > @address=<EMAILS>;
> > > close(EMAILS);
> >
> > Just because you are just reading is no reason not to lock the file.
> > And wouldn't it be better to open the file in read/write mode?
> Yes I agree, but ...

But what?

> > open( EMAILS, ">>", "address.txt" )
> > or die "Could not open address.txt in rw mode: $!";

Umm, minor mistake of mine, that should be "<+" not ">>".

> My server reports misconfiguration- even with chmod set at 755 or 777?
> seems like "," ", " and/or the line:

You are confusing which strings are quoted.  There's a handle, then a
comma, then a quoted string containing the mode to open the file in,
then a quoted string containing the name of the file.  I do not have a
quoted comma, as you seem to be implying.

> die "Could not open address.txt in rw mode: $!";
> reports server misconfig too?

The purpose of having an error message with die is to allow you to find
out what went wrong.  The httpd reports a server misconfig if the CGI
script exits in an unusual manner.  To see why, either put in a line
	use CGI qw(fatalsToBrowser);
or else post a snippet of the log produced.

Anyway, I would assume that the die line is causing the script to exit,
but it the reason it is being reached is that the open is failing. 
Probably because "address.txt" is a relative pathname, and *you* are
assuming that the cwd is the same as where the perl/cgi script is, but
in probable fact, the cwd is something else.

> (no further error details or access to logs)

Why not?  You don't want us to help you?

[snip]
> > while( <EMAILS> ) {
> > next unless /^\Q$email{address}\E$/i;
> > print <<"\t\tHEREDOC"
> > The email address you entered, <B>$email{address}</B>
> > is already in our mailing list.
> > HEREDOC
> > exit;
> > }
> The above reports Software error:
> Can't find string terminator "\t\tThe email address you entered,
> <B>$email{address}</B>is already in our mailing list." anywhere before
> EOF What exactly does that mean? have I implimented this right...

There are two problems, both of which are very important.  First off, I
left off a semicolon after "\t\tHEREDOC"  Second, have foolishly
stripped out the tabs from my post.

> while( <EMAILS> ) {
> next unless /^\Q$email\E$/i;
> print <<"\t\t The email address you entered, <B>$email{address}</B>is
> already in our mailing list.";

Eww, yuck.  What the f*** is this c*** supposed to be?  Don't you
understand what the << does?

> print EMAILS $email{address}, "\n";
> close EMAILS or die "close(address.txt) : $!\n"; # disk full?
> exit;

And you have an unmatched { from the while.

> > # after the while loop, we should be at the EOF...
> > # which coincidentally is right where we want to write to.
> > print EMAILS $email{address}, "\n";
> > close EMAILS or die "close(address.txt) : $!\n"; # disk full?
> > exit;
> >
> > There's no need to explicitly unlock the file, since that should
> > automatically happen when the file is closed.
> OK, thats understood.
> >
> > Note that I'm allowed to indent the string HEREDOC due to the fact
> > that the indent (the \t\t) is part of the string being searched for.
> > If you change the indentation, do it in both places.  If your
> > newsreader strips tabs, umm... get rid of the \t\t before the first
> > string HEREDOC, or something.
>
> By HEREDOC I'm assuming you mean my string "as above between these
> quotation marks" or have I misunderstood? and what do you mean by
> "change it in BOTH places" ?

Well, since you seem to be incapable of seeing tabs, I'll write the code
with the tabs changed to spaces.

        while( <EMAILS> ) {
                next unless /^\Q$email{address}\E$/i;
                print <<"        HEREDOC"; # I forgot the ; last time :)
The email address you entered, <B>$email{address}</B>
is already in our mailing list.
                HEREDOC
                exit;
        }

When perl sees the symbol << it begins parsing a here-document.  It
pulls in the next string, then searches for that string surrounded by
newlines (no extra whitespace allowed).  By having the first instance of
HEREDOC preceded by 16 spaces, it searches for \n, 16 spaces, HEREDOC,
then \n.  Then everything up to (but not including) the first \n becomes
the passed string.  Umm, could somebody give a clearer explanation of
how here documents work?

[snip]
> > --
> > The longer a man is wrong, the surer he is that he's right.

Never quote people's sigs unless you are commenting on them.

> IM having to debug remotely too because flock() is not implemented on
> my platform, although I could comment out- but still get the above
> errors which doesn't further narrow things down much.

Well, you could add a modifiyer to the flock line...
replace:
        flock EMAILS, LOCK_EX
                or die "Could not gain flock for address.txt: $!\n";
with:
        flock EMAILS, LOCK_EX
                or die "Could not gain flock for address.txt: $!\n"
                unless $^O =~ /OS with no flock/;

Then you'll have a script which should run ok on both, assuming
everything else works.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: 27 Jun 2001 22:39:20 -0300
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Re: command line news posting tools
Message-Id: <sa87kxxjsc7.fsf@suntong.personal.users.sourceforge.net>

Philip Newton <pne-news-20010627@newton.digitalspace.net> writes:

> > - I test with a pipe command but it didn't work
> > 
> >  cat file | nntppost 
> > 
> > and neither is:
> > 
> >  cat file | nntppost -
> 
> a) "didn't work" is too vague. Did it cause your printer to shoot out
> empty pages? Did it return an error message?

try it yourself and you can know exactly how it "didn't work"

> b) My PSI::ESP module is not working. Showing us the code of the
> 'nntppost' that you are using would help.

simple:

perl -Mstrict -MNet::NNTP <<'__END__' ${1+"$@"}
    my $n = Net::NNTP->new("news");
    my @article = <>;
    $n->post(\@article) or die "Post error: $!";
    $n->quit;
__END__

Beside, also didn't work when test on command line: paste in some
text, press ^d, nothing happened as if program was still waiting for
something...

-- 
Tong (remove underscore(s) to reply)
  *niX Power Tools Project: http://xpt.sourceforge.net/
  - All free contribution & collection


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

Date: Thu, 28 Jun 2001 02:26:40 GMT
From: "Daniel Berger" <djberg96@hotmail.com>
Subject: Re: Compile perl on Solaris
Message-Id: <ABw_6.43$y76.14795@typhoon.mn.mediaone.net>

"Sourisseau" <pascal.sourisseau@businessobjects.com> wrote in message
news:c9434ed2.0106270928.73fd8c96@posting.google.com...
> Hi,
> We would compile perl on Solaris 2.6 but...........
> we try to understand where there is an error... but we don't.
> If somebody has an idea or can help you,
>
>
> Perl Distribution : 5.6.1
> Solaris 2.6 with already an perl 5.6
> cc : Forte 6 Update 1

Your best bet is to give up on the Forte cc compiler.  I have yet to have
that compiler 'make' anything successfully.  Try using gcc and see what
happens.

Regards,

Dan





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

Date: 27 Jun 2001 19:31:20 -0700
From: orljustin@aol.com (OJ)
Subject: Good perl web board w/image upload
Message-Id: <77d3a68b.0106271831.706fe5b6@posting.google.com>

Hi there,

Anybody have an opinion on a good web board that you can upload images
to?  Needs to be free - no budget - run on unix, too.  I see 'discus'
can take images.  Can you lose the frame look on that?  Any suggs?

Thanks!

oj


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

Date: Thu, 28 Jun 2001 02:20:38 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: How to Build a Perl with Tk Package
Message-Id: <Wvw_6.134882$DG1.22477058@news1.rdc1.mi.home.com>

[Posted and mailed]

In article <3B3A67C4.76096541@yahoo.com>,
	Roger Hsu <rogerhsu2001@yahoo.com> writes:
> Hi all,
> 
> When I run my compiled Perl/Tk codes in a Solaris 7 box, I got the
> following

"compiled Perl/Tk codes"?  What does this mean?  Did you build Perl
and then install the Bundle::Tk from CPAN?

> error messages:
> 
> Can't load module Tk::NBFrame, dynamic loading not available in this
> perl.

Sounds like you don't have everything quite built right, or you've
mucked with the installation after the fact.

-- 
    Clinton A. Pierce            Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org                Perl Developer's Dictionary
"If you rush a Miracle Man,     for details, see http://geeksalad.org     
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Thu, 28 Jun 2001 06:51:13 GMT
From: "Joy Vazapully" <j.vazapully@worldnet.att.net>
Subject: how to setup exit routine using eval 
Message-Id: <BtA_6.12868$C81.1011212@bgtnsc04-news.ops.worldnet.att.net>

Hi

Does anyone know how to set up an exit routine using eval.
It's explained on page 162 of programming perl, but I don't quite understand
it. I know it can be done using END but I was just curious.

Thanks
Joy




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

Date: Thu, 28 Jun 2001 03:08:39 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: is there a way to look ahead/behind in a foreach (@l)?
Message-Id: <1evp4na.1r59ba2q0ldvkN%tony@svanstrom.com>

tuxy <nospam@cfl.rr.com> wrote:

> I could peek ahead or behind in an old-fashioned loop such as:
> 
>   for ($i=2; $i<100; $i++)
>    {print 'yikes!' if ($l[$i]> $l[$i-1]);}
> 
> is there a way to see other elements of an array in a foreach, as in:
>  
>   foreach (@l)
>     {next unless defined $predecessor;
>      print 'yikes!' if ($_ > $predecessor);}

Combine them, sort of...

@::test = (1,2,3,4,5,6,7,8,9);
foreach (@::test) {$::i++; print "$_ $::i @::test[$::i-1]\n"}


        /Tony
-- 
the truth is dead, faith is gone, reality killed... ruled by the plastic
laws of modern life we're pushed towards the hell of personal doubt,
betrayal, hate, lust and murder... the now has become an illusion, a
paradise of a dead tomorrow... (c)2000-2001 tony@svanstrom.com


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

Date: Thu, 28 Jun 2001 03:09:59 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: is there a way to look ahead/behind in a foreach (@l)?
Message-Id: <1evp4zj.x27eclxf3623N%tony@svanstrom.com>

Tony L. Svanstrom <tony@svanstrom.com> wrote:

> tuxy <nospam@cfl.rr.com> wrote:
> 
> > I could peek ahead or behind in an old-fashioned loop such as:
> > 
> >   for ($i=2; $i<100; $i++)
> >    {print 'yikes!' if ($l[$i]> $l[$i-1]);}
> > 
> > is there a way to see other elements of an array in a foreach, as in:
> >  
> >   foreach (@l)
> >     {next unless defined $predecessor;
> >      print 'yikes!' if ($_ > $predecessor);}
> 
> Combine them, sort of...
> 
> @::test = (1,2,3,4,5,6,7,8,9);
> foreach (@::test) {$::i++; print "$_ $::i @::test[$::i-1]\n"}

I change the text that went along with the code, so it looks kind of
weird, but it still works... =)


        /Tony
-- 
the truth is dead, faith is gone, reality killed... ruled by the plastic
laws of modern life we're pushed towards the hell of personal doubt,
betrayal, hate, lust and murder... the now has become an illusion, a
paradise of a dead tomorrow... (c)2000-2001 tony@svanstrom.com


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

Date: Thu, 28 Jun 2001 01:17:03 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: is there a way to look ahead/behind in a foreach (@l)?
Message-Id: <3B3ABDCF.7B2F36E2@earthlink.net>

Craig Berry wrote:
> 
> tuxy (nospam@cfl.rr.com) wrote:
> : I could peek ahead or behind in an old-fashioned loop such as:
> :
> :   for ($i=2; $i<100; $i++)
> :    {print 'yikes!' if ($l[$i]> $l[$i-1]);}
> :
> : is there a way to see other elements of an array in a foreach, as
> : in:
> :
> :   foreach (@l)
> :     {next unless defined $predecessor;
> :      print 'yikes!' if ($_ > $predecessor);}
> 
> Not directly.  You can fake it like this:
> 
>   my $predecessor;
> 
>   foreach (@l) {
>     next unless defined $predecessor;
>     print 'yikes!' if $_ > $predecessor;
>     $predecessor = $_;
>   }

Don't you mean:
  foreach (@l) {
    next unless defined $predecessor;
    print 'yikes!' if $_ > $predecessor;
  } continue {
    $predecessor = $_;
  }

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Thu, 28 Jun 2001 05:49:56 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: is there a way to look ahead/behind in a foreach (@l)?
Message-Id: <3b3ac4d8.19685418@news.erols.com>

On Thu, 28 Jun 2001 10:11:26 +0930, "Wyzelli" <wyzelli@yahoo.com> wrote:

>"Craig Berry" <cberry@cinenet.net> wrote in message
>news:tjktktagsh3c0d@corp.supernews.com...
>>   my $predecessor;
>>
>>   foreach (@l) {
>>     next unless defined $predecessor;
>>     print 'yikes!' if $_ > $predecessor;

     } continue {
     #  :)

>>     $predecessor = $_;
>>   }
>
>At what point do you expect $predecessor to become defined? :)



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

Date: Thu, 28 Jun 2001 05:57:31 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: is there a way to look ahead/behind in a foreach (@l)?
Message-Id: <tjlhqblndc049c@corp.supernews.com>

Wyzelli (wyzelli@yahoo.com) wrote:
: >   my $predecessor;
: >
: >   foreach (@l) {
: >     next unless defined $predecessor;
: >     print 'yikes!' if $_ > $predecessor;
: >     $predecessor = $_;
: >   }
: 
: At what point do you expect $predecessor to become defined? :)

Oh, ouch.  Sorry about that.  Revised version:

  my $predecessor;

  foreach (@l) {
    print 'yikes!' if defined $predecessor && $_ > $predecessor;
    $predecessor = $_;
  }

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Thu, 28 Jun 2001 02:18:06 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: New to perl
Message-Id: <ytw_6.134881$DG1.22475284@news1.rdc1.mi.home.com>

[Posted and mailed]

In article <66690ccf.0106271605.530b975d@posting.google.com>,
	disneyfnatc@msn.com (Adam) writes:
> I downloaded the perl development kit from www.perl.com (the win32
> version because I am running windows ME).  How do I load this on my
> system there does not seem to be a .exe file and the readme is geared
> toward UNIX systems.

If you're really starting off fresh in this environment, head over to 
Activestate and download their build of perl.  It's put together with an
installer bundle and nearly foolproof.

As for your other questions...you might do well to pick up a good book
on perl.  See the signature for one suggestion.

-- 
    Clinton A. Pierce           Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org                Perl Developer's Dictionary 
"If you rush a Miracle Man,     for details, see http://geeksalad.org     
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Thu, 28 Jun 2001 03:22:22 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: New to perl
Message-Id: <gxhoh7VeTpO7EwSx@gratiano.zephyr.org.uk>

In message <66690ccf.0106271605.530b975d@posting.google.com>, Adam
<disneyfnatc@msn.com> writes
>I downloaded the perl development kit from www.perl.com (the win32
>version because I am running windows ME).  How do I load this on my
>system there does not seem to be a .exe file and the readme is geared
>toward UNIX systems.

Your best option is to use the ActiveState version:

        www.activestate.com
        http://aspn.activestate.com/ASPN/Downloads/ActivePerl/

This is more geared towards Windows (and should work under Me).

Basic pointers for a newbie would also be:

1) Read http://www.perl.com/pub/v/faqs   - lots of excellent questions
        and answers
2) Read as much of the group as you feel comfortable with
3) Use http://learn.perl.org/

-- 
James Coupe                                                PGP Key: 0x5D623D5D
"You reinstall Dial-Up Networking.  The Elf screams and becomes  EBD690ECD7A1F
an icon. *** CONGRATULATIONS! *** You completed the BT Internet  B457CA213D7E6
Helpdesk training course in 15 out of a possible 9000 moves."   68C3695D623D5D


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

Date: Thu, 28 Jun 2001 04:29:36 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: newbie question-- need to do a search and replace of text in files including automatic system date
Message-Id: <SQO0Z0egSqO7EwHF@gratiano.zephyr.org.uk>

In message <9hdjch$inp$1@news.netvision.net.il>, Steven Been
<stevenb@netvision.net.il> writes
>Perl script which does the following (batch mode):
>need to search and replace text in files-- replaced text remains constant
>but must include system date which changes everyday automatically?
>any suggetions greaty appreciated

Extract the relevant bits from localtime, stick it together in a
variable along with the constant text.

Then just do a standard search and replace as per:

        "How do I change one line in a file/delete a line in a
        file/insert a line in the middle of a file/append to the
        beginning of a file?"

in the Perl FAQ, with the variable you've just made as the replace
string.

-- 
James Coupe                                                PGP Key: 0x5D623D5D
"You reinstall Dial-Up Networking.  The Elf screams and becomes  EBD690ECD7A1F
an icon. *** CONGRATULATIONS! *** You completed the BT Internet  B457CA213D7E6
Helpdesk training course in 15 out of a possible 9000 moves."   68C3695D623D5D


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

Date: Thu, 28 Jun 2001 01:08:20 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Newbie question: What's the opposite of chop?
Message-Id: <3B3A83C2.6BE86EB4@acm.org>

Richard Wellum wrote:
> 
> Hi,
> 
> I started writing in perl about two days ago - so forgive the simplistic
> nature
> of this question.....
> 
> I used chop after reading a file to an array, to remove the "\n"'s, so I
    ^^^^^^^^^
You should really use chomp instead. chop will remove _any_ character at
the end while chomp will only remove the current value of $/ (usually
"\n")

chomp @raw_data;


> can process the array:
> 
> foreach $all (@raw_data)
>     {
>  chop($all);

   chomp $all;

> .......more code;
>     }
> 
> Now I have finished my manipulation of the array, and want to write this
> array back to the file. How to I add "\n"'s back to the end of each line
> in my array?
> 
> I tried:
> 
>  $ctr=0;
>  foreach $some (@raw_data)
>  {
>      @raw_data[$ctr]="$some\n";
      ^^
This should give you a warning. You _do_ have warnings enabled?

>      $ctr++;
>  }
> 
> Which partially works.... But seems to add newlines at the beginning of
> each line in the file too. Without the newlines my file is no longer an
> array - just a long string...


{
local $" = "\n";
print OUT "@raw_data\n";
}

# OR

print OUT "$_\n" for @raw_data;



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 27 Jun 2001 22:35:12 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Newbie question: What's the opposite of chop?
Message-Id: <3b3ac213$1@news.microsoft.com>

"Richard Wellum" <rwellum@cisco.com> wrote in message
news:3B3A71F0.2A8DEFE6@cisco.com...
At least two issues here

> I used chop after reading a file to an array, to remove the "\n"'s, so I
> can process the array:

You may want to use chomp instead of chop, it is much safer.

> Now I have finished my manipulation of the array, and want to write this
> array back to the file. How to I add "\n"'s back to the end of each line
> in my array?
>  $ctr=0;
>  foreach $some (@raw_data)
>  {
>      @raw_data[$ctr]="$some\n";
>      $ctr++;
>  }

Why not just
    $some = "$some\n"
inside of the loop (forget about the $crt, it complicates things
unnecessary)?

> Which partially works.... But seems to add newlines at the beginning of
> each line in the file too.

See if this fixes the problem.

jue




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

Date: Thu, 28 Jun 2001 14:53:27 +0800
From: Murlimanohar Ravi <eng80956@nus.edu.sg>
Subject: opposite of chop
Message-Id: <191C91BDFE8ED411B84400805FBE794C12BFE937@pfs21.ex.nus.edu.sg>


Hi,
I'm a newbie too but I had an idea - why bother with putting newlines
back in the data when you can merely save the old data in a new variable
before manipulating it? Hope I'm making sense... what I mean to say is:

@old_raw_data = @raw_data;

foreach $all (@raw_data)
    {
chop($all);
 .......more code;
    }

print @old_raw_data;		# or whatever u want to do with the old
data

How does this solution rate in your eyes?
Still learning,
Murli.




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

Date: 28 Jun 2001 01:05:26 GMT
From: abigail@foad.org (Abigail)
Subject: Re: passing variables the 'right' way
Message-Id: <slrn9jl0u5.4a6.abigail@alexandra.xs4all.nl>

Jakob Schmidt (sumus@aut.dk) wrote on MMDCCCLIV September MCMXCIII in
<URL:news:m266dl8sf9.fsf@pocketlife.dk>:
\\ Joe Schaefer <joe+usenet@sunstarsys.com> writes:
\\ 
\\ > Jakob Schmidt <sumus@aut.dk> writes:
\\ > 
\\ > A list assignment is not "a mere lookup".
\\ 
\\ I thought it sorta was.
\\ 
\\ > I think you are confusing 
\\ > that with
\\ > 
\\ >     my $x = $_[0];
\\ 
\\ I can see the difference, but I felt pretty sure that my ( $x ) = @_; and
\\ my $x = $_[ 0 ]; would result in the exact same byte code. Apparantly I
\\ was wrong.


    $ perl -Dt -we 'sub f {my $x = $_ [0]} f'

    EXECUTING...

    (-e:0)  enter
    (-e:0)  nextstate
    (-e:1)  pushmark
    (-e:1)  gv(main::f)
    (-e:1)  entersub
    (-e:1)  nextstate
    (-e:1)  aelemfast
    (-e:1)  padsv[1]
    (-e:1)  sassign
    (-e:1)  leavesub
    (-e:1)  leave

    $ perl -Dt -we 'sub f {my ($x) = @_} f'    

    EXECUTING...

    (-e:0)  enter
    (-e:0)  nextstate
    (-e:1)  pushmark
    (-e:1)  gv(main::f)
    (-e:1)  entersub
    (-e:1)  nextstate
    (-e:1)  pushmark
    (-e:1)  gv(main::_)
    (-e:1)  rv2av
    (-e:1)  pushmark
    (-e:1)  padsv[1]
    (-e:1)  aassign
    (-e:1)  leavesub
    (-e:1)  leave

    $

\\ It still confuses me though, why list assignment wouldn't just be
\\ syntactic sugar for a sequence of lookups and assignments. Perhaps
\\ you can explain it?

    $ perl -Dt -we 'sub f {my ($x, $y, $z, $a, $b, $c, $d) = @_} f'

    EXECUTING...

    (-e:0)  enter
    (-e:0)  nextstate
    (-e:1)  pushmark
    (-e:1)  gv(main::f)
    (-e:1)  entersub
    (-e:1)  nextstate
    (-e:1)  pushmark
    (-e:1)  gv(main::_)
    (-e:1)  rv2av
    (-e:1)  pushmark
    (-e:1)  padsv[1]
    (-e:1)  padsv[2]
    (-e:1)  padsv[3]
    (-e:1)  padsv[4]
    (-e:1)  padsv[5]
    (-e:1)  padsv[6]
    (-e:1)  padsv[7]
    (-e:1)  aassign
    (-e:1)  leavesub
    (-e:1)  leave

See how little this differs from 'my ($x) = @_'? 

    $ perl -Dt -we 'sub f {my $x = $_ [0]; my $y = $_ [1]; my $z = $_ [2];\
                           my $a = $_ [3]; my $b = $_ [4]; my $c = $_ [5];\
                           my $d = $_ [6]} f'

    EXECUTING...

    (-e:0)  enter
    (-e:0)  nextstate
    (-e:1)  pushmark
    (-e:1)  gv(main::f)
    (-e:1)  entersub
    (-e:1)  nextstate
    (-e:1)  aelemfast
    (-e:1)  padsv[1]
    (-e:1)  sassign
    (-e:1)  nextstate
    (-e:1)  aelemfast
    (-e:1)  padsv[2]
    (-e:1)  sassign
    (-e:1)  nextstate
    (-e:1)  aelemfast
    (-e:1)  padsv[3]
    (-e:1)  sassign
    (-e:1)  nextstate
    (-e:1)  aelemfast
    (-e:1)  padsv[4]
    (-e:1)  sassign
    (-e:1)  nextstate
    (-e:1)  aelemfast
    (-e:1)  padsv[5]
    (-e:1)  sassign
    (-e:1)  nextstate
    (-e:1)  aelemfast
    (-e:1)  padsv[6]
    (-e:1)  sassign
    (-e:1)  nextstate
    (-e:1)  aelemfast
    (-e:1)  padsv[7]
    (-e:1)  sassign
    (-e:1)  leavesub
    (-e:1)  leave

    $

Big difference now! It looks like list assignment is generally faster than
doing all the separate lookups and scalar assignment. The one element list
assignment is the exception that proves the rule.



Abigail
-- 
BEGIN {$^H {q} = sub {pop and pop and print pop}; $^H = 2**4.2**12}
"Just "; "another "; "Perl "; "Hacker\n";


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

Date: Thu, 28 Jun 2001 11:08:32 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: Perl *is* strongly typed (was Re: Perl description)
Message-Id: <9he6ub$os5@netnews.hinet.net>

"Abigail" wrote

> This one will eventually loop:
>     perl -wle '$var = 3; while (1) {print ++ $var}'
>
> This one never loops:
>     perl -wle '$var = "3"; while (1) {print ++ $var}'

Sorry, I don't know what you mean.
I got the same result (endless loop).  Do you have any typo?

Thank you.
John Lin





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

Date: Thu, 28 Jun 2001 03:37:19 GMT
From: "coberbeck" <coberbeck@hotmail.com>
Subject: Perl on AS/400
Message-Id: <PDx_6.94291$mG4.43244311@news1.mntp1.il.home.com>

We are running an AS/400 V4R4 and would like to use a PERL script on our
Net.Commerce 3.2 enhanced web-site.  We have found the link to Perl 5.005

http://www.iseries.ibm.com/tstudio/workshop/tiptools/perl.htm

Has anyone had any experience with implementing PERL?  Here is the script we
would like to run from the HTTP web server to accept a post from Yahoo
Store.  Would it work?

#!/usr/local/bin/perl
#
# Install (a modified version of) this program in your webserver's cgi-bin
directory.
#
# This demo program prints the order into /tmp/yahoo-order; you will
probably want
# to do something more interesting with it. Replace the function
handle_order
# It also puts the raw key-value fields into /tmp/yahoo-order.raw
#
# Order fields are:
#
# ID
#   A unique order identifier including the Y! Store account name, such as
acme-451
#
# Date
#   Standard date format, in GMT
#
# {Ship,Bill}-Name, -Firstname, -Lastname
#   These fields are always defined. If your store is configured to have
separate first and last
#   name fields on the order page, then -Name will be the concatenation of
them. If it is configured to have
#   a single entry field, then the split into Firstname and Lastname will be
a guess.
#
#   If you have custom fields, they will appear here too. The field names
look like "Ship-Pack in dry ice"
#   for an extra shipping field, and similarily for a billing field.
#
#
{Ship,Bill}-Address1, -Address2, -City, -State, -Zip, -Country, -Phone, -Ema
il
#   The shipping and billing address. Both will be filled in, and will be
the same if the
#   user only gave one address
#
# Card-Name, -Number, -Expiry
#   Credit card info
#
# Item-Id-N, -Code-N, -Quantity-N, -Unit-Price-N, -Description-N, -Url-N,
#   For values of N from 1 to Item-Count, the relevant attributes of each
item are given.
#   This script contains code to separate these into an @items array.
#   Code is from the "Code" field when editing the item, typically an SKU or
ISBN
#   Unit-Price takes any quantity pricing into account
#
# Tax-Charge, Shipping-Charge, Total
#   Extra charges, and the order total
#

require 5.001;
use strict;

if ($ENV{'REQUEST_METHOD'} ne "POST") {
    die("Expecting a POST, bailing");
}

my $o;
read(STDIN,$o,$ENV{'CONTENT_LENGTH'});

my %o;
for (split(/&/,$o)) {
    $_ =~ s/\+/ /g;
    my($key,$val) = split(/=/,$_,2);
    for ($key,$val) {
        $_ =~ s/%([0-9a-fA-F][0-9a-fA-F])/chr(hex($1))/ge;
    }
    $o{$key} = $val;
}

my @items;
my $i;
for ($i=1; $i<=$o{'Item-Count'}; $i++) {
    push(@items,{map {($_,$o{"Item-$_-$i"})} qw(Id Code Quantity Unit-Price
Description Url)});
}

open(RAW,">/tmp/yahoo-order.raw");
for (sort keys %o) {
    print RAW "$_ = $o{$_}\n";
}
close(RAW);

&handle_order(\%o,@items);

# A successful delivery is indicated by a good HTTP result code.
print "Status: 200 OK\n";
print "\n";
exit(0);


######################################################################
# Replace this function with something that does what you want
#   $info gets a hash ref of all the order fields, like Ship-Name.
#   @items gets an array of hash refs, one for each item.

sub handle_order {
    my($info,@items)=@_;

    open(OUT,">/tmp/yahoo-order");

    print OUT "Order $info->{ID} at $info->{Date}\n";
    print OUT "\n";
    print OUT "Ship to:\n";
    print OUT "  $info->{'Ship-Name'}\n";
    print OUT "  $info->{'Ship-Address1'}\n";
    print OUT "  $info->{'Ship-Address2'}\n";
    print OUT "  $info->{'Ship-City'} $info->{'Ship-State'}
$info->{'Ship-Zip'}\n";
    print OUT "  $info->{'Ship-Country'}\n";
    print OUT "  $info->{'Ship-Phone'}\n";
    print OUT "\n";
    print OUT "Bill to:\n";
    print OUT "  $info->{'Bill-Name'}\n";
    print OUT "  $info->{'Bill-Address1'}\n";
    print OUT "  $info->{'Bill-Address2'}\n";
    print OUT "  $info->{'Bill-City'} $info->{'Bill-State'}
$info->{'Bill-Zip'}\n";
    print OUT "  $info->{'Bill-Country'}\n";
    print OUT "  $info->{'Bill-Phone'}\n";
    print OUT "  $info->{'Bill-Email'}\n";
    print OUT "\n";
    print OUT "Shipping: $info->{'Shipping'}\n";
    print OUT "\n";
    print OUT "Payment: $info->{'Card-Name'} $info->{'Card-Number'}, exp
$info->{'Card-Expiry'}\n";
    print OUT "\n";
    print OUT "Items:\n";

    printf(OUT "  %-15s %-40s %6s %8s %8s\n",
           "Code","Desc","Qty","Each","Total");

    my $item;
    for $item (@items) {

        printf(OUT "  %-15s %-40s %6d %8.2f %8.2f\n",
               $item->{'Code'},
               $item->{'Description'},
               $item->{'Quantity'},
               $item->{'Price'},
               $item->{'Quantity'} * $item->{'Price'});
    }

    printf(OUT "  %-15s %-40s %6s %8s %8.2f\n",
           "","Tax","","",$info->{'Tax-Charge'});

    printf(OUT "  %-15s %-40s %6s %8s %8.2f\n",
           "","Shipping","","",$info->{'Shipping-Charge'});

    printf(OUT "  %-15s %-40s %6s %8s %8.2f\n",
           "","Total","","",$info->{'Total'});


    close(OUT);

}

TIA, Clint
coberbeck@hotmail.com





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

Date: Thu, 28 Jun 2001 02:21:53 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl request
Message-Id: <3B3ACD01.9E498C42@earthlink.net>

Untested code:
while( defined my $from_camera = glob("/directory/ORIGINALS/*") ) {
	my ($base) = $from_camera =~ m/(.*)\./s;
	unlink "/directory/ORIGINALS/$from_camera"
		or warn "Could not unlink $from_camera: $!\n"
		unless -f "/directory/KEEPERS/$base.jpg";
}

Version 2:

my (@keepers,%keepers) = glob("/directory/ORIGINALS/*.jpg");
substr($_,-4,4,"") for @keepers; # get rid of ".jpg" from each
undef @keepers{@keepers};
foreach( glob("/directory/ORIGINALS/*") ) {
	my ($base) = $_ =~ m/(.*)\./s;
	unlink "/directory/ORIGINALS/$_"
		or warn "Could not unlink $from_camera: $!\n"
		unless exists $keepers{$base};
}

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Thu, 28 Jun 2001 00:10:46 -0400
From: "Christopher Shannon" <cshannon@data2design.com>
Subject: Re: PostgreSQL/Perl error
Message-Id: <9heamf$lv$1@news.umbc.edu>

Lisa,

It looks like the module can't find a library file.

I don't know how they handle this on a sun system, but on a linux x86
system, there will be a file named /etc/ld.so.conf that has a list of
directories which point to various shared library directories.  The fix for
this (or the equivalent file / mechanism on a sun system) is to add the
directory which would contain the shared library (the directory wherever
libpq.so sits), run ldconfig, and then you should be up and running.

I hope this helps.

Best Regards, Chris Shannon

"Lisa Koma" <zsh99@yahoo.com> wrote in message
news:d011d382.0106271704.54816c4@posting.google.com...
> Running Solaris 8, PostgreSQL-7.1.2, Perl 5.00503
>
> ERROR
> at /export/home/httpd/perl/test.pl line 7
>
> [Wed Jun 27 20:45:35 2001] [error] install_driver(Pg) failed: Can't
> load
'/source/perl5.005_03/lib/site_perl/5.005/sun4-solaris/auto/DBD/Pg/Pg.so'
> for module
> DBD::Pg: ld.so.1: /source/apache/bin/httpd: fatal: libpq.so: open
> failed: No such file or directory at
> /source/perl5.005_03/lib/5.00503/sun4-solaris/DynaLoader.pm
> line 169.
>
>
> Has anyone seen this error?
> I installed the required DBD-Pg driver to connect to the database and
> I don't seem to figure out why I keep getting this error - ..been
> fighting this for a while now. Please HELP.
>
> At Line 7 of my code, I call DBI->connect - ..see below
>
> my $dbh=DBI->connect("dbi:Pg:dbname=seifutest",$username,$password)
>         or die "can't connect tp Postgrer database\n";




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

Date: Wed, 27 Jun 2001 21:19:08 -0500
From: "Steven Michaels" <smichae@ilstu.edu>
Subject: Process Errors
Message-Id: <9he490$sjc$1@news.ilstu.edu>

Every once in a while on my site, users receive a
process error when the perl scripts are being called
too many times in a short period of time.  My question
is, how would I go about in .htaccess or in the perl
script itself, print an error instead of using the server's
default error message?
Thanks for any help,
Steven Michaels




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

Date: Thu, 28 Jun 2001 10:39:58 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: range operator in scalar context - how to make it true?
Message-Id: <9he58r$lcj@netnews.hinet.net>

"Charles DeRykus" wrote
> John Lin wrote:
> >perl -le "$.=10; print 'OK' if 10..20"
> >
> >perl -le "tell STDIN; $.=10; print 'OK' if 10..20"
> >OK
> >perl -le "tell F; $.=10; print 'OK' if 10..20"
> >OK        # any filehandle would do
> >
> >It looks like the problem is not $. because its value is well-defined
> >and visible to the range-operator all through the process.
> >
> >perl -le "$.=10; print 'OK' if 10..20; print $."
> >10
> >
> >The problem is the range-operator doesn't look at the value at all,
> >unless the runtime is in a special status (reading file) which we
> >triggered by tell (or <>, seek ... etc).
>
> $. though appears to remain undefined until the triggering occurs.
>
> perl -le 'print defined $. ? "yes" : "no"'              # no
> perl -le 'tell STDIN; print defined $. ? "yes" : "no"'  # yes

No, I mean, $. is defined (because I gave it a value).

perl -le "$.=10; print defined $. ? 'yes':'no'; print 'no' unless 10..20"
yes
no

$. is defined, but the range-operator doesn't look at its value.

Thank you.
John Lin





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

Date: Thu, 28 Jun 2001 04:42:50 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: range operator in scalar context - how to make it true?
Message-Id: <GFMIFE.3Gv@news.boeing.com>

In article <9he58r$lcj@netnews.hinet.net>,
John Lin <johnlin@chttl.com.tw> wrote:
>"Charles DeRykus" wrote
>> John Lin wrote:
>> >perl -le "$.=10; print 'OK' if 10..20"
>> >
>> >perl -le "tell STDIN; $.=10; print 'OK' if 10..20"
>> >OK
>> >perl -le "tell F; $.=10; print 'OK' if 10..20"
>> >OK        # any filehandle would do
>> >
>> >It looks like the problem is not $. because its value is well-defined
>> >and visible to the range-operator all through the process.
>> >
>> >perl -le "$.=10; print 'OK' if 10..20; print $."
>> >10
>> >
>> >The problem is the range-operator doesn't look at the value at all,
>> >unless the runtime is in a special status (reading file) which we
>> >triggered by tell (or <>, seek ... etc).
>>
>> $. though appears to remain undefined until the triggering occurs.
>>
>> perl -le 'print defined $. ? "yes" : "no"'              # no
>> perl -le 'tell STDIN; print defined $. ? "yes" : "no"'  # yes
>
>No, I mean, $. is defined (because I gave it a value).
>
>perl -le "$.=10; print defined $. ? 'yes':'no'; print 'no' unless 10..20"
>yes
>no
>
>$. is defined, but the range-operator doesn't look at its value.
>

Right. I was just noting a way to check if internal triggering 
had caused $. to become defined. Otherwise, Without confirming
that, setting $. manually wouldn't have the expected meaning.

--
Charles DeRykus


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

Date: Thu, 28 Jun 2001 00:10:41 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Reading binary data (method and style)?
Message-Id: <3B3AAE41.1FDFC0F@earthlink.net>

Dmitry Epstein wrote:
[snip]
> I could write the format string for unpack() something like this:
> 
> "v2aaaav3a3" etc.
> 
> But, since each field has a particular meaning, what I would like to
> do is to somehow write this with comments.  It would then be easier to
> read and modify the code.  So, what I would like to do is something
> like this (I know the following doesn't work):
> 
> "v   # foo
>  v   # bar
>  a   # baz
> ...
> 
> Is there a good way to do it?

Create another quoting operator for perl, which will strip whitespace
and comments in the same manner as the /x operator does for regular
expressions.  I would suggest calling it qc (quote commented).  Or,
almost as good, write a sub which will strip whitespace and comments,
and call it qc :)  Of course, if you do it as a function, you won't be
able to easily escape whitespace in the same manner as other escapes...
eg, as a quoting operator qc"foo\ bar" == "foo bar"
but as a subroutine call: qc"foo\ bar" == "foobar"
Because with the second, the backslash before the space has already been
parsed and removed by normal quotes by the time it is passed to the sub.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: 27 Jun 2001 22:52:45 -0300
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Re: Selling Scripts
Message-Id: <sa83d8ljrpu.fsf@suntong.personal.users.sourceforge.net>

<tsee@gmx.net> writes:

> "ffg" <john@trumpetweb.co.uk> schrieb im Newsbeitrag
> news:8or_6.4277$4i5.341643@news1.cableinet.net...
> 
> [snip]
> 
> > Also, any tips on the best way to distribute / password protect the
> scripts?
> 
> Just in case you mean password protecting the scripts' code:
> You can't. There is no way to reliably protect a script from being read by
> anybody. In order to make it run, you need perms to be 555 or more.
> Anyway, this is in the faq.

Or, if it really bother you, find a copy of shc. It is not what you
want, but at least it can stop *me* from peeking into your code.

-- 
Tong (remove underscore(s) to reply)
  *niX Power Tools Project: http://xpt.sourceforge.net/
  - All free contribution & collection


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

Date: Thu, 28 Jun 2001 00:41:36 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: shell command
Message-Id: <3B3AB580.534842B@earthlink.net>

Rene Scheibe wrote:
> 
> I need to send SIGUSR1 to ipfm (a running daemon)
> so that it dumps it statistics to a logfile which I then
> read out with the cgi-script and print it in a table on a
> website.
> I don't need and want to dump every 5 minutes to a
> logfile.

Replace the #!/path/to/perl with #!/path/to/suidperl

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Thu, 28 Jun 2001 00:32:18 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: using System() and exec()
Message-Id: <3B3AB352.439CE66A@earthlink.net>

Le Malet Guillaume wrote:
> 
> Hi,
> I'm executing a perl script in background on a debian distribution,
> and in this script I use:
> `sendsms -d 0$nbappel -m $corps[0],$corps[1] pe245`
> to execute a linux command.

Don't use backticks to execute a command, unless you are capturing it's
output.  Use system.

> But when my script is executed in background, this command doesn't
> work anymore.

Define "doesn't work"

> So, I've tried exec "..."; and I've got the same problem as with ``.

Exec replaces the current process with the given command.  You can't use
it for running something in the background.

> So If you've got an idea please tell me.

defined( my $pid = fork ) or die "Couldn't fork in parent: $!\n";
if( !$pid ) {
	exit if fork;
	exec { "/path/to/sendsms" } "sendsms", 
		-d => "0$nbappel",
		-m => join ",", @corps[0,1],
		"pe245";
	die "Could not exec /path/to/sendsms: $!\n";
} else {
	waitpid($pid,0);
}

The second fork is important for umm... I forget, but it's important :)
If this is being used in a CGI program, then you should close STDOUT
somewhere between the if(!$pid) and the exec.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Thu, 28 Jun 2001 11:17:41 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: weird hash behaviour.
Message-Id: <9he7ft$pvd@netnews.hinet.net>

"Entropy Gideoned" wrote
>   DB<19> x $rldr
> 0  HASH(0x202738bc)
>    'Desc' => 'a'
>    'ELvl' => ' '
>    'RecStat' => 'c'
>   DB<20> x $rldr{'Desc'}
> 0  undef
>
> It says that rldr is a hash, good!
> it has a key 'Desc', which has "a" in it.
> but x $rldr{'Desc'} shows undef! So do all the other keys.

Would you try
    x $rldr->{'Desc'}
because $rldr is shown to be a "hash reference".

HTH
John Lin





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

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


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