[6898] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 523 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 23 18:17:13 1997

Date: Fri, 23 May 97 15:00:21 -0700
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, 23 May 1997     Volume: 8 Number: 523

Today's topics:
     Re: ANYONE USING PERL W/ WIN95 <johnsone@camax.com>
     CGI Perl Scripts in a Unix Shell <sps196@ecs.soton.ac.uk>
     Re: Clean #line-numbering xsubpp (Ilya Zakharevich)
     Re: Competent Perl Programmer Needed (Jeff Yoak)
     Finding out if a hash entry is a hash (Cameron Schaus)
     Re: From Unix Perl programming to NT Perl Programming.. <johnsone@camax.com>
     How to pass file names to Perl for writing using $ARGV (Robert Paul Monschke)
     how to redirect STDERR/STDOUT of a command <jadams@fsl.noaa.gov>
     Re: HOW?  rmdir -rf (Chipmunk)
     HTTP::Daemon: How check a client has terminated? <mschilli@blacksun.com>
     Re: if string in list ?? lusol@turkey.cc.Lehigh.EDU
     input record separator <wmooney@voicenet.com>
     Re: Looking for sh to perl convert program <usenet-tag@qz.little-neck.ny.us>
     making new syntax (switch statement) <kshaw@plight.lbin.com>
     Newcomer With Problem (Creating HTML File) <herget@iag.net>
     Re: Newsreader in Perl (Russell Schulz)
     Re: NT Perl limitations... permanent? <johnsone@camax.com>
     Re: OS/2: Locales / I18N problem: What to do? (Ilya Zakharevich)
     Re: RCS-style version mgmt implementation in Perl? <xrcc0494@dcaca037.ca.boeing.com>
     Re: script optimization of grep -c (Chipmunk)
     Re: script optimization of grep -c (Chipmunk)
     Re: split'\|'; except when preceded by '/' (Ilya Zakharevich)
     Re: The perl way? What is it really? (Ilya Zakharevich)
     Want to delete a line from a file using a PERL script <rajaram@corp.sgi.com>
     Re: Want to delete a line from a file using a PERL scri (Nathan V. Patwardhan)
     Re: yet another perl regex Q <owt1@cornell.edu>
     Re: yet another perl regex Q <ajohnson@gpu.srv.ualberta.ca>
     Re: yet another perl regex Q (Chipmunk)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 23 May 1997 16:05:11 -0500
From: Eric Foster-Johnson <johnsone@camax.com>
To: chris <chris.lee@globasatcom.com>
Subject: Re: ANYONE USING PERL W/ WIN95
Message-Id: <33860687.593D@camax.com>

chris wrote:
> 
> anyone that is using perl w/ win95 please help me get started.
> 
> this are the steps i take.
> 
> i wrote a sample program (from a book) using the dos editor.
> i save it as "program1_1"
> i then goto my perl.exe and it opens a small dos-like window.
> i type "$ chmod +x program1_1".
> and then type a line of input that is supposed to be repeated by the
> program but nothing happens.
> 
> i am aware that some commands are for unix, but i do not know the win95
> commands.  also, the first line of my program is "#!/usr/local/bin".  do i
> need to type something else up here for win95?
> 
> PLEASE, give me some much needed beginners advice to start rolling with
> this.
> 
> you can email me at chris@globalsatcom.com.
> 
> thanks.
> chris.

Chris,

It seem dumb, but Windows 95 is not Unix. A great many Perl
books cover Perl from the Unix perspective only. For example:

The chmod command will not work in DOS/Windows.
The #!/usr/local/bin/perl first line of a Unix shell
script (that's what you're creating) will not work in 
DOS/Windows.

This is because Windows is not Unix. But, don't give up
hope. First, be sure you have installed Perl for Windows.
(The fact that you have a perl.exe is encouraging.)

Then, open a DOS window, cd to the directory where
your Perl file (program1_1) is stored and enter:

perl program1_1

Does your Perl script run? If not, try:

perl -v

