[13510] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 920 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 27 13:07:17 1999

Date: Mon, 27 Sep 1999 10:05:12 -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: <938451912-v9-i920@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 27 Sep 1999     Volume: 9 Number: 920

Today's topics:
    Re: 'print' and 'warn' difference (bug report) (M.J.T. Guy)
        <> = new line? (Ran Shoham)
    Re: <> = new line? <cw@dwc.ch>
    Re: a question of buttons (Kragen Sitaker)
    Re: ActivePerl on Windows95 HELP <cimbalnik@cbnet.cz>
    Re: CGI Session? (Kragen Sitaker)
        CGI Using Win32::Service <josh@removeme.netlibrary.com>
    Re: CGI Using Win32::Service <gellyfish@gellyfish.com>
    Re: CGI Using Win32::Service <josh@removeme.netlibrary.com>
        DB_File <joe.buhr@motorola.com>
    Re: Difference between do and require.... (John Porter)
        Editing Perl scripts with emacs <rountree@cs.queensu.ca>
    Re: Editing Perl scripts with emacs (Kai Großjohann)
    Re: Filehandling to local harddisk  (Kragen Sitaker)
    Re: Filehandling to local harddisk <cw@dwc.ch>
    Re: Forms and frames <gellyfish@gellyfish.com>
    Re: Getting the first occurence of a string <tom.kralidis@ccrs.nrcanDOTgc.ca>
    Re: Graphs and Charts (Jacqui Caren) (Jacqui Caren)
    Re: How to create files from CGI script? <flavell@mail.cern.ch>
    Re: I just want to remove a file! Help! (Kragen Sitaker)
        libraries "die"ing rdosser@my-deja.com
    Re: logging func has stopped logging <ltl@rgsun5.viasystems.com>
    Re: Parsing @argv <gellyfish@gellyfish.com>
        pattern matching problem <gregg@scad.edu>
    Re: pattern matching problem (Greg Bacon)
        PH 6.0 Perl problem <jsmith@mcs.drexel.edu>
        Printing Hash of Lists <nospam@thankyou.com>
    Re: Printing Hash of Lists <nospam@thankyou.com>
    Re: Problems with Win32::OLE (Kragen Sitaker)
    Re: Problems with Win32::OLE <jeff@vpservices.com>
    Re: proper 'my' usage (Michael Houghton)
    Re: Question with 'require' and 'import' (M.J.T. Guy)
    Re: Replacement "CD" for win32 systems (Ken Hirsch)
    Re: running other programs from perl (Kragen Sitaker)
        SIGINT SIGNAL NOT BEING CAUGHT <sushant@ntwrks.com>
    Re: Socket module (Kragen Sitaker)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 27 Sep 1999 16:07:57 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: 'print' and 'warn' difference (bug report)
Message-Id: <7so4ot$3ct$1@pegasus.csx.cam.ac.uk>

Kiriakos Georgiou  <kg@olympiakos.com> wrote:
>
>I have found a difference in the way 'print' and 'warn' output the
>exact same string.  I find the way 'print' handles it more convenient.
>I include a small test program which should output the exact same
>string twice, but it doesn't.  In case you wonder why on earth I'd put
>one or more \0 at the end of perl strings, I find it pretty convenient
>to allocate a perl string with something like $str = "\0" x 256; so
>then I can pass this $str to a 'char *' argument of a C function that
>has been wrapped via SWIG.  The C function can deposit something
>interesting back to $str.

This bug (which die() also suffers from) has been mended in the
development track.    Hopefully it'll also be fixed in the next
maintenance release, 5.005_04.

Meanwhile, "don't do that, then".   For example, clean up the argument
with

     $arg =~ tr/\0//d;


Mike Guy


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

Date: 27 Sep 1999 15:52:16 GMT
From: rshoham@acs5.acs.ucalgary.ca (Ran Shoham)
Subject: <> = new line?
Message-Id: <7so3rg$e2u@ds2.acs.ucalgary.ca>

Hello there, 

I'm a Perl newbie.
I'm just wondering, if <> operator allows me to get the "next line" from 
input,  is there a similar way for me to get the "next word"?

any ideas on how to get "next word" are welcome.


Please send reply to my e-mail
at:   
rshoham@acs.ucalgary.ca


Thanks in advance,


Ran


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

Date: Mon, 27 Sep 1999 18:13:47 +0100
From: Christoph Wernli <cw@dwc.ch>
Subject: Re: <> = new line?
Message-Id: <37EFA5CB.16F1C6A0@dwc.ch>

Ran Shoham wrote:
> 
> I'm just wondering, if <> operator allows me to get the "next line" from
> input,  is there a similar way for me to get the "next word"?

Play around with the input separator, i.e:

$/ = " ";

Get the details at

perldoc perlvar

> Please send reply to my e-mail

Ugh. This is Usenet.

-w


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

Date: Mon, 27 Sep 1999 14:38:11 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: a question of buttons
Message-Id: <njLH3.1779$J66.192545@typ11.nn.bcandid.com>

In article <37EF34E2.9448A457@desertigloo.com>,
David P. Schwartz <davids@desertigloo.com> wrote:
>If I put three buttons on an HTML form, with different names and values,
>what shows up in my Perl script when it runs is ...  three buttons
> with different names and values.  Duh.  So, which one was pressed?  I
> don't know where to find this.

