[8003] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1628 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 13 12:20:26 1998

Date: Tue, 13 Jan 98 09:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 13 Jan 1998     Volume: 8 Number: 1628

Today's topics:
     again arrays <jahnel@xarch.tu-graz.ac.at>
     Re: again arrays <xxTony.Curtis@vcpc.univie.ac.at>
     C-style assert()ions (Andy Lester)
     Re: C-style assert()ions (Gabor)
     CPAN packages and makefiles for 5.004 on 95/NT <chris@searle1.demon.co.uk>
     Re: File permissions and umask <jdporter@min.net>
     Re: Find two strings in a file <jdporter@min.net>
     Re: Free Online Computer Books at mcp.com <jdporter@min.net>
     Re: Free Online Computer Books at mcp.com <tchrist@mox.perl.com>
     Re: Free Online Computer Books at mcp.com <jdporter@min.net>
     help with the following error message <djboyd@sam.on-net.net>
     How to get possition of an array? <jahnel@xarch.tu-graz.ac.at>
     Multi-computer execution tool/controller for long proce <clark@s3i.com>
     performing subroutine on a strange set of elements from (Chris Lott)
     Re: performing subroutine on a strange set of elements  <xxTony.Curtis@vcpc.univie.ac.at>
     Re: PERL & IIS 4 (final) hanging - help!! <jim@webworks.co.uk>
     Perl and Oracle's PL/SQL <Kari.Marttila@tietogroup.com>
     Re: perl under windows95 <camerond@mail.uca.edu>
     Re: Searching for an IP address in a string <dboorstein@ixl.com>
     Re: Searching for an IP address in a string <barnett@houston.Geco-Prakla.slb.com>
     Re: socket help needed... <boschini@cilea.it>
     Re: symbolic reference in subroutine (Andrew M. Langmead)
     Re: Testing for valid numeric values <jdporter@min.net>
     Tk402.003 and sfio.. <marius@ace.funcom.com>
     Re: Tk402.003 and sfio.. <marius@ace.funcom.com>
     Re: unlink () doesn't work under NT (Jeremy D. Zawodny)
     Re: Where do I get PERL (Dave Cross)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 13 Jan 1998 17:01:45 +0100
From: Jahnel Klaus <jahnel@xarch.tu-graz.ac.at>
Subject: again arrays
Message-Id: <34BB8FE9.33121EB6@xarch.tu-graz.ac.at>

how can i change a value in an array like that:
@test = ("a","b","c", .......)

$test[2] = "test";
result should be then
@test = ("a","b","test", .......)


klaus



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

Date: 13 Jan 1998 17:12:51 +0100
From: Remove xx to reply <xxTony.Curtis@vcpc.univie.ac.at>
To: jahnel@xarch.tu-graz.ac.at
Subject: Re: again arrays
Message-Id: <7xd8hwtksc.fsf@vcpc.univie.ac.at>

Re: again arrays, Jahnel <jahnel@xarch.tu-graz.ac.at> said:

Jahnel> how can i change a value in an array like that:
Jahnel> @test = ("a","b","c", .......)

Jahnel> $test[2] = "test";
Jahnel> result should be then @test = ("a","b","test", .......)

Yeeeeesssssss.  That's right.


    sub showme { print join(",", @_) . "\n"; }
    
    @test = ( "a", "b", "c", "d");
    showme(@test);
     
    $test[2] = "test";
    showme(@test);

    ==>  a,b,c,d
         a,b,test,d


Wo ist das Problem? :-O ?

tony


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

Date: 13 Jan 1998 14:06:50 GMT
From: petdance@maxx.mc.net (Andy Lester)
Subject: C-style assert()ions
Message-Id: <69fsdq$fur$1@usenet51.supernews.com>

After having been bitten the other night by mixing up an instance method
and a class method, I'd like to do some C-style assertions.  For instance,
say I have this:

package Foo;

sub Bar($) {
    my $self = shift;
    ref $self eq "Foo" or die "Didn't pass a Foo";
    # now I can go on.
    }

What I'd really like to do, for brevity's sake, since a long error message
isn't necessary, is something like:

sub Bar($) {
    my $self = shift;
    assert( ref $self eq "Foo" );
    }

Is there a package somewhere that does this?  I know it wouldn't be too
hard to roll my own, of course, but I'd just as soon use what exists
already.  I see nothing like it in the CPAN.

Thanks,
xoxo,
Andy 

--
--
Andy Lester:        <andy@petdance.com>       http://tezcat.com/~andy/
Chicago Shows List: <shows@ChicagoMusic.com>  http://ChicagoMusic.com/



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

