[15482] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2892 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 28 14:05:45 2000

Date: Fri, 28 Apr 2000 11:05:23 -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: <956945122-v9-i2892@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 28 Apr 2000     Volume: 9 Number: 2892

Today's topics:
    Re: "tailing" to a filehandle (Tad McClellan)
    Re: [REGEXP] Extremely important please read! (Tad McClellan)
        A job for Perl? and What? peliknish@my-deja.com
    Re: A job for Perl? and What? <rootbeer@redcat.com>
    Re: A script to make the output of "perldoc -f ..." mor <franl-removethis@world.omitthis.std.com>
        capture perl -cw from perl <akubi_98@yahoo.com>
    Re: capture perl -cw from perl <aqumsieh@hyperchip.com>
    Re: capture perl -cw from perl <rootbeer@redcat.com>
        control-backslash in a literal string <jrw32982@my-deja.com>
    Re: control-backslash in a literal string <rootbeer@redcat.com>
        DBD:Tab Delimited Databases <grichard@uci.edu>
    Re: DBD:Tab Delimited Databases <jeff@vpservices.com>
    Re: DBD:Tab Delimited Databases <grichard@uci.edu>
    Re: DBD:Tab Delimited Databases <jeff@vpservices.com>
    Re: deleting a record in a TEXT database? (Tad McClellan)
        Errors Installing CGI.pm <grichard@uci.edu>
    Re: File Parsing (Tad McClellan)
    Re: Finding text in a file and renaming that file (Tad McClellan)
    Re: Finding text in a file and renaming that file <lr@hpl.hp.com>
    Re: Getting start with perl (Tad McClellan)
    Re: Hashes -- case insensitive keys? (Tad McClellan)
        HOW CAN I TELL IF A FILE IS OPEN BEFORE I READ IT OR WR <ryan@viadyne.com>
    Re: HOW CAN I TELL IF A FILE IS OPEN BEFORE I READ IT O <lauren_smith13@hotmail.com>
    Re: initialize hash to empty? (Tad McClellan)
    Re: inserting $line into the middle of a list... <lr@hpl.hp.com>
        Installing Modules In General <grichard@uci.edu>
    Re: Installing Modules In General <rootbeer@redcat.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 28 Apr 2000 09:37:21 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: "tailing" to a filehandle
Message-Id: <slrn8gj50h.2io.tadmc@magna.metronet.com>

On Thu, 27 Apr 2000 12:14:21 -0700, jim <support@nidlink.com> wrote:

>    I'm trying to tail a log file

>What am I doing wrong?


Not checking the Perl FAQ before posting to the Perl newsgroup.


>Any help or suggestions would be greatly appreciated, whether following my
>current path or otherwise.


I advise checking the Perl FAQ before posting to the Perl newsgroup:

   perldoc -q tail


   "How do I do a C<tail -f> in perl?"


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


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

Date: Fri, 28 Apr 2000 09:22:51 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: [REGEXP] Extremely important please read!
Message-Id: <slrn8gj45b.2io.tadmc@magna.metronet.com>

On 28 Apr 2000 07:26:02 +0100, Jonathan Stowe <gellyfish@gellyfish.com> wrote:
>On Wed, 26 Apr 2000 21:18:01 +0200 Charles Henry wrote:
>>
>> That was done on purpose. I never type all caps so as not to be filtered.
>> 
>
>Maybe we should just filter all your posts regardless then.


Where did you get your PSI::ESP module?

Your's appear to work. Mine doesn't.


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


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

Date: Fri, 28 Apr 2000 16:32:16 GMT
From: peliknish@my-deja.com
Subject: A job for Perl? and What?
Message-Id: <8eceeg$662$1@nnrp1.deja.com>

Hello,
Currenly I know javascript and HTML but am totally ignorant about perl,
cgi and anything serverside. I want to learn enough perl and whatever
else is necessary to do the following  (see below).  My questions are
1. What else, if anything, *is* necessary?  2. Is it realistic to think
I could learn enough to do this in a week if I studied it full time?
3.  Are there big pieces of code out there I could adapt for this
purpose without having to learn much at all?  (I’d like to learn but I
don’t have much time at the moment.)