Well, you'll get a name=value pair in your CGI input corresponding to
the button that was actually pressed.  i.e. if it was a name="bob"
value="x", you get 'bob=x' somewhere in your query string.

>  I don't know if this is a Perl question or not.

Probably not.  Although CGI.pm does give all the submit buttons a name
so you can tell which one was pressed.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Mon Sep 27 1999
42 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: Fri, 24 Sep 1999 16:23:42 +0200
From: "Pavel Cimbalnik" <cimbalnik@cbnet.cz>
Subject: Re: ActivePerl on Windows95 HELP
Message-Id: <37eb8945.0@news.cvut.cz>

Hi,

I cannot write English very well, but I try help you.

You must set new item in registry :

HKEY_LOCAL_MACHINE \ SYTEM \ CurrentControlSet \ Services \
W3SVC \ Parameters \ Script Map

Insert new string value  :

 .pl            "c:\perl\bin\perl.exe %s %s"

I have got set it on my NT 4.0 Wks CZ and on my NT 4.0 Server. I have got
no problem.

Goodbye.

--
S pozdravem a pranim prijemneho dne

Pavel Cimbalnik (cimbalnik@cbnet.cz, cimbalnik@knihovna.cbnet.cz )
Spravce IS

Okresni knihovna v Prerove
Zerotinovo nam. 36, 751 52 PREROV
tel.: 0641/217761, 307863
http://knihovna.cbnet.cz



qian yin <qianyin@singnet.com.sg> píse v diskusním
příspěvku:37EA475B.8D3AC8FB@singnet.com.sg...
> Hi
> I am a new Perl user, I try ActivePerl on my NT workstation and get the
> same problem as Daniel. The results seem only send to a MS-DOS window and
> not send back to my browser. The fact is the script has been executed
since
> the job of opening and writting to a file have been done.
> So please help me if you know how to solve it.
> My e-mail address is: qianyin@hotmail.com
>
> Regards,
>
> Qian Yin
> --------------
>
> Daniel wrote:
>
> > Hello,
> >
> > I just now installed ActivePerl build 519 on my Windows95 Computer. I
> > wrote this file "readarticlecgi.pl":
> >
> > *************************************************
> >
> > #!/usr/bin/perl
> > print "Content-type: text/html\n\n";
> > print "<HTML>\n<BODY BGCOLOR=\"#FFFFFF\">\n\n";
> >
> > open(ARTICLE1,"article1.txt");
> > while (<ARTICLE1>)
> > {
> >    print;
> > }
> > close (ARTICLE1);
> > print "</BODY>\n";
> > print "</HTML>";
> >
> > *************************************************
> >
> > With my Netscape Browser I loaded it with File/Open Page (Ctrl+O) and I
> > just see an MS-DOS window, which shows quickly my "article1.txt" !
> >
> > What is wrong ? I thought see my file (article1.txt) in my Netscape
> > Browser.
> >
> > Thank you for any help
> >
> > My e-mail is Daniel.LaMarra.at.unige.ch
> > (replace .at. by @, this is to avoid spam)
> >
> > Regards Daniel.
>
>
>




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

Date: Mon, 27 Sep 1999 14:39:26 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: CGI Session?
Message-Id: <ykLH3.1782$J66.194597@typ11.nn.bcandid.com>

In article <37EF35DC.387FDE85@gmx.de>,
Michael Scheferhoff  <m.scheferhoff@gmx.de> wrote:
>Does anybody have an idea, what's the problem?

No.  Can you post some of your script?

-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Mon Sep 27 1999
42 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: Mon, 27 Sep 1999 08:40:11 -0600
From: "Josh Greenberg" <josh@removeme.netlibrary.com>
Subject: CGI Using Win32::Service
Message-Id: <7snvo9$p53$1@news-2.csn.net>

I wrote a Perl interface to NT's Service Control Manager using
Win32::Service.  I am able to list all services on a NT machine and get
their status.  However when accessing the script via the web, I am unable to
stop and start the services on the machine.  Oddly enough, I am able to stop
and start services using similar code from the command line on the machine
itself.  Is this a permissions issues?  Any suggestions?
Thanks!




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

Date: 27 Sep 1999 15:52:14 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: CGI Using Win32::Service
Message-Id: <37ef849e_1@newsread3.dircon.co.uk>

Josh Greenberg <josh@removeme.netlibrary.com> wrote:
> I wrote a Perl interface to NT's Service Control Manager using
> Win32::Service.  I am able to list all services on a NT machine and get
> their status.  However when accessing the script via the web, I am unable to
> stop and start the services on the machine.  Oddly enough, I am able to stop
> and start services using similar code from the command line on the machine
> itself.  Is this a permissions issues?  Any suggestions?

It *is* a permissions issue and something you will want to take up with
your system administrator or a news group about NT configuration..

/J\
-- 
"Like Anne Robinson in a Korean restaurant, it'll be dog eat dog" -
Graham Norton


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

Date: Mon, 27 Sep 1999 10:43:17 -0600
From: "Josh Greenberg" <josh@removeme.netlibrary.com>
Subject: Re: CGI Using Win32::Service
Message-Id: <7so6v3$spa$1@news-2.csn.net>