The above command should print out Perl's version number.
If you get an error from this, then chances are Perl is
not properly installed or Perl is not part of your PATH.

If it runs, then chances are you have an error in
your Perl script. This may be a typing error on your
part or simply that the Perl script calls Unix
facilities that are not available on Windows.

My Web pages have more info on Perl for Windows (I'm the
author of Cross-Platform Perl, a Perl book that covers 
both Unix and Windows):

http://www.pconline.com/~erc/perl.htm

I hope this helps,
-Eric

-- 
Eric Foster-Johnson http://www.pconline.com/~erc
CAMAX, SDRC's CAM Business
7851 Metro Parkway         phone: +1 612 854 5300 fax: +1 612 854 6644
Minneapolis, MN 55425 USA  johnsone@camax.com


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

Date: Fri, 23 May 1997 21:42:09 +0100
From: Sam Stickland <sps196@ecs.soton.ac.uk>
Subject: CGI Perl Scripts in a Unix Shell
Message-Id: <33860121.3A53@ecs.soton.ac.uk>

Hi All!

Can anyone tell me how I can start a Perl script in a Unix shell and
pass it informstion just as though it was started from a web form using
post.  For example say I have a perl script that acts on the text fields
name and eMail, from a form with method=post.  How do I start the script
in the same way from a Unix Shell.  It ought to be simple but I'm having
trouble getting it to work.

I'd appreciate it if you could reply via eMail as I don't have the time
to read the newsgroups that often ;(

Cheers

Sam Stickland

eMail: sps196@ecs.soton.ac.uk


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

Date: 23 May 1997 20:48:05 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Clean #line-numbering xsubpp
Message-Id: <5m4vq5$4f6$2@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to John Tobey 
<jtobey@nfic.com>],
who wrote in article <3385D110.41C67EA6@nfic.com>:
> I haven't developed XS code using the latest xsubpp, so I can't say for
> sure, but after building the modules under 5.004 and comparing c files
> with the corresponding xs files, I doubt whether the current line
> numbering support can be considered complete.

The only way I use the current support for #line in xsubpp is to
remove it with 
	grep -v "^#line"
