[7947] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1572 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 2 20:07:45 1998

Date: Fri, 2 Jan 98 17:02:38 -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           Fri, 2 Jan 1998     Volume: 8 Number: 1572

Today's topics:
     Image::Size 2.5 uploaded to PAUSE (Randy J. Ray)
     Lookup Table <hudson@cybernex.net>
     Re: modifying file lines exceptions <rootbeer@teleport.com>
     newbie lost with MacPerl!! <robertg@cataloniabsnreed.demon.co.uk>
     Perl for (almost) everyone (was: Re: Avoiding regular e <rootbeer@teleport.com>
     Re: Perl not Y2K compliant (I R A Aggie)
     Re: Perl not Y2K compliant (Abigail)
     Re: Perl not Y2K compliant <adavid@netinfo.com.au>
     Re: Perl not Y2K compliant <adavid@netinfo.com.au>
     Re: Perl not Y2K compliant (Abigail)
     Re: PERLIPC - FIFO: parent, child, stalled! <jbattikha@highsynth.com>
     Re: reading in passwords <rootbeer@teleport.com>
     Re: recomended Perl books ? (brian d foy)
     Re: recomended Perl books ? <rootbeer@teleport.com>
     Unix Grep equivalent in Perl <vagarwal@virgo.corp.sgi.com>
     Re: Unix Grep equivalent in Perl (Mike Stok)
     Re: uploading files in perl? (brian d foy)
     Re: uploading files in perl? <rootbeer@teleport.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 2 Jan 1998 23:52:21 GMT
From: randyr@i2496147.nafohq.hp.com (Randy J. Ray)
Subject: Image::Size 2.5 uploaded to PAUSE
Message-Id: <68jujl$bku$1@news1.teleport.com>

Version 2.5 of Image::Size has been uploaded to PAUSE, and will propagate
to all CPAN sites over the next few days.

To build and install, you will need perl 5.002 or later, and sufficient
access to install an extension.

Summary of Changes in 2.5:

* Added support for TIFF images, thanks to Cloyce Spradling for the patches
  and test images.

>From the README file for 2.5:

Image::Size is a library based on the image-sizing code in the wwwimagesize
script, a tool that analyzes HTML files and adds HEIGHT and WIDTH tags to
IMG directives. Image::Size has generalized that code to return a raw (X, Y)
pair, and included wrappers to pre-format that output into either HTML or a
set of attribute pairs suitable for the CGI.pm library by Lincoln Stein.
Currently, Image::Size can size images in XPM, XBM, GIF, JPEG, PNG and the
PPM family of formats (PPM/PGM/PBM).

I did this because my WWW server generates a lot of documents on demand
rather than keeping them in static files. These documents not only use
directional icons and buttons, but other graphics to annotate and highlight
sections of the text. Without size attributes, browsers cannot render the
text of a page until the image data is loaded and the size known for layout.
This library enables scripts to size their images at run-time and include
that as part of the generated HTML. Or for any other utility that uses and
manipulates graphics. The idea of the basic interface + wrappers is to not
limit the programmer to a certain data format.

Please send any reports of problems or bugs to randy@byz.org. I wouldn't
mind a short note to know that you're using this, just so I can justify its
continued development to my manager :-). (In seriousness, a rough idea of
how many others are using this will help promote its upkeep.)

This package is copyright (c) 1997 by Randy Ray (randy@byz.org) and is
made available to the Perl public under terms of the Artistic License used to
cover Perl itself. See the file Artistic in the distribution  of Perl 5.002 or
later for details of copy and distribution terms.

Perl module interface by Randy J. Ray (randy@byz.org), original
image-sizing code by Alex Knowles (alex@ed.ac.uk) and Andrew Tong
(werdna@ugcs.caltech.edu), used with their joint permission.

Some bug fixes submitted by Bernd Leibing <bernd.leibing@rz.uni-ulm.de>.
PPM/PGM/PBM sizing code contributed by Carsten Dominik
<dominik@strw.LeidenUniv.nl>. Tom Metro <tmetro@vl.com> re-wrote the JPG and
PNG code, and also provided a PNG image for the test suite. Dan Klein
<dvk@lonewolf.com> contributed a re-write of the GIF code. Cloyce Spradling
<cloyce@headgear.org> contributed the TIFF sizing code and test images.
A fix for reading binary data on PC-ish operating systems was contributed by
Silas Dunsmore <silasd@psyber.com>.