So here’s what I want to do.  A word game I’ve written in javascript on
a web page requires an array of 100 words.  I want this array of 100 to
be freshly drawn at random from a list I have of about 100,000 english
words (currently in a .txt file with words separated by carriage
returns) to be kept (in whatever form) on the server.



That’s it really.  For example, I want the page when called on one day
to contain:

     Words100 = new Array(“bug”, “albatross”, “whatsoever”, etc. …

And the page when called more than 24 hours later to contain

     Words100 = new Array(“lemur”, “house”, “cormorant”, etc….

Or maybe there's a better way to do this...?


Things that need to be easily variable:  The size of the set of
randomly drawn words and the frequency with which that set is re-
selected.

I'd appreciate any answers to the above questions and/or broad outlines
for how you would go about setting up such a thing.  Or, what the hell,
specific outlines, or, just go ahead and write the whole thing for me
and do my taxes and sweep the yard and fertilize the hydrangea and
defrost my refrigerator.

But seriously, thanks for any help,
ciao,
kurt




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


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

Date: Fri, 28 Apr 2000 10:31:39 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: A job for Perl? and What?
Message-Id: <Pine.GSO.4.10.10004281011180.21722-100000@user2.teleport.com>

On Fri, 28 Apr 2000 peliknish@my-deja.com wrote:

> I want to learn enough perl and whatever else is necessary to do the
> following (see below).  My questions are 1. What else, if anything,
> *is* necessary?

Nothing else is needed; perl is omnipotent. :-)

> 2. Is it realistic to think I could learn enough to do this in a week
> if I studied it full time?

That depends. How big is your brain? But I don't think this is a gigantic
programming problem.

> 3.  Are there big pieces of code out there I could adapt for this
> purpose without having to learn much at all?  (I'd like to learn but I
> don't have much time at the moment.)

So, you can't study this full time after all? Hmmm....

There are plenty of modules on CPAN, and probably most of the ones you'd
need are already on your system. If it's a CGI program, you should
probably use the CGI module, for example.

> I want this array of 100 to be freshly drawn at random from a list I
> have of about 100,000 english words (currently in a .txt file with
> words separated by carriage returns) to be kept (in whatever form) on
> the server.

So, you want to pick 100 entries at random from a file. Pretty easy for
Perl to do. Here's a program to do something similar:

    #!/usr/bin/perl -w

    use strict;

    use constant COUNT => 10;

    open FILE, "/usr/dict/words"
	or die "Can't open words file: $!";

    my @items;
    while (<FILE>) {
	chomp;
	if (COUNT/$. > rand) {
	    # This one deserves to be added, but where?
	    if (@items < COUNT) {
		push @items, $_;
	    } else {
		$items[rand COUNT] = $_;
	    }
	}
    }

    print "Items are: @items\n";

It's not perfect, but I don't think the flaws should keep you awake
nights. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 28 Apr 2000 15:10:48 GMT
From: Francis Litterio <franl-removethis@world.omitthis.std.com>
Subject: Re: A script to make the output of "perldoc -f ..." more readable.
Message-Id: <m3zoqe2rd3.fsf@franl.andover.net>

merlyn@stonehenge.com (Randal L. Schwartz) writes:

> >>>>> "Francis" == Francis Litterio <franl-removethis@world.omitthis.std.com> writes:
> 
> Francis> This script arranges to feed the output of "perldoc -f ..." through
> Francis> pod2man to make it more readable.
> 
> you don't like 
> 
>         perldoc -t -f FUNCNAME
> 
> That's what I use.  Lot less work. :)

OK, I'm a bit confused now.  The man page for perldoc (with Perl
5.005_03) says this:

	-t text output
            Display docs using plain text converter, instead of
            nroff. This may be faster, but it won't look as nice.

and the output of "perldoc -h" says this:

	-t   Display pod using pod2text instead of pod2man and nroff

From those "instead of" clauses, it seems to me that _not_ using -t
should do something close to what my script does (i.e., feed the output
to pod2man and then thru nroff).  Could this be construed to be a bug in
perldoc (or at least it's documentation)?
--
Francis Litterio
franl-removethis@world.std.omit-this.com
PGP public keys available on keyservers.


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

Date: Fri, 28 Apr 2000 18:51:31 +0200
From: "Asmara" <akubi_98@yahoo.com>
Subject: capture perl -cw from perl
Message-Id: <8ecfh7$h9o$1@wrath.news.nacamar.de>

Hi there!

I am having some trouble with capturing a command output.

If I do:
    $cmd = `ls`;

I get the command output. But if I try:
    $cmd = `perl -cw foo.pl`;

I can't get anything!!! How come? What can I do to capture the output of the
perl debugger?
(I don't want to write the output to a file 'perl -cw foo.pl > file.txt')

I even tried: $cmd = `perl -cw foo.pl > echo`; and it doesn't work ...


Manri




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

Date: Fri, 28 Apr 2000 17:28:34 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: capture perl -cw from perl
Message-Id: <7ag0s6rv7h.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>


"Asmara" <akubi_98@yahoo.com> writes:

> Hi there!
> 
> I am having some trouble with capturing a command output.
> 
> If I do:
>     $cmd = `ls`;
> 
> I get the command output. But if I try:
>     $cmd = `perl -cw foo.pl`;
> 
> I can't get anything!!! How come? What can I do to capture the
> output of the perl debugger?

Why are you using the -c switch? This switch asks Perl to check the
syntax of the script only, without executing it. From perlrun:

       -c   causes Perl to check the syntax of the script and
            then exit without executing it.  Actually, it will
            execute BEGIN, END, and use blocks, because these are
            considered as occurring outside the execution of your
            program.

--Ala


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

Date: Fri, 28 Apr 2000 10:53:39 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: capture perl -cw from perl
Message-Id: <Pine.GSO.4.10.10004281050410.21722-100000@user2.teleport.com>

On Fri, 28 Apr 2000, Asmara wrote:

>     $cmd = `perl -cw foo.pl`;
> 
> I can't get anything!!! How come? What can I do to capture the output
> of the perl debugger?

That's not the debugger. But backticks capture only the standard output,
not the standard error stream. But you can perhaps ask /bin/sh to merge
them:

    $cmd = `perl -cw foo.pl 2>&1`;

If, of course, that's what you really wanted. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 28 Apr 2000 15:49:35 GMT
From: John Wiersba <jrw32982@my-deja.com>
Subject: control-backslash in a literal string
Message-Id: <8ecbu8$3a7$1@nnrp1.deja.com>

How do I specify ^\ (control-backslash), using \c notation?  When I try
just "\c\", I get a syntax error.  When I specify "\c\\" I get two
characters (^\ and \).

perl -e 'print "weird\n" if "\c\\" eq "\x1C\x5C"'

--
John Wiersba


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


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

Date: Fri, 28 Apr 2000 09:35:43 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: control-backslash in a literal string
Message-Id: <Pine.GSO.4.10.10004280929320.21722-100000@user2.teleport.com>

On Fri, 28 Apr 2000, John Wiersba wrote:

> How do I specify ^\ (control-backslash), using \c notation?  

You can't; use a different notation.

There was a long, long, looooong discussion of this on the p5p list last
November. Look for the "[ID 19991118.014]" messages here, if you want to
re-live the pain. :-)

    http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-11/thrd9.html

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 28 Apr 2000 09:37:59 -0700
From: "Gabe" <grichard@uci.edu>
Subject: DBD:Tab Delimited Databases
Message-Id: <8eceva$ca0$1@news.service.uci.edu>

I'm new to DBI and DBD modules. Which module do I use for tab delimited
databases. Does DBD:CSV do the trick? I read the readme, but didn't see
anything about changing the comma delimiter to a tab. Does DBD:RAM have
anything to do with it? Can someone point me in the direction of better
documentation about what modules do besides the associated readme files?

Gabe




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

Date: Fri, 28 Apr 2000 10:10:53 -0700
From: Jeff Zucker <jeff@vpservices.com>
To: Gabe <grichard@uci.edu>
Subject: Re: DBD:Tab Delimited Databases
Message-Id: <3909C61D.D5780815@vpservices.com>

Gabe wrote:
> 
> I'm new to DBI and DBD modules. Which module do I use for tab delimited
> databases. Does DBD:CSV do the trick? I read the readme, but didn't see
> anything about changing the comma delimiter to a tab. Does DBD:RAM have
> anything to do with it?

Both of those modules will work.  With DBD::CSV, put {sep_char=>'\t'} in
your connect statement.  With DBD::RAM, the following code access a
tab-delimited file and prints out all the values matching the given
criteria:

#!perl -w
use strict;
use DBI;
my $dbh=DBI->connect('DBI:RAM:',,,{RaiseError=>1});
$dbh->func([['table1','CSV','test_db.tab',{sep_char=>'\t'}]],'catalog');
print $dbh->func("SELECT * FROM table1 WHERE state = 'OR'",'dump');
__END__

> Can someone point me in the direction of better
> documentation about what modules do besides the associated readme files?

There is alot of documentation inside the modules themselves.  Go to the
command line and type perldoc DBD::CSV or perldoc DBD::RAM.  For both
modules you may also want to type perldoc SQL::Statemtent because that
contains the information on the SQL subset used in both modules.  You
can also read about DBD::CSV in the book _Programming the Perl DBI_ by
Bunce and Descartes.  Most of what that says about DBD::CSV also applies
to DBD::RAM.

-- 
Jeff


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

Date: Fri, 28 Apr 2000 10:15:33 -0700
From: "Gabe" <grichard@uci.edu>
Subject: Re: DBD:Tab Delimited Databases
Message-Id: <8ech5p$dcl$1@news.service.uci.edu>

What do you recommend I use, DBD::CSV or DBD::RAM and why? It appears as
though DBD::RAM requires DBD::CSV anyway, so what bother with DBD::RAM?

Gabe


Jeff Zucker <jeff@vpservices.com> wrote in message
news:3909C61D.D5780815@vpservices.com...
> Gabe wrote:
> >
> > I'm new to DBI and DBD modules. Which module do I use for tab delimited
> > databases. Does DBD:CSV do the trick? I read the readme, but didn't see
> > anything about changing the comma delimiter to a tab. Does DBD:RAM have
> > anything to do with it?
>
> Both of those modules will work.  With DBD::CSV, put {sep_char=>'\t'} in
> your connect statement.  With DBD::RAM, the following code access a
> tab-delimited file and prints out all the values matching the given
> criteria:
>
> #!perl -w
> use strict;
> use DBI;
> my $dbh=DBI->connect('DBI:RAM:',,,{RaiseError=>1});
> $dbh->func([['table1','CSV','test_db.tab',{sep_char=>'\t'}]],'catalog');
> print $dbh->func("SELECT * FROM table1 WHERE state = 'OR'",'dump');
> __END__
>
> > Can someone point me in the direction of better
> > documentation about what modules do besides the associated readme files?
>
> There is alot of documentation inside the modules themselves.  Go to the
> command line and type perldoc DBD::CSV or perldoc DBD::RAM.  For both
> modules you may also want to type perldoc SQL::Statemtent because that
> contains the information on the SQL subset used in both modules.  You
> can also read about DBD::CSV in the book _Programming the Perl DBI_ by
> Bunce and Descartes.  Most of what that says about DBD::CSV also applies
> to DBD::RAM.
>
> --
> Jeff




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

Date: Fri, 28 Apr 2000 10:59:40 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: DBD:Tab Delimited Databases
Message-Id: <3909D18C.CB5C9691@vpservices.com>

Gabe wrote:
> 
> What do you recommend I use, DBD::CSV or DBD::RAM

DBD::RAM

> and why? 

Because I wrote it. :-)

I'm joking. (about which module to use, not about having written it). 
Seriously, if you are only using the modules for simple "delimited"
files then it doesn't really matter which you use.  If you have files
that have embedded newlines inside fields, then currently only DBD::CSV
supports that and you should use it.  For very large files DBD::CSV may
currently be faster for some operations.  If you intend to use the
modules with other file formats such as fixed-record files or XML; or if
you want the added ability to quickly prototype databases from strings,
arrays, or hashes, then only DBD::RAM supports the other formats and the
prototyping.

> It appears as
> though DBD::RAM requires DBD::CSV anyway, so what bother with DBD::RAM?

Well, actually, it only requires DBD::File which comes with DBD::CSV, it
doesn't require or use DBD::CSV itself. And as I mentioned above, if you
don't need to support other kinds of file types or the prototyping
ability, there isn't any reason to bother with DBD::RAM.

-- 
Jeff


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

Date: Fri, 28 Apr 2000 09:48:41 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: deleting a record in a TEXT database?
Message-Id: <slrn8gj5lp.2io.tadmc@magna.metronet.com>

On 28 Apr 2000 03:35:18 GMT, Mindunwind Sales Department <mindunwindsales@aol.com> wrote:

>any idea how to do this?  


How do do what?


   perldoc -q delete

   "How do I change one line in a file/
    delete a line in a file/
    insert a line in the middle of a file/
    append to the beginning of a file?"


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


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

Date: Fri, 28 Apr 2000 10:11:14 -0700
From: "Gabe" <grichard@uci.edu>
Subject: Errors Installing CGI.pm
Message-Id: <8ecgtm$d6o$1@news.service.uci.edu>

I ran, "perl Makefile.PL LIB=~/home/mopicmag/www/modules" and everything
seemed fine.
Then I ran, "make" and everything seemed fine.
Then I ran, "make test" and was returned this:

PERL_DL_NONLAZY=1
/usr/bin/perl -I./blib/arch -I./blib/lib -I/usr/lib/perl5/i386
-linux/5.00404 -I/usr/lib/perl5 -e 'use Test::Harness qw(&runtests
$verbose); $v
erbose=0; runtests @ARGV;' t/*.t
 on #! line at t/form.t line 1.te -
