[17309] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4731 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 26 11:05:32 2000

Date: Thu, 26 Oct 2000 08:05:15 -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: <972572715-v9-i4731@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 26 Oct 2000     Volume: 9 Number: 4731

Today's topics:
    Re: [Q] Newbie question <news@emkel.co.za>
    Re: ActivePerl under Windoze 98 schnurmann@my-deja.com
    Re: ActivePerl under Windoze 98 schnurmann@my-deja.com
        can hex crash my script? <xerxes_2k@my-deja.com>
    Re: can hex crash my script? <godzilla@stomp.stomp.tokyo>
    Re: complex (for me anyway) rexexp <ren.maddox@tivoli.com>
        concatenation txt files in one file lrako@hotmail.com
    Re: easy data type/pointer problem (i think!) <abe@ztreet.demon.nl>
        emulating flock <themoriman@ntlworld.com>
    Re: emulating flock (Randal L. Schwartz)
        Godzilla... can you lend an ear? webbgroup@my-deja.com
    Re: HELP -- ioctl.ph not workinking? <phil_xxx@my-deja.com>
    Re: Help with array concatenation <dlorre@caramail.com>
        Hey guys... can you lend an ear? webbgroup@my-deja.com
    Re: Hey guys... can you lend an ear? <godzilla@stomp.stomp.tokyo>
    Re: Hey guys... can you lend an ear? (Tad McClellan)
    Re: Hey guys... can you lend an ear? (Tad McClellan)
    Re: Hey guys... can you lend an ear? <brondsem@my-deja.com>
    Re: Hey guys... can you lend an ear? <brondsem@my-deja.com>
    Re: Hey guys... can you lend an ear? (Garry Williams)
    Re: Hey guys... can you lend an ear? <mjcarman@home.com>
    Re: Hey guys... can you lend an ear? <godzilla@stomp.stomp.tokyo>
    Re: Hey guys... can you lend an ear? (Tom Christiansen)
        Hilfe zu Penguin <Buntaro@gmx.de>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 26 Oct 2000 16:40:09 +0200
From: "Peter Gibbs" <news@emkel.co.za>
Subject: Re: [Q] Newbie question
Message-Id: <39f842df$0$235@helios.is.co.za>

"bh" <bh_ent@my-deja.com> wrote in message
news:8t7dji$sta$1@nnrp1.deja.com...
>
> The hash is made up of logins (the keys) and UIDs (the values) from
> multiple passwd files.  Foreach key, I'd like to search the hash to
> determine if 1) login is always associated with the same UID throughout
> the hash and 2) if not, remove that login (and UID) to a different hash.
> I'd then like to perform the same search for the UIDs.  Foreach value,
> I'd like to determine if 1) UID is always associated with the same
> login throughout the hash and 2) if not, remove that UID (and login) to
> a different hash.

Drew

A quick sample to hopefully get you on your way. This code creates nested
hashes for good and bad logins, each in two versions, keyed by uid/login and
login/uid. As each line is read, it is stored in the good hashes unless the
uid or login has already been flagged as bad, or the uid/login conflicts
with the data already processed. In the latter case, the previously 'good'
data is also reclassified as 'bad'. I'm sure this code is not optimal, but
it should serve to give you some ideas.

#!/usr/bin/perl -w
use strict;

my @HOSTS = qw(a b c);
my %good_uid = ();
my %good_login = ();
my %bad_uid = ();
my %bad_login = ();

read_passwd();

sub read_passwd {
  foreach my $server (@HOSTS) {
    open(PASSWD,"/tmp/passwd.$server")
    || die "Cannot open passwd files: $!";
    while (<PASSWD>) {
      my ($login, $uid) = (split /:/)[0,2];
      if ((exists $bad_uid{$uid} or exists $bad_login{$login})
       or (exists $good_uid{$uid} and not exists $good_uid{$uid}{$login})
       or (exists $good_login{$login} and not exists
$good_login{$login}{$uid})) {
        $bad_uid{$uid}{$login} = 1;
        $bad_login{$login}{$uid} = 1;
        delete $good_uid{$uid};
        delete $good_login{$login};
      }
      else {
        $good_uid{$uid}{$login} = 1;
        $good_login{$login}{$uid} = 1;
      }
    }
    close(PASSWD) || die "Cannot close passwd files: $!";
  }
}






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