-- 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Randy J. Ray                                                       408-343-7578
                                                           randyr@nafohq.hp.com
"Reach up your hand, if your cup be empty/If your cup is full, may it be again"
                                                --Grateful Dead, "Ripple"




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

Date: Fri, 02 Jan 1998 18:58:44 -0500
From: The Hudsons <hudson@cybernex.net>
Subject: Lookup Table
Message-Id: <34AD7F33.AC273E0B@cybernex.net>

Does perl have a function similar to other languages for a lookup
table?  I would imagine that I could use a multi dimensional array to
accomplish the table function, but I'm not quite sure how to go about
implementing it.  Could anyone offer me any insight / help.  Thanks in
advance,

Dunc.



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

Date: Fri, 2 Jan 1998 15:38:19 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Kristin VanDragt <kvandra@uswest.com>
Subject: Re: modifying file lines exceptions
Message-Id: <Pine.GSO.3.96.980102151946.26534b-100000@user2.teleport.com>

On Fri, 2 Jan 1998, Kristin VanDragt wrote:

> I'm trying to read and modify a file.  After searching many different
> sources, I've found that the general solution is to create a temp copy,
> write any changes to it, and then copy over the original.  However, I've
> read that there are exceptions for manipulating files with all lines the
> same length or replacing one a sequence of bytes with another sequences
> of the same length.  I can't find any details.  Anyone know what these
> would be?

With data of a known length at a known position in a file, you can replace
just those bytes in place, something like this. 

    # FILE is opened r/w, of course. 
    seek FILE, $some_position, 0 or die "Can't seek: $!";
    read FILE, $data, $some_length or die "Can't read: $!";

    # Now, update the data
    $data =~ s/old/NEW!/g;

    # Ensure that it is exactly the proper length
    $data = pack("A$some_length", $data);

    # And write it back out
    seek FILE, $some_position, 0 or die "Can't seek: $!";
    print FILE, $data;

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Sat, 03 Jan 1998 01:26:08 +0200
From: Robert Garrigos <robertg@cataloniabsnreed.demon.co.uk>
Subject: newbie lost with MacPerl!!
Message-Id: <34AD778D.261EE981@cataloniabsnreed.demon.co.uk>

Hi everybody,

I'm just starting to learn Perl on a Mac, with MacPerl5, and have a few
problems.

I have a book by Jerry Muelver (Creating cool web pages with Perl) which assumes
that you are on a PC. :-|

The first instruction

perl -e "print 'Hello, World!' \n;"

doesn't seem to work. It doesn't do anything. I tried to type it in a script
window and in the one liner window. The Macperl's on line help docs. are not
much helpful for a beginner. Moreover, I think the book it's talking about
Perl4.

My questions are:

Can I still use this book to learn Perl if I use MacPerl5? What is it that I
should take account of, regarding the two different versions of Perl and of the
platforms?

Of course, it would be much better to use a book to learn Perl based on
MacPerl5. Is there anything like that?

Thank you very muchfor your help.

--
Robert Garrigos

############################################################################
    Bassoon and Contrabassoon player     Sonador de Fagot i Contrafagot
             Reed maker                      Constructor de canyes
              --------------------------------------------------
                                  E-Mail:
                    robertg@cataloniabsnreed.demon.co.uk
              --------------------------------------------------
                            Catalogue on line:
                   http://www.cataloniabsnreed.demon.co.uk

                    The Web page for the Bassoon player!!!

             Postal address: PO Box 7089, 08080 Barcelona, Spain

############################################################################
 



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

Date: Fri, 2 Jan 1998 15:08:12 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: brian d foy <comdog@computerdog.com>
Subject: Perl for (almost) everyone (was: Re: Avoiding regular expressions)
Message-Id: <Pine.GSO.3.96.980102133439.26534Q-100000@user2.teleport.com>

On Fri, 2 Jan 1998, brian d foy wrote:

> Tom Phoenix <rootbeer@teleport.com> wrote: 

> >Perl isn't the right language for everyone; maybe you should consider
> >learning another language that better suits the way you think.
> 
> huh? [this seems like a strange comment from this source.  where's
> Tom and what have you done to him?]

Not everyone can become a programmer, and not every programmer can become
a good Perl programmer. Is there anything strange about that?

(Not everyone can learn to speak, and not every speaker can become a good
speaker of Esperanto. Right?) 