dubious
        Test returned status 2 (wstat 512, 0x200)
 on #! line at t/function.t line 1.
dubious
        Test returned status 2 (wstat 512, 0x200)
Undefined subroutine &Test::Harness::WCOREDUMP called at
/usr/lib/perl5/Test/Har
ness.pm line 222.


Huh? What does this all mean and/or where can I find out what this all
means? I haven't run make install yet.

Gabe





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

Date: Fri, 28 Apr 2000 10:52:05 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: File Parsing
Message-Id: <slrn8gj9cl.2pg.tadmc@magna.metronet.com>

On Fri, 28 Apr 2000 09:54:06 GMT, scarey_man@my-deja.com <scarey_man@my-deja.com> wrote:
>
>> >If I have a file with the following line:
>> >aaaa    bbbb  cccc       dddd
>> >how can I read the line into an array using split, even though the
>> >field separators are different lengths each time e.g. 4 spaces, and
>> >then 2 spaces?
>>
>
>Thanks to all who replied but here is my solution and it works
>(using $_)
>        $/ = "\w";


That line is unnecessary.

$/ affects input.


>        @items =split;


You are not doing any input there.

And if you _were_ doing input, why would you want to get "chunks"
that end with a lower case "w" (which is what you have put into $/) ?


So what did you expect the C<$/ = "\w";> line to do for you?


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


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