Date: 13 Jan 1998 14:46:39 GMT
From: gabor@vinyl.quickweb.com (Gabor)
Subject: Re: C-style assert()ions
Message-Id: <slrn6bmv42.364.gabor@vinyl.quickweb.com>

In comp.lang.perl.misc, Andy Lester <petdance@maxx.mc.net> wrote :
# After having been bitten the other night by mixing up an instance method
# and a class method, I'd like to do some C-style assertions.  For instance,
# say I have this:
# 
# package Foo;
# 
# sub Bar($) {
#     my $self = shift;
#     ref $self eq "Foo" or die "Didn't pass a Foo";
#     # now I can go on.
#     }

This would destroy the ability to inherit from your class.

gabor.
--
    If I don't document something, it's usually either for a good reason,
    or a bad reason.  In this case it's a good reason.  :-)
        -- Larry Wall in <1992Jan17.005405.16806@netlabs.com>


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

Date: 13 Jan 1998 13:51:42 +0000
From: Chris Searle <chris@searle1.demon.co.uk>
Subject: CPAN packages and makefiles for 5.004 on 95/NT
Message-Id: <wk1zyco51t.fsf@searle1.demon.co.uk>

I seem to have a problem using the CPAN makefiles with MakeMaker

It's the same problem each time, but to follow an example through, the
last aattempt was the MIME::Base64 package.

Downloaded the TAR file and extracted successfully. (MIME-Base64-2_04_tar.gz)

perl Makefile.PL neatly generated the makefile + other files as
normal (but see footnote below):

t\base64.t t\quoted-print.tWriting Makefile for MIME::Base64

make returns 

Makefile:629: *** missing separator.  Stop.


The makefile contents around that area are (Line 629 starts $(PM_TO_BLIB)):

--- Start of makefile segment
# --- MakeMaker pm_to_blib section:

pm_to_blib: $(TO_INST_PM)
	@$(PERL) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" \
	"-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -MExtUtils::Install \
        -e "pm_to_blib(qw[ <<pmfiles.dat ],'$(INST_LIB)\auto')"
	
$(PM_TO_BLIB)
<<
	@$(TOUCH) $@


# --- MakeMaker selfdocument section:
--- End of makefile segment


This is happening every time I try to use something from CPAN.

I have jigged the makefile code around, but I'm not being successful.

Any help on this would be appreciated.

I'm using the 5.004 bindist of perl (borland compiled) installed to c:\perl

The make in use is the cygwin32 make (GNU).

I'va also tried borland and MS make packages, same problem.

Cheers for your time.


Footnote regarding perl Makefile.PL:

I use the Wild.pm package to allow dos to glob properly:

#Wild.pm - emulate shell @ARGV expansion on shells that don't
use File::DosGlob;
@ARGV = map { my @g = File::DosGlob::glob($_) if /[*?]/; @g?@g:$_ } @ARGV;
#Return 1 so this is true even if there are no parameters.
1;

This is set as the environment variable PERL5OPT=-MWild.pm

This causes the following problems

Use of uninitialized value at C:\PERL\lib/File/DosGlob.pm line 112.
Subroutine doglob redefined at C:\PERL\BIN/perlglob.bat line 30.
Subroutine glob redefined at C:\PERL\BIN/perlglob.bat line 112.
Subroutine import redefined at C:\PERL\BIN/perlglob.bat line 114.
t\quoted-print.t t\base64.tWriting Makefile for MIME::Base64

Simple to fix, remove the environment variable. May be of interest to
any others using the Wild.pm bits (wish I could remember the name of
the poster of this bit, you did save a life with that one).

-- 
Chris Searle
chris@searle1.demon.co.uk


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

Date: Tue, 13 Jan 1998 08:53:23 -0500
From: John Porter <jdporter@min.net>
Subject: Re: File permissions and umask
Message-Id: <34BB71D3.30D9@min.net>

Kenneth Vogt wrote:
> 
> So if I want xrw_rw_rw would I use:
> 
> umask 011;
> 
> or
> 
> umask 0011;
> 
> or something else?
> 

You want umask 011.

BTW, you may wish to represent the bits as

  rwxrw_rw_

rather than

  xrw_rw_rw 

Because then the letters "line up" with their corresponding
bit positions in the mode:

   421421421
   rwxrwxrwx

hth,
John Porter
jporter@logicon.com


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

Date: Tue, 13 Jan 1998 08:55:49 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Find two strings in a file
Message-Id: <34BB7265.4A6D@min.net>