A computer program is normally written for two audiences: the computer
which will interpret it and the human being who will interpret it. (If
only we could be sure that both will interpret the program in the same
way! :-) 

But not all human beings think in one particular way; every mind is
different, in fact. This leads directly to the fundamental difficulty of
communication: Given a thought in my brain, how can I create something in
some medium which, when perceived, will create the closest analogous
thought in yours? It's a wonder that we can accomplish that awesome task
at all, let alone to be able to succeed so well as we do even when, as the
present example plainly shows, a single sentence (even a difficult one
which is almost always grokked on the first try) can grow to be a baroque
monstrosity, encompassing parenthetical comments, errors like mispellings,
digressions which lead far from the topic at hand, meaningless
self-reference, forgotten punctuation and even an extraneous and
distracting flutzpah near the end. Isn't it? 

Of course, Perl is well-designed to be suitable for the vast majority of
programmers, because Larry has a good understanding of the ways in which
computer programmers tend to think and communicate. And it's suitable for
the vast majority of tasks, because he has a good understanding of the
ways in which computers work. That combination of Larry's skills seems to
be the biggest reason why Perl is as interesting, useful, and popular as
it is. 

Cheers!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!




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

Date: Fri, 02 Jan 1998 16:51:55 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Perl not Y2K compliant
Message-Id: <-0201981651550001@aggie.coaps.fsu.edu>

In article <slrn6aog6q.50c.abigail@betelgeuse.wayne.fnx.com>,
abigail@fnx.com wrote:

+ We still have programmers who can't read manuals.

Have we _ever_ had programmers who can read the manuals?

James - I know that I've over looked things in plain sight...

-- 
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>


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

Date: 2 Jan 1998 22:34:49 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Perl not Y2K compliant
Message-Id: <slrn6aqqvb.50c.abigail@betelgeuse.wayne.fnx.com>

change "void" to "kf8nh" (bsa@void.apk.net) wrote on 1585 September 1993
in <URL: news:34ad25c7$1$ofn$mr2ice@speaker>:
++ In <slrn6ap3l0.50c.abigail@betelgeuse.wayne.fnx.com>, on 01/02/98 at 06:50 AM,
++    abigail@fnx.com (Abigail) said:
++ +-----
++ | Huh, what do you mean "by then"? People said so in the 70's about Y2K too,
++ | and look what happened.
++ +--->8
++ 
++ True, but that's with what amounts to formatted data.  The most probable
++ solution I see is that (long) will be a 64-bit type on most platforms by then.

What makes you think 32bit and 64bits aren't formats?


Abigail
-- 
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'


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

Date: Sat, 3 Jan 1998 20:04:35 +1100
From: Anthony David <adavid@netinfo.com.au>
Subject: Re: Perl not Y2K compliant
Message-Id: <Pine.LNX.3.96.980103200112.440D-100000@adavid>





On Thu, 1 Jan 1998, John Nagle wrote:

>   "gmtime" returns a two-digit year.  Bad.  It's 1998 already.

I can't wait till the Year 2000 comes around and we don't have to
put up with this anymore. Every week a FAQ ref gets posted here.

Sigh.

--
Anthony David  adavid@netinfo.com.au
"You can't confuse Rimmer with a book, a book has a spine."
Red Dwarf VII




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

Date: Sat, 3 Jan 1998 20:35:40 +1100
From: Anthony David <adavid@netinfo.com.au>
Subject: Re: Perl not Y2K compliant
Message-Id: <Pine.LNX.3.96.980103201906.440E-100000@adavid>





On 2 Jan 1998, Abigail wrote:

> 
> Huh, what do you mean "by then"? People said so in the 70's about
> Y2K too, and look what happened. Besides, if you have to work with
> dates 40 years in the future, you might feel the results in a few
> weeks. :)

I don't think MVS was the problem or COBOL. It was parsimonious
programmers using PIC S9(5) COMP-3 to store yyjjj dates to
or writing cute Assembler programs that packed multiple dates
into a 32 bit map to save space. But then those COBOL programs had
to read up to 15 tapes of data (with a good chance of a read failure
sometimes in that run). Gee if dates were Y2K compliant, the
data might have squeezed onto 20 tapes and reruns would
probably be a permanent operation.

PS One hope is that by 2038 all systems will be 64bit (at least).
I'm sure there may be a few Mac Pluses around then though :-).