I actually found my out own solution.  The problem was fixed by forcing the
user to authenticate when accessing this script.  The user must authenticate
as an administrator of the machine.  At this point, the code works fine.
It's really a handy Perl utility script.  At least now, I don't need to get
up from my desk everytime a service crashes.  If anyone wants a copy of this
script, email me.
-Josh

Jonathan Stowe <gellyfish@gellyfish.com> wrote in message
news:37ef849e_1@newsread3.dircon.co.uk...
> Josh Greenberg <josh@removeme.netlibrary.com> wrote:
> > I wrote a Perl interface to NT's Service Control Manager using
> > Win32::Service.  I am able to list all services on a NT machine and get
> > their status.  However when accessing the script via the web, I am
unable to
> > stop and start the services on the machine.  Oddly enough, I am able to
stop
> > and start services using similar code from the command line on the
machine
> > itself.  Is this a permissions issues?  Any suggestions?
>
> It *is* a permissions issue and something you will want to take up with
> your system administrator or a news group about NT configuration..
>
> /J\
> --
> "Like Anne Robinson in a Korean restaurant, it'll be dog eat dog" -
> Graham Norton




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

Date: Mon, 27 Sep 1999 08:51:32 -0500
From: Joe Buhr <joe.buhr@motorola.com>
Subject: DB_File
Message-Id: <37EF7664.25C8D185@motorola.com>

I think this should be a simple problem...  hopefully someon can point
out my err right away, so here goes.

I would like to use the perl DB_File module to store some data.  I'll
show what I'm trying to do in to seperate scripts.  Here's the syntax:

************************************
#!/usr/misc/bin/perl

use DB_File;

tie %h, "DB_File", "test", O_RDWR|O_CREAT, 0644;
            $h{1} = "Joe";
            $h{2} = "Ernie";
            $h{3} = "Charly";
            $h{4} = "Alex";
            $h{5} = "Ted";
            untie %h;
************************************
************************************
#!/usr/misc/bin/perl

use DB_File;

tie %h, "DB_File", "test", O_RDWR|O_CREAT, 0644;
            foreach (1,2,3,4,5) {
                    print "$h{$_}\n";
            }
            untie %h;
*************************************
The file "test" gets created, but no data gets stored in it?  Is that
right?

Heres a listing of the files:
-rwxr-xr-x   1 buhr     3g           250 Sep 27 08:32 program1
-rwxr-xr-x   1 buhr     3g           196 Sep 27 08:32 program2
-rw-r--r--   1 buhr     3g          8192 Sep 27 08:28 test


If anyone can let me know what I'm doing wrong I'd appreciate it.
Thanks,

Joe





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

Date: Mon, 27 Sep 1999 16:06:31 GMT
From: jdporter@min.net (John Porter)
Subject: Re: Difference between do and require....
Message-Id: <slrn7uv5g7.ruu.jdporter@min.net>

In article <37EB5313.1975EE9B@sophos.com>, Csaba Raduly wrote:
>
>Require, or require not: there is no try	- as Yoda said :-)
>( I may be wrong: is there a try-catch mechanism in Perl ? :-)


BEGIN {
  eval { require "U.pm" };
  $success = not $@;
};

unless ( $success ) {
  eval { require "U.pm" };
}


"If at first U don't succeed, try 'try' again."


-- 
John Porter



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

Date: 27 Sep 1999 10:21:45 -0400
From: Eric Rountree <rountree@cs.queensu.ca>
Subject: Editing Perl scripts with emacs
Message-Id: <vztyads1ll2.fsf@cs.queensu.ca>

I use emacs to edit my perl scripts, and I really like the automatic
indentation feature. Unfortunately, the perl mode of my emacs does not
deal well with constructs like the following:

     ${coursesByCourseId{$course}}[4]

The curly braces around the variable names seem to mess up the
automatic indentation.

Is there a way to fix this?

I'm using GNU EMacs 19.34.1 on Solaris 5.6.

Thanks in advance.

Eric
         
--
---------------------------------------------
Eric Rountree, Systems Specialist
Department of Computing & Information Science
Goodwin Hall, Room 551
Queen's University
Kingston, Ontario
Canada  K7L 3N6

(613)533-6784
rountree@cs.queensu.ca


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

Date: 27 Sep 1999 16:46:46 +0200
From: Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann)
Subject: Re: Editing Perl scripts with emacs
Message-Id: <vaf1zbkfm3t.fsf@lucy.cs.uni-dortmund.de>

Perl comes with cperl-mode.el which might do a better job for
indentation.  Recent versions of Emacs also include cperl-mode, but I
don't know whether 19.34 is recent enough.

It may also help to add a space after one of those "{".

kai
-- 
I like BOTH kinds of music.


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

Date: Mon, 27 Sep 1999 14:23:42 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Filehandling to local harddisk 
Message-Id: <O5LH3.1766$J66.193120@typ11.nn.bcandid.com>

In article <37EF714A.461FCF09@gmx.de>,
Michael Scheferhoff  <m.scheferhoff@gmx.de> wrote:
>I have to post news over http. To be able to add attachments to my post
>I have to encrypt then with MIME::Base64.

