[17224] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4646 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 17 21:05:35 2000

Date: Tue, 17 Oct 2000 18: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: <971831112-v9-i4646@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 17 Oct 2000     Volume: 9 Number: 4646

Today's topics:
    Re: Accessing methods created on the fly <frank@the.real.frank.com>
    Re: Can not substitute a "\n" with a regular expression <ren.maddox@tivoli.com>
    Re: Can perl code be sandboxed? (Logan Shaw)
    Re: Can someone help with this scrip? Sytax error! <krahnj@acm.org>
    Re: CGI::Push <jlinch@mediaone.net>
    Re: Convert Text to HTML (Tramm Hudson)
    Re: converting a binary file to ascii <pauls_spam_no@pauls.seanet.com>
    Re: converting a binary file to ascii (Martien Verbruggen)
    Re: converting a binary file to ascii (Craig Berry)
    Re: converting a binary file to ascii <lr@hpl.hp.com>
    Re: converting a binary file to ascii <pauls_spam_no@pauls.seanet.com>
    Re: converting a binary file to ascii <krahnj@acm.org>
    Re: converting a binary file to ascii (Martien Verbruggen)
    Re: CPAN.pm gripe (Martien Verbruggen)
    Re: Create a copy of a variable <ianb@ot.com.au>
    Re: Help with Array <ren.maddox@tivoli.com>
        IO::File or FileHandle - which? <starfire@zipcon.net>
    Re: Is perl object oriented? (John J. Trammell)
    Re: Is perl object oriented? (Jerome O'Neil)
    Re: Is perl object oriented? (Martien Verbruggen)
        Is there a better way? whish_was_a_newbie@db-networks.com
    Re: Is there a better way? <stephenk@cc.gatech.edu>
    Re: Packing multiple strings into one string (Mark-Jason Dominus)
    Re: perl objects and methods (Logan Shaw)
        problems with open2 use in cgi mrbigsecret@my-deja.com
    Re: Save As... Popup box <anmcguire@ce.mediaone.net>
    Re: Save As... Popup box (Martien Verbruggen)
    Re: Save As... Popup box <flavell@mail.cern.ch>
    Re: space <peter.sundstrom@eds.com>
    Re: Starting Background Processes With PERL (Logan Shaw)
        Usage Monitoring nodo70@my-deja.com
    Re: Why doesn't PERL like Gunnar <ianb@ot.com.au>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 18 Oct 2000 00:20:53 GMT
From: "Frank" <frank@the.real.frank.com>
Subject: Re: Accessing methods created on the fly
Message-Id: <8siqd5$le$0@206.230.71.67>

<michaeljgardner@my-deja.com> wrote in message
news:8siaen$6t2$1@nnrp1.deja.com...
> I have a module that creates an object out of a database.  Part of the
> code in the module creates methods (closures) to access the contents of
> a particular field by it's position in the string that makes up that
> record of the database.  This code creates the subroutines.
>
> # HEADERINFO CONTAINS INFO ABOUT THE FIELDS IN THE DATABASE WHICH ARE
> # KEYED BY THE FIELD NAME
> foreach my $name (sort keys %headerinfo){
>
> # SUBROUTINE CREATED ON-THE-FLY, NAMED AFTER FIELD NAME
> # $LINE IS PASSED TO THE SUBROUTINE WITH A RAW RECORD OF DATABASE
>     *$name = *{uc $name}=sub {my($line)=shift;

Have you tried:
     *$name = *{'main::' . uc $name}=sub {my($line)=shift;

Just adding 'main::' might fix it. This defines what package namespace to
drop the new sub in.

hth,

--
$from = <$josiah>;






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

Date: 17 Oct 2000 15:58:22 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Can not substitute a "\n" with a regular expression!
Message-Id: <m3itqrp4lt.fsf@dhcp11-177.support.tivoli.com>

nospamapgraham@ispchannel.com--- (Al) writes:

> I use 
> $text =~ s/\r\n/<BR>/g;
> to catch carriage returns and newlines.
> better yet is
> $text =~ s/\015\012/<BR>/g;
> This should work for windows, *nix, and MacOS text.

Really?  I suppose that depends entirely on where the data comes
from.  If there is only a newline (Unix) or only a carriage return
(Mac), then this will *not* work.

> These lines are in use in working scripts on a Sun Solaris.

Where does the input come from such that it has carriage returns
before the line feeds?

There are many solutions to this problem that will actually work on
varying types of inputs.  Here are a few:

Solution #1:
s/\r\n/\n/g;
s/\r|\n/<br>/g;

Solution #2:
s/\r\n|\r|\n/<br>/g;

Solution #3 (assumes input is local, so $/ is correctly set):
$\="<BR>";
while(<>){
  chomp;
  print;
}

-- 
Ren Maddox
ren@tivoli.com


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

Date: 17 Oct 2000 19:24:51 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Can perl code be sandboxed?
Message-Id: <8siqkj$1fa$1@provolone.cs.utexas.edu>

In article <m366msfcst.fsf@solo.david-steuber.com>,
David Steuber  <nospam@david-steuber.com> wrote:
>Is it possible to run a Perl script in an application that has an
>embedded Perl interpreter, according to the perlembed documentation,
>in such a way that the possibility of trojan horse code is not
>executed?  Or does anything go?
>
>I ask because I am considering the possibility of using Perl as an
>extensible data file format.

While you might be able to implement something that will prevent
code in the data file from removing files, etc., how are you going
to prevent it from doing this?

	1 while 1;

Or even worse because it wastes CPU time and also causes the machine to
swap like crazy:

	1 while "x" x 100_000_000;

  - Logan


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

Date: Tue, 17 Oct 2000 16:09:01 -0700
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Can someone help with this scrip? Sytax error!
Message-Id: <39ECDC0D.11C510A4@acm.org>

Richard Morris wrote:
> 
> Sorry, Newbie here.
> 
> I have a script and when run, gives the message:
> 
> [root@qube rdm3]# perl massadd.pl list
> syntax error at massadd.pl line 31, near "= ) "
> 
> [snip]
> 
> while ($line = ) {

You are trying to assign some value to $line. Put something on the right
hand side of the equals sign.

John


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

Date: Wed, 18 Oct 2000 00:58:16 GMT
From: "Jerry Linch" <jlinch@mediaone.net>
Subject: Re: CGI::Push
Message-Id: <IA6H5.40122$oA2.8797243@typhoon.southeast.rr.com>

I'm using IE 5.50.br549 (or some such). I can use CGI::Push, but I get the
following at the top of the resulting page:

----------------------------------1621093750000000 Content-type: text/html

and this at the end of the page:

----------------------------------1621093750000000

The exact string of numbers changes each time I access the page.

These don't appear in Netscape. Given what I've seen here, I'm not overly
optimistic about this next, but: Is there a way to get rid of the extra
"header" and "footer" information in IE 5.5? For the short term, I can
safely say that the web pages have to be viewed with Netscape, but long term
may be a completely different thing...

TIA

Jerry Linch
jlinch@mediaone.net


"Jeff Zucker" <jeff@vpservices.com> wrote in message
news:39E3941A.F767C724@vpservices.com...
> Troy Rasiah wrote:
> >
> > > Internet Explorer does not support Push.
> > >
> >
> > dang..thats what i thought! hehe
> > anyone know if they plan on supporting it in the near future?
>
> I think it is the next project on their list after they complete the
> construction of www.hellfreezesover.com.
>
> --
> Jeff




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

Date: 18 Oct 2000 00:10:22 GMT
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: Convert Text to HTML
Message-Id: <8sippe$38h$1@sloth.swcp.com>

[posted and cc'd to cited author]

Ian Boreham  <ianb@ot.com.au> wrote:
> But the browser will. It is not a problem with cat. If the text file contained
> something like:
> 
> 1 < 2
> 
> 5 > 4
> 
> ...then the browser is going to try to turn < 2\n\n5 > into a tag. These
> characters and also ampersands need to be escaped.

Why do you think that?  Have you tried running it through a validator or
looking at the DTD for HTML 4.0?  There is nothing wrong with a lone
greater than or less than character, as long as they are surrounded
by white space.

For an example, please see this file and validate it for yourself.

	http://www.swcp.com/~hudson/test.html

No Perl content here.  Move along.  Followups set.

Tramm
-- 
  o   hudson@swcp.com                  hudson@turbolabs.com   O___|   
 /|\  http://www.swcp.com/~hudson/          H 505.323.38.81   /\  \_  
 <<   KC5RNF @ N5YYF.NM.AMPR.ORG            W 505.986.60.75   \ \/\_\  
  0                                                            U \_  | 


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

Date: Tue, 17 Oct 2000 15:10:38 -0700
From: Paul Spitalny <pauls_spam_no@pauls.seanet.com>
Subject: Re: converting a binary file to ascii
Message-Id: <39ECCE5D.673DD316@pauls.seanet.com>

I know that the ascii content of the file I am trying to convert looks
something like this:

Values:
 0   2.743588915081886e-006
     -2.249997454558070e-004
     0.000000000000000e+000
     -4.027310559692743e-010
     0.000000000000000e+000
     7.557832283439269e-004
     -7.585263855829361e-004
     -4.345490800893958e-010
     0.000000000000000e+000

and, by the way, I am using PERL 5.003 on NT4 sp 5.

thanks

Paul



Paul Spitalny wrote:

> Hi,
> I have a binary file, how can I convert it to ascii? I think I need to
> read in the file byte by byte but can't figure out how to do it. Any
> help appreceated!
>
> thanks
>
> Paul
>
> --
> To respond to this posting, remove -nospam- from my email address.
> Sorry for the inconvenience

--
To respond to this posting, remove -nospam- from my email address.
Sorry for the inconvenience




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

Date: Wed, 18 Oct 2000 09:20:53 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: converting a binary file to ascii
Message-Id: <slrn8upk65.294.mgjv@martien.heliotrope.home>

[For the future, please post your reply AFTER the suitably trimmed text
you reply to.]

On Tue, 17 Oct 2000 14:35:07 -0700,
	Paul Spitalny <pauls_spam_no@pauls.seanet.com> wrote:
> Hi Gang,
> Here, I try to be more specific. I have a simulation program that saves
> it's data in binary format (to save on file size). The file is some
> floating point numbers stored in binary form. The binary file is more than
> one lines worth of stuff.

First of all, you will have to work out what the format of this binary
file is. How is the data in that file ordered? You will have to read the
specification for that, or the sources of the program that generate it.

Then, you open the file, and switch the handle to binary mode. You open
the output file:

open(IN, $in_file) or die "Cannot open '$in_file': $!";
binmode(IN);
open(OUT, ">$out_file") or die "Cannot open '$out_file': $!";

(and yes, it does exist on NT. NT is one of the platforms where this is
absolutely necessary).

Next, you read the file in chunks that conform to your data structure in
the file. We can't help you there, because we don't know how that is.
You use read for that. Do not use readline or the <> operator. They are
for text files.

read IN, $buffer, $chunk_len

Then you use unpack to unpack the data from their binary format to an
internal representation. Suppose you just read 4 short integers in network
order from the stream:

my @ints = unpack "4n", $buffer;

You can almost always easily translate any binary stream produced by a C
program (for example) into pack/unpack templates. Read the relevant
documentation for more info.

# perldoc -f pack
# perldoc -f unpack

Again, we can't help you here, because we don't know the format of the
data.

Then, print them out in a suitable text format. You will have to define
that yourself.

print "@ints\n";

When you've processed the data you need, don't forget to be a nice
person and close the file handles:

close(IN);
close(OUT) or die "Couldn't close OUT: $!";

> The result of the print statement is binary hierogliphics! What is it that
> I am failing to do? I have this idea that I need to go through the file

You're reading in text mode. It's a binary file, as you say yourself.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | You can't have everything, where
Commercial Dynamics Pty. Ltd.   | would you put it?
NSW, Australia                  | 


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

Date: Tue, 17 Oct 2000 22:40:21 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: converting a binary file to ascii
Message-Id: <suplaliq89r47f@corp.supernews.com>

Paul Spitalny (pauls_spam_no@pauls.seanet.com) wrote:
: Here, I try to be more specific. I have a simulation program that saves
: it's data in binary format (to save on file size). The file is some
: floating point numbers stored in binary form. The binary file is more than
: one lines worth of stuff.

If the data is stored internally as floating-point numbers, I doubt
"lines" are actually being used.  More likely it's a fixed-record-length
scheme.

: open(NEW,'<bin_only.dat');
: open(OUT,'>thebin.dat');

Never ever ever ever ever do open without checking its success.

: binmode NEW;
: while ($_=<NEW>)

Equivalent to "while (<NEW>)" in the latest perls; inferior in earlier
ones.

:         {
:         $line = $_;
:         print OUT "line is $line\n";

Why not skip the assignment, and just print "line is $_\n"?

: The result of the print statement is binary hierogliphics!

Of course it is; you're not transforming the data at any point, after all.

: What is it that I am failing to do?

If you're lucky enough that the file's floating point values are stored in
the perl format, then see 'perldoc -f unpack'.

: I have this idea that I need to go through the file
: byte by byte and assemble the floating point numbers.

You'll only have to do this if the floats aren't in the standard format.
However, be sure that you know the precise layout of data; floats vs.
doubles, for example.

: Most of the work
: with files that I've done addresses a file line by line. This time, it's
: byte by byte (At least I think it should be).

If I'm right in my guess that this is a fixed record length format file,
you'll want to use read() rather than <>.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Quidquid latine dictum sit, altum viditur."
   |


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

Date: Tue, 17 Oct 2000 16:00:30 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: converting a binary file to ascii
Message-Id: <MPG.145679ec959c76ce98ae41@nntp.hpl.hp.com>

In article <slrn8upk65.294.mgjv@martien.heliotrope.home> on Wed, 18 Oct 
2000 09:20:53 +1100, Martien Verbruggen <mgjv@tradingpost.com.au> 
says...

 ...

> Then you use unpack to unpack the data from their binary format to an
> internal representation. Suppose you just read 4 short integers in network
> order from the stream:
> 
> my @ints = unpack "4n", $buffer;

ITYM 'n4'.

> You can almost always easily translate any binary stream produced by a C
> program (for example) into pack/unpack templates. Read the relevant
> documentation for more info.
> 
> # perldoc -f pack

  ...

  Each letter may optionally be followed by a number giving a repeat
  count. With all types except a, A, Z, b, B, h, H, and P the pack
  function will gobble up that many values from the LIST. 

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 17 Oct 2000 16:34:35 -0700
From: Paul Spitalny <pauls_spam_no@pauls.seanet.com>
Subject: Re: converting a binary file to ascii
Message-Id: <39ECE20B.437EB4BC@pauls.seanet.com>

I have almost got this to work. It appears though that the data I have
uses a UNIX endian-"ness" that is not the same as the endian-ness of my
NT machine. Yipes, now what??

in the left column is what the number should be, in the right column is
the output from my program:

  2.743588915081886e-006        2.74358891508189e-006
 -2.249997454558070e-004        -0.000224999745455807
 0.000000000000000e+000        0
 -4.027310559692743e-010        -4.02731055969274e-010
 0.000000000000000e+000        0
 7.557832283439269e-004        0.000755783228343927
 -7.585263855829361e-004        -0.000758526385582936
 -4.345490800893958e-010        -4.34549080089396e-010
 0.000000000000000e+000        0
 0.000000000000000e+000        0
 2.249997454558070e+000        2.24999745455807
 2.250000000000000e+000        2.25
 2.249998727279035e+000        2.24999872727903
 3.264767994870773e+000        2.95908505230826e-260

See how the last number on the right column is screwed-up, but
everything before that looks fine?? What gives?? Here's how I did it,
perhaps you folks can find the error in my ways (I know, I know, i
didn't check if the file exists before opening it)

open(NEW,'<bin_only.dat');
open(OUT,'>thebin.dat');
binmode NEW;
$index = 0;
while (read(NEW,$in,8))
 {
 $index++;
 $foo = unpack("d",$in);
 print OUT "$foo\n";
 }
close(NEW);
close(OUT);

Thanks to everyone who has helped so far!

Paul


--
To respond to this posting, remove -nospam- from my email address.
Sorry for the inconvenience




Paul Spitalny wrote:

> Hi,
> I have a binary file, how can I convert it to ascii? I think I need to
> read in the file byte by byte but can't figure out how to do it. Any
> help appreceated!
>
> thanks
>
> Paul
>
> --
> To respond to this posting, remove -nospam- from my email address.
> Sorry for the inconvenience

--
To respond to this posting, remove -nospam- from my email address.
Sorry for the inconvenience




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

Date: Tue, 17 Oct 2000 17:34:47 -0700
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: converting a binary file to ascii
Message-Id: <39ECF027.AE679F66@acm.org>

Paul Spitalny wrote:
> 
> I have almost got this to work. It appears though that the data I have
> uses a UNIX endian-"ness" that is not the same as the endian-ness of my
> NT machine. Yipes, now what??
> 

First, endian-ness is related to the CPU not the operating system. :-)
Second, if the endianess of the data was different then none of the
answers would have been correct.
It could be that the data uses other floating point formats - the IEEE
defines 32 bit, 64 bit and 80 bit formats - also some compiler vendors
created their own formats.

John


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

Date: Wed, 18 Oct 2000 11:53:44 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: converting a binary file to ascii
Message-Id: <slrn8upt4o.294.mgjv@martien.heliotrope.home>

On Tue, 17 Oct 2000 16:00:30 -0700,
	Larry Rosler <lr@hpl.hp.com> wrote:
> In article <slrn8upk65.294.mgjv@martien.heliotrope.home> on Wed, 18 Oct 
> 2000 09:20:53 +1100, Martien Verbruggen <mgjv@tradingpost.com.au> 
> says...
> 
> ...
> 
> > Then you use unpack to unpack the data from their binary format to an
> > internal representation. Suppose you just read 4 short integers in network
> > order from the stream:
> > 
> > my @ints = unpack "4n", $buffer;
> 
> ITYM 'n4'.

oops. That is what I meant.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In the fight between you and the
Commercial Dynamics Pty. Ltd.   | world, back the world - Franz Kafka
NSW, Australia                  | 


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

Date: Wed, 18 Oct 2000 09:52:02 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: CPAN.pm gripe
Message-Id: <slrn8upm0i.294.mgjv@martien.heliotrope.home>

On Tue, 17 Oct 2000 14:48:42 GMT,
	David Steuber <nospam@david-steuber.com> wrote:
> This is just a rant.  If you don't like rants, please skip to the next
> thread.
> 
> I find cpan (which does "perl -MCPAN -e shell") to be an incredibly
> useful tool for installing modules.  It may be a bit dangerous to run
> it as root, but that is what I do.  I suppose I could chown the Perl
> tree to a user and run cpan that way.  Maybe that would be a better
> and wiser thing to do.

That's what I do. Or actually, I chgrp the tree to the group perl, or
admin, depending on where I am, and set permissions for group write.
That way I can keep track more easily of who installed what.

> Some modules do not work with CPAN.pm.  One module that I wanted the
> other day, PDL (complete with TriD and OpenGLQ), would not install
> with CPAN.  I was finally able to get it by fetching it the old
> fashioned way with FTP.  I then found that there was a Perl file I had
> to edit to allow it to build.  It did not use the ./configure, make,
> make test, make install mantra.

you mean 

# perl Makefile.PL
# make
# make test
# make install

right? :)

You normally don't have to resort to manual FTP and stuff like that. If

cpan> install Module

fails, you simply do 

cpan> look Module

and you end up in the directory that the CPAN module uses to do the
build. You can then do it manually from there.

Not all modules CAN be installed without interference. One that I know
of is DBD::Sybase, which needs a database configuration file to know
what to run the tests against. Some others need to be told how exactly
libraries that they rely on were compiled. Most of the time,
requirements like that are mentioned in the README file.

cpan> readme Module

I find it hardly ever a real problem when modules don't install. It's a
small effort to jump out of the cpan> prompt temporarily, and do it the
old-fashioned way. In fact, I find myself doing that often enough
anyway.

> I guess my gripe isn't with CPAN.pm, its with module authors who
> deviate from the norm.  I guess I really have no right to complain

There isn't always a choice. And the ExtUtils::MakeMaker stuff works
well enough for many things, but is not always the best way of doing
things.

> about free and usefull software.  After all, jumping through these
> hoops encouraged me to get fftw (World's Fastest Fourier Transform)
> installed.  (Hey, I may write my own DSP software one day.)
> 
> cpan> install module
> 
> is a wonderful thing when it works.  When it doesn't, I get this pain
> right behind my eyes.

I hope that my suggestions will be able to alleviate that pain a bit,
and that you didn't already know about them

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd.   | Then things get worse.
NSW, Australia                  | 


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

Date: Wed, 18 Oct 2000 09:42:25 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: Create a copy of a variable
Message-Id: <39ECD5D0.FBB5654D@ot.com.au>

Ren Maddox wrote:

> Daniel Jones <ddjones@speakeasy.org> writes:
>
> > This syntax:
> >
> > ${@$Instructors}[$i]
> >
> > was a bit tricky, but I got it.
>
> Try this syntax instead:
>
> $Instructors->[$i]

I agree completely, especially as you can use the same syntax no matter
what type of reference it is, and it's so much easier to get right every
time. Just as a comment on the original post, you should have been able
to just write:

  $$Instructors[$i]

to get the same results, although the "->" is better.

Regards,


Ian




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

Date: 17 Oct 2000 15:46:19 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Help with Array
Message-Id: <m3n1g3p55w.fsf@dhcp11-177.support.tivoli.com>

webbgroup@my-deja.com writes:

> I am writing a script that is bringing in raw data( an IP address and a
> hostname) in a file. The file has the IP and hostnames separated by one
> space
> 127.0.0.1 localhost
> 
> I am trying to writing the script that will call that file and go down
> the list line by line and execute like a ping command to see if it is
> up.
> 
> This is what I have so far. I am having trouble calling the names from
> the file and executing the command

You never actually say what the problem is, which just makes it that
much more difficult to help.  In this case, the problem is pretty easy
to spot, but often it helps to tell us what happens when you try it.

> # Get the host file and change it
> open(FILE, "newhosts.txt") || die("Host file not found!\n");
> @mine=<FILE>;

This reads the entire file in to @mine, with each line assigned to one
element of the array.  Also, you probably want to strip the newlines
with chomp.  This can be done at the same time the file is read via:

  chomp(@mine=<FILE>);

On the other hand, using a literal space as the first argument to
split (see below) makes this unnecessary.

> close(FILE,"newhosts.txt");

close only takes filehandles as arguments, so this should simply be:

  close FILE;
> 
> # process the file
> foreach $line(@mine)
>         {
>         print $line;
>         # Change the newhosts.txt file and put them into variables
>         $arg1=$mine[0];

This sets $arg1 to the first line of the file...

>         $arg2=$mine[1];

and $arg2 to the second.

I believe you want something like:

          ($arg1, $arg2) = split " ", $line;

>         # I figure that if I can get the printout working,
>         # I will be able to get it to execute the ping command.
>         print "The IP address is: $arg1 Hostname: $arg2 \n";         }
> 
> 
> Any suggestions??

Scott Searle already posted a better version, but there are a couple
changes I wanted to suggest:

"Scott Searle" <ssearle at maplesoft> writes:

> open(FILE, "hosts.txt") || die "dead";

Always include $! in such die statements:

  open FILE, "hosts.txt" or die "Could not open hosts.txt, $!";

> while(<FILE>) {
>     my ($host, $ip) = split;

Not a big deal, but the specified format has this reversed:

      my ($ip, $host) = split;

>     print("IP of $host is $ip\n");
> }
> close(FILE);

-- 
Ren Maddox
ren@tivoli.com


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

Date: 17 Oct 2000 17:03:45 -0700
From: starfire <starfire@zipcon.net>
Subject: IO::File or FileHandle - which?
Message-Id: <971826983.289853@news.zipcon.net>

I need to manipulate a filehandle, and either the IO::File or the FileHandle
modules will do what I want.  Which one should I use?  I'm developing on Perl
version 5.005_03, but want maximum backwards and forwards compatibility.  
Optimizing portability would be good, too.

perldoc IO::File says "Derived from FileHandle.pm by Graham Barr", whereas
perldoc FileHandle says "... since FileHandle is descended from IO::File".
Fess up, guys!

Richard Anderson
Raycosoft


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

Date: 17 Oct 2000 22:25:58 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Is perl object oriented?
Message-Id: <slrn8uoq4d.895.trammell@nitz.hep.umn.edu>

On Tue, 17 Oct 2000 14:50:52 -0700, John Golubenko <java@dashmail.net>
wrote: 

>First before you try to fool someone....
>do you know Java? Did you wrote any application in Java?
>You opinion is simply based in other's opinion, and you have no
>idea what OOP means. And it's absolutely dosnt mean you have to hate
>other languages, because you are using Perl.
>So, keep your opinions for yourself.

Sir, we all bow before your insightful analysis of Perl's OO
capacities.  Please sit, sir.  Yes, right there, next to
G*******!.  That noise?  That's the sound of a thousand AHBOU
submissions.  Don't worry your little head about that.

-- 
John J. Trammell
johntrammell@yahoo.com


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

Date: Tue, 17 Oct 2000 22:27:34 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Is perl object oriented?
Message-Id: <qn4H5.741$h77.324957@news.uswest.net>

John Golubenko <java@dashmail.net> elucidates:
> First before you try to fool someone....
> do you know Java? Did you wrote any application in Java?

Yep.  And I cant figure out why I can't call methods
on int, float, char or any other primitive.

Now why is that?



-- 
"Civilization rests on two things: the discovery that fermentation 
produces alcohol, and the voluntary ability to inhibit defecation.  
And I put it to you, where would this splendid civilization be without 
both?" --Robertson Davies "The Rebel Angels" 


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

Date: Wed, 18 Oct 2000 10:14:57 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Is perl object oriented?
Message-Id: <slrn8upnbh.294.mgjv@martien.heliotrope.home>

[Please, in the future, put your reply AFTER the suitably trimmed down
text you reply to]

On Tue, 17 Oct 2000 14:50:52 -0700,
	John Golubenko <java@dashmail.net> wrote:
[reordered post]
> "Randal L. Schwartz" wrote:
> 
> > >>>>> "nobull" == nobull  <nobull@mail.com> writes:
> >
> > nobull> "Mark" <mark@mediamasters.net> writes:
> > >> Is perl a object oriented language?
> >
> > nobull> No, not like Java or Smalltalk, but like many languages it has some
> > nobull> facilities to allow an object oriented programming approach.
> >
> > Perl *is* pseudo-OO like Java, but not pure OO like Smalltalk.
> >
> > Please keep the categories straight.  Didn't you get the handout? :)
> >
> > nobull> perldoc perltoot
> >
> > and perldoc perlboot, for a gentler introduction.
> 
> First before you try to fool someone....
> do you know Java? Did you wrote any application in Java?
> You opinion is simply based in other's opinion, and you have no
> idea what OOP means. And it's absolutely dosnt mean you have to hate
> other languages, because you are using Perl.
> So, keep your opinions for yourself.

Euhmmm... What's your problem? Randal didn't say anywhere that he hated
Java. Especially not in relation to Perl. If anything, he put Java and
Perl on the same level, as pseudo-OO languages.

Why are you getting so defensive about this anyway? And what are
you getting defensive about? Java is pseudo-OO. It's slightly more OO
than Perl, but that makes no difference.

I really don't get what your problem is. categorisations like these
don't mean a thing about a language's usability. They don't say anything
about how much one likes or dislikes a language. 

Did you forget to take your Prozac or something?

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Think of the average person. Half of
Commercial Dynamics Pty. Ltd.   | the people out there are dumber.
NSW, Australia                  | 


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

Date: Tue, 17 Oct 2000 22:49:15 GMT
From: whish_was_a_newbie@db-networks.com
Subject: Is there a better way?
Message-Id: <eqlpuskf5htipkckgrhmldeaef236hs63c@4ax.com>

I have some text file in descending order. I need to extract the top
25 lines as unique.

I have tried a hash with:
 ...
%seen = ();
@toprint = grep { ! $seen{$_} ++ } @asked; 

but it sometimes looses the descending order.

Here is the code that I use:
 ...
$i = 0;
while(<INFILE>) {
    $i++;
    if ($i > 25)) {
        last;
    }
    @data = split(",",$_);
    $data[1] =~ s/\W+$//g;
    $data[1] =~ s/\"//g;
    ## this is where the make it unique starts
    $duplicate = 0;
    foreach $item(@asked) {
        if (uc($data[1]) eq uc($item)) {
            $duplicate = 1;
        }
    }
    if ($duplicate == 0) {
        push(@asked, $data[1]);
    }
}
 ....
Then I print....

Thanks



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

Date: Tue, 17 Oct 2000 19:27:40 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: Is there a better way?
Message-Id: <39ECE06C.78B8E6A6@cc.gatech.edu>

whish_was_a_newbie@db-networks.com wrote:

> I have some text file in descending order. I need to extract the top
> 25 lines as unique.
>
> I have tried a hash with:
> ...
> %seen = ();
> @toprint = grep { ! $seen{$_} ++ } @asked;
>
> but it sometimes looses the descending order.
>
> Here is the code that I use:
> ...
> $i = 0;
> while(<INFILE>) {
>     $i++;
>     if ($i > 25)) {
>         last;
>     }
>     @data = split(",",$_);
>     $data[1] =~ s/\W+$//g;
>     $data[1] =~ s/\"//g;
>     ## this is where the make it unique starts
>     $duplicate = 0;
>     foreach $item(@asked) {
>         if (uc($data[1]) eq uc($item)) {
>             $duplicate = 1;
>         }
>     }
>     if ($duplicate == 0) {
>         push(@asked, $data[1]);
>     }
> }
> ....
> Then I print....
>
> Thanks

You were right the first time around wrt using a hash.
Why not do something like:
%seen=@asked=();
while(<INFILE>) {
  $data = (split /,/)[1];
  $data=~s/"|W+$//g;
  next if $seen{uc $data};  #check for duplicates
  $seen{uc $data} = 1;
  push @asked,$data;
  last if @asked >= 25;
}
The first 25 unique items are now in @asked, in the order they appeared
in the file.

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: Tue, 17 Oct 2000 22:33:12 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Packing multiple strings into one string
Message-Id: <39ecd3a8.2e06$81@news.op.net>

In article <7xr95gkwtw.fsf@ruckus.brouhaha.com>,
Paul Rubin  <phr-n2000@nightsong.com> wrote:
>> >But I don't see any way to do the unpacking that's not a lot clumsier
>> >(since the BER-compressed lengths are themselves of variable length).
>> 
>> Oh, the unpacking works fine.  The whole point of BER is that the
>> final byte is explicitly marked.
>
>Yes, of course it works fine, it's just clumsy to implement in Perl,
>since you either have to do the BER-decoding in perl or else use
>unpack to pick off the BER number, then compute the length of the BER
>number either by repacking or by arithmetic, then skip over that many
>bytes.


Huh?  You just use 

        unpack "w/A*", $packed;

exactly like using pack(), only in reverse.


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

Date: 17 Oct 2000 18:42:30 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: perl objects and methods
Message-Id: <8sio56$1a3$1@provolone.cs.utexas.edu>

In article <Pine.GSO.4.21.0010160924080.25707-100000@crusoe.crusoe.net>,
Jeff Pinyan  <japhy@pobox.com> wrote:
>As of Perl 5.6, you can make subroutines lvalues -- which means they can
>be assigned to.
>
>  package Foo;
>  sub id :lvalue {
>    return $_[0]{id};
>  }
>
>  package main;
>  bless $obj, 'Foo';
>  $obj->id = 100;
>  print $obj->id;  # 100

This doesn't seem to actually work for me.  For one, thing, if I run
the code as posted, I get a "Can't bless non-reference value" error,
but I fix that by adding "$obj = {};" immediately before the bless.
Still, it doesn't seem to actually modify the object.

After seeing the original post in this thread, I monkeyed around with
it quite a bit and found that I couldn't get subroutine lvalues to work
if what I was returning was a member of a hash rather than a plain old
scalar.  The manual page is vague about this, but it seems like it's
only supported with scalars.

That's why I suggested in another post that it doesn't seem like
it's possible without doing something really, really ugly.

You could make your object a scalar, and that might work, but most
people want to store more than just a scalar per object, so you'd have
to make your object somehow refer to a number of external scalars.

However, even that doesn't seem to work.  It seems like this would
print "13", but it prints "0":

	#! /usr/local/bin/perl

	package foo;

	sub new
		{
		my $class = shift;

		my $self = {};
		bless $self, $class;
		return $self;
		}

	sub id : lvalue
		{
		my $self = shift;
		my ($newvalue) = @_;

		if (defined $newvalue)
			{
			${$self->{id}} = $newvalue;
			}
		else
			{
			return ${$self->{id}};
			}
		}

	package main;

	$x = new foo;

	$x->id(0);
	$x->id = 13;
	print $x->id, "\n";

So instead, you might try storing all the attributes in real package
variables, like this:

	#! /usr/local/bin/perl

	package foo;

	sub new
		{
		my $class = shift;

		my $self = {};
		bless $self, $class;
		return $self;
		}

	sub new_variable_name
		{
		$name = 'a' if not defined $name;

		return "_john_doe_" . $name++;
		}

	sub id : lvalue
		{
		my $self = shift;
		my ($newvalue) = @_;

		if (not exists $self->{id})
			{
			$self->{id} = new_variable_name;
			}

		if (defined $newvalue)
			{
			${$self->{id}} = $newvalue;
			}
		else
			{
			eval "return \$$self->{id}";
			}
		}

	package main;

	$x = new foo;

	$x->id(0);
	$x->id = 13;
	print $x->id, "\n";

But somehow, even that doesn't work, which is odd since I expected it
to.  (Maybe the lvalue variables have to be lexicals rather than
globals or something.)

  - Logan


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

Date: Wed, 18 Oct 2000 00:21:25 GMT
From: mrbigsecret@my-deja.com
Subject: problems with open2 use in cgi
Message-Id: <8siqdv$ks6$1@nnrp1.deja.com>

I've got a cgi script using open2 and it works
fine on the command line, but when used via a
browser seems to call itself and start over once
it hits the open2 call. I'll get any printed
statements down to the open2 call, then the same
statements again, followed by the rest of the
script's output. I've duplicated all of the
environment variables in my shell and still get
the same results. Below is a simple example that
doesn't work. Anyone know what's up? I've looked
around, but not seen a lot of info about this.
Thanks for any ideas.

#!/usr/bin/perl
use IPC::Open2;
print "Content-type: text/html\n\n";
print "BEGINNING OF HTML DOCUMENT<br>\n";
my $pid = open2(\*PWR, \*PWW, 'cat') || die "Can't
open $pwprog: $!\n";
print PWW "Hello, world.\n";
print PWW "How are you?\n";
print PWW "I am fine.\n";
close(PWW);
while (<PWR>){
   chop;
   print "D: ", $_, "<br>\n";
}
close(PWR);
print "-> waitpid<br>\n";
waitpid($pid, 0);
print "waitpid -><br>\n";


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


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

Date: Tue, 17 Oct 2000 17:01:53 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: Save As... Popup box
Message-Id: <Pine.LNX.4.21.0010171638200.26267-100000@hawk.ce.mediaone.net>

On Tue, 17 Oct 2000, Rob Donovan quoth:

RD> Thanks for the people who actually said something worth reading, I now have
RD> the answer.

But how many people did you have to bother to get it?  Any answer
greater than 0 is too many.

RD> To the other people who just seem to bitch...
RD> 
RD> I'm so sorry for posting the question in 'maybe' the wrong group.

There is no 'maybe'.  HTML and CGI do not equate to Perl.

RD> I thought that perl might be able to do something about my problem. Just
RD> because I did not understand that it was not perl and actually the browser
RD> should not be a problem.

Ah, but it is.  You would not go to say, a fast-food restaurant, and
order fettuchini alfredo, would you?  If you did, can you imagine the
look on the face of the person taking your order?  More than likely
he would point you toward more appropriate dining facilities, and
depending on how demanding you were, he may do so in a disgruntled
manner.

RD> Isn't this the place to learn things?????

Yes, where things equates to Perl.  However, the purpose of the NG
is more than just "to learn things", it is also a place of discussion.

RD> It certainly is not very friendly!!!!

Well, when you come to a newsgroup, you are expected to follow the customs
of the newsgroup.  This means:

1. formatting your post in the proper manner.
2. doing the prerequisite lurking.
3. doing your own research before posting your questions.
4. making a sincere attempt to stay on-topic.
5. testing code before posting it.
6. making a sincere attempt to remain calm and polite.

among other things.  Even the most experience posters ocassionally fall
prey to one or more items listed above ( and that list is by no means
all-inclusive ).   Remember, every comment, tidbit of advice, lecture,
correction, etc, that you get here is gratis.  Nobody here is required
to help you, or anyone else.  If you expect help here, the least you
can do is play by the rules.

RD> Life an't that long, relax guys.

Indeed. :-) Take Care!

[ snip upside down quoted text ]

anm
-- 
$ # = "%.6g" ; stat $0 or die $! ;
_ = q.Just another Perl Hacker.  ;
print $ #                        ;
main'_ . v10                     ;



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

Date: Wed, 18 Oct 2000 09:07:27 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Save As... Popup box
Message-Id: <slrn8upjcv.294.mgjv@martien.heliotrope.home>

On Tue, 17 Oct 2000 20:51:11 +0200,
	Rob Donovan <rob@robdon.com> wrote:
> Thanks for the people who actually said something worth reading, I now have
> the answer.
> 
> To the other people who just seem to bitch...

Did you even READ what I posted? About what the reasons for all this
so-called bitching are?

Seems not.  Or you're simply an arsehole.

Well, I certainly won't see any more of your posts.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd.   | bundled with your Microsoft product.
NSW, Australia                  | 


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

Date: Wed, 18 Oct 2000 01:28:20 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Save As... Popup box
Message-Id: <Pine.GHP.4.21.0010180122240.7053-100000@hpplus03.cern.ch>

On Tue, 17 Oct 2000, Rob Donovan wrote:

> Thanks for the people who actually said something worth reading, I now have
> the answer.

My scorefile is feeling hungry.

> To the other people who just seem to bitch...

My score file just knows that a new entry is ready and waiting.

> I'm so sorry for posting the question in 'maybe' the wrong group.

Liar.  You are angry that you got told that you were certainly posting
on the wrong group.  And that tells us that you're not interested in
learning, so any further response will be futile.

> Isn't this the place to learn things?????

Yes and no.  It's not the place to learn how usenet is organised, or
how to solve WWW problems.

> It certainly is not very friendly!!!!

I've always found the denizens approachable, and ready to go out of
their way in a good cause.

> Life an't that long, relax guys.

Yes, thank you, we do.  Happily, without you.

Oh, and an uypside-down quoter to boot.  Well, if there had been any
doubt, you just removed it.




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

Date: Wed, 18 Oct 2000 11:03:53 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: space
Message-Id: <8siij3$of1$1@hermes.nz.eds.com>


default <default@att.com> wrote in message news:39EC3EB4.C097F7A7@att.com...
> How much space will 5.6.0 take up on a unix box?

Under Solaris 7, it takes around 13-14Mb.




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

Date: 17 Oct 2000 19:10:58 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Starting Background Processes With PERL
Message-Id: <8sipqi$1ed$1@provolone.cs.utexas.edu>

In article <8sfhak$s16$1@nnrp1.deja.com>,  <hankahn2@my-deja.com> wrote:
>I have a script that I want to spawn off other
>perl scripts.  I don't care if they ever come
>back I just want them to start.  These jobs will
>take a long time to complete so I want the perl
>script to keep on going after it starts the
>process.

"perldoc -f fork".

  - Logan


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

Date: Tue, 17 Oct 2000 22:02:12 GMT
From: nodo70@my-deja.com
Subject: Usage Monitoring
Message-Id: <8sii8u$e2p$1@nnrp1.deja.com>

I am trying to develope a usage monitoring tool that is a need to have
a network base tool to monitor the usage of a series of NT and Unix
based machine and report the results.

 1) Non-intrusive (light weight on the network and on the machine it
self)
 2) Preferably web based.
 3) The tool converts raw information to meaningful data that can be
easily read.
 4) Anyone can execute one of couple of series of steps to get the
information.
 6) One should be able to store the information for different
representations. week/month/year

Anyone can help where is good to start or where I can get resource?
Your help would be appreciate it.


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


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

Date: Wed, 18 Oct 2000 10:13:16 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: Why doesn't PERL like Gunnar
Message-Id: <39ECDD0C.932862E7@ot.com.au>

Peter Prinz wrote:

> If the problem is caused by the fact that '\G' is a special caracter for
> regular expressions,
> how can I match the string "\\Gunnar" ??

Yes,

It means anchor the match where the last /g match finished, i.e. at the
start of the string, in this case. Rafael mentioned "quotemeta" in his
post. There is an in-string version of that, "\Q", that switches off
metacharacter parsing within the pattern, until a "\E" is encountered.

Regards,


Ian




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

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


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