> 
> Oh well, perhaps you mean only a few geeks will still use Unix by
> then, and the rest has moved to Windows.

Oh No!! Another 40 years or Windows....

Regards Anthony

--
"You can't confuse Rimmer with a book, a book has a spine."
Red Dwarf VII




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

Date: 3 Jan 1998 00:14:50 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Perl not Y2K compliant
Message-Id: <slrn6ar0qs.50c.abigail@betelgeuse.wayne.fnx.com>

Anthony David (adavid@netinfo.com.au) wrote on 1586 September 1993 in
<URL: news:Pine.LNX.3.96.980103201906.440E-100000@adavid>:
++ 
++ > Huh, what do you mean "by then"? People said so in the 70's about
++ > Y2K too, and look what happened. Besides, if you have to work with
++ > dates 40 years in the future, you might feel the results in a few
++ > weeks. :)
++ 
++ I don't think MVS was the problem or COBOL. It was parsimonious
++ programmers using PIC S9(5) COMP-3 to store yyjjj dates to
++ or writing cute Assembler programs that packed multiple dates
++ into a 32 bit map to save space. But then those COBOL programs had

My point is, that it is basically the same problem. There is no
fundamental difference between wrapping a year in 2 chars, or wrapping
a date in 32 bits. For the same reason that moving from YY to YYYY
dates can be a problem with existing data, moving from 32 to 64 bits
will be a problem.

++ to read up to 15 tapes of data (with a good chance of a read failure
++ sometimes in that run). Gee if dates were Y2K compliant, the
++ data might have squeezed onto 20 tapes and reruns would
++ probably be a permanent operation.
++ 
++ PS One hope is that by 2038 all systems will be 64bit (at least).

The system being 64 bit doesn't magically solve the problem. Nowadays,
computers can write 4 character strings as well, yet that didn't solve
the Y2K problem.




Abigail
-- 
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'


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

Date: Fri, 02 Jan 1998 18:29:07 -0500
From: Jihad Battikha <jbattikha@highsynth.com>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: PERLIPC - FIFO: parent, child, stalled!
Message-Id: <34AD7843.DAEA1AC0@highsynth.com>

Tom Phoenix wrote:

> still allowing you to do what you need. (But do you really need symbolic
> refs? Those are easy to get wrong.)

Actually, the references won't be that exacting -- I'll be generating
them on-the-fly using a session ID (based on date, time of order, IP
address, and a random number).  I already have a script that does that &
I'll just hook the new stuff to it.  The only symbolics refs left when
I'm done will probably only be path variables.

> > Please note in this version of the script I'm using PGP in the process &
> > it's meant for CGI usage.
> 
> Of course, if the data to be encrypted is sent in plain text over the web,
> you're wasting your time. :-)

I'll have an SSL option for people.  Beyond that, I really don't have
that much control over data traversing the 'Net in plaintext on it's way
to the web server (even with SSL since SSL is really only a verification
system, not a real-time encryption system).

> And since you've got two security concerns (PGP and CGI both) it's doubly
> advisable to use taint checking, as described in the perlsec manpage.

I looked at this recently - a lot of stuff to learn for a newcomer, but
I'll be doing my best.  There's so much to learn!  I don't mind, though,
since the best way to learn is with a REAL project. :-)

> >   chdir;
> 
> This is probably not a good idea in a CGI script. I say that because the
[---snip---]
> probably don't, if you use full path names everywhere, which is a good
> idea.)

Indeed chdir; is probably useless here, but it was in the Perlipc doc,
so I just kept it in ;-)  My final script will probably end up
specifying implicit paths.

> >     system('mknod', $FIFO, 'p') || &error('mkfifo');
> 
> Is there a reason you're not using mkfifo instead of mknod?

Not really.  I was testing with both of them and did end up using
mkfifo.  Mknod showed up in my example by accident :-)

> >   # I'm thinking that this below where I'm stalling.
> 
> >   open (FIFO, "> $FIFO") || &error('open fifo'); # to block
> >     print FIFO "Text to encrypt...\n";
> >   close FIFO;
> 
> I believe that that will block until there's a reader for this. Of course,
> the other problem is that this isn't secure: Another process could sneak
> in here and become the reader, thereby acquiring your text to encrypt.
> Maybe you want to see the discussion of PGP in this newsgroup in the
> recent weeks, and possibly the PGP module from CPAN.