Encode is probably a better term than encrypt.

> This works fine if the file is
>placed on the machine where my webserver is running, but I want to
>encrypt files on my local harddrive with the help of a Perl/CGI script
>running on my webserver. To do that I need to be able to open the file
>over http and then read the fiel to an array. I don't know how to open
>the file over http. Does anybody know how to open a file via http?

Use the LWP:: modules.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Mon Sep 27 1999
42 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: Mon, 27 Sep 1999 16:20:39 +0100
From: Christoph Wernli <cw@dwc.ch>
Subject: Re: Filehandling to local harddisk
Message-Id: <37EF8B47.7A87F6CA@dwc.ch>

Michael Scheferhoff wrote:
> 
> I have to post news over http. To be able to add attachments to my post
> I have to encrypt then with MIME::Base64. This works fine if the file is
            ^^^^^^^

That wshould read encode, I suppose.

> placed on the machine where my webserver is running, but I want to
> encrypt files on my local harddrive with the help of a Perl/CGI script
> running on my webserver. To do that I need to be able to open the file
> over http and then read the fiel to an array. I don't know how to open
> the file over http. Does anybody know how to open a file via http?

How about a file-upload-field ? (cf. CGI.pm)

-w


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

Date: 27 Sep 1999 15:10:07 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Forms and frames
Message-Id: <37ef7abf_2@newsread3.dircon.co.uk>

Michael C. Albers <mcalbers@introweb.nl> wrote:
>  Hi,
> 
> Can anyone help me with the following problem?
> 
> I've have three frames (top, middle and bottom). The top frame isn'nt
> important right now.
> 
> In the middle frame people can enter some fields.
> In the bottom frame are the submit and reset buttons.
> 
> How can I get the values given in the middle frame using the buttons ib
> the bottom frame?
> 

If you are using the module CGI.pm then you should see the section in
the documentation for that module entitled:

  "WORKING WITH NETSCAPE FRAMES"

If you are not then should the CGI faq at:

  <http://wwww.webthing.com/tutorials/cgifaq.html>

If after that you should post to the appropriate group for this sort of
question which is comp.infosystems.www.authoring.cgi.

<followups set>

/J\
-- 
"The Tory Party is like a wonky shopping trolley - it pulls to the
left, it pulls to the right, but you just can't get it to go forward"
- John Prescott


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

Date: Mon, 27 Sep 1999 11:22:55 -0400
From: Tom Kralidis <tom.kralidis@ccrs.nrcanDOTgc.ca>
Subject: Re: Getting the first occurence of a string
Message-Id: <37EF8BCF.F9C2E9B3@ccrs.nrcanDOTgc.ca>

Larry,

> > Furthermore, how can one assign each occurence to an array, then
> > extracting values bewteen each interval?
> 
> You'll have o be more specific than that.  I can't understand it, and
> your example code doesn't help.
> 

To be more specific:

I am trying to extract fields from a file, outputting into a report.  To
be simple, here's an example file:

Tom
F 222
break
G 444
break
H 999
Tom
F 999
G 222
break
H 421
Tom
F 345
break
G 983
H 922
break

 ..and so on.  Each file may have multiple instances of the 'Tom' field. 
I would like to output something like (based on the file above):

Number of Tom fields: 3
First Tom
F = 222
H = 999
number of breaks = 2
Second Tom
F = 999
H = 421
number of breaks = 1
Third Tom
F = 345
H = 922 
number of breaks = 2

I would also do some math on the numerical fields, but that's not a
problem.

I suppose the best thing to do is do a foreach on each instance of
'Tom', to find the specific info and put it to variables, etc.

foreach $Tom (occurence_of_Tom_field) # how to assign?
{
  $F = $1 if (/^F = (\d+)/);
  $H = $1 if (/^H = (\d+)/);
  $break++ if $_ eq "break";
  print FILE <<EOF;
  F = $F
  H = $H
  number of breaks = $break
EOF
;
}

My question is how one can work on a file by breaking it up into
'chunks'.

Can the above also be done if one knows exatcly how where the lines and
their values occur after the capture of the 'Tom' field?

Any advice??

Thanks alot

 ..Tom


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

Date: Mon, 27 Sep 1999 15:57:19 GMT
From: Jacqui.Caren@ig.co.uk (Jacqui Caren) (Jacqui Caren)
Subject: Re: Graphs and Charts
Message-Id: <FIq6zK.E58@ig.co.uk>

In article <37c74e1d.108684064@news1.on.sympatico.ca>,
T. Alex Beamish <talexb@tabsoft.on.ca> wrote:
>On Fri, 27 Aug 1999 18:52:36 GMT, Stone Cold <paulm@dirigo.com> wrote:
>
>>How does Perl handle graphics?  I'd like to create some code that will
>>1. connect to a database via DBI module 2. grab data from database and
>>3. Output the data via web interface into a graph/chart using CGI.
>>
>>Can this be done?  Is there a module already created that I could
>>call?
>
>Paul,
>
>Yes, it can be done. I've done it on the Carlson Online site at
>www.carlsononline.com.
>
>You connect to a database from a mod-perl script by doing something
>like

<snip>

>No, I can't send you my scripts.