:-(. 

> *** xsubpp	Wed Dec  4 20:44:30 1996
> --- xsubpp	Fri May 23 02:27:57 1997

You did not explain what is your patch relative to.  If it is
w.r.t. 5.004, the patch will be _very_ wellcomed on p5-p.

Ilya


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

Date: Fri, 23 May 1997 15:58:37 GMT
From: jeff@yoak.com (Jeff Yoak)
Subject: Re: Competent Perl Programmer Needed
Message-Id: <5m4pc5$7al@sjx-ixn6.ix.netcom.com>

shaug@callamer.com (O'Shaughnessy Evans) wrote:

>In article <864089070.16009@dejanews.com>,
>	staff@zoron.net writes:
>> Competent perl programmer needed for full time employment with fast
>> growing Internet based company. Salary DOE. contact staff@zoron.net for
>> additional information, or to submit resumes. HTML, C and UNIX experience
>> a big plus!
> 
> I think that a competent webmaster would be useful, as well.  
> Check out www.zoron.net to see what I mean.

That's not really fair.  They weren't advertising a website and they
may very well be constructing it and be in the testing process.  If
none of that data is security-sensitive what's wrong with having that
online?

Cheers,
Jeff

Jeff Yoak  jeff@yoak.com  http://yoak.com/



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

Date: 23 May 1997 19:32:26 GMT
From: cam@cs.ualberta.ca (Cameron Schaus)
Subject: Finding out if a hash entry is a hash
Message-Id: <5m4rca$i6p$1@scapa.cs.ualberta.ca>

I am trying to find out if an entry in a hash table is another hash table.
To do this, I am using if($hashref->{'entry'} =~ /HASH/) { ... }.  I
wasn't sure if this was the 'proper' way to do this or not.  If there
is a better way, I'd love to hear it, as my solution won't work if there
is a value in the hash table that contains the string HASH.  I suppose that
I should mention that I am using perl 5.003.  

Gotta love those hash tables!

Cam
cam@cs.ualberta.ca



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

Date: Fri, 23 May 1997 16:12:52 -0500
From: Eric Foster-Johnson <johnsone@camax.com>
To: Daniel Schnaider <snaider@galcom.co.il>
Subject: Re: From Unix Perl programming to NT Perl Programming... Help!
Message-Id: <33860854.3F7C@camax.com>

Daniel Schnaider wrote:
> 
> Hello,
> 
> I a Unix Perl programmer.
> I am trying to make a program in Perl for NT that send me mail after it
> checks some things...
> I dowloaded a program called postmail that suppose to send mail using
> pipe.
> It doesn't seem to work! If somebody know how can I send mail trough
> PERL for NT or how to use this product... let me know
> 
> Thank you,
> 
> Daniel

Daniel,

I believe there's a freeware program called Blast that
can send email from NT systems. (Of course, the issue is
what kind of email, as PC email systems often don't
follow standards.)

Good luck,
-Eric

-- 
Eric Foster-Johnson http://www.pconline.com/~erc
Author of Cross-Platform Perl, covering Windows and Unix.
CAMAX, SDRC's CAM Business
7851 Metro Parkway         phone: +1 612 854 5300 fax: +1 612 854 6644
Minneapolis, MN 55425 USA  johnsone@camax.com


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

Date: 21 May 1997 21:25:00 GMT
From: jointer@Eng.Sun.COM (Robert Paul Monschke)
Subject: How to pass file names to Perl for writing using $ARGV
Message-Id: <5lvp7c$s5g$1@engnews2.Eng.Sun.COM>


What I want to do is to execute a program as follows:

prog  file1  file2  file3  file4 file5

Some of these will be read and some will be write/append.

I have no problem with read, but I don't know how to do write/append using $ARGV.


I have tried the following:

prog  file1  file2  >file3  >file4 >>file5

But when passed through to the program, open says the writes and append files
don't exist.  Obviously, it is using > as part of the file name.

I have also tried varous forms of the >$ARGV[1] in the open file in the program,
but this doesn't work either.

I also have a PERL5 book and have been unable to find the solution in the book.

Thanks, Paul 

Thanks, Paul




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

Date: Fri, 23 May 1997 14:18:06 -0600
From: James Adams <jadams@fsl.noaa.gov>
Subject: how to redirect STDERR/STDOUT of a command
Message-Id: <3385FB7E.3A78@fsl.noaa.gov>

Hello,

	I am running a command from within my perl script and I would like for
the output messages from the command to not be printed when I run my
script.  I am just invoking the command as such:

`fmbatch $batchFile`;

The problem is that this command prints initialization messages (I don't
know if they're going to STDOUT or STDERR, I think it's STDOUT).  I have
tried the tricks that work at the command line such as adding ">>
/dev/null" or ">& /dev/null" to the command in order to redirect these
messages, but these don't work in Perl.

	Can anyone suggest what I can do to run this command "quietly" ?

	Please Cc: your response to jadams@fsl.noaa.gov if possible.

	Thanks so much for any suggestions !


-James


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

Date: 23 May 1997 20:37:04 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: HOW?  rmdir -rf
Message-Id: <5m4v5g$jv8$1@dartvax.dartmouth.edu>

In article <3383A8F1.41C67EA6@ccis.adisys.com.au>
"Richie !" <richard@ccis.adisys.com.au> writes:

> In perl, I know how to remove an empty directory (using rmdir),
> but what I'd like to know how to recursively remove a non-empty
> directory (ie. as in unix: rm -rf)
> 
> I've come up with:
> 
> ------------------------------------------
> #!/usr/local/bin/perl
> 
> $thedir="crap";
> 
> opendir(it, $thedir);
> @files = (grep(!/^\.\.?$/, readdir(it)));
> close(it);
> foreach $f (@files) {
>         unlink ($thedir."/".$f) || die ("Cannot remove
> $thedir."/".$f\n");
> }
> 
> rmdir ($thedir) || die ("Cannot rmdir $thedir\n");
> ------------------------------------------
> 
> But this doesn't cater for non-empty subdirectories.

Well, if you want it to be recursive, it should be a subroutine.

# very much untested ;-)
sub remove_dir {
  my($dir) = @_;              # keep in mind that $dir may end in '/'

  (-d $dir) || die "$dir is not a directory\n";
  opendir(DIR, $dir);
  my(@files) = (grep(!/^\.\.?$/, readdir(DIR)));
  close(DIR);
  chdir($dir) || die "Cannot chdir $dir\n";

  my($f);
  foreach $f (@files) {
    if (-d $f) {              # file is a directory
      &remove_dir($f);        #   so recurse
    } else {
      unlink($f) || die "Cannot remove $f from $dir\n";
                              # die will not print the whole path
    }
  }

  chdir("..") || die "Cannot chdir .. from $dir\n";
  rmdir($dir) || die "Cannot rmdir $dir\n";
}


Alternatively, this might also work:

`rm -rf $dir`;

Chipmunk


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

Date: Fri, 23 May 1997 12:26:11 -0700
From: Michael Schilli <mschilli@blacksun.com>
Subject: HTTP::Daemon: How check a client has terminated?
Message-Id: <3385EF53.3FD3@blacksun.com>

Hi folks,

I use HTTP::Daemon and fork another process in order to communicate with
a client. But since clients can suddenly point their browsers somewhere
else, the connection can be terminated. In such a case, on the server
side, I would like to terminate the (spawned) process, as soon as I know
the client is no longer there. How can I check that? 

Any help apprechiated!
  
-- 
Michael
------------------------------------------------------------------------
Michael Schilli                                  Black Sun Interactive
                                                 50 Osgood Place
mschilli@blacksun.com                            San Francisco, CA 94133


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

Date: 23 May 1997 18:30:55 GMT
From: lusol@turkey.cc.Lehigh.EDU
Subject: Re: if string in list ??
Message-Id: <5m4nov$i7g@fidoii.cc.Lehigh.EDU>

     Abigail wrote in article <EAGDHK.EpM@nonexistent.com> :
>
>On 19 May 1997 17:49:22 -0400, Michael Mellinger wrote in
>comp.lang.perl.misc URL: news:v5ck9kvqgil.fsf@panix2.panix.com:
>++ 
>++ Is there a simple way to determine if a value is in a list?  I figure
>++ that this should be a one liner.
>++ 
>++ @a=('one','two','three');
>++ 
>++ while(<>) { 
>++ 
>++   ($f1,$f2,$f3)=split(',', $_);
>++   if ( $f2 in @a ) {  # How do I do this?
>++      print "Hello world\n";
>++   }
>
>
>I think that was answered here only a few days ago.
>
>Grep for grep in your man page.
>
>
>Abigail

Here are some generic list functions I find useful.  And now that I revisit
them, I see that lsearch needs some work )-:


# List functions.

sub ldifference {		# @d = ldifference \@l1, \@l2;

    my($l1, $l2) = @ARG;
    my %d;
    @d{@$l2} = (1) x @$l2;
    return grep(! $d{$ARG}, @$l1);

} # end ldifference

sub lintersection {		# @i = lintersection \@l1, \@l2;

    my($l1, $l2) = @ARG;
    my %i;
    @i{@$l1} = (1) x @$l1;
    return grep($i{$ARG}, @$l2);

} # end lintersection

sub lsearch {			# $o = lsearch $regexp, @list;

    # Search the list using the supplied regular expression and return it's 
    # ordinal, or -1 if not found.

    my($regexp, @list) = @ARG;
    my($i);

    for ($i=0; $i<=$#list; $i++) {
        return $i if $list[$i] =~ /$regexp/;
    }
    return -1;

} # end lsearch

sub lunion {			# @u = lunion \@l1, \@l2;

    my($l1, $l2) = @ARG;
    my %u;
    @u{@$l1,  @$l2} = 1;
    return keys %u;

} # end lunion

1;


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

Date: Fri, 23 May 1997 14:33:11 -0400
From: Bill Mooney <wmooney@voicenet.com>
Subject: input record separator
Message-Id: <Pine.SUN.3.96.970523141959.21982A-100000@omni1>

I am having a problem in which I want to read the STDIN until I read a
newline and then I want to slurp the rest of the file into a string. The
problem is that I can read the header information but then having trouble
loading a variable with the rest of the file. If anyone could give me any
help, I would sure appreciate it. 

Here's the code:

#!/usr/local/bin/perl

%header = ();
 
foreach $line (<STDIN>) {
   chop($line);
 
  #if line is blank, get out of loop
   if (length($line) == 0) {
      undef $/;                    
      $message = <STDIN>;      #  <---PROBLEM: not slurping rest of STDIN
      last;
   }

   # Load hash with header info
   ($hdr_name, $hdr_val) = split (/[: ]/, $line, 2);
   $header{"$hdr_name"} = $hdr_val;
}

exit(0);

BTW.  this is perl 5.003

Thanks in advance
-Bill



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

Date: 23 May 1997 18:37:00 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: Looking for sh to perl convert program
Message-Id: <5m4o4c$2kn$1@news.netusa.net>

Zenin  <zenin@best.com> wrote:
>Ken Hargreaves <ken@zadall.com> wrote:
>> Is there any kind of utility to convert bourne shell scripts to perl
>> scripts? Thanks.
>	#!/usr/local/bin/perl
>	system <<"EndOfBourneScript";
>		your bourne script goes here
>	EndOfBourneScript
>
>Actually, I got this from Randal when I asked this question. ;-P

It has some problems. Certain obscure cases of here documents in 
"your bourne script" will break it. You will probably have better
luck with

	#!/usr/local/bin/perl
	$/=undef;
	$script=<DATA>;
	exit((system $script)/256);
	__END__
	your bourne script goes here

Passing an argument list is left as an exercise for the reader.

Elijah
------
nesting scripts using this technique is much easier, you will note


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

Date: 23 May 1997 12:46:24 -0700
From: kendall shaw <kshaw@plight.lbin.com>
Subject: making new syntax (switch statement)
Message-Id: <52aflmhsz3.fsf@plight.lbin.com>


Is it possible to make a switch statement?

Going on the idea of:

for($asdf) {
	/abc/ && do { print "abc\n"; last;};
	/def/ && do { print "def\n"; last;};
}

and reading about prototypes, I thought maybe sompthing like:

sub switch($&) {
	eval( for($_[0]) $_[1]);
}

Don't kill me please.


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

Date: Fri, 23 May 1997 00:52:01 -0400
From: Clinton Herget <herget@iag.net>
Subject: Newcomer With Problem (Creating HTML File)
Message-Id: <33852271.7DAC@iag.net>

Hi. I am just beginning to learn Perl, as I need to use CGI with my
webpages. To make a long story short, I have a perl CGI script that
creates HTML files on the server. Well, it is supposed to. The script
runs without error, except no file is created. I belive this is the line
of code that creates the file: 

open(HTML, ">$page_dir$pagename\.html") || die "I can't create that
file\n";

Can anybody see anything wrong with that? I looked in my Perl book and
it looks okay to me. I have triple-checked the directories. Somebody
said it might be file permissions are the problem, but I am trying to
run it on an NT server, which doesn't use them. Any help you could give
me would be appreciated.


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

Date: Fri, 23 May 1997 08:42:14 -0600
From: Russell_Schulz@locutus.ofB.ORG (Russell Schulz)
Subject: Re: Newsreader in Perl
Message-Id: <19970523.084214.6W7.rnr.w164w@locutus.ofB.ORG>

Kurt Koller <kk@minimalist.com> writes:

> Anyone have a code fragment or more of a basic NNTP newsreader in perl? 
> Nothing fancy.  Anyone know?

there are two that I know of:

brn - ftp.ee.umanitoba.ca:/pub/msdos/waffle/brn*
prn - [no ftp address known; author is tshiono@cv.sony.co.jp ]
-- 
Russell_Schulz@locutus.ofB.ORG  Shad 86c


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

Date: Fri, 23 May 1997 16:17:07 -0500
From: Eric Foster-Johnson <johnsone@camax.com>
To: Bob Shair <rmshair@uiuc.edu>
Subject: Re: NT Perl limitations... permanent?
Message-Id: <33860953.13D8@camax.com>

Bob Shair wrote:
> 
> I've a client trying to move some applications written
> in Perl to NT.  The NT Perl interpreter we've found,
> Perl-Win32 at activeware.com, seems to be missing a
> number of features we've been using in OS/2, of which
> the most important is fork(!).
> 
> Is this a temporary restriction?  This could be a
> show-stopper! (yeah, break my heart, it would, NOT)
> --
> Bob Shair                          Open Systems Consultant
> 1018 W. Springfield Avenue         rmshair@uiuc.edu
> Champaign, IL 61821                217/356-2684
> < Not employed by or representing the University of Illinois >

Bob,

As far as I am aware, Windows (of any flavor) does not
support fork(). But, there should be a Win32::Process
module, where you can call the Create() subroutine
to launch a Windows process. The Perl for Win32
should have documentation on this call. In addition,
chapter 6 of my book, Cross-Platform Perl, discusses
process-launching on Unix and Windows.

Hope this helps,
-Eric

-- 
Eric Foster-Johnson http://www.pconline.com/~erc
CAMAX, SDRC's CAM Business
7851 Metro Parkway         phone: +1 612 854 5300 fax: +1 612 854 6644
Minneapolis, MN 55425 USA  johnsone@camax.com


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

Date: 23 May 1997 20:41:34 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: OS/2: Locales / I18N problem: What to do?
Message-Id: <5m4vdu$4f6$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Koos Pol
<Koos_Pol@nl.compuware.com.NO_JUNK_MAIL>],
who wrote in article <5m489g$mdj@news.nl.compuware.com>:
> 
> On my OS/2 Warp box, I get the following diagnostics on running programs. Who
> can tell me what to do? 

As usual, if everything else fails, try to read the docs (at last!).

Ilya


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

Date: Fri, 23 May 1997 17:26:14 GMT
From: "robert c. combs" <xrcc0494@dcaca037.ca.boeing.com>
Subject: Re: RCS-style version mgmt implementation in Perl?
Message-Id: <3385D336.41D7@dcaca037.ca.boeing.com>

Abigail wrote:
> 
> On 22 May 1997 00:13:14 -0400, Paul D. Smith (psmith@baynetworks.com) wrote
> in comp.lang.perl.misc
> <URL: news:p5enb0nnz9.fsf@baynetworks.com>:
> ++ Uh, I think it'd probably be faster and easier to port RCS itself to the
> ++ Mac.  Heck, maybe someone's already done it (try asking on
> ++ gnu.utils.bug).
> ++
> ++ Aside from a working diff there's nothing in RCS that's very
> ++ system-dependent.  If it works on DOS (and it does) it could surely work
> ++ on Macs.
> 
> The O'Reilly book about RCS ("Applying RCS and SCCS" by Bolinger &
> Bronson) mentions ports to DOS, Windows/NT and OS/2, but I can't
> find a reference to Mac.
> 
> Abigail
There is a mac version of RCS (and CVS also) I'm not sure where I found
it, but I think it was in a GNU archive.

