[17302] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4724 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 25 18:06:03 2000

Date: Wed, 25 Oct 2000 15:05:24 -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: <972511523-v9-i4724@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 25 Oct 2000     Volume: 9 Number: 4724

Today's topics:
    Re: [Q] Newbie question <bh_ent@my-deja.com>
    Re: [Q] Newbie question <jeff@vpservices.com>
    Re: [Q] Newbie question <tim@ipac.caltech.edu>
    Re: [Q] Newbie question <bh_ent@my-deja.com>
    Re: Accessing methods created on the fly <sigbus@cyberspace.org>
        ActivePerl under Windoze 98 schnurmann@my-deja.com
        ActivePerl under Windoze 98 schnurmann@my-deja.com
    Re: ActivePerl under Windoze 98 <camerond@mail.uca.edu>
        easy data type/pointer problem (i think!) joelyhughes@my-deja.com
        easy data type/pointer problem (i think!) joelyhughes@my-deja.com
    Re: File locking <mikecook@cigarpool.com>
        Grep and cut associated data ? New at this ! HELP msalerno@my-deja.com
    Re: Grep and cut associated data ? New at this ! HELP <Allan@due.net>
    Re: Grep and cut associated data ? New at this ! HELP (Tad McClellan)
    Re: Grep and cut associated data ? New at this ! HELP <tim@ipac.caltech.edu>
    Re: Help with array concatenation <lincmad001@telecom-digest.zzn.com>
    Re: here and filehandle (Anno Siegel)
    Re: here and filehandle <tim@ipac.caltech.edu>
    Re: here and filehandle <bart.lateur@skynet.be>
    Re: How do I print to a file with wrap text on? (Tom Christiansen)
    Re: How to open and read PDF file <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: How to pass a String to the STDIN of an other prg? dragnovich@my-deja.com
    Re: How to send via sendmail after a 1 hour delay? <maraism@ironhilltech.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 25 Oct 2000 17:58:37 GMT
From: bh <bh_ent@my-deja.com>
Subject: Re: [Q] Newbie question
Message-Id: <8t7708$md6$1@nnrp1.deja.com>

In article <8t706o$nlt$1@internal-news.uu.net>,
  Erik van Roode <newsposter@cthulhu.demon.nl> wrote:
> bh <bh_ent@my-deja.com> wrote:
> > Hi, I am new to perl, and I am interested in writing a program that
> > will let me create a table (or database or what have you) from
several
> > password files (UNIX /etc/passwd) and:
> > 1) verify all logins and UIDs are the same in all files (if they
exist)
> > 2) determine a UID in a given range (say 1000-9999) that is not in
use
> > in any of the files.
>
> > I have started this project several times.  I've tried using hashes
and
> > arrays as the storage types, but just can't get the comparison
routines
> > to work.  Is there a better structure?
>
>   Your approach sounds right. Exactly what problem are you having with
> your comparison routines? Just a wild guess, you are used 'eq' for
> string comparisons, and == for numeric comparisons?
>
>   You could write a _short_ sample of demonstrating what goes wrong.
> Include a good description what you want it to do, and what it does
> instead.
>
> Erik
>
>
The problem with the comparison routines is I don't know what to do
with the hash I build from the password files.  I know what I want, I
just don't know how to code it.

The existing code is:

sub no_dupes {
  my (%uid, $login, $uid);
  foreach my $server (@HOSTS) {
    open((PASSWD),"/tmp/passwd.$server")
    || die "Cannot open passwd files: $!";
    while (<PASSWD>) {
      ($login, $uid) =(split /:/)[0,2];
      $uid{$login} = $uid;
    }
    close(PASSWD) || die "Cannot close passwd files: $!";
  }
}

From this, I'd like to search the hash for duplicates (ie, the same
key, or the same value, or the same key AND value).   Ultimately, I'd
like to format this (or these) hash(es) into a lookup table, so I can
determine an unused UID as I add new users.  The goal is to assign
users the same UID across multiple systems, while maintaining an index
of those users and UIDs.

Thanks again for helping yet another perl-pup!

Drew Myers
perotsystems


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


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

Date: Wed, 25 Oct 2000 11:40:51 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: [Q] Newbie question
Message-Id: <39F72933.63EC0369@vpservices.com>