How about something such as the below?
I am using something similar in a template engine to 
generate various forms of graphs...
Note the use of Apache::DBI and mod_perl to allow
DBI
to keep persisten connections and cached (prepared)
SQL queries. This makes the whole think much much faster.



use Apache::DBI;
use CGI;

my $dbh = DBI->connect(...);
my $cgi = new CGI;

my $owner = $cgi->param('owner') || 'jacqui';
print "Content-type: image/gif\n\n";

    my $csr = $dbh->prepare_cached(qq{
select
  IDENTITY,
  sum(transactions)
from
  tablename
where
  OWNER = ?
group by
  IDENTITY ASC
order by
  sum(transactions) DESC
});
    $csr->execute($owner);


	my ($titles,$xvals,$yvals) =([],[],[]);
	my ($x,$id,$tr) = (0); 
	while (($id,$tr) = $csr->fetchrow_array()) {
		push @$titles,"$id";
		push @$xvals, $x++;
		push @$yvals, $tr;
	}

	$csr->finish();

	use GIFgraph::pie;
	my $pie = new GIFgraph::pie(500,300);
	$pie->set(
		x_label => "identity",
		y_label => 'transaction count',
		title   => "records by Identity for $owner"
	);
	my $gif = $pie->plot([$titles,$xvals,$yvals]);
	return $gif;

Jacqui

-- 
Paul Ingram Group Ltd,140A High Street,Godalming GU7 1AB United Kingdom
Email: J.Caren@ig.co.uk Fax: +44 1483 862801 Phone: +44 1483 862800
A rather special Perl vacancy :-) http://www.ig.co.uk/about/jobs.html
Use SmartCards in e-commerce systems? http://www.smartaxis.com/



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

Date: Mon, 27 Sep 1999 16:52:37 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: How to create files from CGI script?
Message-Id: <Pine.HPP.3.95a.990927164154.13205A-100000@hpplus01.cern.ch>

On Mon, 27 Sep 1999 kdevine@my-deja.com wrote:

> I have had multiple problems with permissions and such when using Perl
> for CGI scripting. 

It's easy to make mistakes, but usually also easy to see why they were
mistakes and remedy them.  The value of $! usually helps.

> I have found that running system commands from Perl
> alleviate some of the problems.  Executing a system("touch $filename")
> may solve the problem instead of expecting the file to be created from
> an open(DATA,">$filename") command. 

Have you, indeed?  And it never occurred to you to investigate why this
strangeness was happening?

> This has solved my problem many times.

I would hardly call it a "solution", to fire up an entire separate
process (maybe even a shell) just in order to create a file, while
leaving the original problem uninvestigated.  Quite apart from the
security hole you seem to have created if the filename were to contain,
ahem, certain embarrassing characters.  When it's necessary to call the
"system" function (which in this case I very much doubt), you might want
to consider the multi argument (or LIST) form of the system command. 
And never, never forget to test the result of system, open etc. and take
appropriate action if it failed, including reporting $! to help in
diagnosing the problem.




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

Date: Mon, 27 Sep 1999 14:33:14 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: I just want to remove a file! Help!
Message-Id: <KeLH3.1775$J66.193930@typ11.nn.bcandid.com>

In article <7snbhf$vau$1@nnrp1.deja.com>, Wise Guy  <WiseGuy_73@go.com> wrote:
>bonobo <bonoboNOhkSPAM@webtv.net> wrote:
>> #!/usr/bin/perl -T
>> for (@ARGV) {
>>     if ($_ =~ /^([-\@\w.]+)$/) {
>>         $data = $1;                     # $data is untainted
>>     } else {
>>         die "Bad data in $data";        # log this somewhere
>>     }
>>     unlink $data;
>> }
>
>Use quotemeta before using the name of the file to take care of the "/".

Wrong answer, Wise Guy.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Mon Sep 27 1999
42 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: Mon, 27 Sep 1999 16:46:59 GMT
From: rdosser@my-deja.com
Subject: libraries "die"ing
Message-Id: <7so71v$i2u$1@nnrp1.deja.com>

Greetings,

I find myself increasingly annoyed by library subroutines that take the
liberty of "die"ing for me instead of setting an error code/message and
returning undef.

Is there a way to prevent this - other than wrapping everything in an
eval, which seems expensive.

Shouldn't there be a standard for libraries not to engage in this
sort of behavior?

Thanks,
Ralph Dosser


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 27 Sep 1999 14:22:38 GMT
From: lt lindley <ltl@rgsun5.viasystems.com>
Subject: Re: logging func has stopped logging
Message-Id: <7snuje$omi$1@rguxd.viasystems.com>

kev <kevin.porter@fast.no> wrote:
:>sub baldricklog
:>{
:>        open( LOG, ">>$basedir/baldrick.log" );
:>        print LOG time, "\t@_\n";
:>        close( LOG );
:>}

:>Today, however, it has stopped writing to the file baldrick.log. It is
:>just a zero-length file with nothing ever being written to it, even
:>though I still have all my baldricklog() calls still in the program.
:>Can anyone tell me what is going on here? I guess there may be some sort
:>of a flushing problem (please tell me how to flush output, if needed),

perldoc -q flush

But that isn't your problem.

:>but why would it work fine for months and then suddenly refuse to write
:>anmything to the file?