Martien Verbruggen wrote:
> 
>         $a ||= $b;
> 
> is the same as
> 
>         $a = $a || $b;

Sure, I dig that, man.  What I was confused by is where the value
of $b was coming from.  (I've got it now, btw, thanks to many patient
responses from the group.)

John Porter


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

Date: Tue, 13 Jan 1998 09:07:17 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Free Online Computer Books at mcp.com
Message-Id: <34BB7515.738A@min.net>

I'll bet some of you will be curious, as I was, which books on Perl
are available to be read this way.  MCP has included a listing of the
available books, at http://www.mcp.com/personal/ebooklist.html

For your convenience, here are the books relating to Perl:

	Perl 5 Unleashed -- Husain
	Teach Yourself Perl in 21 Days -- Till
	Using Perl 5 for Web Programming, Special Edition -- O'Foghlu
	Perl 5 By Example -- Medinets
	Perl 5 Quick Referencee -- O'Foghlu
	PC Magazine Programming Perl 5.0 CGI Web Pages for Microsoft 
		Windows NT -- Hagey
	Web Programming with Perl 5 -- Middleton et al.
	CGI Programming Unleashed -- Berlin
		[I gather this uses only Perl for CGI, unlike some books]
	Teach Yourself CGI Programming with Perl 5 in a Week -- Herrmann

jporter@logicon.com


mcp@weblogic.cncoffice.com wrote:
> 
> Mcp.com, the Web site for Que, Sams, and other Macmillan computer book
> publishers, has free full-text books online.  If you  register in
> mcp.com's *Personal Bookshelf,* you can have up to 5 active books online,
> and you can change books at any time.  The books are active for 90 days.
> Then you can choose 5 different books - or choose the same ones.  The
> company has a little over 150 books that it rotates. Topics include
> Visual C++ , Visual Basic, and Database Programming; Perl,  TCP/IP ,
> ActiveX, HTML, Java, and JavaScript; Web graphics; and general
> productivity applications.    The Personal BookShelf is located at:
> http://www.mcp.com/personal/


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

Date: 13 Jan 1998 14:20:14 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Free Online Computer Books at mcp.com
Message-Id: <69ft6u$168$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, jdporter@min.net writes:
:I'll bet some of you will be curious, as I was, which books on Perl
:are available to be read this way.  MCP has included a listing of the
:available books, at http://www.mcp.com/personal/ebooklist.html

Note that these books range in quality from Kinda Ok to Terrible,
including dead books that were withdrawn from publication.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
    last|perl -pe '$_ x=/(..:..)...(.*)/&&"'$1'"ge$1&&"'$1'"lt$2'
    That's gonna be tough for Randal to beat...  :-)
            --Larry Wall in  <1991Apr29.072206.5621@jpl-devvax.jpl.nasa.gov>


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

Date: Tue, 13 Jan 1998 11:32:21 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Free Online Computer Books at mcp.com
Message-Id: <34BB9715.5850@min.net>