bh wrote:
> 
> > > Hi, I am new to perl, and I am interested in writing a program that
> > > will let me create a table (or database or what have you) from
> > > several password files

Others are pointing you towards hash solutions which are certainly
capable of doing what you want and should certainly be in your Perl bag
of tricks no matter what you do.  To take you up on your comment in
parentheses there, you may also want to go the database route and use
DBI with DBD::RAM which will let you treat the passwd files as databases
without converting them into some other format.  There's a bit of a
leraning curve to pick up DBI (and SQL if you don't know it yet) but, if
in the long run your goal is database-like querries and comparisons,
this may be a good route for you.  See:

	http://www.symbolstone.org/technology/perl/DBI/

[p.s. in the future please aim for a more informative subject line -- it
helps others who might have the same question as you do and will later
search the group's archives at www.dejanews.com and also makes it more
likely that those with knowledge about your problem will see and respond
to your posting.]

-- 
Jeff


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

Date: Wed, 25 Oct 2000 12:23:41 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: [Q] Newbie question
Message-Id: <39F7333D.DF2D0F1F@ipac.caltech.edu>

bh wrote:
> 
> Hi, I am new to perl, and I am interested in writing a program that
> will let me create a table (or database or what have you) from several
> password files (UNIX /etc/passwd) and:
> 1) verify all logins and UIDs are the same in all files (if they exist)
> 2) determine a UID in a given range (say 1000-9999) that is not in use
> in any of the files.
> 
> I have started this project several times.  I've tried using hashes and
> arrays as the storage types, but just can't get the comparison routines
> to work.  Is there a better structure?

If it's a particular comparison that's failing, show us a working code snippet
with data that reproduces the problem, and we can probably help you. If it's
more complicated than that, reduce your code as much as you can to generate a
test case and post that. We really can't help much without the specific code in
question.

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Wed, 25 Oct 2000 19:51:18 GMT
From: bh <bh_ent@my-deja.com>
Subject: Re: [Q] Newbie question
Message-Id: <8t7dji$sta$1@nnrp1.deja.com>

In article <39F72933.63EC0369@vpservices.com>,
  Jeff Zucker <jeff@vpservices.com> wrote:
> bh wrote:
> >
> > > > Hi, I am new to perl, and I am interested in writing a program
that
> > > > will let me create a table (or database or what have you) from
> > > > several password files
>
> Others are pointing you towards hash solutions which are certainly
> capable of doing what you want and should certainly be in your Perl
bag
> of tricks no matter what you do.  To take you up on your comment in
> parentheses there, you may also want to go the database route and use
> DBI with DBD::RAM which will let you treat the passwd files as
databases
> without converting them into some other format.  There's a bit of a
> leraning curve to pick up DBI (and SQL if you don't know it yet) but,
if
> in the long run your goal is database-like querries and comparisons,
> this may be a good route for you.  See:
>
> 	http://www.symbolstone.org/technology/perl/DBI/
>
> [p.s. in the future please aim for a more informative subject line --
it
> helps others who might have the same question as you do and will later
> search the group's archives at www.dejanews.com and also makes it more
> likely that those with knowledge about your problem will see and
respond
> to your posting.]
>
> --
> Jeff
>
Jeff,

Thanks for the suggestion!  I tried following your suggestion (and the
advice on the download page) but couldn't get all the modules installed
correctly.  As I already have a tremendous headache from this little
project, I'd like to try completing it with the hash method I guess (or
the array of hashes, or whatever), but I'm not sure how to phrase the
comparisons.

It should go something like this (please forgive me, my knowledge of
perl and programming in general is rudimentary at best):