In my most recent post, you'll see I found a way around the blocking
problem.  As far as another process sneaking in (perhaps my provider's
daily backup system?), what I'm going to try and play around with is
starting the FIFO with a read instead of a write.  That way, no other
process will be able to read from the FIFO until it's written to
(afterwhich the FIFO is deleted).  I just hope I can trick PGP into not
immediately giving up & thinking it sees an EOF if the write process
doesn't happen quickly enough.  Even more stuff I have to learn about...

I looked at the CPAN PGP module & it's just too darn thick.  It's also
terribly documented for such an eloborate package.  I'd rather be safe
right now with an actual supported payware PGP binary than take my
chances with the CPAN package (which will probably be a nightmare to
beta-test and tweak for my needs).

> >   open(PGP,"| $pgpcmd -o $encrypted $FIFO") || &error('pgp failed');
> >   close(PGP);
> 
> You probably meant to use system instead of open, since you weren't really
> piping to PGP.

You're right.  That's a leftover from playing around with
STDIN/STDOUT...although, technically, it still works and saves my script
for cleanup in case the PGP forked/exec'd process doesn't return (which
could hang my parent script).  Maybe I'm totally wrong about this...

> > P.S.  Normally, I'd use STDIN/STDOUT (IPC::Open2 or IPC::Open3) with PGP
> > rather than a named pipe, but there's a bug with the 5.5 version of PGP
> > (on Windows95/NT) that defaults to using 'stdin' as the decrypted file
> > name.  Hence, the need for a named pipe.
> 
> Hmmm.... I'd prefer to fix the bug than to run it insecurely. :-)

I sent them the bug report initially & they didn't acknowledge the bug
so I sent them a second report detailing the problem precisely but
somehow I don't think I can count on a new release anytime soon... :-)

> (But
> maybe you could let 'stdin' be the named pipe, and use it for passing the
> _encrypted_ text back to your code....)

That's what I was doing a couple of weeks ago (and it worked great!) but
that still left me with a problem:  If I had a large amount of files
encrypted for any particular day, I'd have to manually extract each file
one at a time (and rename them one at a time) to avoid all of them
overwriting each other during a batch decryption.

I'd rather be spending time playing with Perl :-))

> Hope this helps!

Yes, indeed!  Thank you for all the helpful info!  Now I guess I'll have
to dig into dejanews & find those recent PGP discussions you were
talking about...

--
Jihad Battikha
jbattikha@highsynth.com
http://www.highsynth.com


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

Date: Fri, 2 Jan 1998 15:58:22 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: "Devin P. Anderson" <dev@sgi.net>
Subject: Re: reading in passwords
Message-Id: <Pine.GSO.3.96.980102155337.26534j-100000@user2.teleport.com>

On Fri, 2 Jan 1998, Devin P. Anderson wrote:

> > Sure.. I'd recommend using IO::Stty, available on CPAN.
> 
> Looks good to me, but I can't find the module on CPAN. ????

Check again; it's there. If your mirror doesn't have it, here are some you
can try.

    http://www.perl.com/CPAN/
    http://www.perl.org/CPAN/

Start in the modules directory, go to the by-module subdirectory, and you
should find it soon enough. Hope this helps! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Fri, 02 Jan 1998 16:33:02 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: recomended Perl books ?
Message-Id: <comdog-ya02408000R0201981633020001@news.panix.com>
Keywords: from just another new york perl hacker

In article <68jh07$7dj@obi-wan.fdt.net>, "Tiago Stock" <tiagosdelete@gdn.net> posted:

>Please follow this thread in recommending your favorite Perl reference book.
>
>I'm just starting and would like input from more experienced users in which
>book to buy.
>I'm sure more readers would appreciate this as well.

sure.  we appreciate it every week.  past responses can be read
with DejaNews.

-- 
brian d foy                                  <comdog@computerdog.com>
Fifth Avenue on Fire! <URL:http://computerdog.com/brian/fire/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Fri, 2 Jan 1998 15:46:39 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Tiago Stock <tiagosdelete@gdn.net>
Subject: Re: recomended Perl books ?
Message-Id: <Pine.GSO.3.96.980102154557.26534f-100000@user2.teleport.com>

On Fri, 2 Jan 1998, Tiago Stock wrote:

> I'm just starting and would like input from more experienced users in
> which book to buy. 

> I'm sure more readers would appreciate this as well.

