[18976] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1171 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 21 11:05:48 2001

Date: Thu, 21 Jun 2001 08:05:18 -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: <993135918-v10-i1171@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 21 Jun 2001     Volume: 10 Number: 1171

Today's topics:
    Re: adding newline in binary files <bard.selbekk@edbteamco.NO_SPAMcom>
    Re: CGI.pm, cookies and redirect PLS HELP! <tschmelter@statesman.com>
        Create smarter web site with new website components <info@lgbsys.com>
    Re: Create smarter web site with new website components (Bernard El-Hagin)
    Re: Difficulty exporting from modules (Matthew Miller)
    Re: Exception handling ? (Anno Siegel)
        Executing UNIX shell commands in PERL (Rainer Moser)
    Re: Executing UNIX shell commands in PERL (Steven Smolinski)
    Re: Executing UNIX shell commands in PERL <pne-news-20010621@newton.digitalspace.net>
    Re: how does one go about assigning the ip address from <josef.moellers@fujitsu-siemens.com>
        how does one go about assigning the ip address from get (Demitri Borg)
    Re: How i Install module in NT platform (isterin)
        How to check for open files on NT <marklaw@mediaone.net>
    Re: HowTo: Run a command in backticks as root? <john.imrie@pa.press.net>
    Re: Install Perl on HP <h.m.brand@hccnet.nl>
    Re: Install Perl on HP (Richard J. Rauenzahn)
    Re: int sub - strange behaviour (Zur Aougav)
    Re: int sub - strange behaviour (Anno Siegel)
        Memory usage. (Marko R. Riedel)
    Re: Memory usage. <mjcarman@home.com>
        Opening and Reading Named Pipes <narendra@spiff.hr.att.com>
    Re: Opening and Reading Named Pipes <pne-news-20010621@newton.digitalspace.net>
        Pattern matching with variables (Loki)
    Re: Pattern matching with variables <pne-news-20010621@newton.digitalspace.net>
    Re: premature end of script or malformed header <john.imrie@pa.press.net>
        Redirecting stderr under Windows <somewhere@in.paradise.net>
    Re: Reference-problem <sserena@freesurf.ch>
    Re: Reference-problem (Eric Bohlman)
    Re: Reference-problem <pne-news-20010621@newton.digitalspace.net>
        Returning undef from embedded Perl (Dave Weaver)
        Small Database Becomes Large Database <dempsey@dickinson.edu>
    Re: Small Database Becomes Large Database <somewhere@planet.earth>
    Re: Small Database Becomes Large Database <dempsey@dickinson.edu>
    Re: Small Database Becomes Large Database (Anno Siegel)
    Re: string tokenization <bart.lateur@skynet.be>
    Re: Why does this split not work? (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 21 Jun 2001 11:15:48 GMT
From: Bard Selbekk <bard.selbekk@edbteamco.NO_SPAMcom>
Subject: Re: adding newline in binary files
Message-Id: <Xns90C786C5AD9D4bardselbekkedbteamco@134.47.108.15>

Philip Newton <pne-news-20010620@newton.digitalspace.net> wrote in 
news:1ci1jt8gspfv2e7i1k9e19mamvlcmmk9m2@4ax.com:

> On 20 Jun 2001 15:29:30 GMT, Bard Selbekk
> <bard.selbekk@edbteamco.NO_SPAMcom> wrote:
> 
>> The real version even checks that the return value of read is 448.
> 
> What do you do if it's not? (Can the last record of the file be short,
> by the way?)

Well, the script just sends a mail to the administrator, telling him to 
give the file some manual attention. And yes, the last record _can_ be 
short, but that should be a very rare case.

-Bard


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

Date: Thu, 21 Jun 2001 13:13:09 GMT
From: Tim Schmelter <tschmelter@statesman.com>
Subject: Re: CGI.pm, cookies and redirect PLS HELP!
Message-Id: <3B31F313.F93F49D7@statesman.com>

CPERL520335 wrote:

> >
> >drop the 'print $query->header' line and mod your redirect thusly:
> >
> >print $query->redirect(-location=>$site1,
> >                       -cookie=>$mycookie);
> >
> >hth-
>
> Now the cookie isn't being set. :(
>
> I also tried:-
> print $query->header(-cookie=>$my_cookie,-location=>$sitelocation);
>
> and:-
>
> print $query->redirect(-cookie=>$my_cookie,-location=>$sitelocation);
>
> Pls help, I need to get this done.

Here's a guess...