-bob


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

Date: 23 May 1997 19:46:55 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: script optimization of grep -c
Message-Id: <5m4s7f$b35$2@dartvax.dartmouth.edu>

In article <5ltcgi$l3m$1@mark.ucdavis.edu>
ez041407@chip.ucdavis.edu (Eric Finley) writes:

> #!/usr/intel/bin/perl -w
> open(FILE, $ARGV[1]) || die "Could not open $ARGV[1]\n$!\n";
> $i = 0;
> while(<FILE>) {
>     $i++ if (/$ARGV[0]/)
> }
> print "$ARGV[0] found $i times in $ARGV[1]\n"

Oo, here's one way to optimize it.
Since $ARGV[0] has the same value everytime you do the match:
$i++ if (/$ARGV[0]/o);

Chipmunk


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

Date: 23 May 1997 19:45:35 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: script optimization of grep -c
Message-Id: <5m4s4v$b35$1@dartvax.dartmouth.edu>

In article <5ltcgi$l3m$1@mark.ucdavis.edu>
ez041407@chip.ucdavis.edu (Eric Finley) writes:

> I frequently have to do a "grep -c <word> <file>" on very large (~100Meg)
> files and wrote this script to hopefully do it faster, grep take >5 min.
> Is there any way to optimize this code?

