[8589] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2206 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 30 02:07:19 1998

Date: Sun, 29 Mar 98 23:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 29 Mar 1998     Volume: 8 Number: 2206

Today's topics:
    Re: 'Search and Replace' for multiple files <sray@netnuevo.com>
    Re: 'Search and Replace' for multiple files <rootbeer@teleport.com>
    Re: 'Search and Replace' for multiple files brian_r_parkes@hotmail.com
        (Q)Setuid and FindBin <jdf@pobox.com>
    Re: CGI - Multiple values in an associative array <rootbeer@teleport.com>
    Re: CGI - Multiple values in an associative array (Tom Mornini)
    Re: Editing a flatfile... <bholzman@mail.earthlink.net>
    Re: Editing a flatfile... <rootbeer@teleport.com>
    Re: Error on WINDOWS95 machine <metcher@spider.herston.uq.edu.au>
    Re: Is there a "Newsgroup" for Newbies to Perl? <jhurd@ucs.indiana.edu>
        MySQL installation on Redhot 5.0 <basarane@boun.edu.tr>
    Re: MySQL installation on Redhot 5.0 <sray@netnuevo.com>
        Need help with "shared memory" module IPC::Shareable ! <captain@pirate.de>
    Re: Need help with "shared memory" module IPC::Shareabl <zenin@archive.rhps.org>
        perl to c <president@whitehouse.gov>
    Re: perl to c (Nathan V. Patwardhan)
    Re: Rotating HTML using Perl <bholzman@mail.earthlink.net>
    Re: Rotating HTML using Perl <rootbeer@teleport.com>
    Re: Sysadmin struggeling with PERL/Sed and etc... <rjk@coos.dartmouth.edu>
    Re: The "Y2k-bugs-are-not-just-a-legacy-problem" FAQ (Daniel P. B. Smith)
    Re: Use Perl to update Monolith server <trid@we.be.catchin.spamz.at.primenet.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sun, 29 Mar 1998 19:08:58 -0800
From: Stephanie Ray <sray@netnuevo.com>
Subject: Re: 'Search and Replace' for multiple files
Message-Id: <351F0CC9.23DE7C93@netnuevo.com>

Cat worked wonderfully! I always did like cats :-)

A couple of things-  I had to be careful to use backquotes, and not
single (forward quotes) and to double quote the search & replace string
as well as use a semicolon:

 perl -p -i -e  "s/search-for/replace-with/;" `cat test.txt`

Thank you -very- much.

David A. Black wrote:

> Hello -
>
> In comp.lang.perl.misc you write:
>
> >Can anyone tell me how to iterate through a list of file names and
> >perform a search and replace on each one?
>
> >The following is not doing a blessed thing for me!
>
> >#!/usr/local/bin/perl -w
>
> >open (INPUT, "test.txt") or die "Can't open test.txt: $!\n";
> >while ($line = <INPUT>) {
> >        $filename = $line;
> >        chop($filename);
> >        print "filename = $filename\n";
> >        open HANDLER, "+>>$filename";
>
> You should check the return value on this open(), too.
>
> >        select HANDLER;
> >        s/foo/bar/;
>
> OK, you've operated on $_, but you haven't output anything!
>
> >        select STDOUT;
> >close HANDLER;
> >}
>
> But there are better approaches, anyway.  For instance, on the command
> line:
>
> perl -pi.bak -e 's/foo/bar/' filename1 filename2...
>
> or
>
> perl -pi.bak -e 's/foo/bar/' `cat test.txt`
>
> David Black
> dblack@saturn.superlink.net



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

Date: Sun, 29 Mar 1998 20:09:29 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Stephanie Ray <sray@netnuevo.com>
Subject: Re: 'Search and Replace' for multiple files
Message-Id: <Pine.GSO.3.96.980329200825.28198M-100000@user2.teleport.com>

On Sun, 29 Mar 1998, Stephanie Ray wrote:

> The following is not doing a blessed thing for me!

>         open HANDLER, "+>>$filename";

Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.

Did you ever use that filehandle once you opened it? Hope this helps!

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




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

Date: Sun, 29 Mar 1998 23:21:59 -0600
From: brian_r_parkes@hotmail.com
Subject: Re: 'Search and Replace' for multiple files
Message-Id: <6fna0n$j9h$1@nnrp1.dejanews.com>