Date: Thu, 26 Oct 2000 13:06:18 GMT
From: schnurmann@my-deja.com
Subject: Re: ActivePerl under Windoze 98
Message-Id: <8t9a85$ci3$1@nnrp1.deja.com>

Well, we can start here: DBI-1.14.

In article <39F81851.CD3436E@patriot.net>,
  H C <carvdawg@patriot.net> wrote:
> It might help if you could tell us which modules, specifically, you're
> having
> trouble with.  Without that info, most of the answers may be just
> speculation...
>
> schnurmann@my-deja.com wrote:
>
> > For some reason, when I try to install perl modules via ppm, it
can't
> > find them.
> >
> > If I download them, unzip/untar and then run perl Makefile.PL,
Windoze9
> > then complains that the programme performed an illegal
instruction.  I
> > then have to reboot.  Anyone seen this before?  Is this a windoze 98
> > problem?  I am running ActivePerl 5.6.0, build 618.
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
> --
> Q: Why is Batman better than Bill Gates?
> A: Batman was able to beat the Penguin.
>
>


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


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

Date: Thu, 26 Oct 2000 13:05:24 GMT
From: schnurmann@my-deja.com
Subject: Re: ActivePerl under Windoze 98
Message-Id: <8t9a6f$che$1@nnrp1.deja.com>

My Windoze 98 machine cannot use ppm to install, but another NT machine
around here, running the same version of ActivePerl can.  i think it is
related to my being on Darwin, but I am not sure.

I know how to run through installing with nmake, but on some modules,
doing perl Makefile.PL causes an illegal instruction error.

as to the double posting, that is my fault.  Right after I hit send I
realized I forgot some info.  I hit stop to add it, but I guess I
wasn't fast enough.

In article <BFNJ5.25177$rD3.1693432@newsread2.prod.itd.earthlink.net>,
  "Ed Grosvenor" <secursrver@hotmail.com> wrote:
> Here's another thought.  Many of the modules you're probably looking
for
> aren't available through ActiveState.  What I've found is that you
have to
> go to CPAN for the majority of not-so-standard modules.  Now, CPAN
works in
> Windows/DOS.  All you have to do is make sure you have a GNU Zip
utility, a
> TAR utiltiy, and NMAKE available on your system.  Then select as many
> mirrors as you can in your config file...because you never know which
ones
> will be working at any given moment.  It's not as pretty as it is in
Linux,
> but I've managed to get everything I've needed that way.  Best of
luck to
> ya.
> Cameron Dorey <camerond@mail.uca.edu> wrote in message
> news:39F73B99.D007D219@mail.uca.edu...
> > schnurmann@my-deja.com wrote:
> > >
> > > For some reason, when I try to install perl modules via ppm, it
can't
> > > find them.
> > >
> > > If I download them, unzip/untar and then run perl Makefile.PL,
Windoze9
> > > then complains that the programme performed an illegal
instruction.  I
> > > then have to reboot.  Anyone seen this before?  Is this a windoze
98
> > > problem?  I am running ActivePerl 5.6.0, build 618.
> >
> > Before I answer, take note: if you don't get an answer within one
minute
> > of posting your question, that's normal, you don't have to post
again,
> > we'll see it eventually.
> >
> > Now...
> >
> > What modules are you trying to install with PPM?
> >
> > Are you certain that they are available for the 6xx builds?
> >
> > Where are you downloading them from?
> >
> > If you are downloading them from ActiveState, you can PPM them from
your
> > hard drive just like they were at the AS repository. Unzip and read
the
> > README file. If you are getting them from CPAN because you couldn't
> > use/find them at AS, read the HTML FAQ about installing modules
which
> > came with your Perl.
> >
> > If you are following the FAQ correctly, you might have a corrupted
> > nmake.exe and you need to download a new one.
> >
> > Cameron
> >
> > --
> > Cameron Dorey
> > Associate Professor of Chemistry
> > University of Central Arkansas
> > Phone: 501-450-5938
> > camerond@mail.uca.edu
> >
>
>


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


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