How does your script as it is right now compare to grep in terms of
speed?

Chipmunk


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

Date: 23 May 1997 18:55:34 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: split'\|'; except when preceded by '/'
Message-Id: <5m4p76$jbs$2@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Dan Boorstein 
<danboo@ixl.com>],
who wrote in article <3384986C.4A19A768@ixl.com>:
> Hello All,
> 
> Here is the problem.
> 
>   A string with: no linefeeds
>                  fields separated by |
>                  nested |'s are escaped with \ (i.e., \|)
> 
> I want to split this string on unescaped |'s, removing
> the \'s preceding the escaped |'s. I thought this would
> be a 2 line split-regex block, but has turned into
> something much less elegant which I pieced together
> from various FAQ's and Dejanews articles. Behold:

Note that your problem is most probably not what you described, since
your string may contain something like \\|, which you _most probably_
*want* to split on.

Note also that _lookbehind_ discussed in other followups *is*
available in bleeding-edge installations (the patch for this - with
syntax (?<=...) and (?<!...) - was issued approx. a week ago).

Ilya


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

Date: 23 May 1997 18:50:36 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: The perl way? What is it really?
Message-Id: <5m4ots$jbs$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Abigail
<abigail@fnx.com>],
who wrote in article <EALu75.18I@nonexistent.com>:
> In a sense this is true. A break/continue/next/last is nothing more
> than a goto, and we'll all know what Dijkstra said: Goto considered
> harmful.