Unless told otherwise, CGI.pm sends a 200 OK (or possibly, "allows the
server to send a 200 OK") HTTP status message to the browser. I'm
guessing that, since you're browser is getting a 200 OK message first,
it's going to ignore subsequent HTTP redirects.

Try this: (UNTESTED)

print $query->header(-status=>'302 Found',
    -location=>$site1,
    -cookie=>$my_cookie
);

--
Tim Schmelter
Public Key available from http://www.keyserver.net
CAD7 2ABB 05A4 2F00 4CAE 7D2F 127C 129A 7173 2951



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

Date: Thu, 21 Jun 2001 14:56:16 +0200
From: "LGB Systems" <info@lgbsys.com>
Subject: Create smarter web site with new website components
Message-Id: <9gsqt6$o7a$1@news.tpi.pl>

Hello,

Easy WebControls is a suit of Cross-Browser Dynamic HTML components that
provides a user- and developer-friendly way for you to build cool web sites
with easily customized, site navigation tools containing rich set of
features, that can organize web site content in a hierarchical manner made
up of pure DHTML and object-oriented JavaScript. Using portable, optimized,
pre-built DHTML widgets can save you a lot of time and effort, because the
hard part has already been done for you. No knowledge of JavaScript is
required.

Professional web site builders can easily customize our components to create
sophisticated, commercial-quality web sites. Novice web authors can use Easy
WebControls to create a fully functional web pages without writing a single
line of JavaScript code. Absolutely no DHTML, JavaScript or Java knowledge
is required.

Visit http://www.easywebcontrols.com

Kind Regards
Easy WebControls Authors














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

Date: Thu, 21 Jun 2001 13:44:43 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Create smarter web site with new website components
Message-Id: <slrn9j3upi.ctb.bernard.el-hagin@gdndev32.lido-tech>

On Thu, 21 Jun 2001 14:56:16 +0200, LGB Systems <info@lgbsys.com> wrote:
>Hello,
>
>Easy WebControls is a suit of Cross-Browser Dynamic HTML components

How does one go about wearing a suit of Cross-Browser Dynamic HTML
components? And does one dry clean it or can it be just tossed in
the washing machine like other cheap suits?

Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'


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

Date: 21 Jun 2001 14:33:58 GMT
From: namille2@news.vt.edu (Matthew Miller)
Subject: Re: Difficulty exporting from modules
Message-Id: <9gt0km$iur$1@solaris.cc.vt.edu>

On Thu, 21 Jun 2001 18:25:19 +1000, Ron Savage <ron@savage.net.au> wrote:
>> Next question: after making the correction you suggested, I uncommented
>> this line:
>> our @ISA = qw( CWidgit );
>> in package CWidget::Menu. After my test program exits this message is
>> printed twice:
>> Can't locate package CWidgit for @CWidget::Menu::ISA during global destruction.
>>
>> The original post shows the ISA line that was commented out. Any ideas why this
>> happens?
>
>Don't know.
>
>Try putting the CWidget package before the derived one.

Nope, that doesn't fix it :( I think I may try moving Menu from out
under the CWidget package...

Thanks, Matthew

-- 
Alcohol is like a kick in the face, pot is more like a gentle
scalp massage.  - Greenman


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

Date: 21 Jun 2001 11:07:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Exception handling ?
Message-Id: <9gskgk$2rf$1@mamenchi.zrz.TU-Berlin.DE>

According to BeyondContol Inc. <beyondcontrol@runbox.com>:
> Hi,
> 
> I'm running a scripts that loads subroutines from other script files.
> My problem is that every time that any subroutine from those files fails
> (like trying to manipulate undefined objects), my main script dies with it.
> Now, I'm not going to sell myself out by running the subroutines using
> system('perl xxx.pl'),  I want to run them (relatively) cleanly as
> subroutines.
 
This sounds as if you were not only loading but actually executing
routines in the files you "load". (Otherwise, "system 'perl xxx.pl'"
wouldn't be an alternative.)  This is not the way it's meant to be.
Normally, you only define subroutines in an external file and call
them in the main program.  The only thing you directly do in a file
like that is what needs to be done for initialization, before any
subroutine is called.

> Is there an equivalent to the try/catch c++ directives?
> I saw something in the form of an Exception module at CPAN, but I'm not sure
> it'll catch errors not thrown using this same module....

There is, as other respondents have pointed out.  However, eval and
related techniques are only a last resort to catch fatal errors in
routines you can't control (from a standard module, for instance).
Your own routines can (and should) be written so that they deal
with errors in the way you want.  In particular, if you want to
carry on after an error, return an error condition and let the
main program deal with it.  

Anno


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

Date: Thu, 21 Jun 2001 13:06:29 GMT
From: moser@ivk.uni-stuttgart.de (Rainer Moser)
Subject: Executing UNIX shell commands in PERL
Message-Id: <3b31eee2.20333818@news.uni-stuttgart.de>

Hi everyone,

I am trying to execute shell commands from a PERL script. The shell
script uses aliases. If I execute a system command in the way 	

system("my_alias") 

I get the error 'my_alias - command not found', because the aliases
are not known in this environment. So I decided to execute

system("source sysalias.def; my_alias")

but then I get the error 'source - command not found'.
The question is: how can I execute shell scripts using aliases from
within PERL?

Thanks


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

Date: Thu, 21 Jun 2001 13:40:55 GMT
From: steven.smolinski@sympatico.ca (Steven Smolinski)
Subject: Re: Executing UNIX shell commands in PERL
Message-Id: <HPmY6.41291$Vl2.2359569@news20.bellglobal.com>

Rainer Moser <moser@ivk.uni-stuttgart.de> wrote:
> 
> system("source sysalias.def; my_alias")
> 
> but then I get the error 'source - command not found'.
> The question is: how can I execute shell scripts using aliases from
> within PERL?

See system() in perlfunc.

That string will be passed to your shell, probably "/bin/sh -c".  That
shell, depending upon what it is, doesn't appear to support 'source'.
Some shells use unary prefix dot (i.e., ". sysalias.def; my_alias"), but
you should really check your system manual for /bin/sh.

Steve
-- 
Steven Smolinski => http://arbiter.ca/


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

Date: Thu, 21 Jun 2001 16:20:37 +0200
From: Philip Newton <pne-news-20010621@newton.digitalspace.net>
Subject: Re: Executing UNIX shell commands in PERL
Message-Id: <1k04jt0jtnmceg618k4el174lekbumtsti@4ax.com>

On Thu, 21 Jun 2001 13:40:55 GMT, steven.smolinski@sympatico.ca (Steven
Smolinski) wrote:

> That string will be passed to your shell, probably "/bin/sh -c".  That
> shell, depending upon what it is, doesn't appear to support 'source'.
> Some shells use unary prefix dot (i.e., ". sysalias.def; my_alias"), but
> you should really check your system manual for /bin/sh.

IIRC, 'source' is csh. So the OP should probably invoke csh directly.
(How to pass the script to csh as an argument I don't know, but the OP
should be able to glean the information from the man pages for csh.)

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Thu, 21 Jun 2001 14:00:34 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: how does one go about assigning the ip address from gethostbyname to  variable...
Message-Id: <3B31E1E2.F8312D7B@fujitsu-siemens.com>

Demitri Borg wrote:
> =

> Does anyone happen to have a place where i could read up on how to
> assign the output from gethostbyname() to a variable ?

"Programming Perl" by Larry Wall et al?

Or here:

	$ip =3D join ".", unpack("C4", (gethostbyname("localhost"))[4]);

> Thank you.

You're welcome,
-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: Thu, 21 Jun 2001 11:23:44 GMT
From: demitri-borg@home.com (Demitri Borg)
Subject: how does one go about assigning the ip address from gethostbyname to variable...
Message-Id: <3b31c8d1.221794914@news.grlnd1.tx.home.com>

Does anyone happen to have a place where i could read up on how to
assign the output from gethostbyname() to a variable ?

any help is greatly appreciated.

Thank you.


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

Date: 21 Jun 2001 07:03:51 -0700
From: isterin@hotmail.com (isterin)
Subject: Re: How i Install module in NT platform
Message-Id: <db67a7f3.0106210603.75271e61@posting.google.com>

helgi@NOSPAMdecode.is (Helgi Briem) wrote in message news:<3b31b190.1900517710@news.isholf.is>...
> On 20 Jun 2001 06:41:57 -0700, ELI@PELEPHONE.CO.IL (Eli)
> wrote:
> 
> >hi all
> >
> >how i install module on NT platform
> >i get the instruction from the wab
> >after i unzip the zip file
> >i get into the new create directory
> >the step that i sould do is :
> >1. perl Makefile.pl
> >2. Dmake
> >3.Dmake test
> >4.Dmake install
> >
> >but after i run the first step , i can't run make or dmake
> >i try also perl -V:Dmake but noting done
> >unother think there are missing the install file of it ok
> 
> What's a wab? :-)
> What's a Dmake?  Do you have Dmake?

dmake is the Borland make utility.  Which can't be used with compiling
the modules anyways since ActivePerl was compiled with VC++.

> Why are you trying to make a Perl module under NT?

You are right, most modules are available as binaries from
ActiveState.  There are times where I compile modules on wintel, since
I might want the latest version and/or a module not available through
ppm repository.  Rare, but happens.  Still must use VC++ and it's
nmake utility and not Borland.



> Use PPM and save yourself a world of hurt.

Definitelly.

Ilya


> 
> Regards,
> Helgi Briem


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

Date: Thu, 21 Jun 2001 12:30:09 GMT
From: "Mark Law" <marklaw@mediaone.net>
Subject: How to check for open files on NT
Message-Id: <lNlY6.5153$bK1.93930@typhoon.mw.mediaone.net>

I'm writing a store and forward FTP application to pick up files in NT
directories and move them from a staging area.  The files are deposited at
random times, and some are quite large, >6GB.  I obviously don't want to
start the FTP tranfer of the files until they have been completely written
to the staging area.  Since the file directory entry is created at the time
the transfer begins to the staging area, I don't know how to test when the
transfer to the staging area is complete.  I've looked at Lockfile::Simple,
Win32::File and Win32API::File, Win32::NetAdmin, Win32::NetResource,
Win32::Process, Win32API::Net.  None seem to be able to tell when a file is
"closed" for writing by other processes.

I would like to do something simple like:
    if ( ! $fileopen =
SOME_UNKNOWN_PACKAGE::some_unknown_method($filename) ) {
            ....don't process file, some other process has it open for
writing
    } else {
           ....begin FTP process
    }

Has anyone run across this before?




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

Date: Thu, 21 Jun 2001 12:10:49 +0100
From: John Imrie <john.imrie@pa.press.net>
Subject: Re: HowTo: Run a command in backticks as root?
Message-Id: <3B31D639.8080300@pa.press.net>

Simon Devlin wrote:

> Thanks to both of you for this, I'll try the suggestions.  I take the
> point about being careful with NMAP, but this is a tool for internal,
> corporate use (which I agree doesn't remove the need for security, but
> at least means it's not being fronted on an internet facing webserver)

Another solution would be so set up sudo to allow the apache user to run 
nmap



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

Date: Thu, 21 Jun 2001 13:49:34 +0200
From: "H. Merijn Brand" <h.m.brand@hccnet.nl>
To: comp.lang.perl.misc
Subject: Re: Install Perl on HP
Message-Id: <Xns90C78CA57930Merijn@192.0.1.90>

Philip Newton <pne-news-20010620@newton.digitalspace.net> wrote in 
news:csg1jt00moe7q2s2jq2l3u4nkk9s9afe7q@4ax.com:

> [Posted and CC'ed to ralphwang@hotmail.com]
> 
> Are you the same Ralph Wang who just sent me email asking essentially
> the same question as you just posted in the newsgroup?
> 
> I got this when I tried to respond:
> 
>   wang_yifu@yahoo.com.tw:
>     SMTP error from remote mailer after end of data:
>     host mx1.mail.tw.yahoo.com [202.1.238.35]:
>     554 delivery error:
>     dd This user doesn't have a yahoo.com.tw account
> (wang_yifu@yahoo.com.tw) - mta103.mail.tpe.yahoo.com
> 
> I can't reply if you use an address that doesn't exist.

He did the same with me. Same result. He just ended up in my Killfile, for I 
don't think this is the right way to deal with newsgroup replies.

-- 
H.Merijn Brand    Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)
using perl-5.6.1, 5.7.1 & 626 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
     WinNT 4, Win2K pro & WinCE 2.11 often with Tk800.022 &/| DBD-Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/


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

Date: 20 Jun 2001 18:14:58 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: Install Perl on HP
Message-Id: <993060897.313714@hpvablab.cup.hp.com>

"H. Merijn Brand" <h.m.brand@hccnet.nl> writes:
>> They do? I thought the perl4 that comes with HP-UX was only for the
>> kernel debugger q4 and for nothing else (just like the cc that comes
>> with it is *only* for rebuilding the kernel, so it doesn't need any
>> steenking ANSI compliance).

That's what I was told.

>Ever studied the way swinstall works? (or swlist or swremove or ...)
>Shhhhst, don't anyone else ... ;-)

Are you _sure_?  I've never seen SD use /usr/contrib/bin/perl -- and
have used it on machines that didn't have the CONTRIB bundle installed.
As a sanity check, I also ran strings on the executables.  And tusc
doesn't show perl being forked/exec'd on a swlist.  Where have you see
/usr/contrib/bin/perl used?

Now, if someone was using perl in their postinstall/preinstall scripts,
then they were being naughty!  (Although a quick grep of those scripts
on my 11.00 box shows perl only in 'properly'.)

>http://devresource.hp.com/OpenSource/ and 
>http://devresource.hp.com/OpenSourcebin/ are great examples of HP's effort 
>into the open source world. Use it!

Thanks -- although I don't work in that group, we appreciate the
support!

Rich
-- 
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant     | I speak for me,     |   19055 Pruneridge Ave. 
Development Alliances Lab|            *not* HP |                MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014


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

Date: 21 Jun 2001 03:40:57 -0700
From: aougav@hotmail.com (Zur Aougav)
Subject: Re: int sub - strange behaviour
Message-Id: <bccc87cc.0106210240.91d8c74@posting.google.com>

"Ron Savage" <ron@savage.net.au> wrote in message news:<DQcY6.8681$qJ4.352026@ozemail.com.au>...
>...

IMHO you can use:

my $tolerance = 1E-3;
my $tolerance2 = 5E-3;      # "better" 
for my $i (0.555, 1.555, 0.565, 1.565, 0.575, 1.575, 0.949, 1.949){
        print "$i => ", sprintf("%.2f. ", $i);
        print "$i => ", sprintf("%.2f. ", $tolerance+$i).". ";
        print "$i => ", sprintf("%.2f. ", $tolerance2+$i)." \n";
}

In the original problem:

         print int(1E-3+100*39.80)."\n";         # will print a correct 3980
 
In simple words it says: "we accept some errors at 1E-3, but *not* at 1E-2".

I agree it's not an elegant solution, but we need to work hard for better accuracy... :-)

Zur


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

Date: 21 Jun 2001 11:39:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: int sub - strange behaviour
Message-Id: <9gsme2$4kp$1@mamenchi.zrz.TU-Berlin.DE>

According to Ron Savage <ron@savage.net.au>:
> George
> 
> See below.

Why are you doing this?  It's customary to "see below" on Usenet.
Moreover, inserting your sig in this place may fool some newsreaders
into thinking that all the rest of your post is signature.

> --
> Cheers
> Ron  Savage
> ron@savage.net.au
> http://savage.net.au/index.html
 
[snip]

> Hmmm. And despite Greg's reponse, I don't see sprintf rounding-to-even.
> Math::Currency does. Try (tested code):
> 
> -----><8-----
> #!/perl/lib/perl
> 
> use strict;
> use warnings;
> 
> # ---------------------------------------------------------------
> 
> print sprintf("Perl V %vd. \n", $^V);
> 
> for my $i (0.555, 1.555, 0.565, 1.565, 0.575, 1.575)
> {
>  print "$i => ", sprintf("%.2f. \n", $i);
> }
> -----><8-----
> 
> My output:
> -----><8-----
> Perl V 5.6.1.
> 0.555 => 0.56.
> 1.555 => 1.55. # Sure looks odd to me :-).
> 0.565 => 0.56.
> 1.565 => 1.56.
> 0.575 => 0.57.
> 1.575 => 1.58.
> -----><8-----

Perl rounds the way the underlying C compiler rounds.  In most cases
C relies on a hardware rounding function, so that is what ultimately
determines the rounding behavior.

However, your tests don't show whether or not your machine rounds to
even.  On a binary machine, rounding to even can only occur when
you round to integer values.  That is because the last digit (in
decimal) of the number in question must be exactly 5.  On a binary
computer the only numbers with that property are numbers n + 1/2
for integer n.  In other words, the numbers you are rounding are
internally only approximations of 1.555 (or whatever) and rounding
to even doesn't apply.

Anno


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

Date: 21 Jun 2001 14:19:38 +0200
From: mriedel@neuearbeit.de (Marko R. Riedel)
Subject: Memory usage.
Message-Id: <20010621121942.301BFABB.NOFFLE@naproxy.neuearbeit.de>



Greetings.

I would like to know whether the following code fragment reads the entire
file into memory. I would prefer that the file be processed line by
line. Would you please suggest a fix if it does read the entire file.

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

my $DATE = '/bin/date';

my $data = '/var/log/messages';

my $current = `$DATE +"%b %e %H"`;
chomp $current;


open DATA, $data or die "couldn't open $data: $!\n";
@curscanlog = grep /^$current.*scanlogd/o, <DATA>;
close DATA;

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

Regards,

Marko Riedel


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

Date: Thu, 21 Jun 2001 08:07:48 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Memory usage.
Message-Id: <3B31F1A4.1324D5C9@home.com>

"Marko R. Riedel" wrote:
> 
> I would like to know whether the following code fragment reads
> the entire file into memory.

Yes. grep() puts the filehandle in list context.

> I would prefer that the file be processed line by line.

Piece o'cake.
 
> open DATA, $data or die "couldn't open $data: $!\n";
> @curscanlog = grep /^$current.*scanlogd/o, <DATA>;

my @curscanlog;
while (<DATA>) {
    push(@curscanlog, $_) if /^$current.*scanlogd/o;
}

> close DATA;

-mjc


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

Date: Thu, 21 Jun 2001 10:33:48 -0400
From: Narendra Ravi <narendra@spiff.hr.att.com>
Subject: Opening and Reading Named Pipes
Message-Id: <3B3205CC.3658A501@spiff.hr.att.com>


I am trying to write a simple named pipes manager.
Currently, this program
 a. reads a list of named pipe - file pairs,
 b. opens them (Read ONLY) and
 c. writes the data on the pipe to the associated file

I am having a problem opening the named pipe. The following
snippet of Perl show my attempts:

###########################################################################
#!/opt/perl5/bin/perl -w

use strict ;
use Fcntl ;
use IO::File ;
use IO::Pipe ;

###########################################################################
#   MAIN program
###########################################################################

my $pipename = "/usr/tmp/eqpt_trace" ;
my $pfh ;

if ( -p $pipename) {
  print "Trying to Open $pipename\n" ;
  sysopen (FIFO, $pipename, O_RDONLY)
    or die "Can't write $pipename: $!\n" ;
}

# do the following in a loop with select
# a. Read from pipe
# b. Write to log file


1;
###########################################################################

I have tried replacing the sysopen with

  $pfh = new IO::File, "$pipename" O_RDONLY;

I would appreciate if you posted as well as emailed responses.

Thank you,
-- 

 -- Narendra Raavi     Email : narendra@spiff.hr.att.com
    MT  A4-4B27       Phone : 732-420-7792


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

Date: Thu, 21 Jun 2001 16:59:33 +0200
From: Philip Newton <pne-news-20010621@newton.digitalspace.net>
Subject: Re: Opening and Reading Named Pipes
Message-Id: <ft24jtstv71hc0p19a6qdgmg3dnl7hi0v6@4ax.com>

[Posted and emailed]

On Thu, 21 Jun 2001 10:33:48 -0400, Narendra Ravi
<narendra@spiff.hr.att.com> wrote:

> I am having a problem opening the named pipe. The following
> snippet of Perl show my attempts:

And the error messages you are getting are...?

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 21 Jun 2001 07:49:04 -0700
From: si.cox@bbsrc.ac.uk (Loki)
Subject: Pattern matching with variables
Message-Id: <7dfd76cc.0106210649.3392b708@posting.google.com>

Have a script to scan a database of filenames.  This allows the entry
of a pattern to match against.
For this example i will say we are searching for .EXE files.

Now as . is a special char in pattern matching i have to proceed the .
with a \

If i have the line read: if (m/\.EXE/) {...... etc then the script
works.
However if the line reads: if (m/$pattern/) {...... with $pattern =
"\.EXE" predeclared then it finds files like userexe.cfg as it is
treating the . as a wildcard and ignoring the preceeding \.  Ive also
tried declaring $pattern as ".EXE" with the line reading if
(m/\$pattern/) {...... and this doesnt work either.

I know when perl does a pattern match it translates variables before
doing the match but surely this means it should work declaring
$pattern = "\.EXE".

any thoughts?


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

Date: Thu, 21 Jun 2001 17:04:07 +0200
From: Philip Newton <pne-news-20010621@newton.digitalspace.net>
Subject: Re: Pattern matching with variables
Message-Id: <cv24jtc4hcqchit6djf39sn5bin295d2a5@4ax.com>

On 21 Jun 2001 07:49:04 -0700, si.cox@bbsrc.ac.uk (Loki) wrote:

> However if the line reads: if (m/$pattern/) {...... with $pattern =
> "\.EXE" predeclared then it finds files like userexe.cfg as it is
> treating the . as a wildcard and ignoring the preceeding \.

Yes. This is because the backslash in "\." is interpreted by the
double-quote mechanism; $pattern ends up containing the characters 

    . E X E

(note: no backslash). So when that's interpolated into the regex, the
dot is treated as "match any non-newline". If you want the backslash to
be seen by the regex mechanism, either double it so it'll survive the
double it "\\.EXE", use single quotes '\.EXE', or (most flexibly) use \Q
in the regex: m/\Q$pattern/ . This will protect the dot with a backslash
automatically, and also other non-alphanumeric characters. (See also
`perldoc -f quotemeta`.)

> Ive also tried declaring $pattern as ".EXE" with the line reading if
> (m/\$pattern/) {...... and this doesnt work either.

No, because that matches "dollar sign-p-a-t-t-e-r-n".

> I know when perl does a pattern match it translates variables before
> doing the match but surely this means it should work declaring
> $pattern = "\.EXE".

No, because the regex engine doesn't see the backslash, as explained
above. (See also `perldoc perlop`, the section "Gory details of parsing
quoted constructs".)

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Thu, 21 Jun 2001 12:05:16 +0100
From: John Imrie <john.imrie@pa.press.net>
Subject: Re: premature end of script or malformed header
Message-Id: <3B31D4EC.6020609@pa.press.net>

Christophe Gibert wrote:

> I am running a cgi script written in perl that causes an internal server
> 
> error. the error logs say "premature end of script" or "malformed header
> 
> from script" but the script is running when it is launched from the
> shell. And it is so simple that it it can not be wrong
> My server is apache 1.3.14
> 
> What'ts wrong ?
> 
> --
> Christophe Gibert
> http://www.e-xode.com/cv/christophe.htm
> Reportage multimedia interactif : les enfants tibétains exilés
> http://www.e-xode.com

You haven't red the perl FAQ :-)



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

Date: Thu, 21 Jun 2001 22:55:27 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Redirecting stderr under Windows
Message-Id: <V9mY6.2$ri.53301@news.interact.net.au>

I refuse to believe there isn't a simple solution to this one.

I want to run a command and capture both stdout and stderr, ie:

my $result=qx(command 2>&1);

The above works fine on Unix systems, but not under Windows (not sure about
NT).

I thought that I'd be able to just manually redirect STDERR, but FAQ8 says:

Note that you cannot simply open STDERR to be a dup of STDOUT in your Perl
program and avoid calling the shell to do the redirection. This doesn't
work:

    open(STDERR, ">&STDOUT");
    $alloutput = `cmd args`;  # stderr still escapes

I did a search on Google Groups and found a 1996 reference to a similar
problem where the solution was to install a DOS redirect utility.  Surely
there has to be a way.





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

Date: Thu, 21 Jun 2001 15:21:09 +0200
From: "Stefan Serena" <sserena@freesurf.ch>
Subject: Re: Reference-problem
Message-Id: <9gssca$3g0$1@news1.sunrise.ch>

> First off: Please trim the quoted text and place your reply below
> the part(s) you are replying to.  Don't slap it on top and let
> your readers sort it out.

Ok. Sorry!

>     foreach ( $apple, $orange, $lemon, $banana ) {
>         # do something with $_ here.
>     }
>
> Note that foreach makes $_ an alias to each variable in turn, so
> everything you do to $_ really happens to $apple, $orange, etc.

Didn't know that. I thought it makes a copy to $_
That means, the following code changes every entry of the array?

foreach $entry (@allentries) {
    $entry = $entry x 2;    # can be anything...
}

Stefan




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

Date: 21 Jun 2001 13:22:22 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Reference-problem
Message-Id: <9gssee$oag$1@bob.news.rcn.net>

Stefan Serena <sserena@freesurf.ch> wrote:
> Thx! I've written that I _could_ use a hash, because Rafael Garcia-Suarez
> recommended to rather use hashes than symbolic references.
> Everybody sais that using symbolic references is a bad idea. But, lets say I
> have 20 variables: $apple, $orange, $lemon, $banana and so on. They have to
> remain like that (no hash or array). Then, I have to perform 5 tasks with
> each of these variables. I could write 100 lines or use a procedure, but
> wouldn't it be better to put the names of the variables into an array and
> work with symbolic references?

No.  Fill the array with real references to the variables.



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

Date: Thu, 21 Jun 2001 16:16:03 +0200
From: Philip Newton <pne-news-20010621@newton.digitalspace.net>
Subject: Re: Reference-problem
Message-Id: <da04jtgieoost9efe9f3bmvdubfdvm58g9@4ax.com>

On Thu, 21 Jun 2001 15:21:09 +0200, "Stefan Serena"
<sserena@freesurf.ch> wrote:

> That means, the following code changes every entry of the array?
> 
> foreach $entry (@allentries) {
>     $entry = $entry x 2;    # can be anything...
> }

Try it and see :) In Perl, it's very easy to try out little things like
this because you don't have to go through the whole compile-and-link
cycle.

(Short answer: yes, it changes every entry. And you could have written
$entry x= 2 instead.)

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 21 Jun 2001 05:41:51 -0700
From: davew@wsieurope.com (Dave Weaver)
Subject: Returning undef from embedded Perl
Message-Id: <bbbfa68d.0106210441.5f3c3791@posting.google.com>

I have an application with an embedded Perl interpreter, and I'm
using perl_call_pv() from my program to call Perl subroutines.

I'd like my Perl subroutines to be able to return undef to
indicate an error, but despite reading though perlembed and
perlcall I can't see how to do this.

My current code goes like this:

int call_perl(const char *subname, const char *arg) {
    dSP;
    ENTER;
    SAVETMPS;

    PSUHMARK(sp);
    XPUSHs(sv_2mortal(newSVpv(arg, strlen(arg))));
    PUTBACK;

    int count = perl_call_pv(my_perl, subname, G_SCALAR);
    int val;

    SPAGAIN;
    if (count == 1) val = POPi;

    FREETMPS;
    LEAVE;

    return val;
}

How can I determine if the return value is undef?

Thanks in advance,
-- 
Dave.
davew@wsieurope.com


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

Date: Thu, 21 Jun 2001 13:20:58 GMT
From: Paul Dempsey <dempsey@dickinson.edu>
Subject: Small Database Becomes Large Database
Message-Id: <3B31F4CE.C5895879@dickinson.edu>

I have a simple Unix DBM file of about 200 records, each record about
300 bytes. I needed to change the keys for this file, so I read the file
in and wrote to a different DBM file with the new key.

The problem is my new data file has grown from 250 KB to to 25 MB in
size. I can't figure this out. I even wrote the old data to a text file
and created the new DBM file from that text data, but I still got a 25
MB file.

Here's the code:

open (TEXTIN, "facdatnew.txt");		# text file to get keys
dbmopen(%OLDFAC,"facdesc",undef);	# old DBM
dbmopen(%NEWFAC,"newfacdesc",0700);	# new DBM

while (<TEXTIN>) {
	chomp;
	@facinfo = split(/\|/);
	$oldkey = "$facinfo[0]|$facinfo[1]";
	$newkey = "$facinfo[10]";
	$NEWFAC{$fackey} = $OLDFAC{$oldkey};
	}

close (TEXTIN);
dbmclose(%OLDFAC);
dbmclose(%NEWFAC);

Any thoughts? Or is there a better way to change record keys in a DBM
file?
Thanks,

Paul Dempsey
Web Manager
Dickinson College


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

Date: Thu, 21 Jun 2001 16:15:43 +0200
From: "Dimitri Gunsing" <somewhere@planet.earth>
Subject: Re: Small Database Becomes Large Database
Message-Id: <9gsvfb$9se$1@proxy.pbnec.nl>

> $oldkey = "$facinfo[0]|$facinfo[1]";
> $newkey = "$facinfo[10]";
> $NEWFAC{$fackey} = $OLDFAC{$oldkey};

Shouldn't $NEWFAC{$fackey} be $NEWFAC{$newkey} ?




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

Date: Thu, 21 Jun 2001 14:28:30 GMT
From: Paul Dempsey <dempsey@dickinson.edu>
Subject: Re: Small Database Becomes Large Database
Message-Id: <3B3204A1.59FB06E6@dickinson.edu>

Dimitri Gunsing wrote:
> 
> > $oldkey = "$facinfo[0]|$facinfo[1]";
> > $newkey = "$facinfo[10]";
> > $NEWFAC{$fackey} = $OLDFAC{$oldkey};
> 
> Shouldn't $NEWFAC{$fackey} be $NEWFAC{$newkey} ?

You're right. But that's not the problem, just an error copying the code
to the email.

-Paul


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

Date: 21 Jun 2001 14:42:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Small Database Becomes Large Database
Message-Id: <9gt15e$fip$2@mamenchi.zrz.TU-Berlin.DE>

According to Paul Dempsey  <dempsey@dickinson.edu>:
> I have a simple Unix DBM file of about 200 records, each record about
> 300 bytes. I needed to change the keys for this file, so I read the file
> in and wrote to a different DBM file with the new key.
> 
> The problem is my new data file has grown from 250 KB to to 25 MB in
> size. I can't figure this out. I even wrote the old data to a text file
> and created the new DBM file from that text data, but I still got a 25
> MB file.
> 
> Here's the code:
> 
> open (TEXTIN, "facdatnew.txt");		# text file to get keys
> dbmopen(%OLDFAC,"facdesc",undef);	# old DBM
> dbmopen(%NEWFAC,"newfacdesc",0700);	# new DBM

"dbmopen" is deprecated.  Use "tie" instead.

> while (<TEXTIN>) {
> 	chomp;
> 	@facinfo = split(/\|/);
> 	$oldkey = "$facinfo[0]|$facinfo[1]";
> 	$newkey = "$facinfo[10]";
> 	$NEWFAC{$fackey} = $OLDFAC{$oldkey};
                ^^^^^^^
                should be $newkey, as has been noted
> 	}
> 
> close (TEXTIN);
> dbmclose(%OLDFAC);
> dbmclose(%NEWFAC);
> 
> Any thoughts? Or is there a better way to change record keys in a DBM
> file?

The method is fine, provided all relevant keys are generated this
way.  As for thoughts, while you have included code, the question
hinges on a) the type of database you use, and b) the contents of
file "facdatnew.txt", both of which we don't know.  Show a few
lines of the file, so we get an idea how $oldkey and $newkey relate.

Anno


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

Date: Thu, 21 Jun 2001 10:07:53 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: string tokenization
Message-Id: <8oh3jt4piicakqvm48sr87i3d854664dbk@4ax.com>

Matthew Zhang da LBNL wrote:

>The way I am tackling this is
>that I will look for the index of the white space of each line I read
>then substr. to get the first token...

Too much hard work. split / / will do that just for you.

	$addresses = 'one@domain two@domain three@domain';
	@address = split / /, $addresses;	# <-- HERE
	foreach (@address) { print "Send mail to <$_>\n" }  # demo

Or with a regex:

	@address = $addresses =~ /(\S+)/g;
	
-- 
	Bart.


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

Date: 21 Jun 2001 10:27:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why does this split not work?
Message-Id: <9gsi78$t5f$2@mamenchi.zrz.TU-Berlin.DE>

According to tuxy  <nospam@cfl.rr.com>:

First off, please place your reply *below* the quoted text.  It's
customary on Usenet.

> Hi Ren:
> 
> I solved the problem. I went to a box with Perl 5.004 and botta-bing
> botta-boom just as I suspected, my code is pristine, it's Perl 5.6
> that's wacked. Apparently. Anyhow, now I either have to re-write this
> algorithm in something 5.6-friendly, or  have to revert to 5.004 on this
> other box. Neither prospect is overly appealing.

I doubt your analysis is correct.  Please show the code that exhibits
the difference between 5.004 and 5.6.

> A little surprizing too that in a forum this large, none of the guru's
> would chime in with "oh split has some serious problems in 5.6".... That
> message would have saved me many hours of study and experimentation. Oh
> well what can I expect for free LOL..

That's because there is no serious problem with split in 5.6.  If
there still is a bug in split, it must be a pretty obscure one.
Again, please show code to substantiate your claim.

Anno


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

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


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