Date: Thu, 26 Oct 2000 13:26:07 GMT
From: arse <xerxes_2k@my-deja.com>
Subject: can hex crash my script?
Message-Id: <8t9bd7$di1$1@nnrp1.deja.com>

on my latest script, if details are entered incorrectly, the script
prints out all the details, into an array for the javascript to then put
it back into the correct boxes on the form. a side efect of this is that
if in one of the boxes i entered

some really boring text\nyup

when and an error in another field. this would then come back out to the
browser ok.but then when JS puts it in the box it comes out like this:

some really boring text
yup

anyway that was all the crappy background.what i want to know is is
there anyway of crashing/cuasing faal errors on the script by entering ,
for instance hex chars' in the form of \x22.

--
[][][]{}{}~~';:.<<//?|1¬!"£$$%^^&*(())__+/*+
oooh random characters i must be coool!


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


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

Date: Thu, 26 Oct 2000 06:51:26 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: can hex crash my script?
Message-Id: <39F836DE.E19A4F94@stomp.stomp.tokyo>

arse wrote:

(snipped)

> what i want to know is is there anyway of crashing/cuasing 
> faal errors on the script by entering , for instance hex 
> chars' in the form of \x22.


Why don't you simply test this and discover? Duh?

Godzilla!


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

Date: 25 Oct 2000 23:50:55 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: complex (for me anyway) rexexp
Message-Id: <m3zojsqk7k.fsf@dhcp11-177.support.tivoli.com>

Dave Brondsema <brondsem@my-deja.com> writes:

> I have a string and I want to change every ", " to " . " if the ", " is
> between "print" and ";".  I have some experience with regexps, but I
> haven't done anything like this before.

Here's a quick-and-dirty solution...

s/(print[^;]*;)/(my$x=$1)=~s!, ! . !g;$x/eg

Note that this makes no attempt to handle cases such as a ";" embeded
in a string.  Or a ", " in a string for that matter.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 26 Oct 2000 14:34:05 GMT
From: lrako@hotmail.com
Subject: concatenation txt files in one file
Message-Id: <8t9fct$h53$1@nnrp1.deja.com>

Hi ,

I received a whole application on a CD . The CD is structured as
follows (more or less):

C:\tables
C:\views
C:\procs
C:\triggers
 ...

Yes.It is on Windows NT.

Each directory contains SQL statements to create DB objects.
eg: the C:\tables directory contains files named:
PIN_ACCOUNT_HELPER.ora
PIN_ADDRESS_HELPER.ora
PIN_DOMAIN.ora
PIN_CURRENCY.ora
 ....

Each file is a CREATE statement which can be processed manually in
program entering it as a parameter.

So I would like to create a kind of big txt file which is a
concatenation of the contents of all files in a given directory.

How can I do that in a NT environnement ? In UNIX it would be very
easy...

A colleague said a Perl script will do. But no one here knows Perl.

Anyone can help ?

Thanks

Lalaina
CRM Consultant





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


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

Date: Thu, 26 Oct 2000 16:16:19 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: easy data type/pointer problem (i think!)
Message-Id: <5uegvschd3t3pjrpehkuou07kik2a2ah45@4ax.com>

On Wed, 25 Oct 2000 19:30:16 GMT, joelyhughes@my-deja.com wrote:

> Hi,
> I'm sure i'm making an elementary mistake here but please can you have
> a look at the following code snippets
> 
> My problem is basically this; FetchURL obviously pulls in URLS and it
> works fine if I place the url as a direct string parameter or
> a 'simple' variable, but if I try to use the result of $Request-
> >QueryString (a MS ASP call), nothing happens.
> 
> What am I doing wrong? I'm am using ActiveState on NT

You might want to look at the aspSamples that came with the AP
distribution:

	\Perl\eg\aspSamples\qstring.asp