Especially the readers who have failed to read the FAQ's entry in section
two on this very topic.

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Fri, 02 Jan 1998 15:57:19 -0800
From: Vandana Agarwal <vagarwal@virgo.corp.sgi.com>
Subject: Unix Grep equivalent in Perl
Message-Id: <34AD7EDF.41C6@virgo.corp.sgi.com>

I am wondering if there is an equivalent of the Unix grep command in
Perl for searching a pattern in a file.

What I want to do is given a file with key values only, extract the
records from a master file (tab delimited ) where value in one of the
fields matches the key read from the keyfile.

To keep things simple, we can assume that the keyfile only contains the
keys and the keys appear as the first field in the master file.

Here is my very first try at this :
while (<KeyFile>) {
	$key = $_;
        while (<MasterFile>) {
                ($masterkey,$restofrecord) = split(/    /);
                if ($key == $masterkey) {
                        print OutFile $_;
                }
        }

As you can see, all it does is prints only one record that matches
between the two files and obviously gets out of the loop.  

What I would like to do is 

	while (<KeyFile>) {
		$key = $_;
		$masterrec = grep($key,masterfile); /* don't know the syntax */
				
		print outfile, $masterrec;     
	}

instead of sequentially going thru the master file for each key in
keyfile. Not sure if there is a way to do this. Searched thru the
Camel/Lama books, but to no avail.

Any suggestions/pointers to existing scripts related with file
comparisons etc..!!!
-- 
Vandana Agarwal
USFO Systems Integration
===============================
email : vagarwal@corp.sgi.com  
tel   : 650-933-5401            
===============================


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

Date: 2 Jan 1998 19:37:50 -0500
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Unix Grep equivalent in Perl
Message-Id: <68k18u$44e$1@stok.co.uk>

In article <34AD7EDF.41C6@virgo.corp.sgi.com>,
Vandana Agarwal  <vagarwal@virgo.corp.sgi.com> wrote:
>I am wondering if there is an equivalent of the Unix grep command in
>Perl for searching a pattern in a file.

Perl will search for patterns in scalars, and it can read scalar values
from a file.

>What I want to do is given a file with key values only, extract the
>records from a master file (tab delimited ) where value in one of the
>fields matches the key read from the keyfile.
>
>To keep things simple, we can assume that the keyfile only contains the
>keys and the keys appear as the first field in the master file.

>As you can see, all it does is prints only one record that matches
>between the two files and obviously gets out of the loop.  
>
>What I would like to do is 
>
>	while (<KeyFile>) {
>		$key = $_;
>		$masterrec = grep($key,masterfile); /* don't know the syntax */
>				
>		print outfile, $masterrec;     
>	}
>
>instead of sequentially going thru the master file for each key in
>keyfile. Not sure if there is a way to do this. Searched thru the
>Camel/Lama books, but to no avail.

You could adapt the match_any at the bottom of
http://www.perl.com/CPAN/doc/FMTEYEWTK/regexps.html
so that you read in all of the keys and pass in an array of patterns of
the form

  "/^\Q$key\E\t/"

where $key is the value of key read from the key file.  The \Q \E protect
you from metacharacters in the keys.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Fri, 02 Jan 1998 16:31:42 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: uploading files in perl?
Message-Id: <comdog-ya02408000R0201981631420001@news.panix.com>
Keywords: from just another new york perl hacker

In article <34AD5149.2DB301F2@through.the.newsgroup>, Rich Stevens <reach.me@through.the.newsgroup> posted:

>    I am trying to make a program that will allow users to upload files
>to my Web server.  If you have ever used GeoCities for posting Web
>pages, you know what I'm looking for.  I want my script to take a
>filename and upload it to me through a Web page.  I would really
>appreciate any help.

CGI.pm should help.  good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
Fifth Avenue on Fire! <URL:http://computerdog.com/brian/fire/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Fri, 2 Jan 1998 16:02:54 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Rich Stevens <reach.me@through.the.newsgroup>
Subject: Re: uploading files in perl?
Message-Id: <Pine.GSO.3.96.980102160127.26534l-100000@user2.teleport.com>

On Fri, 2 Jan 1998, Rich Stevens wrote:

>     I am trying to make a program that will allow users to upload files
> to my Web server.  

> I would really appreciate any help. 

You should use a module to write it; there are several helpful ones
available on CPAN or already installed on your system. Hope this helps! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

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

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