Some of the Perl-related books at MCP are mentioned in Camel Critiques
(http://language.perl.com/critiques/); they are rated, too:

Decent - Teach Yourself Perl in 21 Days -- Till
So-so  - Using Perl 5 for Web Programming, Special Edition -- O'Foghlu
So-so  - Perl 5 By Example -- Medinets
Poor   - Perl 5 Quick Referencee -- O'Foghlu
Poor   - Perl 5 Unleashed -- Husain

The others are not (yet) discussed in Camel Critiques:

         PC Magazine Programming Perl 5.0 CGI Web Pages for NT -- Hagey
         Web Programming with Perl 5 -- Middleton et al.
         CGI Programming Unleashed -- Berlin
         Teach Yourself CGI Programming with Perl 5 in a Week --
Herrmann

John Porter


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

Date: Tue, 13 Jan 1998 11:28:18 -0500
From: "David J. Boyd" <djboyd@sam.on-net.net>
Subject: help with the following error message
Message-Id: <34BB9622.653646AD@sam.on-net.net>

I get the following error message:
      Cannot create a file when that file already exists.

>From the following code seqment:
  $FirstProcessObj->Wait(INFINITE) || &ProcessError("WAIT");
  $FirstProcessObj->GetExitCode($ExitCode) || warn
&ProcessError("GetExitCode");
  &RptError ("Exit code for Process wait is: $ExitCode");

What does it mean?



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

Date: Tue, 13 Jan 1998 14:56:37 +0100
From: Jahnel Klaus <jahnel@xarch.tu-graz.ac.at>
Subject: How to get possition of an array?
Message-Id: <34BB7295.EAFC72FD@xarch.tu-graz.ac.at>

I have a problem:
@daytime =
("00:00-01:00","01:00-02:00","02:00-03:00","03:00-04:00","04:00-05:00","05:00-06:00","06:00-07:00","07:00-08:00","08:00-09:00","09:00-10:00","10:00-11:00","11:00-12:00","12:00-13:00","13:00-14:00","22:00-23:00","23:00-00:00");

thats my defined  array
$time is the sring i get from SDTIN
$time="03:00-04:00"

How to i get the possition (or indexnumber) of $time from  @daytime?
I want to have a result like this $n = 3 as $time is number 3 in
@daytime at this example.
TIA
Klaus



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

Date: 13 Jan 1998 09:40:28 -0500
From: Clark Dorman <clark@s3i.com>
Subject: Multi-computer execution tool/controller for long processes
Message-Id: <d1zycl9nm.fsf@elmo.s3i.com>


Greetings,

I asked about this once before, but now I'm trying again.  I need to
run several hundred iterations of a large, complex model (runtime ~2
hours, several system calls: initialize, run, process results).  I
have access to a number (about 8) 4-cpu workstations and a couple of
8-cpu workstations.  What I need to do is monitor the cpu usage of the
workstations, launch jobs when cpu's are available, and report to the
user how things are going.  I have a solution, but it's not a very
good one.  I have an idea for a better one, but I'm not sure about how
to make it work.

Present solution
-----------------
I have a main perl process.  It uses rup to see how cpus are on other
machines.  When one is available, it uses rsh to launch a perl process
controlling a single iteration on that machine, doing the initialize,
run, and results process.  When the iteration is finished, the rsh-ed
control process creates a file, saying whether the process succeeded
(ran to completion) or failed (for whatever reason, about 5% of the
iterations fail).  The main perl process keeps track of progress by
looking for the files.  

Problems with the present solution:  

	o I have no idea how an iteration is doing without launching
	  another rsh-ed process to check up on it.

	o Response time is very slow, due to problem above.

	o I have too many rsh-ed processes IMO, ~40

	o The file communication process (write in rsh-ed process,
   	  read in main process) is very kludgey.

	o If something goes wrong, it is almost impossible to kill,
  	  with zombie and isolated processes everywhere.


Possible Solution
-----------------
The main process should use rsh one process per workstation.  It
should connect to them using sockets.  Each workstation process keeps
track of the iterations on its machine.  When a cpu becomes available,
it tells (by socket) that it is available for a process and the main
process tells it to run iteration number XX (or not to, if we are at
the end).  To find out about a process, the main process sends a
message to the appropriate rsh-ed process asking about it, and the
rsh-ed process sends information back (see below about this).

What I Don't Understand
------------------------
This section could be very long (since I don't understand a great
deal), but I have several problems largely related to keeping the main
process informed with the state and figuring out who talks to who
first.  I have been reading ``Unix Network Programming'' by W. Richard
Stevens, and I think that it is a very good book (I have learned a ton
about sockets, bind, connect, 3-way handshakes, etc.), but it deals
with fairly low level processes and it is not clear how to use the
information in a large scale process controller.

The rsh-ed process connects to the main process by a socket (main is
server, rsh-ed is client).  If the rsh-ed process wants to launch
another run, it writes to the main process, so it would seem that I
want to have the client write first (main process read first).
However, when I want to ask about how a run is doing, the main process
needs to ask the client for information so it writes first (with the
client/rsh-ed process reading first).  

One solution is to fork off reading and writing children so that we
can do either.  For the client, I think that this is ok, but for the
main process, I need to keep state information consistent.  Forked
socket readers and writers would not know about what is happening
after the fork, and the main process doesn't know what is going on in
the children.  For example, a forked socket reader somehow needs to
ask the main process parent what the next iteration that should be
executed is.  

Finally, how do I communicate with the outside world (i.e. get user
input and tell him what's going on) while doing all this?  I think
that in this case, I need to fork a child of the main process that
waits for user input, but how does it know what is going on after the
fork?

Another Solution
----------------
I think that I need threads which perl does not have yet.  I would
then need to synchronize all the data (and I haven't gotten that far
in the book yet :-) but it would make more sense.

Does anyone know of an already-created tool that does this sort of
thing?  Or does someone have suggestions to answer the above problems?
I cannot imagine that this has not been solved before, probably
multiple times, but I cannot find example solutions.  Any help is
greatly appreciated.  

-- 
Clark Dorman				"Evolution is cleverer than you are."
http://cns-web.bu.edu/pub/dorman/D.html                -Francis Crick


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

Date: Tue, 13 Jan 1998 16:18:05 GMT
From: eclectic@polarnet.com (Chris Lott)
Subject: performing subroutine on a strange set of elements from array
Message-Id: <34bc92e5.564146490@news3.polarnet.com>


I have a 64 element array @foo. I want to perform a certain subroutine
on elements 1,3,5,7,10,12,14,16,17 ...

I can't easily see a logical way to do this without doing each one
separately, ie

@foo[1] = xxx
@foo[3] = xxx

Is there a way to perform a subroutine on many selected elements this
way?

c

--
Chris Lott
fncll[at]uaf[dot]edu


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

Date: 13 Jan 1998 17:24:57 +0100
From: Remove xx to reply <xxTony.Curtis@vcpc.univie.ac.at>
To: eclectic@polarnet.com
Subject: Re: performing subroutine on a strange set of elements from array
Message-Id: <7xafd0tk86.fsf@vcpc.univie.ac.at>

Re: performing subroutine on a strange set of elements from
array, Chris <eclectic@polarnet.com> said:

Chris> I have a 64 element array @foo. I want to perform a
Chris> certain subroutine on elements 1,3,5,7,10,12,14,16,17
Chris> ...

Chris> I can't easily see a logical way to do this without
Chris> doing each one separately

Chris> Is there a way to perform a subroutine on many
Chris> selected elements this way?

Yeah, use "map" or a loop of some kind over the indices.

E.g.

    @ix = ( 1,3,5,7,... );

    foreach $i (@ix) {
        do_something_to $foo[$i];
    }

hth,
tony


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

Date: Mon, 12 Jan 1998 17:14:03 -0000
From: "jim craig" <jim@webworks.co.uk>
Subject: Re: PERL & IIS 4 (final) hanging - help!!
Message-Id: <34ba500d.0@orac.idiscover.net>

I had the same problem which was remedied by appending %s %s to the the file
extension mapping, so in my case I end up with c:\perl\bin\perl.exe %s %s

I hope this solves your problem


nospam@XX.co.uk wrote in message
<884280387.6115.0.nnrp-05.9e980333@news.demon.co.uk>...
>We are running PERL (build 315) and IIS 4 (the final release).  When
>we call a simple perl script, the browser shows server contacted,
>waiting for reply, but just hangs forever.  When we look in the
>process monitor a copy of perl.exe is open.  Even after we stop the
>request this does not go away.  If you then request the perl script
>again, it hangs again, and a new copy of perl.exe (along with the
>original) is visible in process monitor.
>
>We have setup the directory containing the PERL script with script
>priveleges in the properties tab on Internet Service MMC.  We haev
>mapped the file extension to the executeable perl.exe in the
>properties sheet.   We have granted the annoymous web user execute
>priveleges for both the directory containing the script, and the
>perl.exe executable.  We have added the registery mapping recommended
>by Microsoft Knowledge Base.
>
>What is going wrong?!!
>
>Please help with this - explain how it shold be done!
>
>Many thanks in advance for your help.
>
>Please e-mail answers to richard@the-web-works.co.uk
>
>**************************************************************
>www.the-web-works.co.uk
>info@the-web-works.co.uk
>






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

Date: Tue, 13 Jan 1998 15:02:34 +0200
From: Kari Marttila <Kari.Marttila@tietogroup.com>
Subject: Perl and Oracle's PL/SQL
Message-Id: <34BB65EA.B51FB85B@tietogroup.com>

I would like to know if it is possible to embed Oracle's PL/SQL scripts
into a perl script. And if it is, how is this done?

I would appreciate a personal reply also! Thanks!

Kari.Marttila@tietogroup.com





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

Date: Tue, 13 Jan 1998 10:01:04 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
To: Lynchqvctc <lynchqvctc@aol.com>
Subject: Re: perl under windows95
Message-Id: <34BB8FC0.6F7EC31A@mail.uca.edu>

Lynchqvctc wrote:
> 
> >Subject: Re: perl under windows95
> >From: "David A. Frantz" <wizard@eznet.net>
> >Date: Sun, Jan 11, 1998 01:19 EST
> >Message-id: <34b86392.0@news.eznet.net>
> >
> >Well if your running Windows 95 why not just double click on the
> script you
> 
> This should work... if the .pl scripts are associated with perl.exe
> (this
> doesn't necessarily happen with Win95, and might have to be done
> manually).

This does not always work in Win95 (don't know about NT), because if you
are looking for output, a DOS box appears, the script runs, and the box
disappears (along with any output, error messages, etc.). Now, if you
have a 386 machine that you can seriously underclock (say, to 1 KHz),
mabye you can see the results in the DOS box before it goes away, but
that's not a solution most folks would really like ;^). Or, put in a
final line, calling for a dummy user input (which would work if the
script had no errors causing it to die before running, but is IMHO
really silly).

Open a DOS window from the taskbar (DON'T Start->Run->perl foobar.pl),
and it stays active until YOU decide to terminate it. For writing short
programs, I just keep the window active and alternate between it and
Notepad, hitting F3 to redisplay the "C:\> perl foobar.pl" w/o having to
retype in the script name each time it is modified.

BTW, with the GS port, I had to modify my autoexec.bat file manually.

Okay, others have said this more succinctly, but on another branch of
this thread. Had to get my $.02 in.

Cameron Dorey
camerond@mail.uca.edu


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

Date: Tue, 13 Jan 1998 09:13:19 -0500
From: Dan Boorstein <dboorstein@ixl.com>
To: alester@bfsec.bt.co.uk
Subject: Re: Searching for an IP address in a string
Message-Id: <34BB767F.AD68BB6C@ixl.com>

Adrian Lester wrote:
> 
> Dear all,
> 
> Could you please offer some help.  I'm trying to search a hosts file
> for an IP address.  I thought it would work when I used quotemeta, but
> it still doesn't find the IP address in the file.  I've already checked
> the file permissions before calling the sub routine.
> 
> I should get the message "Found IP Address" once, but it is never
> printed; the if test always fails.  Why?
> 
>         if ( ($safeIPAddress =~ $safeLine) and
>              ( not $doneYet )
>            )
>         {
>             print STDOUT "Found IP address\n";
>             $doneYet = 1;
>         }

the first thing i noticed was the improper attempt to match

does read:
         if ( ($safeIPAddress =~ $safeLine) and
should read:
         if ( ($safeIPAddress =~ /$safeLine/) and

hope that helps,

dan


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

Date: Tue, 13 Jan 1998 09:18:12 -0600
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
To: alester@bfsec.bt.co.uk
Subject: Re: Searching for an IP address in a string
Message-Id: <34BB85B4.DB2F8120@houston.Geco-Prakla.slb.com>

[automagically cc'ed to poster]
Adrian Lester wrote:
> 
> Dear all,
> 
> Could you please offer some help.  I'm trying to search a hosts file
> for an IP address.  I thought it would work when I used quotemeta, but
> it still doesn't find the IP address in the file.  I've already checked
> the file permissions before calling the sub routine.
> 
> I should get the message "Found IP Address" once, but it is never
> printed; the if test always fails.  Why?
> 
First, how are you calling the subroutine?  I got a strange result when
I called CheckHostsFile with CheckHostsFile("localhost",127.0.0.1);   In
the subroutine, $ipAddress ended up as "1270.1".  I don't understand,
but quoting it as "127.0.0.1" preserved the . characters.

Second:  How are you starting the script?  What are you passing the
subroutine?  What other modules are you 'use'ing?  (FileHandle,
perhaps?)


> sub CheckHostsFile
> {
>     my ($hostname, $ipAddress) = @_;
> 
>     my $hostsFile = new FileHandle "/etc/hosts";
>     my $done_yet  =0;
>     my ($safeIPAddress, $line, $safeLine);
> 
>     $safeIPAddress = quotemeta $ipAddress;
>     while (<$hostsFile>)
>     {
>         $line = $_;
>         $safeLine = quotemeta $line;
Add:
	$safeLine = quotemeta $safeLine;

See Below.
> 
>         if ( ($safeIPAddress =~ $safeLine) and
Change to:
	if (  ($safeLine =~ /$safeIPAddress/) and

See below.
>              ( not $doneYet )
>            )
>         {
Have you run this in debug mode (perl -d scriptname)?  Have you printed
out $safeLine and $safeIPAddress after this step in the execution?

Here is what I have:
  DB<8> print $safeIPAddress
127\.0\.0\.1
  DB<9> print $safeLine
127\.0\.0\.1\   localhost\      \
 
  DB<10> s

I notice several things wrong here.  Do you?

1.  Your comparison is backwards.  You will never find $safeLine in
$safeIPAddress, but you might find $safeIPAddress in $safeLine.

2.  Until you double backslash escape the "." characters in
$safeIPAddress, this will never work.  $safeLine has 127\.0\.0\.1  When
the regex engine encounters 127\. in $safeIPAddress, it gets converted
to 127.0.0.1 
(127any_one_character0any_one_character0any_one_character1) but your
line you are searching in only has 127\.0\.0\.1    localhost

3.  Make the above changes, and it should work okay.


>             print STDOUT "Found IP address\n";
>             $doneYet = 1;
>         }
>     }
> }
> 
> Adrian Lester
> alester@bfsec.bt.co.uk

-- 
"Security through obscurity is no security at all."
		-comp.lang.perl.misc newsgroup posting

------------------------------------------------------------------------
* Dave Barnett               U.S.: barnett@houston.Geco-Prakla.slb.com *
* DAPD Software Support Eng  U.K.: barnett@gatwick.Geco-Prakla.slb.com *
------------------------------------------------------------------------


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

Date: Tue, 13 Jan 1998 15:51:27 +0100
From: Matteo Boschini <boschini@cilea.it>
Subject: Re: socket help needed...
Message-Id: <34BB7F6F.531A@cilea.it>

Hi everybody, thanx for the help, but I found out, with some help, what
was wrong:
instruction was 
STDOUT->autoflush();

this gives error both on irix 5.3 and HP-UX 10.20, pelr 5.004.1

Can't locate object method "autoflush" via package "IO::Handle" at
 ./unix_server

 .......

commented out this line and everything works fine;-)
 thanx again

matteo


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

Date: Tue, 13 Jan 1998 16:34:26 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: symbolic reference in subroutine
Message-Id: <EMqE1E.Gsw@world.std.com>

ikarn@otenet.gr writes:

>I  need to creat in a subroutne a number of hashes, called
>%hash1,%hash2,%hash3 etc. 

Are you sure? In most cases, when I see people ask about symbolic
references here in comp.lang.perl.misc, they would be much better off
using an array of hashes or hash of hashes.

$hash[$element]{$key} = 'something';
or
$hash{'hash' . $element}{$key} = 'something';

Perl stores its variables (except variables created via the my()
operator) in a special hash called the symbol table. When you are
using symbolic references to create variable on the fly, you are just
using perl's symbol table as the root level of a complex data
structure. You might as well create your own.

>Then, when I access then in the main, I can
>only get the
> last one

Besides creating valid perl statements where you left things as "..."
your code ran fine.  (just a suggestion. If you are going to make up
code, you might as well make up a valid test case for others to run to
figure out your problem. Maybe some of the things you left as "..."
are where the problem lies.) Also, did you look at this code under the
debugger? The "V" command would be especially helpful. It dumps all
the variables in the symbol table. Also you could use the "x" command
to examine %hash1, %hash2, and %hash3.

This is the code I ran:

#!/usr/bin/perl
# I  need to creat in a subroutne a number of hashes, called
# %hash1,%hash2,%hash3 etc. Then, when I access then in the main, I can
# only get the
# last one, i.e.
$key = 'a';
sub formhash{
    @array=(1,2,3);
    foreach $element(@array){
	$symhash="hash".$element;
	# ....
	${$symhash}{$key}= $symhash;
    }#end of array loop
}#end of S/R formhash

# Then, the main accesses these hashes as
&formhash();
foreach $element(@array){
$symhash="hash" . $element;
# ...
print "${$symhash}{$key}\n"; }

This would be the way to do the same thing with a complex data
structure.

#!/usr/bin/perl -w

use strict;

my $key = 'a';
my %hash;
my @array=(1,2,3);

sub formhash{
    my $element;
    foreach $element(@array) {
        my $value = 'hash' . $element;
	$hash{$value}{$key}= $value;
    }
}

formhash();
my $element;
foreach $element(@array) {
   my $value = 'hash' . $element;
   print "$hash{$value}{$key}\n";
}

For more about complex data structures, see the perlref and perldsc
man pages. (The perlref page may be a bit rough on first go
through. You're probably best off reading it, absorbing what you can,
reading the perldsc man page to see references in action, then going
back to perlref again.)
-- 
Andrew Langmead


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

Date: Tue, 13 Jan 1998 09:45:29 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Testing for valid numeric values
Message-Id: <34BB7E09.1618@min.net>

Matthew Cravit wrote:
> 
> sub IsNumeric($) {
>         $_[0] =~ m/\D/ ? 0 : 1;
> }
> 
> Hope this helps.

This subroutine returns True for arguments such as
"Half-baked g0ggle-b0x d0-g00ders..."

Keep trying :-)
(And see Brian's post)

John Porter
jporter@logicon.com


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

Date: 13 Jan 1998 16:27:55 +0100
From: Marius Kjeldahl <marius@ace.funcom.com>
Subject: Tk402.003 and sfio..
Message-Id: <523eisxukk.fsf@ace.funcom.com>

I have successfully built Tk402.003 on my system, but the tests
fail. The first box (that lets you select the other Tk demos) appears,
but as soon as I selected an item, it exited with an error about not
being able to resolve a symbol. When rerunning 'make test', the last
output I get is:

make[1]: Entering directory `/usr/src/Tk402.003/pTk'
make[1]: Leaving directory `/usr/src/Tk402.003/pTk'
make[1]: Entering directory `/usr/src/Tk402.003/doc'
make[1]: Leaving directory `/usr/src/Tk402.003/doc'
/usr/bin/perl -I./blib/arch -I./blib/lib demos/widget
/usr/bin/perl: can't resolve symbol 'sfsscanf'
make: *** [test_dynamic] Error 1

I suspect this has something to do with me installing perl with sfio
(which was recommended for fastcgi development if my memory serves me
right). Since everything else works great with sfio, I am not sure why
it fails. I have looked in my sfio directory, and it seems only the .a
files are being made (I tried to look for a .so file that maybe was
put in a wrong place or something, but this does not seem to be the
problem since it seems perl is statically linked with sfio).

Does anybody know how I can make this work?

Marius

perl -V outputs:
This is perl, version 5.004_03

Copyright 1987-1997, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.

You have new mail in /var/spool/mail/marius
ace.funcom.com:/usr/src/Tk402.003$ perl -V
Summary of my perl5 (5.0 patchlevel 4 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.0.30, archname=i686-linux
    uname='linux ace.funcom.com 2.0.30 #3 wed jul 30 07:59:58 met dst 1997 i686 '
    hint=previous, useposix=true, d_sigaction=define
    bincompat3=y useperlio=define d_sfio=define
  Compiler:
    cc='cc', optimize='-O2', gccversion=2.7.2.2
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include -I/usr/src/sfio/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include -I/usr/src/sfio/include'
    stdchar='char', d_stdstdio=undef, usevfork=false
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=4, usemymalloc=n, randbits=31
  Linker and Libraries:
    ld='cc', ldflags ='-L/usr/local/lib -L/usr/src/sfio/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lndbm -lgdbm -ldb -ldl -lsfio -lm -lc
    libc=/lib/libc.so, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib -L/usr/src/sfio/lib'


Characteristics of this binary (from libperl): 
  Built under linux
  Compiled at Oct  8 1997 12:01:24
  @INC:
    /usr/lib/perl5/i686-linux/5.00403
    /usr/lib/perl5
    /usr/lib/perl5/site_perl/i686-linux
    /usr/lib/perl5/site_perl
    .


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

Date: 13 Jan 1998 16:35:59 +0100
From: Marius Kjeldahl <marius@ace.funcom.com>
Subject: Re: Tk402.003 and sfio..
Message-Id: <521zycxu74.fsf@ace.funcom.com>

Further investigation shows that it is _only_ the ./demos/widget demo
that fails to run with the message noted earlier:

perl: can't resolve symbol 'sfsscanf'

The other demos runs fine. I would still like to know why it fails
though..

Marius


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

Date: Tue, 13 Jan 1998 15:49:23 GMT
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: unlink () doesn't work under NT
Message-Id: <34bb8cf5.94042886@igate.hst.moc.com>

[original author automagically cc'd via e-mail]

On 13 Jan 1998 11:16:25 GMT, Ko Kin <ckko@cse.cuhk.edu.hk> wrote:

>Hi all,
>
>I used an unlink () statement in my Perl script running under NT 4, but 
>it doesn't seem to work.  Any advice?

What error did it issue?

Jeremy
-- 
Jeremy D. Zawodny                 jzawodn@wcnet.org
Web Server Administrator          www@wcnet.org
Wood County Free Net (Ohio)       http://www.wcnet.org/


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

Date: Tue, 13 Jan 1998 14:54:14 GMT
From: Dave.Cross@gb.swissbank.com (Dave Cross)
Subject: Re: Where do I get PERL
Message-Id: <DAVE.CROSS.98Jan13145414@ln4d110swk.gb.swissbank.com>

In article <01bd1fef$22af4ac0$1c8714d1@nwlink.com> "jch" <nospamhebert@nwlink.com> writes:

> if you are looking for perl for a winNT server go to www.activestate.com
> if you are looking for perl for a UNIX server get any book on perl and it
> will come with it.

Actually, the *definitive* books on Perl don't come with any CDs or disks.
You can get Perl from www.perl.com.

Dave...


-- 
"...but Man created all gods equal."

Dave.Cross@gb.swissbank.com


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 1628
**************************************

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