The problem is that you're not actually reading the file
you want to change. You should have a go at the following.

You'll have to store the changes in a temporary file or
slurp the whole file in at once. We'll do the former since
the file might be vary large

So, once we have the filename in $filename:

open (FILETOSCAN,"$filename");
open (TEMPFILE,">/tmp/tmp.txt"); # Where you put this will depend
                                 # on the environment.
while (defined($aline=<FILETOSCAN>)) # put a line in $aline
{
     $aline =~ s/foo/bar/g;     # This will replace all instances of
                                # foo with bar on the line.
     print TEMPFILE "$aline";
}

close (TEMPFILE);
close (FILETOSCAN);

rename ("$filename","$filename.bak"); #backup the original file.
rename ("/tmp/tmp.txt","$filename"); # put the amended file back.

All this should go inside your while loop below.

Brian

In article <351EDC88.165F12BA@netnuevo.com>,
  Stephanie Ray <sray@netnuevo.com> wrote:
>
> Can anyone tell me how to iterate through a list of file names and
> perform a search and replace on each one?
>
> The following is not doing a blessed thing for me!
>
> #!/usr/local/bin/perl -w
>
> open (INPUT, "test.txt") or die "Can't open test.txt: $!\n";
> while ($line = <INPUT>) {
>         $filename = $line;
>         chop($filename);
>         print "filename = $filename\n";
>         open HANDLER, "+>>$filename";
>         select HANDLER;
>         s/foo/bar/;
>         select STDOUT;
> close HANDLER;
> }
>
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 29 Mar 1998 23:23:00 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: (Q)Setuid and FindBin
Message-Id: <yaxsoli3.fsf@mailhost.panix.com>

I'd like other users to be able to restart and kill a server that I've
written.  Toward that end I've created a couple of scripts.  It's my
understanding that in order for others to kill a process that I own,
the killing process must be run setuid me.

Do I misunderstand?  If so, the next part of the question is
irrelevant, though perhaps still interesting.

When I flip the setuid bit of the script, FindBin acts bizarre, to
wit:

  jonathan$ ls -l stop_server 
  -rwsr-xr-x   1 jonathan adrift       394 Mar 29 22:38 stop_server

  jonathan$ ./stop_server 
  Cannot find current script '/dev/fd/4' at /usr/local/lib/perl5/FindBin.pm line 185
  BEGIN failed--compilation aborted at /usr/local/lib/perl5/FindBin.pm line 185.
  BEGIN failed--compilation aborted at /dev/fd/4 line 4.

Any lectures or pointer to lectures about the use of setuid will be
greatly appreciated, as will any enlightenment about this screwy
FindBin behavior.  Thanks.
-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY


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

Date: Sun, 29 Mar 1998 19:34:20 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Tom Mornini <tmornini@netcom.com>
Subject: Re: CGI - Multiple values in an associative array
Message-Id: <Pine.GSO.3.96.980329193258.28198K-100000@user2.teleport.com>

On Sun, 29 Mar 1998, Tom Mornini wrote:

> Tom Phoenix (rootbeer@teleport.com) wrote:

> : > - but what kind of strain does that put on the server? 
> 
> : Perl doesn't care. :-) But you could ask in a newsgroup about servers, if
> : that's what you need. 
> 
> This is a really assinine response to this question.

No, it's not. This newsgroup is about Perl, not about servers. 

> : Good luck!
> 
> Do you really mean that? 

Yes, of course.

> I remember when this newsgroup was really an
> amazing resource. 

Some people still consider it such. Cheers!

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



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

Date: Mon, 30 Mar 1998 06:35:04 GMT
From: tmornini@netcom.com (Tom Mornini)
Subject: Re: CGI - Multiple values in an associative array
Message-Id: <tmorniniEqMCyH.7JF@netcom.com>

Tom Phoenix (rootbeer@teleport.com) wrote:
: On Sun, 29 Mar 1998, Tom Mornini wrote:

: > Tom Phoenix (rootbeer@teleport.com) wrote:

: > : > - but what kind of strain does that put on the server? 
: > 
: > : Perl doesn't care. :-) But you could ask in a newsgroup about servers, if
: > : that's what you need. 
: > 
: > This is a really assinine response to this question.

: No, it's not. This newsgroup is about Perl, not about servers. 