(THE FOLLOWING IS MY BRAND OF PSUEDO-CODE, PLEASE DON'T CRUCIFY ME)

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.

I hope that makes some kind of sense.
Thanks again for all the help.

Drew


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


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

Date: Wed, 25 Oct 2000 16:05:46 -0400
From: "Chet the Nairobian Death Monkey With Bleach Alternative" <sigbus@cyberspace.org>
Subject: Re: Accessing methods created on the fly
Message-Id: <20001025.160544.1127@warhammer.vwrsp.com>

In article <8siaen$6t2$1@nnrp1.deja.com>, michaeljgardner@my-deja.com
wrote:

> 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;
> # ELEMENTS 3 AND 1 OF THE ARRAY ARE THE POSITION AND LENGTH OF THE
> # FIELD NAME.
>   $fieldvalue=substr($line,$headerinfo{$name}[3],$headerinfo{$name}[1]);
>         $fieldvalue=~s/[^0-9A-Za-z-.]//g;
>         $fieldvalue;
>                               }
> };
> 
> This works, all I have to do is read a record of the database into a
> scalar, and then use the subroutine on the scalar to return the
> appropriate data.
> 
> $line='field1field2field3...fieldn'
> $value=MODULENAME::FIELD1($line)
> 
> in this case, $value would be 'field1'.  My problem is that I'd like to
> use the subroutine without having to type the module name every time I
> want to access the contents of a given field.
> 
> I've tried monkeying around with the @EXPORT and @EXPORT_OK arrays, and
> even PUSHing the names of the subroutines created on the fly into the
> arrays, but each time I get an error saying
> 
> undefined subroutine &Main::Subname
> 
> Is there a way to export these subroutines created on the fly so that I
> don't have to invoke the package/module name every time I want to use
> them??
> 
> Thanks, Michael

A problem with using @EXPORT and @EXPORT_OK for this 
is that they take place at compile time (or at run time if you're
using eval to require/use the module, but it'd have the same
problem).  Since these sub routines don't at the time when
the module is used/required, they won't really get exported.
You could try modifying the main symbol table (or your
caller's symbol table):

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

package Foo;

sub create_anon_subs
{
  $main::{'foo'} = sub { print 'anon sub foo',"\n"; };
  $main::{'bar'} = sub { print 'anon sub bar',"\n"; };
}

package main;

&Foo::create_anon_subs();

&foo();
&bar();

__END__

Though you _can_ do this, I personaly think it's bad form, 
and doens't promote very good deveopment practices.

I feel the same way about @EXPORT for that matter...but
that's just my personal opinion.

good luck

Kyle R. Burton


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

Date: Wed, 25 Oct 2000 18:48:12 GMT
From: schnurmann@my-deja.com
Subject: ActivePerl under Windoze 98
Message-Id: <8t79t8$pa5$1@nnrp1.deja.com>

For some reason, when I try to install perl modules via ppm, it can't
find them.  Cannot find PPD file...

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.


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

Date: Wed, 25 Oct 2000 18:47:56 GMT
From: schnurmann@my-deja.com
Subject: ActivePerl under Windoze 98
Message-Id: <8t79so$pa2$1@nnrp1.deja.com>

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.


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

Date: Wed, 25 Oct 2000 14:59:21 -0500
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: ActivePerl under Windoze 98
Message-Id: <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


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

Date: Wed, 25 Oct 2000 19:29:49 GMT
From: joelyhughes@my-deja.com
Subject: easy data type/pointer problem (i think!)
Message-Id: <8t7cb2$rgb$1@nnrp1.deja.com>

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

# this works fine...
$file = $INET->FetchURL("http://www.sun.com/");

#so does this...
$base2 = "http://www.sun.com/";
$file = $INET->FetchURL($base2);

#but this does diddlysquat...
$base = $Request->QueryString("site");
$Response->Write($base);  (this writes out http://www.sun.com/ -
honest!)
$file = $INET->FetchURL($base);

I'm guessing its something like $base in this case is a pointer and
somehow I need to dereference it or something?

I write out $base to the browser as well as $base2 and then both come
up as http://www.sun.com/

I also have done a eq test between $base and $base2 and it says they
are not equal. Maybe this just means that string are never equal as
they are always points and yuo need to call a different function to see
if they are the same)

Any ideas anyone? I'm new to Perl but I really like it :-)

regarsd

Joel




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


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

Date: Wed, 25 Oct 2000 19:30:16 GMT
From: joelyhughes@my-deja.com
Subject: easy data type/pointer problem (i think!)
Message-Id: <8t7cc8$rht$1@nnrp1.deja.com>

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

# this works fine...
$file = $INET->FetchURL("http://www.sun.com/");

#so does this...
$base2 = "http://www.sun.com/";
$file = $INET->FetchURL($base2);