-- 
Good luck,
Abe

##
perl -Mstrict -wle 'sub Just{&$_}sub another{&$_}sub Perl{&$_}sub hacker{&$_}$_=sub{(split /::/,(caller $^W)[3])[-$^W].$"};print@{[Just,another,Perl,hacker]}'


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

Date: Thu, 26 Oct 2000 14:49:58 +0100
From: "The Moriman" <themoriman@ntlworld.com>
Subject: emulating flock
Message-Id: <fEWJ5.948$h%4.10050@news2-win.server.ntlworld.com>

Hi,

flock doesn't work on the server that I use.
Is the script I have below a fair enough attempt to "lock" the file?

@temp = stat("shortfile.txt");                                  #Get file
statistics.
    if ($temp[7] > 0) {                                             #If file
length > 0 then

# it should be safe to

# work on file.
        open(SFT, "+<shortfile.txt") or die "can't open: $!";
        chomp(@currenttext = <SFT>);                    #Get all text from
file.
        truncate(SFT,0);                                            #Set
memnum.txt to 0 bytes.
        close (SFT) or die "can't close: $!";                #Close file to
reset _actual_ size

#so any further calls to this

#procedure should fail.

            #do what ya gotta

        open(SFT, "+<shortfile.txt") or die "can't open: $!";    #Re-open
file (0 length).
        print SFT @newtext or die "can't write: $!";               #Print
updated info.
        close(SFT) or die "can't close: $!";
#Close file.
    }

Would leaving the 'chomp'ing until _after_ I have closed the truncated file
improve the speed by a significant degree?

TIA

TMMan




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

Date: 26 Oct 2000 07:11:26 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: emulating flock
Message-Id: <m17l6vpu9d.fsf@halfdome.holdit.com>

>>>>> "The" == The Moriman <themoriman@ntlworld.com> writes:

The> Hi,
The> flock doesn't work on the server that I use.
The> Is the script I have below a fair enough attempt to "lock" the file?

Nope.  You need an "atomic" operation, in which the "testing" and the
"setting" occur in one indivisible amount of time.  Here's how yours could
fail:

1) You notice file is non-empty
2) process B notices file is empty
3) you open file, and truncate it
4) process B opens file and truncates it

Oops.  Now you both think you have it exclusively!

You must find an atomic "test-and-set" operation supported by your
O/S.  It's harder than it looks. {grin}

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 26 Oct 2000 14:13:03 GMT
From: webbgroup@my-deja.com
Subject: Godzilla... can you lend an ear?
Message-Id: <8t9e57$fso$1@nnrp1.deja.com>

Godzilla,

I am pretty sure I did it right. Look down below. I opened it, executed
it, and closed it. ?????

foreach (@host){

        $line = $_;
        ($host,$ip) = split(" ",$line);
        print "Now querying $host  ...\n";
        print `/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip`;
        }##### Close of foreach
close(FILE);

TIA


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


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

Date: Thu, 26 Oct 2000 14:18:30 GMT
From: Phil xxx <phil_xxx@my-deja.com>
Subject: Re: HELP -- ioctl.ph not workinking?
Message-Id: <8t9efe$g8d$1@nnrp1.deja.com>

Thanks!!!!

Now it reconises it I get :

disabling ioctl methods - constants not found

Any ideas?


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


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

Date: Thu, 26 Oct 2000 14:44:34 GMT
From: Dominique Lorre <dlorre@caramail.com>
Subject: Re: Help with array concatenation
Message-Id: <8t9g0f$hnd$1@nnrp1.deja.com>

In article <251020001305230079%lincmad001@telecom-digest.zzn.com>,
  Linc Madison <lincmad001@telecom-digest.zzn.com> wrote:
> > In article <8sri9d$r4f$1@plonk.apk.net>,
> >   "Jody Fedor" <Jodyman@usa.net> wrote:
> >
> > > $yr = "2000"; # Hard code for testing
> > > @days = (31,28,31,30,31,30,31,31,30,31,30,31);
>
> One small problem right there: February 2000 had 29 days.
I just extracted 2 lines from the original program for discussing the
design issues... Anyway the original program was taking care of this,
not completely though. You can fix it with code like this:
days[1] =(!($yr%4) && (($yr%100) || !($yr%400))) ? 29 : 28 ;
HTH


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


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

Date: Thu, 26 Oct 2000 12:59:04 GMT
From: webbgroup@my-deja.com
Subject: Hey guys... can you lend an ear?
Message-Id: <8t99ql$c3u$1@nnrp1.deja.com>

I am writing a script that is querying a series of routers. When I
execute the snmp command alone I get output, but when I execute the
script, nothing appears on the screen. What's the beef??

All I need is to see if the router responds and I can go onto the next
one

open(FILE,"hostfile.txt") || die
        "Cannot file host file \"hostfile.txt\";
@host = <FILE>;
foreach (@host){

        $line = $_;
        ($host,$ip) = split(" ",$line);
        print "Now querying $host  ...\n";
        $output = print `/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip`;
        print $output;
        }##### Close of foreach
close(FILE);


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


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

Date: Thu, 26 Oct 2000 06:47:56 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Hey guys... can you lend an ear?
Message-Id: <39F8360C.69E56A66@stomp.stomp.tokyo>

webbgroup@my-deja.com wrote:
 
> I am writing a script that is querying a series of routers.
> When I execute the snmp command alone I get output, but when
> I execute the script, nothing appears on the screen.


A blank screen is a fairly decent hint your script
is not printing. Could it be something is wrong
with your print commands?


Godzilla!


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

Date: Thu, 26 Oct 2000 08:26:38 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Hey guys... can you lend an ear?
Message-Id: <slrn8vg8nu.f69.tadmc@magna.metronet.com>

On Thu, 26 Oct 2000 12:59:04 GMT, webbgroup@my-deja.com 
   <webbgroup@my-deja.com> wrote:


> Subject: Hey guys... can you lend an ear?


Hey guy... can you put the subject in your Subject: ?


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 26 Oct 2000 08:43:56 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Hey guys... can you lend an ear?
Message-Id: <slrn8vg9oc.f69.tadmc@magna.metronet.com>

On Thu, 26 Oct 2000 12:59:04 GMT, webbgroup@my-deja.com 
   <webbgroup@my-deja.com> wrote:
>I am writing a script that is querying a series of routers. When I
>execute the snmp command alone I get output, but when I execute the
>script, nothing appears on the screen. What's the beef??
         ^^^^^^^


Eh?

You are printing the return value from print(), so you should
see some sort of "true" value (probably a "1") being printed...

I don't know why you are not seeing output from the first
print() call, but you should be seeing a one from the second
print() call.



>All I need is to see if the router responds and I can go onto the next
>one
>
>open(FILE,"hostfile.txt") || die
>        "Cannot file host file \"hostfile.txt\";


You should include the $! special variable in your diagnostic message.

You can avoid backslashing by using alternate quoting.

You should use single quotes for constant strings.
   

   open(FILE, 'hostfile.txt') || 
      die qq/Cannot open host file "hostfile.txt" $!/;