A break/continue/next/last is *MUCH* more than a goto.

Ilya


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

Date: Fri, 23 May 1997 11:41:28 -0700
From: Rajaram Balasubramanian <rajaram@corp.sgi.com>
Subject: Want to delete a line from a file using a PERL script
Message-Id: <3385E4D8.41C6@corp.sgi.com>

Hi,


I know how to append a line to a file.

ex :
open(PHONE,'>>data');
print PHONE "hello there\n";

I would like to know how to REMOVE a LINE from a FILE.


-- 

Regards
Rajaram Balasubramanian
Email : rajaram@corp.sgi.com


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

Date: 23 May 1997 18:59:22 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Want to delete a line from a file using a PERL script
Message-Id: <5m4pea$ipf@fridge-nf0.shore.net>

Rajaram Balasubramanian (rajaram@corp.sgi.com) wrote:

: I would like to know how to REMOVE a LINE from a FILE.

Skip it: next if $line eq 'whatever';

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 22 May 1997 12:54:59 -0400
From: Owen Taylor <owt1@cornell.edu>
Subject: Re: yet another perl regex Q
Message-Id: <lz206z8n18.fsf@cu-dialup-1222.cit.cornell.edu>


allen@gateway.grumman.com (John L. Allen) writes:

> I know this is probably explained in the Hip Owls book somewhere, but
> I don't have it handy, so please suffer my ignorance.  Why doesn't
> either of the following replace the *last* three blanks in $_ with 'bar'?
> 
> 	perl -e '$_="foo      xxx"; s/ {3}(?=.*)$/bar/; print'
> 
> 	perl -e '$_="foo      xxx"; s/ {3}(?=.*?)$/bar/; print'