Probably because your script cannot open the file.  You are not
testing for success on the open.  Does the file already exist prior
to running the script?  Is it owned by someone other than the userid
under which the script is running?  Permissions on the $basedir directory?

open(LOG, ">>$basedir/baldrick.log") 
	or die "Failed open $basedir/baldrick.log: $!";
then look in your server error log to see the problem.


-- 
// Lee.Lindley   /// Programmer shortage?  What programmer shortage?
// @bigfoot.com  ///  Only *cheap* programmers are in short supply.
////////////////////    50 cent beers are in short supply too.


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

Date: 27 Sep 1999 15:06:59 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Parsing @argv
Message-Id: <37ef7a03_2@newsread3.dircon.co.uk>

Brian Orpin <abuse@borpin.demon.co.uk> wrote:
> Is there a simple way of parsing @ARGV?  I am sure that I have seen a
> parse-argv module in the past but can find no reference to it (but may
> not have looked in the right place).
> 

What you mean like Getopt::Std ?

/J\
-- 
"They're called Virgin Trains because they don't go all the way" -
Simon Hoggart, The Guardian


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

Date: Mon, 27 Sep 1999 10:59:37 -0400
From: Gregory Geller <gregg@scad.edu>
Subject: pattern matching problem
Message-Id: <37EF8659.D708BC5D@scad.edu>


I'm sort of a novice at perl and I was wondering if anyone could help me
with a problem.

Basically I have a colon delimited file and I want to see if one of the
fields does not match the string "MAC".

I do a:

while (<>) {
 .
 .
if ($5 !~ /MAC/i) { next; }
 .
 .
}

This works fine.  I end up processing only the lines that contain "MAC"
in field $5.  But if I do:

$type = "MAC";

while(<>) {
 .
 .
if ($5 !~ /$type/i) {next; }
 .
 .
}

This results in the program not processing any lines.  Apparently the if
statement evaluates to 1 every time.  I've looked
at the Programming Perl book and it seems that I should be able to do
this, but it's not working the way I expect.

Can someone out there tell me what I am overlooking?

Thanks a bunch,
Greg



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

Date: 27 Sep 1999 16:45:29 GMT
From: gbacon@ruby.itsc.uah.edu (Greg Bacon)
Subject: Re: pattern matching problem
Message-Id: <7so6v9$ot0$1@info2.uah.edu>

In article <37EF8659.D708BC5D@scad.edu>,
	Gregory Geller <gregg@scad.edu> writes:

: Basically I have a colon delimited file and I want to see if one of the
: fields does not match the string "MAC".

Do you mean colon delimited or colon separated?  How you should
process lines depends on your answer to that question.

:These:fields:are:colon:delimited:
These:fields:are:colon:separated

I'm assuming that you meant colon separated, so the loop you'll want
to use looks something like

    while (<>) {
        chomp;
        my @f = split /:/;

        next unless $f[4] =~ /MAC/i;

        ...;
    }

: $type = "MAC";
: 
: while(<>) {
: .
: .
: if ($5 !~ /$type/i) {next; }
: .
: .
: }
: 
: This results in the program not processing any lines.

There are a couple of problems with your approach.  One is that when
Perl sees interpolation of a variable into a regular expression pattern
(as you did with /$type/), it can't know whether your pattern will
change, so it is forced to recompile your regular expression each time
through.  You can use the /o regular expression flag to hint to the
compiler that the contents of your variable won't change.  This would
look like

    if (/$var/io) { ... }

In addition, if the contents of a backreference are important to you,
you should squirrel them away somewhere so you don't trash them with
the next regular expression match.  Do something like

    my $type = "MAC";  # we assume this doesn't change

    while (<>) {
        chomp;
        my @f = split /:/;

        next unless $f[4] =~ /$type/io;

        ...;
    }

Hope this helps,
Greg
-- 
UNIX should be used as an adjective.
    -- AT&T


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

Date: Mon, 27 Sep 1999 12:20:36 -0400
From: Justin R. Smith <jsmith@mcs.drexel.edu>
Subject: PH 6.0 Perl problem
Message-Id: <938449366.1251614880@news2.usol.com>

Has anyone solved this yet? I'm referring to the problem (apparently unique to
Redhat systems) that prevents AnyDB from working properly.

I have several projects that desparatly need the ability to use AnyDB and am on
the verge of switching to a different version of  Linux...

Thank you!


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

Date: Mon, 27 Sep 1999 10:26:55 -0500
From: "Campos" <nospam@thankyou.com>
Subject: Printing Hash of Lists
Message-Id: <37ef8cb7_4@news1.prserv.net>

I've checked out the docs at CPAN, but I must be interpreting them wrong.


I am trying to print out a list from within a hash. To print the entire list
(fred, barney, george, jane), the docs say to do the following:

%hol = (
                flintstones => ["fred", "barney"],
                jetsons => ["george", "jane"],
)
foreach $family ( keys %hol) {
                print "$family: @( $hol($family))\n";
}

However, this actually results in:
flintstones: @( (flintstones))
jetsons: @((jetsons))

To me, this is not printing out "the whole thing."  Am I reading the docs
wrong?

Also, how do I print out just the names of the flintstones (fred, barney).?

Thanks




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