>@host = <FILE>;
>foreach (@host){


Why read the whole file into memory if you are only going to
process it line-by-line anyway?

You also don't need the @host temporary variable:

   while ( <FILE> ) {



>        $line = $_;

If you want it in $line, why don't you just put it there in the
first place instead of putting it somewhere else and then copying
it to where you really want it?

   foreach my $line (@hosts) {

or

   while ( defined $line = <FILE> ) {


>        $output = print `/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip`;


Here you print the STDOUT from snmpwalk. Does snmpwalk make output
on STDOUT (or is it on STDERR instead)?

If you don't need to capture the STDOUT from the program, then
you shouldn't capture the STDOUT from the program.

You appear to want the output from snmpwalk to go to the same
STDOUT (or STDERR) that your Perl program is using. You can
get that with:

   !system "/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip" or
      die 'problem running "snmpwalk"';

No need to capture it into your Perl program when all you do
with the captured data is print it anyway...


>        print $output;


Here you print the "true" or "false" return value from print(),
NOT the output from the snmpwalk program.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 26 Oct 2000 14:16:19 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: Hey guys... can you lend an ear?
Message-Id: <8t9eba$g6u$1@nnrp1.deja.com>

In article <8t99ql$c3u$1@nnrp1.deja.com>,
  webbgroup@my-deja.com wrote:
> I am writing a script that is querying a series of routers. When I
> execute the snmp command alone I get output, but when I execute the
> script, nothing appears on the screen. What's the beef??
>
> All I need is to see if the router responds and I can go onto the next
> one
>
> open(FILE,"hostfile.txt") || die
>         "Cannot file host file \"hostfile.txt\";
> @host = <FILE>;
> foreach (@host){
>
>         $line = $_;
>         ($host,$ip) = split(" ",$line);
>         print "Now querying $host  ...\n";
>         $output = print `/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip`;
>         print $output;

I think you want either:
$output = `/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip`;
print $output
OR
print `/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip`;


>         }##### Close of foreach
> close(FILE);
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

--
Dave Brondsema


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


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

Date: Thu, 26 Oct 2000 14:18:35 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: Hey guys... can you lend an ear?
Message-Id: <8t9efh$g8g$1@nnrp1.deja.com>

In article <8t99ql$c3u$1@nnrp1.deja.com>,
  webbgroup@my-deja.com wrote:
> I am writing a script that is querying a series of routers. When I
> execute the snmp command alone I get output, but when I execute the
> script, nothing appears on the screen. What's the beef??
>
> All I need is to see if the router responds and I can go onto the next
> one
>
> open(FILE,"hostfile.txt") || die
>         "Cannot file host file \"hostfile.txt\";
> @host = <FILE>;
> foreach (@host){
>
>         $line = $_;
>         ($host,$ip) = split(" ",$line);
>         print "Now querying $host  ...\n";
>         $output = print `/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip`;
>         print $output;
>         }##### Close of foreach
> close(FILE);
>


Do you even get "Now querying $host  ...\n" ?  If you don't get that, I
think something's really messed up (or @host is empty).

--
Dave Brondsema


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


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

Date: Thu, 26 Oct 2000 14:35:55 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Hey guys... can you lend an ear?
Message-Id: <fjXJ5.363$Si.20193@eagle.america.net>

On Thu, 26 Oct 2000 08:43:56 -0400, Tad McClellan <tadmc@metronet.com> wrote:
>On Thu, 26 Oct 2000 12:59:04 GMT, webbgroup@my-deja.com 
>   <webbgroup@my-deja.com> wrote:
>...
>
>   while ( defined $line = <FILE> ) {

while ( defined($line = <FILE>) ) {

-- 
Garry Williams


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

Date: Thu, 26 Oct 2000 09:13:35 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Hey guys... can you lend an ear?
Message-Id: <39F83C0F.9DE3C95F@home.com>

webbgroup@my-deja.com wrote:
> 
> I am writing a script that is querying a series of routers. When I
> execute the snmp command alone I get output, but when I execute the
> script, nothing appears on the screen. What's the beef??

Debugging step #1: Begin your program with -w and use strict.

> open(FILE,"hostfile.txt") || die
>         "Cannot file host file \"hostfile.txt\";

This doesn't parse. You're missing a closing quote.

> @host = <FILE>;
> foreach (@host){

If your hostfile is large, it's more memory-friendly to parse it
line-by-line instead of gulping up the whole thing. You also should add
a chomp() here to get rid of the newline.

>         $line = $_;
>         ($host,$ip) = split(" ",$line);

Not really wrong, but a little redundant. You can replace the prior two
lines with
    my ($host, $ip) = split;

>         print "Now querying $host  ...\n";
>         $output = print `/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip`;
                    ^^^^^
Why the print() here? To capture the output of your command, use
    $output = `/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip`;

>         print $output;
>         }##### Close of foreach
> close(FILE);

-mjc


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

Date: Thu, 26 Oct 2000 07:40:54 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Hey guys... can you lend an ear?
Message-Id: <39F84276.65640745@stomp.stomp.tokyo>

webbgroup@my-deja.com wrote:

> I am pretty sure I did it right.

If you did it right, you would have return data.

I am skeptical. A SNMP query of a remote host
rarely returns any data at all, regardless
of what SNMP object you select to query.


> Look down below. I opened it, executed it, and closed it. ?????

I did look and I read deceit at play.


>         print "Now querying $host  ...\n";

You have indicated nothing appears on your screen,
which indicates your script is running and not
crashing; no error message. 

You should, at least, read:

" Now querying   ... "


Godzilla!


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

Date: 26 Oct 2000 09:01:48 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Hey guys... can you lend an ear?
Message-Id: <39f8475c@cs.colorado.edu>

In article <slrn8vg9oc.f69.tadmc@magna.metronet.com>,
Tad McClellan <tadmc@metronet.com> wrote:

Tad, rest assured that this is *not* tchrist-picks-on-tad day.  I
wouldn't say these things if it were someone who knew less, because
they wouldn't be as likely to appreciate the subtleties.

>>All I need is to see if the router responds and I can go onto the next
>>one
>>
>>open(FILE,"hostfile.txt") || die
>>        "Cannot file host file \"hostfile.txt\";
>
>
>You should include the $! special variable in your diagnostic message.
>You can avoid backslashing by using alternate quoting.
>You should use single quotes for constant strings.
>
>   open(FILE, 'hostfile.txt') || 
>      die qq/Cannot open host file "hostfile.txt" $!/;

"Should" is a strong term, and you might wish to consider relaxing
this to a "maybe you would prefer".  Double quotes provide a more
visually distinctive graphical representation than single quotes,
both because they are pixelwise bigger, and also because they're
guaranteed to be readily distinguishable from backquotes.

One could also write it in these ways, although there exist
lamers who will whinge at the first:

    open(FILE, "hostfile.txt") 
	|| die "Cannot open host file `hostfile.txt': $!";

    open(FILE, "hostfile.txt") 
	|| die "Cannot open host file 'hostfile.txt': $!";

    open(FILE, "hostfile.txt") 
	|| die "Cannot open host file hostfile.txt: $!";

    open(FILE, "hostfile.txt") 
	|| die "Cannot open hostfile.txt: $!";

I would probably, for the sake of brevity and thus at least in this
case clarity and consistency, gravitate toward the lattermost of
those.

>>@host = <FILE>;
>>foreach (@host){
>
>Why read the whole file into memory if you are only going to
>process it line-by-line anyway?

I don't know why people do this; it's distressingly common though,
isn't it?  I think they're simply unfamiliar with the standard idiom
in Perl for processing a file(handle) a line (or record) at a time.

>You also don't need the @host temporary variable:
>   while ( <FILE> ) {
>>        $line = $_;
>
>If you want it in $line, why don't you just put it there in the
>first place instead of putting it somewhere else and then copying
>it to where you really want it?
>
>   foreach my $line (@hosts) {

Or, so that it reads correctly in English:

    for my $line (@hosts) { }

or, I suppose, if for some reason you prefer that it be a global,

    for our $line (@hosts) { }

I'm partial to putting my/our right there so that I don't have to
do a full lexical scan to determine the otherwise ambiguous scope
of the loop index variable.

>or
>   while ( defined $line = <FILE> ) {

I'm afraid that won't quite work precisely as it is there written.
Assignment is of lower precedence than the unary operator defined().
Thus that parses as

    while ( defined($line) = <FILE> ) {

As defined() does not produce an lvalue, the compiler will thwap
you.  (And there's no low-precedence form of assignment.  Parentheses
are not a sign of moral weakness, and ought not be automatically
avoided.) But even if one were to write it in a way that were
syntactically acceptable to the compiler, such as

    while (defined($line = <FILE>) ) {

Then you're actually doing something that the compiler has already
done for you.  Witness how this:

    % perl -MO=Deparse -e 'while ( defined($line = <FILE>) ) { print $line }'
    while (defined($line = <FILE>)) {
	print $line;
    }
    -e syntax OK

Is compiled to the same thing as this:

    % perl -MO=Deparse -e 'while ( $line = <FILE> ) { print $line }'     
    while (defined($line = <FILE>)) {
	print $line;
    }
    -e syntax OK

This is not generally true, of course; an arbitrary
while(EXPR) does not compile to while(defined EXPR) for
all possible EXPRs.  

If you peer deeply into the abyss of src/perl/op.c, you'll notice
that OP_GLOB (which that actually is; even if you write it as
readline(FILE)), OP_READDIR, and OP_EACH all create new OP_DEFINEDs
in the specific circumstance that their assignments are the unique
tests in a while-like loop.  Thus, if you use implicitly boolean-test
the result a scalar assignment readline or <>, readdir, or each in
a while-ish test, than it gets a free defined() wrapped around it.
It's a DWIM thing.

Interstingly, this continues to function properly when you employ
(for lack of a better term) a specific scoping modifier, which, unlike
your use of defined(), can be used sans parens:

    % perl -MO=Deparse -e 'while (my $line = <FILE>) { print $line }'
    while (defined(my $line = <FILE>)) {
	print $line;
    }
    -e syntax OK

    % perl -MO=Deparse -e 'while (our $line = <FILE>) { print $line }'
    while (defined($line = <FILE>)) {
	print $line;
    }
    -e syntax OK

    % perl -MO=Deparse -e 'while (local $line = <FILE>) { print $line }'
    while (defined(local $line = <FILE>)) {
	print $line;
    }
    -e syntax OK

>You appear to want the output from snmpwalk to go to the same
>STDOUT (or STDERR) that your Perl program is using. You can
>get that with:
>
>   !system "/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip" or
>      die 'problem running "snmpwalk"';

It's certainly a shame that system() has its true/false status
returns flipped like that.  I'm not sure, though, that adding more
Boolean arithmetic there is necessarily more legible.  One could
easily argue that factoring out gratuitous not-like operations makes
code easier to read; after all, that's why we've got unless() and
until().   So, you *could* just write that this way:

    system("/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip") 
	&& die "problem running snmpwalk";

Although because people are used to the consistency of a "\n\t||
die" for error handling, that might be far enough away from that
as to cause raised eyebrows.  There is a camp that slightly prefers
that it be written as follows:

    system("/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip") == 0
	|| die "problem running snmpwalk";

Although perhaps that's just drifting a bit close to going back to
more Boolean arithmetic.

Less shell-escapishly, you could write it this way:

    system(qw[/opt/OV/bin/snmpwalk -c !!r0ygb1v12], $ip) == 0
	|| die "problem running snmpwalk";

And perhaps you should specify the path in a variable
so they don't want didn't work.

    $snmpwalk = "/opt/OV/bin/snmpwalk";  # config'd earlier

    system($snmpwalk, "-c", "!!r0ygb1v12]", $ip) == 0
	|| die "problem running $snmpwalk";

It might also be nice to say which of $! and/or $? went wrong.

	|| die "problem running $snmpwalk (wait status=$?)";

But that's a longer and gnarlier story, whose ramifications I've
not fully elaborated upon here.

>No need to capture it into your Perl program when all you do
>with the captured data is print it anyway...

Quite.

--tom


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

Date: 26 Oct 2000 08:57:08 -0500
From: Lie Wynn <Buntaro@gmx.de>
Subject: Hilfe zu Penguin
Message-Id: <MPG.1462560259476984989682@news1.premium-news.de>

Hi Leute

hat zufaellig einer eine Idee wo es zum Penguin Module fuer Perl ein 
Tutorial oder etwas in der Art gibt. Ich hab zwar schon danach gesucht 
aber leider nichts brauchbares gefunden.
Fuer Hinweise gibt es zwar keine Belohnung baer ich hoffe es findet sicht 
trozdem jemand ;-)

By Leute


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

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


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