Do the semantics of the question mean so much to you? Would you have
answered the question, if you were able, if the question was:

Is this efficient in Perl?

The person who asked the question wanted to know something about Perl,
not about servers. In addition, the people in a server newsgroup aren't
necessarily knowledgeable in Perl.

You can be fairly certain that their response would have been:

Ask this question in a Perl newsgroup.

So, perhaps you would have used your time and everyone's bandwidth
more efficiently if you'd have just answered the question, or ignored
it completely.

-- Tom Mornini
-- InfoMania


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

Date: Sun, 29 Mar 1998 21:02:57 -0500
From: Benjamin Holzman <bholzman@mail.earthlink.net>
To: Mark Priatel <mpriatel@chat.carleton.ca>
Subject: Re: Editing a flatfile...
Message-Id: <351EFD51.DD3FB1E7@mail.earthlink.net>

http://www.perl.com/CPAN/doc/FAQs/FAQ/PerlFAQ.html#How_do_I_change_one_line_in_a_fi

Mark Priatel wrote:
> 
> Hi guys,
> 
> While learning Perl, I whipped up this little phonebook program,
> (original, huh?).  Anyhow, my method for changing the data in the
> flatfile seems really convoluted.   Surely there must be an easier way,
> given all of Perl's search/replace function.   Anyhow, here's part of
> the script:
> 
> ####  READ DATA INTO ARRAY
> 
> open (DB, "phone.txt");
>  @phonedata = (sort <DB>);
> close (DB);
> 
> #### OPEN DATABASE FOR EDITING
> 
>  open (DB,">phone.txt");
>     foreach $i (@phonedata){
>       chop($i);
>      ($c_last,$c_first,$c_phone,$c_dept) = split(/\|/,$i);
> 
> ###
> This part figures out which entry to modify by comparing the original
> data of the entry selected to be edited to actual entry in the file.
> Once it finds it, it replaces it with the new data....All I'm trying to
> do is find and replace a string in a file...
> ###
>    if($last eq $c_last &&
>          $first eq $c_first &&
>          $phone eq $c_phone &&
>          $dept eq $c_dept){
>          print DB "$n_last|$n_first|$n_phone|$n_dept\n";}  #If it
> matches enter the new data
> 
>        else{
>          print DB "$c_last|$c_first|$c_phone|$c_dept\n"} #Otherwise,
> just enter the old data
> 
>    }
> close (DB);
> ##END
> 
> Anyhow, there are a few things I don't like about this script.  1.  I
> have to open the DB twice. 2. I rewriting the entire file..
> 
> Any suggestions on how to optimize this?  Can the s/// function be used
> here?
> 
> Mark.


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

Date: Sun, 29 Mar 1998 20:11:48 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Mark Priatel <mpriatel@chat.carleton.ca>
Subject: Re: Editing a flatfile...
Message-Id: <Pine.GSO.3.96.980329200949.28198N-100000@user2.teleport.com>

On Sun, 29 Mar 1998, Mark Priatel wrote:

> open (DB, "phone.txt");

Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.


>  @phonedata = (sort <DB>);
> close (DB);
> 
> #### OPEN DATABASE FOR EDITING
> 
>  open (DB,">phone.txt");

Why close and reopen? You should just open it for read/write, then keep it
open.

>       chop($i);

chomp is generally safer than chop.

Hope this helps!

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



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

Date: Mon, 30 Mar 1998 11:01:30 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: Error on WINDOWS95 machine
Message-Id: <351EEEEA.D27A5E8C@spider.herston.uq.edu.au>

my $best_guess = !(-d $ENV{TEMP});

$i_give_up = !$best_guess;

--

Jaime Metcher

Dennis Kowalski wrote:
> 
> This pertains to the WIN32 environment
> 
> I have several users using WINDOWS95 workstations with drives from a NT
> 4.0 server mapped to their machine.
> 
> They execute perl and perl scripts off of the server.
> 
> Everyone works fine except one user who gets an error anytime a perl
> script does a system command.
> 
> for example
> 
>   system("del filex");
> 
> The error he gets is
> 
> ERROR:  can not create cmd file
> 
> it doesn't seem to matter what the command to be system'ed is.
> 
> I am sure it has something to do with his WINDOWS95 setup but I do not
> know what it could be.
> 
> Has anyone else running on a WINDOWS95 machine had this problem.
> 
> I am running Activeware build 315.
> 
> Thanks


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