#but this does diddlysquat...
$base = $Request->QueryString("site");
$Response->Write($base);  (this writes out http://www.sun.com/ -
honest!)
$file = $INET->FetchURL($base);

I'm guessing its something like $base in this case is a pointer and
somehow I need to dereference it or something?

I write out $base to the browser as well as $base2 and then both come
up as http://www.sun.com/

I also have done a eq test between $base and $base2 and it says they
are not equal. Maybe this just means that string are never equal as
they are always points and yuo need to call a different function to see
if they are the same)

Any ideas anyone? I'm new to Perl but I really like it :-)

regarsd

Joel




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


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

Date: Wed, 25 Oct 2000 14:24:20 -0700
From: "Michael Cook" <mikecook@cigarpool.com>
Subject: Re: File locking
Message-Id: <McIJ5.1750$EA3.198443@news.uswest.net>

Thanks Bart! That was the final piece,
    Michael
--
== CigarPool ==
http://www.cigarpool.com

"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:9p3dvs8kcjg969pirlmbmnn8jltrpe9fko@4ax.com...
> Michael Cook wrote:
>
> >    But my question is not *how* to flush per filehandle, but *should* I?
>
> I'll stress just once again, that setting autoflush happens per
> filehandle. For example, by default, autoflush is on for STDERR, but not
> for STDOUT if the data is being sent to a file.
>
> So, you have to set autoflush individually for each filehandle for which
> you want it to be in effect.
>
> --
> Bart.




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

Date: Wed, 25 Oct 2000 18:15:58 GMT
From: msalerno@my-deja.com
Subject: Grep and cut associated data ? New at this ! HELP
Message-Id: <8t780j$ng7$1@nnrp1.deja.com>

The below text is an example of a text file that I need to edit.
What I need to do is search for an entry and then I need to remove all
lines associated with that entry.  For example, I need it remove all
entries associated with Device/Sub_device IDE1.  That includes all of
the lines that follow any entry with IDE1 until I hit the next device.
Pretty much, begin cut at the line with IDE1 and stop before IDE2.
You all get the idea.  Please let me know what would be the easiest way
to accomplish this.  Also please keep in mind that I am very new to
perl.

Thanks,

Matt

Ex.

Device: NVR IDE4
attribute: NMP IPRC
attribute: RULE_SET RCPE

Sub_device: NVR IDE4 CPEID 1
attribute: RULE_SET RCPE.DEV
attribute: SUFFIX deviceEntry 1

Device: NVR IDE1
attribute: NMP IPRC
attribute: RULE_SET RCPE

Sub_device: NVR IDE1 CPEID2 1
attribute: RULE_SET RCPE.DEV
attribute: SUFFIX deviceEntry 1

Device: NVR IDE2
attribute: NMP IPRC
attribute: RULE_SET RCPE

Sub_device: NVR IDE2 CPEID6 1
attribute: RULE_SET RCPE.DEV
attribute: SUFFIX deviceEntry 1


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


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

Date: Wed, 25 Oct 2000 14:39:56 -0400
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Grep and cut associated data ? New at this ! HELP
Message-Id: <8t79di$8ni$1@slb6.atl.mindspring.net>

<msalerno@my-deja.com> wrote in message news:8t780j$ng7$1@nnrp1.deja.com...
: The below text is an example of a text file that I need to edit.
: What I need to do is search for an entry and then I need to remove all
: lines associated with that entry.  For example, I need it remove all
: entries associated with Device/Sub_device IDE1.  That includes all of
: the lines that follow any entry with IDE1 until I hit the next device.
: Pretty much, begin cut at the line with IDE1 and stop before IDE2.
: You all get the idea.  Please let me know what would be the easiest way
: to accomplish this.  Also please keep in mind that I am very new to
: perl.


Look for the discussion of the range operator (..) used in a scalar context.
You can find it perlop.  This will provide the functionality you are after.

HTH

AmD

--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
The product of an arithmetical computation is the answer to an equation; it is
not the solution to a problem.
 - Ashley-Perry Statistical Axioms[4]




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

Date: Wed, 25 Oct 2000 15:37:39 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Grep and cut associated data ? New at this ! HELP
Message-Id: <slrn8vedk3.ca6.tadmc@magna.metronet.com>

On Wed, 25 Oct 2000 18:15:58 GMT, msalerno@my-deja.com 
   <msalerno@my-deja.com> wrote:
>The below text is an example of a text file that I need to edit.
>What I need to do is search for an entry and then I need to remove all
>lines associated with that entry.  For example, I need it remove all
>entries associated with Device/Sub_device IDE1.

>Please let me know what would be the easiest way
>to accomplish this.


I don't know if the easiest way is an option for you.

If you control the data format, the it will be waaaaay easier
if you can put a "marker" at the end of each record. 

Then you could set the $/ special variable (see perlvar.pod)
to the marker string, and get "a record at a time" very
painlessly.


But, since I'm not sure if you can do that or not, I'll have
to "build up" the records myself.


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

my $record;                    # accumulate a "record" here

while (<DATA>) {
   if ( /^Device: / ) {        # process previous record, and start new record
      if ( defined $record) {  # previous record exists, process it
         print $record unless $record =~ /IDE1/;
#         print $record unless $record =~ /\bIDE1\b/; # need word boundaries?
      }
      $record = $_;   # initialize the next (new) record
   }
   else {             # add this line to the record being accumulated
      $record .= $_;
   }
}
print $record unless $record =~ /IDE1/;  # don't forget the final record



__DATA__
Device: NVR IDE4
attribute: NMP IPRC
attribute: RULE_SET RCPE

Sub_device: NVR IDE4 CPEID 1
attribute: RULE_SET RCPE.DEV
attribute: SUFFIX deviceEntry 1

Device: NVR IDE1
attribute: NMP IPRC
attribute: RULE_SET RCPE

Sub_device: NVR IDE1 CPEID2 1
attribute: RULE_SET RCPE.DEV
attribute: SUFFIX deviceEntry 1

Device: NVR IDE2
attribute: NMP IPRC
attribute: RULE_SET RCPE

Sub_device: NVR IDE2 CPEID6 1
attribute: RULE_SET RCPE.DEV
attribute: SUFFIX deviceEntry 1
------------------------------------------


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


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

Date: Wed, 25 Oct 2000 14:04:45 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Grep and cut associated data ? New at this ! HELP
Message-Id: <39F74AED.C7541049@ipac.caltech.edu>

msalerno@my-deja.com wrote:
> 
> The below text is an example of a text file that I need to edit.
> What I need to do is search for an entry and then I need to remove all
> lines associated with that entry.  For example, I need it remove all
> entries associated with Device/Sub_device IDE1.  That includes all of
> the lines that follow any entry with IDE1 until I hit the next device.
> Pretty much, begin cut at the line with IDE1 and stop before IDE2.
> You all get the idea.  Please let me know what would be the easiest way
> to accomplish this.  Also please keep in mind that I am very new to
> perl.

For the specific data you gave you can do

open(FILE,"<mydatafile") or die "Can't open; $!";
$/ = ""; # See perlvar
my $exclude = "IDE1";
while(<FILE>) { # See perlop under "I/O Operators"
    print if ! /^(sub_)?device:.*\s$exclude(\s|$)/i; # See perlre
}

I'll let you research that. It relies on there being an empty line between the
paragraphs. If that's not true and there's no other simple way to define the
"paragraphs" of data (those lines associated with one device or subdevice)
you'll have to do something more complicated in the while loop.

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Wed, 25 Oct 2000 13:05:23 -0700
From: Linc Madison <lincmad001@telecom-digest.zzn.com>
Subject: Re: Help with array concatenation
Message-Id: <251020001305230079%lincmad001@telecom-digest.zzn.com>

> 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.

(To think I scoffed at people who said there would be a Y2K problem
with software failing to recognize 2/29/00!)


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

Date: 25 Oct 2000 18:33:11 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: here and filehandle
Message-Id: <8t7917$51j$1@lublin.zrz.tu-berlin.de>

Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote in comp.lang.perl.misc:
>I was shocked! How could Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
>say such a terrible thing:
>
>>Identifying undefined scalars, while never a real problem, is a
>>frequent and tedious chore and anything to help with the task would
>>be welcome.  Having undefined values interpolate as something
>
>Okay, stupid question time. What is preventing the compiler (okay
>interpreter) from telling us which variable was undefined?

 ...and what makes it occasionally lie about the line number?  Well,
I think that's fixed.