Date: Fri, 28 Apr 2000 10:45:44 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Finding text in a file and renaming that file
Message-Id: <slrn8gj90o.2pg.tadmc@magna.metronet.com>

On Fri, 28 Apr 2000 08:24:47 -0400, Morbus Iff <morbus@disobey.com> wrote:

>I'm not sure how'd you'd change the name of a file within Perl 
>(anyone know?),


   perldoc -f rename


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


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

Date: Fri, 28 Apr 2000 10:07:47 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Finding text in a file and renaming that file
Message-Id: <MPG.1373653a2ae896998a9a2@nntp.hpl.hp.com>

In article <morbus-A0ADDD.08244728042000@news.totalnetnh.net> on Fri, 28 
Apr 2000 08:24:47 -0400, Morbus Iff <morbus@disobey.com> says...
> In article <0bf0fd7e.04c584a0@usw-ex0104-028.remarq.com>, fortbruce 
> <bruceNObrSPAM@mccausland.com.invalid> wrote:
> 
> > I'm pretty new to Perl and require some assistance with a Perl
> > script.  I have some dynamic text files which I need to be able
> > to first: find the first occurance of text which begins with a
> > tilda character and ends with a comma, I then need to change the
> > name of that file to match the characters between that string
> > and move that file to a different directory. This script will be
> > run on an NT machine and the input files are FTP'd to a
> > directory on that machine.
> 
> Welp, I'm not sure how'd you'd change the name of a file within Perl 
> (anyone know?), but if you can piece together my thoughts, you can (has 
> not been tested or syntax checked). Paricularly, I think the regexp will 
> cause a problem, but you get the idea at least...