Date: 30 Mar 1998 02:16:50 GMT
From: James Hurd <jhurd@ucs.indiana.edu>
Subject: Re: Is there a "Newsgroup" for Newbies to Perl?
Message-Id: <6fmvai$o3t$1@flotsam.uits.indiana.edu>

	Then is is impossible for a non-programmer to use Perl,
 so this debate is actually as ridiculous as it initally appears.

Tad McClellan <tadmc@flash.net> wrote:


: Maybe (probably) not an "expert" programmer, nor a "trained"
: programmer, nor even a "good" programmer, but still a "programmer"
: (by the definition of "programmer").




: : Why did you co-author
: : Learning Perl--just for the money?  For leisure reading by those who already
: : know how to program in Perl? Or did you write it to teach people how to use
: : the language.  


: Or maybe he wrote it for non-programmers who want to become
: programmers (ie. who want to use the Perl *programming* language)...


: :The arrogance of some of the "professional" programmers in
: : this newsgroup is appalling. And, your answer is the most appalling.
: : Whereas you should be encouraging people to learn Perl (at the very least so
: : that they buy your books), your answer is designed to drive them away.  


: I think his answer was designed to force folks to admit that they
: must become programmers if they intend to program.


: : If
: : learning Perl is guaranteed to make me into an elitist maybe I should mail
: : you the books you wrote and have you mail me my money back--before I sell my
: : soul to the devil.


: Good one!


: : Get off it!  Try to help people who want to learn to program.  You are
:                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

: That sounds to me like "programmer" rather than "non-programmer"...


: : obviously not a professional teacher; therefore, you should not attempt to
: : teach by writing, by advising newbies, or by conducting workshops and
: : classes.  Stick to programming if you are a programmer.


: <g>


: : Tom Christiansen wrote in message <6f5fm2$lr4>
: : >Nonprogammers should not use any programming language.   Period.
:    ^^^^^^^^^^^^^

: Since this predicate is false the rest of the assertion does not apply.


: : >Nonsurgeons should perform any surgical interventions.  Period.

: : What???  You don't mean that!!


: I think he meant to say "should not perform" there.



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

-- 
        _______________________Jim Hurd__________________________
	When one hears galloping hoofbeats, one should initially 
	      think about horses _then_ think about zebras.  
        ---------------------------------------------------------


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

Date: Mon, 30 Mar 1998 03:16:11 +0300
From: Ersin Basaran <basarane@boun.edu.tr>
Subject: MySQL installation on Redhot 5.0
Message-Id: <Pine.A32.3.96.980330030623.46454C-100000@hamlin.cc.boun.edu.tr>

I can not install mysql on Redhat 50.0 I try to install at least 4
versions of MySQL but it failed again and again. The versions I remember
are 
mysql-3.21.23
mysql-3.21.27
mysql-3.20.32

And now I am trying to install it from a binary package..

Is there anyone who had failed in installing MySQL on Redhat 5.0?...!!


ERSIN BASARAN
basarane@boun.edu.tr
ASSISTANT IN
BOGAZICI UNIVERSITY
BEBEK ISTANBUL
TURKEY



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

Date: Sun, 29 Mar 1998 19:16:41 -0800
From: Stephanie Ray <sray@netnuevo.com>
Subject: Re: MySQL installation on Redhot 5.0
Message-Id: <351F0E98.E8D8801A@netnuevo.com>

I haven't yet (Just recently tried installing Red Hat for the first time)
but I do know that installing mSQL by hand under Slackware was very easy...
just carefully read the accompanying documentation.

Ersin Basaran wrote:

> I can not install mysql on Redhat 50.0 I try to install at least 4
> versions of MySQL but it failed again and again. The versions I remember
> are
> mysql-3.21.23
> mysql-3.21.27
> mysql-3.20.32
>
> And now I am trying to install it from a binary package..
>
> Is there anyone who had failed in installing MySQL on Redhat 5.0?...!!
>
> ERSIN BASARAN
> basarane@boun.edu.tr
> ASSISTANT IN
> BOGAZICI UNIVERSITY
> BEBEK ISTANBUL
> TURKEY





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