Date: Mon, 27 Sep 1999 10:36:08 -0500
From: "Campos" <nospam@thankyou.com>
Subject: Re: Printing Hash of Lists
Message-Id: <37ef8ee0_3@news1.prserv.net>

Oops, sorry.  Figured it out.

should be @{ $hol{$family}}\n"; instead of (()).

Thanks though ; )


Was reading the
Campos wrote in message <37ef8cb7_4@news1.prserv.net>...
>I've checked out the docs at CPAN, but I must be interpreting them wrong.
>
>
>I am trying to print out a list from within a hash. To print the entire
list
>(fred, barney, george, jane), the docs say to do the following:
>
>%hol = (
>                flintstones => ["fred", "barney"],
>                jetsons => ["george", "jane"],
>)
>foreach $family ( keys %hol) {
>                print "$family: @( $hol($family))\n";
>}
>
>However, this actually results in:
>flintstones: @( (flintstones))
>jetsons: @((jetsons))
>
>To me, this is not printing out "the whole thing."  Am I reading the docs
>wrong?
>
>Also, how do I print out just the names of the flintstones (fred, barney).?
>
>Thanks
>
>




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

Date: Mon, 27 Sep 1999 14:16:00 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Problems with Win32::OLE
Message-Id: <A_KH3.1759$J66.192038@typ11.nn.bcandid.com>

In article <37EF4D40.DD0D3114@fhtw-berlin.de>,
Christian Habermehl  <Christian.Habermehl@fhtw-berlin.de> wrote:
>I have some problems with the ActivePerl Win32::OLE module. Sometimes my
>program doesn't work, sometimes it does. 

My Perl gives a syntax error when I say
my QueryString = "";

 . . . so I guess your Perl must be much more, um, advanced than mine.

Is this really the cut-and-pasted code that sometimes works?

>        $CategoryRecord = $Connection->Execute(QueryString);

Oh, is this guaranteed to return a defined value?  What happens if
there's some kind of error in executing?


-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Mon Sep 27 1999
42 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: 27 Sep 1999 15:31:29 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Problems with Win32::OLE
Message-Id: <37EF8C0E.DBA75FCD@vpservices.com>

Christian Habermehl wrote:
> 
> I have some problems with the ActivePerl Win32::OLE module. Sometimes my
> program doesn't work, sometimes it does.

In that case you really need to find out what part of the program is
failing and why.  This is called error checking and one can program
without it (the way you did in your script) but that is pretty
dangerous.

> Can't call method "Fields" on an undefined value at C:\SCRIPTE\test.pl line 55.

Calling the script with -w to give warnings about uninitialized
variables might have warned you about where and why this happens.  Here
are some other things that could warn you:

>     my $Connection      = Win32::OLE->new("ADODB.Connection");

No error checking, how will you know when or why the connection fails?

>     $Connection->Open("DSN=TestDB; UID=test; PWD=test");

No error checking, how will you know when or why the open fails?

(And etc. for all the other unchecked method calls in your script.)

Read up about Win32::OLE->lastError() method and use it liberally.

Basically if you can not connect to the database, or you can not open a
table, or you can not execute a statement in the table, then you will
not be able to find out what is in a particular field.  Your script
bombs because you can't find out what is in a field, but without knowing
which of those prerequisites failed, it is hard to say why.

-- 
Jeff


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

Date: 27 Sep 1999 10:55:17 -0400
From: herveus@Radix.Net (Michael Houghton)
Subject: Re: proper 'my' usage
Message-Id: <7so0gl$gf3$1@saltmine.radix.net>

Howdy!

In article <37EA3DF3.49BC937B@catnmoose.com>,
Marty Landman  <marty@catnmoose.com> wrote:
[snip]
>I'm concerned specifically about producing an inefficiency when coding
>something like this:
>
>sub bar    {
>    my @me = @global_you;
>    my $she = $global_factor;
>    for(@me)    {
>        my $he = $_/$she;
>        ....
>    }
>}
>
>Is there a penalty to be paid by saying 'my $he' within the for loop in
>bar?  Or is this a reasonable way of doing my declarations?
>
There is a difference between

my $foo;
for (...)
{
    $foo = ...
}

and

for (...)
{
    my $foo = ...
}

If you take a reference to $foo in the loop, you get different results
for the two cases... In the second case, each iteration of the loop
results in a different instance of $foo. That distinction may be 
important to the correctness of your code.

yours,
Michael
-- 
Michael and MJ Houghton   | Herveus d'Ormonde and Megan O'Donnelly
herveus@radix.net         | White Wolf and the Phoenix
Bowie, MD, USA            | Tablet and Inkle bands, and other stuff
                          | http://www.radix.net/~herveus/


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

Date: 27 Sep 1999 16:28:55 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Question with 'require' and 'import'
Message-Id: <7so607$4f7$1@pegasus.csx.cam.ac.uk>

Rick Delaney  <rick.delaney@home.com> wrote:
>Greg Boug wrote:
>> 
>>             require "Something::else::$_";
>>             "Something::else::$_"->import(); # I know this is wrong
>
>    eval "use Something::else::$_";

Always check for success:

     eval "use Something::else::$_"
            or die qq("use Something::else::$_" failed: $@);


Mike Guy


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