s/\ {3}         # 3 blanks
  (?=.*)        #     immediately followed by anything (or nothing)
  $             # and immediately followed by the end of the line
 /bar/x;         

Because the (?= ) construct is zero width, the $ is interpreted
as coming immediately after '\ {3}'.

So, as a next try, we have

s/\ {3}	        # 3 blanks
  (?=.*         #     immediately followed by anything (or nothing)
   $)           #        then the end of the line
 /bar/x;         

But ... this will match the _first_ set of three spaces. Finally, then:

s/\ {3}	        # 3 blanks
  (?=[^\ ]*     #     immediately followed by some non-spaces (or nothing)
   $)           #        then the end of the line
 /bar/x;         

Hope this helps,
                                        Owen Taylor


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

Date: Fri, 23 May 1997 13:54:51 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: yet another perl regex Q
Message-Id: <3385E7FB.4DCCD7B6@gpu.srv.ualberta.ca>

Andrew Johnson wrote:
> 
> 
> #!/usr/bin/perl -w
> $_ = "123    45  67";
> substr($_,rindex($_,"   "),3)="XXX";
> print;
> 

oops, forget failure checking
should be:

#!/usr/bin/perl -w
$_="123    45  67";
substr($_,$off,3)="XXX" if ($off=rindex($_,"   "))>-1;
print;