Date: Mon, 30 Mar 1998 03:15:33 +0200
From: Mark Seuffert <captain@pirate.de>
Subject: Need help with "shared memory" module IPC::Shareable !
Message-Id: <351EF235.4DBD@pirate.de>

Hi there,

I want to use shared memory, so I installed module IPC::Shareable from
CPAN. No problems so far, 'make test' was fine, also some scripts I have 
written to check out how to use shared memory.
Then I found a "bug": whenever I try to search for a free shared memory
block and it's allready in use, the script exits... no return values.
Documentation says: "Calls to tie() will return true if successful,
*undef* otherwise." 
What happens: Successfull ties return true, without success the script
exits. Here is a script to reproduce my problem:

---- schnip ----
#!/usr/bin/perl
use IPC::Shareable;
$glue='test';

#create shared memory block and let it alive
%options = ( 'create' => 'yes', 'exclusive' => 'no', 
             'mode' => 0600, 'destroy' => 'no' );
tie($scalar, IPC::Shareable, $glue, { %options }) or die "tie error\n";

#try to create the same block again, should exit now
%options = ( 'create' => 'yes', 'exclusive' => 'no', 
             'mode' => 0600, 'destroy' => 'yes' );
tie($scalar, IPC::Shareable, $glue, { %options }) or die "tie error\n";

# but no "tie error" is printed, instead it exits itself with:
# shmget returned undef: File exists at ./test8.pl line 9
#
# I think this is a bug, it's not possible to check if a block is
# unused.
---- schnap ----

I searched in the module source code, and found out that the author used
'croak' if a operation fails. Is this the normal way to write moduls? 
What I would like to have: that the calling script is not forced to
exit, instead giving back return values.... of if a 'die' is really
neccesary, a signal should be created that could be trapped.
Sombody has experience with IPC::Shareable or ideas how to fix my
problem?

Any help is appreciated. :)

thx, Mark (sorry about my english, send also email as reply)


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

Date: 30 Mar 1998 03:59:09 GMT
From: Zenin <zenin@archive.rhps.org>
Subject: Re: Need help with "shared memory" module IPC::Shareable !
Message-Id: <891230761.845065@thrush.omix.com>

[posted & mailed]

Mark Seuffert <captain@pirate.de> wrote:
: I searched in the module source code, and found out that the author used
: 'croak' if a operation fails. Is this the normal way to write moduls?

	I much perfer confess() for most failed operations, because it gives
	the user a much better idea what happend.  If there is a bug in my
	code (no, that never happends:-) it will also give them a much
	better pointer to the real problem.  The only thing croak() should
	be used for is invalid argument checks, IMHO.  Hell, even that
	really should be confess() just incase it's 5 calls deep...
	
	That said, yes it is a vary common way to write module exceptions.

: What I would like to have: that the calling script is not forced to
: exit, instead giving back return values....

	The program is not forced to exit (see below).  I prefer return()
	for most functions, and confess() for most methods, but it REALLY
	depends on what you're trying to do and the way you're doing it.
	There are times that confess() is valid for a function, and that
	return() (with an error message stored in a package global or
	similar) is much more valid.

: of if a 'die' is really
: neccesary, a signal should be created that could be trapped.

	Already done: $SIG{'__DIE__'}

	That said, it's much better to wrap such code in an eval block
	that works the same as the common try/catch method of other
	languages:

	## TRY
	eval {
	    something_that_might_die_croak_confess_whatever();
	    more ('stuff');
	};
	## CATCH
	if ($@) {
	    ## TEST Exception
	    if ($@ =~ /file not found/i) {
	        do_cleanup ('or whatever');
	    } else {
	        ## Unknown exception, just let it keep going
	        die $@;
	    }
	}

: Sombody has experience with IPC::Shareable

	Yes.

: or ideas how to fix my problem?

	No, sorry.  IPC::Shareable looked good, but I could never get it to
	really play nice when I pushed it.  I fell back to using sockets
	because I know them much better. -At least, until threads are
	stable. :-)

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: Mon, 30 Mar 1998 03:10:52 +0100
From: Bill Clinton <president@whitehouse.gov>
Subject: perl to c
Message-Id: <351EFF2C.B7E80DA@whitehouse.gov>

Are there any tools available for converting perl code to c or c++?

Thanks.
Magnus.



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