The fact that the culprit may not be a variable is a hint.  The
undefined value often comes from a place where any expression
is allowed.  "{}->{ a}" is a perfectly legal way to say "undef"
in Perl, and so are more complex expressions.

Where the check for undef is done, perl is concerned with values
(sv's) and has only very vague ideas where they come from.

Anno


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

Date: Wed, 25 Oct 2000 11:52:49 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: here and filehandle
Message-Id: <39F72C01.8560E066@ipac.caltech.edu>

Gwyn Judd wrote:
> 
> Okay, stupid question time. What is preventing the compiler (okay
> interpreter) from telling us which variable was undefined?

Better answers coming from People Who Really Know, I'm sure, but ...

I'd swear I read a thread about this on p5p but now I can't find it. The upshot
was that doing so would require carrying too much information in the op tree and
would create bloat and inefficiency for a smallish gain.

Personally I'd be willing to pay the price, sometimes. Perhaps I could say

use warnings 'BLOATED_OPTREE';

in those cases ...

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Wed, 25 Oct 2000 21:05:23 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: here and filehandle
Message-Id: <2nievs807chq4uu86l4vbm4ketbvk0brk9@4ax.com>

Gwyn Judd wrote:

>Okay, stupid question time. What is preventing the compiler (okay
>interpreter) from telling us which variable was undefined?

Because Perl carries around values, not variables? undef() is a valid
value in Perl, which is unlike the situation with most other languages.

-- 
	Bart.


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

Date: 25 Oct 2000 13:29:53 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: How do I print to a file with wrap text on?
Message-Id: <39f734b1@cs.colorado.edu>

In article <Pine.LNX.4.21.0010250221140.10235-100000@fnord.io.com>,
Robert Campbell  <poohba@fnord.io.com> wrote:
>I have this script that is a random quote generator that is ran by cron
>and what it does is sends the new quote to my .signature file.  The only
>problem is that it sends it but the text isn't wrapped.  Also, is there an
>easier way to do this?
>
>#!/usr/bin/perl -w
>
>$file = "/home/p/poohba/rap.quote";
>$signature = "/home/p/poohba/.signature";
>
>open (FILE, $file) || die "Can't open $file:  $!\n";
>@quotes=<FILE>;
>close(FILE);
>
>
>$num = int(rand(@quotes));
>$saying = $quotes[$num];
>($quote,$author) = split(/:/, $saying);
>print "$quote\n\t\t\t\t\t\t$author\n";
>open (SIGNATURE, ">$signature") || die "Can't open $signature:  $!\n";
>print SIGNATURE "$quote\n\t\t\t\t\t\t$author\n";
>close(SIGNATURE);

Resend.  I think the daemon ate my homework.

--tom

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	sig-poohba
#
echo x - sig-poohba
sed 's/^X//' >sig-poohba << 'END-of-sig-poohba'
X#!/usr/bin/perl
Xuse 5.006;
Xuse warnings;
Xuse strict;
X
Xconfig();
Xmy $quip = getsig();
Xwritesig($quip);
Xexit;
X
X################################
X
Xsub config {
X    # you should not use a hardcoded directory!
X    my $home =    $ENV{HOME}
X               || $ENV{LOGDIR}
X               || (getpwuid($<))[7]
X               || "/home/p/poohba";
X
X    die "no home: $home" unless -d $home;
X
X    # also, better to use @ARGV than hardcoding a name
X    our $quotefile = @ARGV ? $ARGV[0] : "$home/rap.quote";
X
X    die "no quotefile $quotefile" unless -f $quotefile;
X
X}
X
Xsub getsig {
X    my  $sigfh;
X    our $quotefile;
X
X    open($sigfh, "<", $quotefile)
X        || die "cannot open $quotefile for reading: $!";
X
X##### Uncomment next line to effect standard fortune format processing
X    # local $/ = "\n%%\n";
X
X    # Fetch random line from textfile using constant space
X    # Semi-(proof by induction) of this available in Perl Cookbook
X    my $sigline;
X    local $_;
X    while (<$sigfh>) {
X        $sigline = $_ if rand($.) < 1;
X    }
X
X    close($sigfh)
X        || die "cannot close $quotefile: $!";
X
X    chomp($sigline);  # honors $/, which makes std fortune fmt cool
X
X    return $sigline;
X}
X
Xsub writesig {
X    my ($quote, $author) = split(/\s*:\s*/, $_[0]);
X    $author = "--" . ($author || "Anonymous");
X
X    for ($quote ||= "This signature intentionally left blank.") {
X        1 while s/\t+/' ' x (length($&)*8 - length($`)%8)/e;  # detab
X    }
X
X    # Wrap quote at up to *but not exceeding* three lines, because we
X    # need to leave one for the attribution, and Thou Shalt Not Exceed
X    # Four Lines Of Signature.  Format each such line with a 4-space
X    # indent, plus up to 72 characters following it, wrapping at word
X    # boundaries and hyphens.  Then add right-justified author
X    # attribution on line following.
X
Xformat sigformat =
X    ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
X$quote
X   ~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
X$quote
X   ~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
X$quote
X                                                @>>>>>>>>>>>>>>>>>>>>>>>>>>
X$author
X.
X
X    local $~ = 'sigformat';
X    write;
X
X}
X
END-of-sig-poohba
exit



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

Date: Wed, 25 Oct 2000 11:53:45 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: How to open and read PDF file
Message-Id: <39F72C39.F6D5D933@jpl.nasa.gov>

shilong88@my-deja.com wrote:
> I am new to Perl. I am doing a project which needs to open PDF format
> file and read a title line of the file. Can anybody teach me how to do
> it or tell me where can I find related information? Thanks in advance.

Have you tried http://search.cpan.org?  It has a number of PDF related
modules.  If you only want to find the title line, perhaps there is a
regex that can identify that line.

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King


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

Date: Wed, 25 Oct 2000 20:18:39 GMT
From: dragnovich@my-deja.com
Subject: Re: How to pass a String to the STDIN of an other prg?
Message-Id: <8t7f6l$u7m$1@nnrp1.deja.com>

Yes but I cant do this $responce=`called.pl hi`;  because the program
that Im calling gets parameters that ARE NOT relatined with the data I
neet to pass.. for example...
> program -a say data
Write something:

etc... the programn respondes accordin the parameters I send so the
data I need to send cant be sended as commands strings =)

By the way, Thanks. I will try the other aswers

> You need to look up what the system function does:
>
>     perldoc -f system
>
> There you will find that it does *not* return the standard output of
the
> called program, but rather its exit status.  To get the standard
output
> of the called program, use the backtick quoting operator (also known
as
> qx//), as in:
>
>      $responce=`called.pl hi`;
>
> for example.  See:
>
>      perldoc perlop
>
> Second, you will find that extra parameters supplied to system do not
> appear on STDIN in the called program, but rather appear as command
line
> arguments.  I am guessing that STDIN probably returns end-of-file
right
> off in this case.
> --
> Bob Walton
>

--
------------------------
Juan Carlos Lopez
QDesigns President & CEO
http://www.qdesigns.com


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


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

Date: Wed, 25 Oct 2000 16:46:29 -0400
From: "Michael Maraist" <maraism@ironhilltech.com>
Subject: Re: How to send via sendmail after a 1 hour delay?
Message-Id: <39f7467f$1_2@news.dca.net>


"Joe Smith" <inwap@best.com> wrote in message
news:8t5f9u$eh2$1@nntp1.ba.best.com...
> In article <T_IG5.781$gu5.275051@news.uswest.net>,
> Jim Gaasedelen <jim@usjet.net> wrote:
> >You probably need to use Cron.
>
> No, 'cron' is for repeating jobs.  Use 'at' to run once at a specific
time.

Well, I had a similar problem not too long ago, and cron actually solved it
well for me.
You have a cron-script that runs every hour (or less).  It checks
/var/spool/my-activity for queue'd events.  It checks their time-stamp to
see if nearly an hour has passed ( round up to say 20 minutes ).

Your script would then place the "job" into the spooler.

The use of 'at' would work, except you'd be putting additional load on the
system.  What if you had 100 requests per hour, then you'd have 100 at job's
queued, each requiring seperate invocations.  The cron script would swipe
all jobs in one fell swoop.  The only problem is the granularity of the
activity.  If that's really important than you either need to write your own
daemon (with the same /var/spool... job queue) or resort to 'at'.

-Michael




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

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


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