It was responsible of you to label your sketch as such, and not as a 
program.  Whether it was wise of you to post it in that form is a 
different question.  Most of those who post here regularly put some time 
in to provide good paradigms for others to follow.  You didn't do that.

>    # read in directory
>    opendir (DIR, "$dir");

The quotes are superfluous and misleading, and there is no diagnostic 
for failure.

>    my @files = readdir (DIR);
>    closedir (DIR);
> 
>    # read in each file, and look for your line
>    foreach my $file (@files) {

The above lines perpetuate the 'slurp the whole file into an array and 
then loop over it, processing element by element' programming pattern, 
which should be disparaged, not promoted.  Replace the above by:

    while (my $file = <DIR>) {

>       open (FILE, $file);

There is no diagnostic for failure.

>       @lines = <FILE>;
>       
>       foreach $line (@lines) {

The above lines perpetuate the 'slurp the whole file into an array and 
then loop over it, processing element by element' programming pattern, 
which should be disparaged, not promoted.  Replace the above by:

        while (my $line = <FILE>) {

>          if ($line =~ /^~(.*),$/) {
>             open (NEWFILE, ">$1");

There is no diagnostic for failure.

>             print NEWFILE @lines;

Why are you copying the same file into each of the potential targets?

>             close(NEWFILE);
> 
>             # delete the old file
>             unlink ($file);
>             last;
>          }
>       }    
>     }
> 
> As mentioned, this is rough, has no error checking, hasn't been syntax 
> checked or tested. User beware ;)

Good disclaimer; bad idea.

As noted by others, 'rename' is the correct way to do it.

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


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

Date: Fri, 28 Apr 2000 09:46:18 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Getting start with perl
Message-Id: <slrn8gj5ha.2io.tadmc@magna.metronet.com>

On Fri, 28 Apr 2000 11:47:04 +0800, Norazman Abu Sahir <norazman@ti.com> wrote:

>Can anybody explain to how to do with perl (integrating new module so that it
>can be use
>by my exixting perl)


There should be installation instructions included with the module.

Is there a README file in the (unpacked) directory?


Or, type

   perldoc -q module


   "How do I install a CPAN module?"

   "How do I keep my own module/library directory?"


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


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

Date: Fri, 28 Apr 2000 10:10:36 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Hashes -- case insensitive keys?
Message-Id: <slrn8gj6us.2io.tadmc@magna.metronet.com>

On Thu, 27 Apr 2000 21:04:58 -0400, J. B. Moreno <planb@newsreaders.com> wrote:

>Ah, no problem then -- I know that keys doesn't return any kind of
                                                        ^^^^^^^^
>sorted list.


But it _does_ return a sorted list.

It is sorted according to the (internal) hash function.

(which is why the "apparently" qualifier is included in
 the description of keys())


So it _is_ sorted, it's just that the order it is sorted into
is not directly useful from the programmer's point of view.


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


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

Date: Fri, 28 Apr 2000 17:07:53 GMT
From: "Ryan Downing" <ryan@viadyne.com>
Subject: HOW CAN I TELL IF A FILE IS OPEN BEFORE I READ IT OR WRITE TO IT ?
Message-Id: <JzjO4.15349$nB3.1698367@news1.rdc2.on.home.com>

Is there a call that I can use to determine whether or not someone or
something is accessing a file. If I try and read the file I want to make
sure that it is not being updated at the same time.

Any suggestions would be greatly appreciated.

Ryan.




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

Date: Fri, 28 Apr 2000 10:40:56 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: HOW CAN I TELL IF A FILE IS OPEN BEFORE I READ IT OR WRITE TO IT ?
Message-Id: <8ecig7$jsr$1@brokaw.wa.com>

Re: HOW CAN I TELL IF A FILE IS OPEN BEFORE I READ IT OR WRITE TO IT ?

Ryan, many people have ignored your posting on sight.  People don't like to
be shouted to, and will ignore posts that have all caps in the title.  Using
all caps will not make people more inclined to read your posts, no matter
how PROMINENT it may appear.

You have a good idea about how to describe your question, but you don't seem
to know when to use the Shift key.

Ryan Downing <ryan@viadyne.com> wrote in message
news:JzjO4.15349$nB3.1698367@news1.rdc2.on.home.com...
> Is there a call that I can use to determine whether or not someone or
> something is accessing a file. If I try and read the file I want to make
> sure that it is not being updated at the same time.

perldoc -q lock
perldoc -f flock

Lauren




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

Date: Fri, 28 Apr 2000 09:33:03 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: initialize hash to empty?
Message-Id: <slrn8gj4of.2io.tadmc@magna.metronet.com>


[ Please put your comments following the quoted text that you
  are commenting on.

  Jeopardectomy performed.
]


On Fri, 28 Apr 2000 10:31:42 +0200, Frederic Aussedat <Frederic.Aussedat@Alcatel.fr> wrote:
>steve a écrit:
>> 
>> How do I initialize a hash to empty?
>> 
>> but how for a hash
>> 
>>     %hash = ();
       ^^^^^^^^^^^


That is how you do it.


>do
>
>%hash={};


That is not how you do it.

He wants the hash to be empty.

You have shown a hash with one entry.


-----------------------
#!/usr/bin/perl -w

%hash={};
print 'There are ', scalar keys %hash, " elements in %hash\n";

%hash=();
print 'There are ', scalar keys %hash, " elements in %hash\n";
-----------------------

output:

Reference found where even-sized list expected at ./prog line 3.
There are 1 elements in %hash
There are 0 elements in %hash


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


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

Date: Fri, 28 Apr 2000 09:47:17 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: inserting $line into the middle of a list...
Message-Id: <MPG.1373606ff8dfe0ae98a9a0@nntp.hpl.hp.com>

[Like some others, I have no objection to private email copies of 
postings.  But they should be clearly labeled as such.

comp.lang.perl.modules removed from followups.]

In article <39097DBD.EB936B1D@bmjgroup.com> on Fri, 28 Apr 2000 13:02:05 
+0100, Kourosh A Mojar <kmojar@bmjgroup.com> says...
> Thank you for your kind reply. The one line of code you offered seems
> like a good logical alternative to my attempts. A few notes for which
> you may be able to help me further with. The original file may need more
> than one table (second file) to be inserted, thus </TABLEDATA> (ive
> decided to use </TABLECAPTION> now) could appear more than once and
> needs individual attention (im using a counter to determine the next
> table position).

Then the strategy I showed isn't optimal.

> The script with your addition now loops continuously inserting the same
> table over and over again followed by  </TABLEDATA>. It also seems to be
> missing the first line of the table file?

There is no obvious reason for that.

> My script (snip) looks something like the following:
> 
> if ($DoMerge =~ "on"){ 

If this is a pattern match, then use regex notation, not string 
notation.  If it is an equality match, then use the 'eq' operator, not 
the pattern-match operator.

> $Table_Count = 1;

Start counting from 0.

> if ($line =~ "</TABLECAPTION>") {

If this is a pattern match, then use regex notation, not string 
notation.  If it is an equality match, then use the 'eq' operator, not 
the pattern-match operator.

> 	# define and open table file for input
> 	$TABLEFILE = "$TABLEPATH$Topic_ID\.t$TABLEREF[$Table_Count-1]";

You are assigning to a variable.  All caps implies a constant.

The '.' doesn't need to be escaped in a string.

Use $Table_Count++ as the index, so you don't need the separate 
increment below.

> 	open (TABLE_IN, $TABLEFILE) || die "Can't open $TABLEFILE.";

Include $! in the diagnostic.

> 	@table_lines = <TABLE_IN>;	# slurp file into array
> 	close (TABLE_IN);		# close file now all lines in list
> 	chomp @table_lines;		# Remove new lines
> 	
> 	@lines = map { m!</TABLECAPTION>! ? @table_lines : (), $_ } @lines;

Instead of reprocessing the whole input list inside your loop that 
searches for the marker, maintain a single output array and push these 
new lines onto it at this point.

   my @out_lines;
   for (@lines) {
       if (m!</TABLECAPTION>!) {
           # Open an input file as above, then ...
           chomp (my @table_lines = <TABLE_IN>);
           push @out_lines, @table_lines;
       }
       push @out_lines, $_;
   }
 	
> 	print "\nMerged $TABLEFILE\n";
> 	$Table_Count++;
> 	}
> }

In accordance with Usenet protocols and common sense, don't copy the 
whole article you are responding to, especially not at the end.  
Interleave the comments after what you are commenting on; snip out the 
things you aren't commenting on.

 ...

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


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

Date: Fri, 28 Apr 2000 10:26:28 -0700
From: "Gabe" <grichard@uci.edu>
Subject: Installing Modules In General
Message-Id: <8echq7$dlj$1@news.service.uci.edu>

I'm running into a lot of problems trying to install the CGI and DBI
modules. Basically, how do I know that any of the steps involved in
installing a module were successful and that I should go on to the next
step? These are the steps I've been trying to take.

perl Makefile.PL LIB=~/WhereIPutMyModules
make
make test
make install

After I run these programs, generally a bunch of messages get displayed that
I don't understand, and for the CGI and DBI modules I've just tried to
install some of the messages appear to be error messages. When running make
for the DBI module, after a bunch of crap, the last two lines read:

Perl.c:698: parse error at end of input
make: *** [Perl.o] Error 1

So I didn't runt make test or make install. What do I do? In general how do
I know when to proceed?

Gabe




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

Date: Fri, 28 Apr 2000 11:04:49 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Installing Modules In General
Message-Id: <Pine.GSO.4.10.10004281102470.21722-100000@user2.teleport.com>

On Fri, 28 Apr 2000, Gabe wrote:

> how do I know that any of the steps involved in installing a module
> were successful and that I should go on to the next step? These are
> the steps I've been trying to take.
> 
> perl Makefile.PL LIB=~/WhereIPutMyModules
> make
> make test
> make install

If your shell supports it, it's easy to use the shell's && to make each
item contingent upon the previous one's success.

    perl Makefile.PL LIB=~/Wherever && make && make test && make install

Of course, it's even easier to use the CPAN module in most cases:

    perl -MCPAN -e shell

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

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


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