Date: 30 Mar 1998 03:19:34 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: perl to c
Message-Id: <6fn306$3ci@fridge.shore.net>

Bill Clinton (president@whitehouse.gov) wrote:
: Are there any tools available for converting perl code to c or c++?

Only if you promise not to bed us.

ba-da-bing!

--
Nathan V. Patwardhan



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

Date: Sun, 29 Mar 1998 21:25:17 -0500
From: Benjamin Holzman <bholzman@mail.earthlink.net>
To: ffinstad@best.com
Subject: Re: Rotating HTML using Perl
Message-Id: <351F028D.4B3614FD@mail.earthlink.net>

Yes.  It's also possible with a simple Server Side Include.

Franco Finstad wrote:
> 
> I'd would like to have different text displayed each time my homepage is
> loaded. I need the text to be read from a text file that I'm constantly
> updating. Is this possible using Perl?
> 
> Any help is appreciated.
> 
> Thanks
> Franco Finstad


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

Date: Sun, 29 Mar 1998 20:07:50 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Franco Finstad <ffinstad@best.com>
Subject: Re: Rotating HTML using Perl
Message-Id: <Pine.GSO.3.96.980329200641.28198L-100000@user2.teleport.com>

On Sun, 29 Mar 1998, Franco Finstad wrote:

> I'd would like to have different text displayed each time my homepage is
> loaded. I need the text to be read from a text file that I'm constantly
> updating. Is this possible using Perl? 

If it's possible using any language, it's possible using Perl. The people
in a newsgroup about web-related issues should be able to help you more. 
Good luck! 

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



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

Date: Sun, 29 Mar 1998 23:24:57 -0500
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: Sysadmin struggeling with PERL/Sed and etc...
Message-Id: <351F1E99.28410FC7@coos.dartmouth.edu>

Joergen W. Lang wrote:
> 
> David C McCall <cyberman@sonoma.edu> writes:
> 
> > I've got 2 files each with the same number of lines of text.
> > I would like to merge these files line by line appending the
> > 2nd files 1st line to the 1st files 1st line, and so on....to
> > a 3rd file.....
> 
> [snipped:
>  program which reads both files into arrays
>  creates a third array merging the contents of the first two arrays
>  and then prints that array out to the new file]

Could you possibly do that any less efficiently?!

Not only are you unnecessarily storing the contents of both original files in
memory, you're *duplicating* the contents of the files in the third array. 
What's wrong with reading in a line from each original file and printing them
out directly?

BTW, you also ignored the specification to append the lines together.  You
need to remove the newlines from the first file.

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Mon, 30 Mar 1998 03:50:41 GMT
From: dpbsmith@world.std.com (Daniel P. B. Smith)
Subject: Re: The "Y2k-bugs-are-not-just-a-legacy-problem" FAQ
Message-Id: <EqM5CH.CrD@world.std.com>

Nice! Post it here periodically!
-- 
Daniel P. B. Smith
dpbsmith@world.std.com


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

Date: 29 Mar 1998 22:19:01 -0700
From: Todd Santos <trid@we.be.catchin.spamz.at.primenet.com>
Subject: Re: Use Perl to update Monolith server
Message-Id: <6fna05$qdm@nntp02.primenet.com>

use IO::Socket;

# blah blah blah, program program program, etc. etc. etc.

sub update {
	$woot = IO::Socket::INET->new(
		PeerAddr => "members.ml.org",
		PeerPort => 80,
		Proto => "tcp" ) || die "couldn't connect to ml: $!\n";

	$woot->autoflush( 1 );
	printf $woot "GET /mis-bin/ms3/blahblahblah\n";
	read( $woot, $_, 15 ) );
		if( $_ ne "HTTP/1.0 200 OK" ) {
			printf STDERR "Host $host updated.\n";
			return 0;
		} else {
			printf STDERR "Host $host NOT updated.\n";
			return 1;
		}
}

I'm not sure if 200 is the right numeric, though. adjust read() and if()
accordingly.


: In article <Pine.GSO.3.96.980329051421.3818Z-100000@user2.teleport.com>, Tom Phoenix <rootbeer@teleport.com> wrote:

pfft. teleport. hey, rick, how's that platypus? *innocent look*

drinking and posting again, sorry.

-- 
I ran out of ideas for sigs.
This is sig number 4.


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

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

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

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 2206
**************************************

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