Date: Mon, 27 Sep 1999 12:00:24 -0400
From: kenhirsch@myself.com (Ken Hirsch)
Subject: Re: Replacement "CD" for win32 systems
Message-Id: <MPG.12595e95fbf05d93989682@news.earthlink.net>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <7snhc6$1ct$1@kite.ansa.co.uk>, simon.plant@citrix.com says...
> 
> Jeff Zucker <jeff@vpservices.com> wrote in message
> news:37EC2034.27F26EA1@vpservices.com...
> > Simon Plant wrote:
> > >
> > >    I need a replacement "CD" command for windows nt
> > > which will accept the directory to change to with
> > > forward slashes in...
> > >
> > > IE     "cd c:/winnt/system
> > >
> > There is nothing wrong with that.  It works fine.
> > That is what it is supposed to do.
> >
> > >  :(  Ayy ideas gratefully received.
> >
> > Try reading the perlfaq8 section called (I kid you not):
> >
> > I {changed directory, modified my environment} in a perl
> > script. How come the change disappeared when I exited the
> > script? How do I get my changes to be visible?
> 
> Actually, following Netiquette, I had read that artice before posting, but
> it was (and still is) decidly
> unhelpfull, infact as unhelpful as your response was.

The FAQ tells you:

"In the strictest sense, it can't be done -- the script executes as a 
different process from the shell it was started from. Changes to a 
process are not reflected in its parent, only in its own children created 
after the change." 

It cannot be done.  With a UNIX shell there are ways of getting the 
parent shell to execute commands that are returned from a process (using 
backticks or the . (dot) or source commands).  The shell that comes with 
Windows (or NT) is not capable of this.

> 
> Yes you are right "cd c:/winnt/system" leaves you in the CWD because you are
> essentially saying
> 
> "cd c:"  with the arguments /winnt  and /system.
> 

In Perl, 
  chdir "c:/winnt/system"
will work just fine.  It just has no effect on the parent process.

End of story.



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

Date: Mon, 27 Sep 1999 14:25:02 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: running other programs from perl
Message-Id: <27LH3.1767$J66.193338@typ11.nn.bcandid.com>

In article <slrn7uuvja.ksf.James@linux.home>,
James Stevenson <mistral@stevenson.zetnet.co.uk> wrote:
>i would like to be able to run many programs at once from
>perl i would like to know if this is possible and how can i do it?
>are there already existing scripts that can do this
>or can somebody please point me in the right direction

The simplest way to do this is like this:
system("program1 &");
system("program2 &");
system("program3 &");

There are more complex ways of doing this that have more features.

HTH.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Mon Sep 27 1999
42 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: Mon, 27 Sep 1999 10:46:42 -0400
From: Sushant Gargya <sushant@ntwrks.com>
Subject: SIGINT SIGNAL NOT BEING CAUGHT
Message-Id: <37EF8352.89FDF9C2@ntwrks.com>

Hi everyone,
Story is a little wierd, so please bear with me:
Last night, I wrote a program on a NT machine using perl that catches
the
interrupt signal. It was working lastnight. This morning when I tried to

interrupt the program, the signal was not being caught. After a little
debugging I
wrote the following bare program:
    print "In main....\n";
    $SIG{'INT'} = 'handler';
    sleep(10);
    $SIG{'INT'} = 'DEFAULT';
     print "End of progarm";
    sub handler {
        print "Caught sigint\n\n";
        exit(0);
    }
The output with perl 5.005:
    ON NT Machine:
            K:\perl>sigint.pl
            In main....^C                      (pressed control+c here)
            K:\perl>^C
    ON LINUX.:
            No output when I do "./sigint.pl";
            When I do control+c, I get:
                    In main....
                    Caught sigint
Any ideas why NT machine is not catching the sigint??? I know for sure
it did
last night when I first wrote the program.  Next, when the script is run
on linux,
I don't even see the print output (In main..), Howcome? Any help would
be greatly
appreciated.  Please direct all the responses to sushant@vnet.net
-sushant



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

Date: Mon, 27 Sep 1999 14:31:50 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Socket module
Message-Id: <qdLH3.1774$J66.194173@typ11.nn.bcandid.com>

In article <Pine.GSO.4.10.9909270151440.20430-100000@user2.teleport.com>,
Tim Judd  <tjudd@teleport.com> wrote:
>using the Socket module..
>
>  inet_aton    gives you the IP address (packed, no doubt) from a hostname
>
>or
>
>  inet_ntoa    gives you the hostname (packed, I think) from an IP address
>
>
>I can sucessful get the inet_aton to work, but I can *NOT* get the
>inet_ntoa to work for me.
>
>Can somebody paste a snippet that gets the inet_ntoa to work?

perl -MSocket -e 'print inet_ntoa(inet_aton("127.0.0.1")), "\n"'

This outputs:
127.0.0.1

That's what inet_ntoa is supposed to do.

If you want the hostname from DNS, you use gethostbyaddr:

perl -MSocket -e 'print scalar gethostbyaddr(inet_aton("127.0.0.1"), AF_INET), "\n"'

This outputs:
localhost

perldoc -q hostname actually tells you about this, as does perldoc -f
gethostbyaddr.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Mon Sep 27 1999
42 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 920
*************************************


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