regards
andrew


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

Date: 23 May 1997 20:53:23 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: yet another perl regex Q
Message-Id: <5m5043$mbq$1@dartvax.dartmouth.edu>

In article <5m1nc0$jee@gateway.grumman.com>
allen@gateway.grumman.com (John L. Allen) writes:

> I know this is probably explained in the Hip Owls book somewhere, but
> I don't have it handy, so please suffer my ignorance.  Why doesn't
> either of the following replace the *last* three blanks in $_ with 'bar'?
> 
>         perl -e '$_="foo      xxx"; s/ {3}(?=.*)$/bar/; print'
> 
>         perl -e '$_="foo      xxx"; s/ {3}(?=.*?)$/bar/; print'
> 
> and _don't_ tell me it's because of the .* because .+ doesn't work either.
> 
> I expected backtracking to occur from the end of $_ until three blanks
> are found.  Why doesn't it work?

Because it doesn't match anything in the string.
(Note that neither substitution affects $_)

This gives a clue:
perl -e '$_="foo      xxx"; s/ {3}(?=.*?$)/bar/; print'
which prints:
foobar   xxx

As does this:
perl -e '$_="foo      "; s/ {3}(?=.*?)$/bar/; print'
which prints:
foo   bar

And this, from the perlre manpages, explains the problem:
     (?=regexp)
               A zero-width positive lookahead assertion.  For example,
               /\w+(?=\t)/ matches a word followed by a tab, without
               including the tab in $&.

Note: zero-width
Thus, your regexp, / {3}(?=.*?)$/, matches 3 spaces at the end of the
string, and the three spaces are followed by any number of characters
(possibly zero).  I'm not sure if I can explain that clearly - the key
to understanding the problem is understanding what your regexp matches.
"   xxx" is not matched because the three spaces, although they are
followed by any number of characters, are not at the end of the string.
"   " is matched because the three spaces are at the end of the string,
and they are followed by any number of characters (in this case zero).

Either of these will work:

perl -e '$_="foo      xxx"; s/ {3}([^ ]*)$/bar$1/; print'
which matches 3 spaces, any number of non-spaces, and the end of
string, replaces the spaces with 'bar', and replaces the non-spaces
with themselves.

perl -e '$_="foo      xxx"; s/ {3}(?=[^ ]*$)/bar/; print'
which matches 3 spaces that are followed by any number of non-spaces
and the end of string, replaces the spaces with 'bar', but doesn't
actually match the non-spaces.

Chipmunk


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

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

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