[6362] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 984 Volume: 7

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 20 21:17:17 1997

Date: Thu, 20 Feb 97 18:00:22 -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           Thu, 20 Feb 1997     Volume: 7 Number: 984

Today's topics:
     Re: ?simple? question (Tad McClellan)
     Are 'or' and '||' *really* equivalent? (Cal...)
     Re: Are 'or' and '||' *really* equivalent? (Abigail)
     Re: Are 'or' and '||' *really* equivalent? (Andrew M. Langmead)
     Re: backreferences in a character class? (Tad McClellan)
     Checking for redirection (file input) (J. Mello)
     Choosing the best method for finding an item on a list. (Alexandre Bento Freire)
     Re: dbmopen() dbmclose() using CGI variables <khera@kcilink.com>
     Re: Deleting files in perl <khera@kcilink.com>
     Re: efficiency of many fixed strings vs one regex (Rahul Dhesi)
     Re: efficiency of many fixed strings vs one regex (Ilya Zakharevich)
     efficiency with while? <yingchen@fir.fbc.com>
     Extensions: run-time or compile-time??? eric@mindvox.com
     Re: finding full path to file name (Jason C Austin)
     How to send two HTML pages from a CGI script ((James Ringrose))
     Re: How to spam - legitimately <KErskine@Software-By-Ragazzi.com>
     Re: How to spam - legitimately <brett@speedy.speakeasy.org>
     MacPerl Questions (JALOTTA)
     Re: Newbie ODBC module question <billc@tibinc.com>
     Question about sorts (Jete Software Inc.)
     Re: Question about sorts (Dave Thomas)
     Re: Quick technique to split a words into chars? <billc@tibinc.com>
     Re: Quick technique to split a words into chars? (Tad McClellan)
     Re: Scoping problem using my() [kinda long] (Ilya Zakharevich)
     Re: tail -f in perl <tchrist@mox.perl.com>
     undump <dedens@pi.net>
     Re: unlink on Win95 ("John Dallman")
     Re: why can't "system" return a long? (Jason C Austin)
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: Thu, 20 Feb 1997 17:40:41 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: ?simple? question
Message-Id: <pdnie5.v65.ln@localhost>

Hayes, Dianne (dianne.hayes@systecinc.com) wrote:

: I do not know much about perl and think that it might be able do what I   
: need.  I was wondering, though, if someone could confirm this before I   
: delve into the llama and camel books to figure out how to do it.


I think you should begin delving  ;-)


: Here's what I need to do:

: I have two files with (many) rows of data in them.  They were originally   
: supposed to be one file, but due to legacy system constraints, the data   
: had to be split into two files.  I need to recombine the data in some   
: way.  I know that there are three key fields in each file that will   
: signify a match for the data.  Is there some way to use perl to match the   
: rows, combine them, and put them into a new file?


This is the kind of stuff Perl was invented to do.


: I am not looking for a complete solution (as I am stubborn and like to   
: know how things work), but I would like some sort of confirmation that it   
: is possible (and maybe a hint to lead me in the right direction).


Probably need to start with regexs (perlre and perlop man pages) to
help recoginize the 'keys'.


: Anybody out there have any ideas?


Go for it!


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Thu, 20 Feb 1997 17:11:21 -0600
From: cjewell@cellnet.com (Cal...)
Subject: Are 'or' and '||' *really* equivalent?
Message-Id: <856479847.19266@dejanews.com>

It seems that 'or' and '||' don't function as advertised. Or, more
accurately, I don't understand what appears to be a subtle difference
between 'or' and '||'.

>From the Turquoise Camel, pg 94:

    Logical and, or, not, and xor

    As more readable alternatives to &&, ||, and !, Perl provides the
    and, or and not operators. The behavior of these operators is
    identical -- in particular, they shortcircuit the same way

    [typos mine, inconsisent use of series comma theirs].

The perlop man page tells us:

    The || and && operators differ from C's in that, rather than returning
    0 or 1, they return the last value evaluated. [...]

    As more readable alternatives to && and ||, Perl provides ``and'' and
    ``or'' operators (see below). The short-circuit behavior is identical.
    The precedence of ``and'' and ``or'' is much lower, however, so that
    you can safely use them after a list operator without the need for
    parentheses:

Ok, I'm using 'or' but I'm not using it a list context (at least I don't
think I am).

Here's an example:

#!/bin/perl -w

my ($falseValue, $trueValue, $result);

$falseValue = 0;
$trueValue = 1;

$result = $falseValue || $trueValue;
print "\$result is $result\n";
# yields         $result is 1

$result = $falseValue or $trueValue;
print "\$result is $result\n";
# yields         $result is 0

I don't get it.

--
Cal...

cjewell@cellnet.com

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Fri, 21 Feb 1997 00:45:33 GMT
From: abigail@ny.fnx.com (Abigail)
Subject: Re: Are 'or' and '||' *really* equivalent?
Message-Id: <E5xGry.223@nonexistent.com>

On Thu, 20 Feb 1997 17:11:21 -0600, Cal... wrote in comp.lang.perl.misc:
++ It seems that 'or' and '||' don't function as advertised. Or, more
++ accurately, I don't understand what appears to be a subtle difference
++ between 'or' and '||'.
++ 
++ From the Turquoise Camel, pg 94:
++ 
++     Logical and, or, not, and xor
++ 
++     As more readable alternatives to &&, ||, and !, Perl provides the
++     and, or and not operators. The behavior of these operators is
++     identical -- in particular, they shortcircuit the same way
++ 
++     [typos mine, inconsisent use of series comma theirs].
++ 
++ The perlop man page tells us:
++ 
++     The || and && operators differ from C's in that, rather than returning
++     0 or 1, they return the last value evaluated. [...]
++ 
++     As more readable alternatives to && and ||, Perl provides ``and'' and
++     ``or'' operators (see below). The short-circuit behavior is identical.
++     The precedence of ``and'' and ``or'' is much lower, however, so that
++     you can safely use them after a list operator without the need for
++     parentheses:
++ 
++ Ok, I'm using 'or' but I'm not using it a list context (at least I don't
++ think I am).
++ 
++ Here's an example:
++ 
++ #!/bin/perl -w
++ 
++ my ($falseValue, $trueValue, $result);
++ 
++ $falseValue = 0;
++ $trueValue = 1;
++ 
++ $result = $falseValue || $trueValue;
++ print "\$result is $result\n";
++ # yields         $result is 1
++ 
++ $result = $falseValue or $trueValue;
++ print "\$result is $result\n";
++ # yields         $result is 0
++ 
++ I don't get it.

To quote your quote:
  "The precedence of ``and'' and ``or'' is much lower"

In particular, the precedence of "and" and "or" is lower than of "=".

Compare:
$result = ($falseValue || $trueValue);
$result = ($falseValue or $trueValue);

That should give the same.
$result = $falseValue or $trueValue;
is equivalent with:
($result = $falseValue) || $trueValue;


Abigail




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

Date: Fri, 21 Feb 1997 01:13:49 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Are 'or' and '||' *really* equivalent?
Message-Id: <E5xI31.6oH@world.std.com>

cjewell@cellnet.com (Cal...) writes:
>$falseValue = 0;
>$trueValue = 1;

>$result = $falseValue || $trueValue;
>print "\$result is $result\n";
># yields         $result is 1

>$result = $falseValue or $trueValue;
>print "\$result is $result\n";
># yields         $result is 0

>I don't get it.

"or" is a lower precedence than "=".  With some redundance parens,
this makes the first:

      $result = ($falseValue || $trueValue);

(Evaluate $falseValue, if false, evaluate $trueValue. Assign the
result to $result)

and the second:

      ($result = $falseValue) or $trueValue;

(Assign $falseValue to $result, if false, evaluate $trueValue and
throw the result away.)
-- 
Andrew Langmead


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

Date: Thu, 20 Feb 1997 17:36:58 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: backreferences in a character class?
Message-Id: <q6nie5.v65.ln@localhost>

Dave Thomas (dave@fast.thomases.com) wrote:
: On Thu, 20 Feb 1997 14:53:30 -0600, Tad McClellan <tadmc@flash.net> wrote:
: > Brett Denner (dennerbw@lmco.lmtas.com) wrote:
: > 
: > Hi Brett.
: > 
: > : Can I use a backreference in a character class?
: > 
: > : I need to do a pattern match with the following format:
: > 
: > :     $_ = q/ "Hi, 'Fred', or whoever you are." /;
: > 
: > :     /(["'])([^$1]*)$1/ and $string = $2;
: > 
: > 
: > 
: > /(["'])([^\1]*)\1/ and $string = $2;


: Bzzzt!^H^H^H^H^H^H    ;-) 

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

$_ = q/ "Hi, 'Fred', or whoever you are." /;

/(["'])([^\1]*)\1/ and $string = $2;
print "$string\n";


# quoted the other way around
$_ = q/ 'Hi, "Fred", or whoever you are.' /;

/(["'])([^\1]*)\1/ and $string = $2;
print "$string\n";
--------------


It does what he wanted...



: Aren't character classes set up at regex compile time?


Hmmm. I dunno. Does Jeffrey's book say when it happens? I still
haven't managed to get a copy.


: Certainly

:    my $str = 'abcdabcd';
:    $str =~ s/(a).*[\1]/XXX/;
:    print "$str\n";

: doesn't work.


Sure doesn't. Looks like you're right. However...


: However, you could try using something like (untested)

:     /['"](.*?)\1/ and $string = $1;


: However, this approach (and the original) won't work with escape characters
                          ^^^^^^^^^^^^^^^^

???

What I posted _does_ seem to work. 

What's going on here?

(not a rhetorical question. Here's a chance to actually _learn_
 something on c.l.p.m  ;-)


: in the string.


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 20 Feb 1997 23:00:51 GMT
From: kingjamm@u.washington.edu (J. Mello)
Subject: Checking for redirection (file input)
Message-Id: <5eil33$gj2@nntp1.u.washington.edu>

I'm currently having a hard time trying to find out if a file is being
redirected via a "<" into my shell. For instance...

   foo.perl < testfile

If the testfile is being redirected in, I want to just process it, but
otherwise I want to interactively call an editor so the user can enter the
data in.  I've tried searching for a "<" in @ARGV, but for some reason,
arguments to your shell don't include pipes or redirections. I'm not sure
if what to test for in this case, as STDIN is open, and and if you do
something like "if($_ = <STDIN>)", the script just reads from stdin.

Just for further info, I'm using the Getopt package...

-Thanks
-James Mello

ps Please mail me at james@picco.com.... I'm not always checking my
incoming mail to my .edu account




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

Date: Thu, 20 Feb 97 21:51:15 GMT
From: hawk@ip.pt (Alexandre Bento Freire)
Subject: Choosing the best method for finding an item on a list.
Message-Id: <5eik61$djr@barracuda.ip.pt>

I need to decide the best to find an item on a list.

 As far as I kwnon, I can use:
  1. for () if
  2. grep
  3. Associative array. 

 The 1st seems me the faste one, but require more code.
 The 2nd doesn't stop, after finding.
 The 3rd requires hashing, witch creates an overhead.

 The best solution would be a stoping grep, after finding.
 Or a method of using Associative array that didn't hast
 the all array.

 Many times, I just want to know, if the string is there, without
 caring is index on the list.

 Could you give me some pointers, and identifing if also runns on perl 4.
 'On some machines I have to use perl 4'.


                                                Thanks
                                                        Alexandre
 


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

Date: 20 Feb 1997 18:50:11 -0500
From: Vivek Khera <khera@kcilink.com>
Subject: Re: dbmopen() dbmclose() using CGI variables
Message-Id: <x7raibf364.fsf@kci.kciLink.com>

what are the file permissions on the file you're trying to open from
your CGI program?  are they set such that the user-id of the httpd
process can write to it?  if not, then that's your problem.
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D.                Khera Communications, Inc.
Internet: khera@kciLink.com       Rockville, MD       +1-301-258-8292
PGP/MIME spoken here              http://www.kciLink.com/home/khera/


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

Date: 20 Feb 1997 18:48:58 -0500
From: Vivek Khera <khera@kcilink.com>
Subject: Re: Deleting files in perl
Message-Id: <x7sp2rf385.fsf@kci.kciLink.com>

try the unlink function.

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D.                Khera Communications, Inc.
Internet: khera@kciLink.com       Rockville, MD       +1-301-258-8292
PGP/MIME spoken here              http://www.kciLink.com/home/khera/


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

Date: 20 Feb 1997 23:13:43 GMT
From: dhesi@76864516.trackme.com (Rahul Dhesi)
Subject: Re: efficiency of many fixed strings vs one regex
Message-Id: <5eilr8$8oh@samba.rahul.net>

Thanks to all.  I was looking for, and am still looking for, some
theoretical basis for how to select pattern-matching strategies.   I
will look for the book by Jeffrey Friedl.
-- 
Rahul Dhesi <dhesi@spams.r.us.com>
a2i communications, a quality ISP with sophisticated anti-junkmail features
*** Now featuring Strategy C for junk-mail-proof News postings ***
|| "please ignore Dhesi" -- Mark Crispin <mrc@CAC.Washington.EDU> ||


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

Date: 21 Feb 1997 01:07:00 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: efficiency of many fixed strings vs one regex
Message-Id: <5eisfk$l7u$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Jim Anderson 
<jander@jander.com>],
who wrote in article <d8tvsha1.fsf@jander.com>:
> > > Is it better if I combine them into the following?
> > > 
> > >    /\@(somedomain|anotherdomain|yetanother|fourthdomain)\.com/ && &found;
> > 
> > a) All the questions like this one should be solved by using
> > Benchmark.pm.
> 
> According to Jeffrey, p.284, the Benchmark module in not appropriate
> for use with regexps due to "problems" with $&. He gives an example of
> what he uses to Benchmark.

Jeffrey did a remarkable job documenting Perl's
weaknesses. Unfortunately, Perl is not M$'s product, thus his work
would be appreciated by future generation. Not for what is true
there, but for what is NO LONGER true there.

In particular, I could not find anything $&-related in anything
Benchmark-related in recent perls.

Ilya


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

Date: Thu, 20 Feb 1997 16:19:17 -0500
From: Ying Chen <yingchen@fir.fbc.com>
Subject: efficiency with while?
Message-Id: <330CBFD5.41C67EA6@fir.fbc.com>

Hi all -
 
Stil pretty new to perl programming -
Can someone suggest something more efficient than
doing something like this:

open (FILEIN, $very_large_file_name);

while (<FILEIN>) {
   @lines = (@lines, $_);
}

I suppose what I really wanted to do is to extract
all the file input all at once then process it...
any idea would be very much appreciated...

Thanks in advance -

Ying


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

Date: Thu, 20 Feb 1997 18:01:41 -0600
From: eric@mindvox.com
Subject: Extensions: run-time or compile-time???
Message-Id: <856482562.20958@dejanews.com>

 I'm using the perl compiler to generate 'bytecode' and I want to have
all of my methods and variables ready to use at compile-time so they'll
actually make it into the bytecode. Everything pretty much works, except
for a few methods from a particular extension.

 I assume that since this extension is bootstrapped, methods aren't
looked up until run-time. My question is, Is there ANY way to look these
methods up at compile-time? I tried building a new perl with the
extension linked statically but that didn't seem to work. Do I have to
change the syntax of the module ( bootstrap($module) ) to something else?

 Am I misunderstanding the way extensions work? Is it impossible to
achieve this?

thanks a lot!

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 19 Feb 1997 18:21:39 GMT
From: jason@wisteria.cs.odu.edu (Jason C Austin)
Subject: Re: finding full path to file name
Message-Id: <JASON.97Feb19132139@wisteria.cs.odu.edu>

In article <JASON.97Feb19125642@wisteria.cs.odu.edu> jason@wisteria.cs.odu.edu (Jason C Austin) writes:
=> 	I would use chdir() and then pwd:

	A little bug in that subroutine.  It didn't handle files off
the root directory right.  Here's the corrected version.

sub getpath {
    $_=$_[0];
    my ($dirname, $basename);

    -e $_ || return(0);
    if (-d $_) {
	$dirname=$_;
	$basename=0;
    } else {
	if (!(($dirname,$basename)=m:^ (.* /) ([^/]+) $:x)) {
	    $basename=$_;
	    $dirname='.';
	}
    }
    chomp($pwd=`cd $dirname; pwd`);
    if ($basename) {
	if ($pwd eq '/') {
	    return("/$basename");
	} else {
	    return("$pwd/$basename");
	}
    } else {
	return("$pwd");
    }
}
--
Jason C. Austin
austin@visi.net


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

Date: Fri, 21 Feb 1997 01:35:37 GMT
From: jringrose@worldnet.att.net ((James Ringrose))
Subject: How to send two HTML pages from a CGI script
Message-Id: <330cfbe4.6685770@news.tiac.net>

Hi,

My Web site has a series of scripts that access a data base and build
an html page to allow users to select a particular record.

Because of the file size this takes a few seconds to run, during which
their browsers give no indication of progress or anything else. As a
result they tend to get impatient and click away at the URL,
effectively stopping the script from completing.

Is there any way of sending a page at the beginning of the script,
followed by a second page when the data has been parsed?

I tried writing the first page then the second:

	print "Content-type: text/html\n\n";
	print "<HTML><HEAD></HEAD>\n";
	print "<BODY>\n";
	print "Stand BY";
	print "</BODY>\n";
	print "</htm>\n";

flush(STDOUT);

	print "Content-type: text/html\n\n";
	print "<HTML><HEAD></HEAD>\n";
	print "<BODY>\n";
	print "Stand BY";
	print "</BODY>\n";
	print "</htm>\n";

But this does not work. I assume because the http: request is all done
once the first {print "</htm>\n";} has been sent.

Any suggestions / hints.

Regards
James Ringrose :-)
=============================================================== 
Email: jringrose@tiac.net 
=============================================================== 








Regards
James Ringrose :-)
=============================================================== 
Email: jringrose@tiac.net 
=============================================================== 


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

Date: Thu, 20 Feb 1997 14:39:02 -0800
From: "Kevin B. Erskine" <KErskine@Software-By-Ragazzi.com>
To: chris@ixlabs.com
Subject: Re: How to spam - legitimately
Message-Id: <330CD286.7373@Software-By-Ragazzi.com>

You might try what we use.

We have a what's new page and when we update this it automatically
e-mails everyone who wants to know

               The NetMind's URL-minder keeps track of Web pages and
other resources on the
               World Wide Web, and sends you e-mail whenever your
personally registered
               resources change. You can have the URL-minder keep track
of any Web resource
               accessible via HTTP, FTP, or GOPHER -- anything you like!

		http://www.netmind.com/URL-minder/

Just a thought.

Chris Schoenfeld wrote:
> =

> We have a client who has 18,000 registered web site users.
> =

> They want the users to have the ability te request certain daily data
> sent to them via email (they give us the address when they register).
> =

> All of these emails will be different based on user preferences.
> =

> What is the most efficient way of sending these out without calling
> sendmail 18,000 times?
> =

> We are using Perl5 on a Solaris box.
> =

> --
> Chris Schoenfeld
> IX Development Laboratories
> Santa Rosa, California
> (707)-543-8030 Ext. 12

-- =

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Kevin B. Erskine	-   KErskine@Software-By-Ragazzi.com

Software By Ragazzi	-   Sales@Software-By-Ragazzi.com
  			-   Support@Software-By-Ragazzi.com

Visit our web page	-   http://www.Software-By-Ragazzi.com/

   "Begin a new era of productivity; =

	     leave the mundane aspects of programming to us!"=A9
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


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

Date: 20 Feb 1997 15:27:46 -0800
From: Brett McCormick <brett@speedy.speakeasy.org>
Subject: Re: How to spam - legitimately
Message-Id: <7vohdf3vnx.fsf@speedy.speakeasy.org>


You can invoke sendmail in SMTP mode and feed those commands to it
(probably better than making a net connection)

Valdis Kletnieks <valdis.kletnieks@vt.edu> writes:
> 
>  MAIL FROM:<whatever>
>  RCTP TO:<user1@site1.com>
>  DATA
>  From:
>  To:
>  Date:
>  Subject: 
> 
>  Your message here...
>  .
>  MAIL FROM:<whatever>
>  RCTP TO:
> 
> and so on...One connection, 18,000 messages.  This will
> of course mean your program needs to learn to speak SMTP.
> If you'd using Perl, I think there's a SMTP module to help...


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

Date: 20 Feb 1997 23:11:30 GMT
From: jalotta@aol.com (JALOTTA)
Subject: MacPerl Questions
Message-Id: <19970220231100.SAA10799@ladder02.news.aol.com>

Greetings.   Just 2  questions.

1.   How can I use MacPerl and the MPW window to write stdout to a
scrolling window.   For example.

: hello.pl
Hello World

: count.pl  < myinfile.dat
File myinfile.dat has 18 records


2.  I read the notes on droplets but I can't seem to get them to work with
regard to knowing the file droped apon them.  I save it as a droplet and I
look in $ARGV[0], by the file name doesn't seem to be there.


Thank you,

Joe Alotta
Just Another Perl Hacker From Way Backer


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

Date: Thu, 20 Feb 1997 19:53:18 -0500
From: Bill Cowan <billc@tibinc.com>
To: john.oharra@transquest.com
Subject: Re: Newbie ODBC module question
Message-Id: <330CF1FE.38E2@tibinc.com>

OHarra, John wrote:
> 
> I installed the ODBC module per the instructions, downloaded the new
> ODBC drivers from Microsoft and the latest version of PERL, and when I
> run the TEST.PL script, I get the following error:
> 
> Error: Parse exception
> 
> Where did I go wrong?
> 
> John OHarra
> TransQuest, Inc.
> mailto:john.oharra@transquest.com

Be careful to check Win32::ODBC revision doc regarding which build 30x
of Win32 Perl to use. I think the "Error: Parse exception" was happening
on mismatch of ODBC version and 30x build of Perl.

FYI: There was also a very recent announcement of a new Win32::ODBC
release you may want to check.

-- Bill
-----------------------------------------------------------------------
Bill Cowan <billc@tibinc.com>    Voice:919-490-0034   Fax:919-490-0143
Tiburon, Inc./3333 Durham-Chapel Hill Blvd Suite E-100/Durham, NC 27707


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

Date: 20 Feb 1997 11:23:10 -0500
From: jete@dgs.dgsys.com (Jete Software Inc.)
Subject: Question about sorts
Message-Id: <5ehtpe$bda@DGS.dgsys.com>



I have two classes of error messages which I need to sort numerically
by class. The class is denoted by a character attribute (V or R) and
then has a numeric value.
ex.
	"V1", V3", "R12", "V2", "R1"

and they serve as keys in the associative arry %ERROR_List

      foreach $key (sort mysort keys %ERROR_list) {
         print "$ERROR_list{$key}\n";
      }

sub mysort {
   my($letter_a, $letter_b);
   my($num_a, $num_b);

   $a =~ /(\w)(\d+)/;
   $letter_a = $1;
   $num_a = $2;

   $b =~ /(\w)(\d+)/;
   $letter_b = $1;
   $num_b = $2;

   if ($letter_a <=> $letter_b) { return; }
   if ($num_a <=> $num_b) { return; }
}

When I run it, I get the following message:

Sort subroutine didn't return a numeric value at Check_Forms.pl line 98, 
<IN> chunk 1.

Why??? 

-- Norman



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

Date: 21 Feb 1997 00:18:31 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: Question about sorts
Message-Id: <slrn5gpq9n.nvo.dave@fast.thomases.com>

On 20 Feb 1997 11:23:10 -0500, Jete Software Inc. <jete@dgs.dgsys.com> wrote:
> 
>    if ($letter_a <=> $letter_b) { return; }
                    ^^                    ^^   no value returned!
		    
>    if ($num_a <=> $num_b) { return; }
                                    ^^         no value returned
 
> When I run it, I get the following message:
> Sort subroutine didn't return a numeric value at Check_Forms.pl line 98, 
> <IN> chunk 1.


(see above)

Also remember that '<=>' is a numeric comparison operator.

How abount something like

   return ($letter_a cmp $letter_b) or ($num_a <=> $num_b);

The 'or' means that the numeric comparison only gets run if the alpha one
returns 0.

Dave



-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: Thu, 20 Feb 1997 19:49:25 -0500
From: Bill Cowan <billc@tibinc.com>
To: Premkumar Natarajan <pnataraj@emerald.tufts.edu>
Subject: Re: Quick technique to split a words into chars?
Message-Id: <330CF115.A01@tibinc.com>

Premkumar Natarajan wrote:
> 
> Is there a quick way to split words into chars, something like
> 
> @chars = choptochars($string);
> 
> Currently I am doing it using chop in a loop terminated at length of the
> string.
> 
> Thanks
> 
> Prem

What about doing split with empty pattern?

  DB<10> $a = 'abcd'

  DB<11> @chars = split(//, $a)

  DB<12> print join(',', @chars)
a,b,c,d
  DB<13>

-- Bill
-----------------------------------------------------------------------
Bill Cowan <billc@tibinc.com>    Voice:919-490-0034   Fax:919-490-0143
Tiburon, Inc./3333 Durham-Chapel Hill Blvd Suite E-100/Durham, NC 27707


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

Date: Thu, 20 Feb 1997 17:20:59 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Quick technique to split a words into chars?
Message-Id: <r8mie5.e35.ln@localhost>

Premkumar Natarajan (pnataraj@emerald.tufts.edu) wrote:
: Is there a quick way to split words into chars, something like 

: @chars = choptochars($string);


@chars = split //, $string;


: Currently I am doing it using chop in a loop terminated at length of the
: string.

: Thanks

You're welcome.

--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 21 Feb 1997 00:47:38 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Scoping problem using my() [kinda long]
Message-Id: <5eirba$kh2$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Doug Alcorn
<doug.alcorn@sonoco.com>],
who wrote in article <330a1697.21624751@news.conterra.com>:
>   DB<2> X fraction
>   DB<3> X fraction
>   DB<4> 

Do not use `X' unless you know what you are doing. Use `x' instead.
	x $fraction

Ilya



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

Date: 21 Feb 1997 00:30:13 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: tail -f in perl
Message-Id: <5eiqal$rs0$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Torfinn Keringen <tor@kmd.dk> writes:
:Hey, I some help,
:
:I have this script who makes logfiles, D0220 - D0221 - DYYMM and 
:so on, one each day.
:
:What I need is a script that work like tail -f, but in addition
:find out if there is a new file, if there is continue reading
:that file, else wait for a new file. 


/*
 * @(#) xtail.c 2.1 89/07/26 19:15:42
 *
 * Package:	xtail version 2
 * File:	xtail.c
 * Description:	main program
 *
 * Mon Jul 10 02:56:22 1989 - Chip Rosenthal <chip@vector.Dallas.TX.US>
 *	Original composition.
 */

#ifndef LINT
static char SCCSID[] = "@(#) xtail.c 2.1 89/07/26 19:15:42";
#endif

#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#define  INTERN
#include "xtail.h"

#ifdef M_XENIX
# undef  NULL
# define NULL 0
#endif


int sigcaught = 0;

SIGTYPE sigcatcher(sig)
int sig;
{
    /* extern SIGTYPE (*signal)(); */
    if ( sig == SIGQUIT )
	(void) exit(0);
    sigcaught = sig;
#ifdef STATUS_ENAB
    (void) signal(SIGINT,sigcatcher);
    (void) signal(SIGQUIT,sigcatcher);
#endif
}


main(argc,argv)
int argc;
char *argv[];
{
    int open_files_only, already_open, iteration, i;
    struct entry_descrip *entryp;
    struct stat sbuf;

    /* 
     * Initialize.
     */
    List_file.num = 0;
    List_dir.num = 0;
    List_zap.num = 0;
    Sorted = FALSE;
    Reset_status = FALSE;
    Debug = FALSE;
    sigcatcher(0);


    /*
     * Place all of the entries onto lists.
     */
    for ( i = 1 ; i < argc ; ++i )  {

	if ( i == 1 && strcmp(argv[i],"-D") == 0 ) {
	    Debug = TRUE;
	    continue;
	}

	/*
	 * Temporarily throw this entry onto the end of the zapped list.
	 */
	entryp = new_entry( &List_zap, argv[i] );

	/*
	 * Stat the file and get it to its proper place.
	 */
	switch ( stat_entry( &List_zap, List_zap.num-1, &sbuf ) ) {

	case ENTRY_FILE:		/* move entry to file list	*/
	    move_entry( &List_file, &List_zap, List_zap.num-1 );
	    entryp->size = sbuf.st_size;
	    entryp->mtime = sbuf.st_mtime;
	    break;

	case ENTRY_DIR:			/* move entry to dir list	*/
	    move_entry( &List_dir, &List_zap, List_zap.num-1 );
	    entryp->size = sbuf.st_size;
	    entryp->mtime = sbuf.st_mtime;
	    if ( scan_directory( entryp->name ) != 0 ) {
		message( MSSG_OPEN, entryp );
		rmv_entry( &List_dir, List_dir.num-1 );
	    }
	    break;

	case ENTRY_ZAP:			/* keep entry on zap list	*/
	    break;

	case ENTRY_SPECIAL:		/* entry is a special file	*/
	    message( MSSG_NOTAFIL, entryp );
	    rmv_entry( &List_zap, List_zap.num-1 );
	    break;

	default:			/* stat error			*/
	    message( MSSG_STAT, entryp );
	    rmv_entry( &List_zap, List_zap.num-1 );
	    break;

	}

    }

    /*
     * Make sure we are watching something reasonable.
     */
    if ( List_file.num == 0 ) {
	if ( List_dir.num == 0 && List_zap.num == 0 ) {
	    (void) fprintf(stderr, "%s: no valid entries specified\n", argv[0]);
	    (void) exit(1);
	}
	(void) puts("\n*** warning - no files are being watched ***");
    }


    /*
     * From this point on we want to reset the status of an entry any
     * time we move it around to another list.
     */
    Reset_status = TRUE;


    /*
     * Force a check of everything first time through the loop.
     */
    iteration = CHECK_COUNT;


    /* 
     * Loop forever.
     */
    for (;;) {

	/*
	 * Once every CHECK_COUNT iterations check everything.
	 * All other times only look at the opened files.
	 */
	open_files_only = ( ++iteration < CHECK_COUNT );
	if ( !open_files_only )
	    iteration = 0;


	/*
	 * Make sure that the most recently modified files are open.
	 */
	if ( !Sorted )
	    fixup_open_files();


	/*
	 * Display what we are watching if a SIGINT was caught.
	 */
	if ( sigcaught ) {
	    show_status();
	    sigcatcher(0);
	}


	/*
	 * Go through all of the files looking for changes.
	 */
	Dprintf(stderr, ">>> checking files list (%s)\n",
	    ( open_files_only ? "open files only" : "all files" ));
	for ( i = 0 ; i < List_file.num ; ++i ) {

	    entryp = List_file.list[i];
	    already_open = ( entryp->fd > 0 ) ;

	    /*
	     * Ignore closed files except every CHECK_COUNT iterations.
	     */
	    if ( !already_open && open_files_only )
		continue;

	    /*
	     * Get the status of this file.
	     */
	    switch ( stat_entry( &List_file, i, &sbuf ) ) {
	    case ENTRY_FILE:		/* got status OK		*/
		break;
	    case ENTRY_DIR:		/* huh??? it's now a dir	*/
		move_entry( &List_dir, &List_file, i-- );
		continue;
	    case ENTRY_ZAP:		/* entry has been deleted	*/
		message( MSSG_ZAPPED, entryp );
		move_entry( &List_zap, &List_file, i-- );
		continue;
	    case ENTRY_SPECIAL:		/* entry is a special file	*/
		message( MSSG_NOTAFIL, entryp );
		rmv_entry( &List_file, i-- );
		continue;
	    default:			/* stat error			*/
		message( MSSG_STAT, entryp );
		rmv_entry( &List_file, i-- );
		continue;
	    }


	    /*
	     * See if an opened file has been deleted.
	     */
	    if ( already_open && sbuf.st_nlink == 0 ) {
		message( MSSG_ZAPPED, entryp );
		move_entry( &List_zap, &List_file, i-- );
		continue;
	    }

	    /*
	     * If nothing has changed then continue on.
	     */
	    if ( entryp->size==sbuf.st_size && entryp->mtime==sbuf.st_mtime )
		continue;

	    /*
	     * If the file isn't already open, then do so.
	     *   Note -- it is important that we call "fixup_open_files()"
	     *   at the end of the loop to make sure too many files don't
	     *   stay opened.
	     */
	    if ( !already_open && open_entry( &List_file, i ) != 0 ) {
		--i;
		continue;
	    }

	    /*
	     * See if the file has been truncated.
	     */
	    if ( sbuf.st_size < entryp->size ) {
		message( MSSG_TRUNC, entryp );
		entryp->size = 0;
	    }

	    /*
	     * Seek to where the changes begin.
	     */
	    {
		extern long lseek();
		if ( lseek( entryp->fd, entryp->size, 0 ) < 0 ) {
		    message( MSSG_SEEK, entryp );
		    rmv_entry( &List_file, i-- );
		    continue;
		}
	    }

	    /*
	     * Dump the recently added info.
	     */
	    {
		int nb;
    		static char buf[BUFSIZ];
		message( MSSG_BANNER, entryp );
		while ( ( nb = read( entryp->fd, buf, sizeof(buf) ) ) > 0 ) {
		    (void) fwrite( buf, sizeof(char), (unsigned) nb, stdout );
		    entryp->size += nb;
		}
		if ( nb < 0 ) {
		    message( MSSG_READ, entryp );
		    rmv_entry( &List_file, i-- );
		    continue;
		}
	    }

	    /*
	     * Update the modification time.
	     */
	    entryp->mtime = sbuf.st_mtime;

	    /*
	     * Since we've changed the mtime, the list might no longer be
	     * sorted.  However if this entry is already at the top of the
	     * list then it's OK.
	     */
	    if ( i != 0 )
		Sorted = FALSE;

	    /*
	     * If we've just opened the file then force a resort now to
	     * prevent too many files from being opened.
	     */
	    if ( !already_open )
		fixup_open_files();

	}


	/*
	 * Go through list of nonexistent entries to see if any have appeared.
	 *   This is done only once every CHECK_COUNT iterations.
	 */
	if ( !open_files_only ) {
	    Dprintf(stderr, ">>> checking zapped list\n");
	    for ( i = 0 ; i < List_zap.num ; ++i ) {
		entryp = List_zap.list[i];
		switch ( stat_entry( &List_zap, i, &sbuf ) ) {
		case ENTRY_FILE:	/* entry has appeared as a file	*/
		    message( MSSG_CREATED, entryp );
		    move_entry( &List_file, &List_zap, i-- );
		    break;
		case ENTRY_DIR:		/* entry has appeared as a dir	*/
		    message( MSSG_CREATED, entryp );
		    move_entry( &List_dir, &List_zap, i-- );
		    break;
		case ENTRY_ZAP:		/* entry still doesn't exist	*/
		    break;
		case ENTRY_SPECIAL:	/* entry is a special file	*/
		    message( MSSG_NOTAFIL, entryp );
	    	    rmv_entry( &List_zap, i-- );
		    break;
		default:		/* error - entry removed	*/
	    	    message( MSSG_STAT, entryp );
	    	    rmv_entry( &List_zap, i-- );
		    break;
		}
	    }
	}


	/*
	 * Go through the list of dirs to see if any new files were created.
	 *   This is done only once every CHECK_COUNT iterations.
	 */
	if ( !open_files_only ) {
	    Dprintf(stderr, ">>> checking directory list\n");
	    for ( i = 0 ; !open_files_only && i < List_dir.num ; ++i ) {
		entryp = List_dir.list[i];
		switch ( stat_entry( &List_dir, i, &sbuf ) ) {
		case ENTRY_DIR:		/* got status OK		*/
		    break;
		case ENTRY_FILE:	/* huh??? it's now a reg file	*/
		    move_entry( &List_file, &List_dir, i-- );
		    continue;
		case ENTRY_ZAP:		/* entry has been deleted	*/
	    	    message( MSSG_ZAPPED, entryp );
	    	    move_entry( &List_zap, &List_dir, i-- );
		    continue;
		case ENTRY_SPECIAL:	/* entry is a special file	*/
		    message( MSSG_NOTAFIL, entryp );
		    rmv_entry( &List_dir, i-- );
		    continue;
		default:		/* stat error			*/
		    message( MSSG_STAT, entryp );
		    rmv_entry( &List_dir, i-- );
		    continue;
		}
		if ( entryp->mtime == sbuf.st_mtime )
		    continue;
		if ( scan_directory( entryp->name ) != 0 ) {
		    message( MSSG_OPEN, entryp );
		    rmv_entry( &List_dir, i-- );
		}
		entryp->mtime = sbuf.st_mtime;
	    }
	}


	/*
	 * End of checking loop.
	 */
	{
	    extern unsigned sleep();
	    (void) fflush(stdout);
	    (void) sleep(SLEEP_TIME);
	}

    }

    /*NOTREACHED*/

}

-- 
	Tom Christiansen	tchrist@jhereg.perl.com
    Even if you aren't in doubt, consider the mental welfare of the person who
    has to maintain the code after you, and who will probably put parens in
    the wrong place.  --Larry Wall in the perl man page 


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

Date: 21 Feb 1997 01:27:33 GMT
From: dedens <dedens@pi.net>
Subject: undump
Message-Id: <312A754F.7F27@pi.net>

yo,

i was reading about undump, i want to download it to
make exe files from my perl scripts.
why? i got a cutsomer and i dont want him to
check out the script.
do you know where i can find it (undump)

thanks
Daniel Edens
Dedens@pi.net
http://www.rcg.nl/users/daniel


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

Date: Thu, 20 Feb 1997 23:50:18 GMT
From: jgd@cix.compulink.co.uk ("John Dallman")
Subject: Re: unlink on Win95
Message-Id: <E5xE7u.M2n@cix.compulink.co.uk>

gt1535b@acmex.gatech.edu (The next Pele) (I doubt it) wrote:

> Hi there.  I'm running the Win95 port of perl, and I was wondering
> if there was any difference b/t the Unix Perl version of unlink and
> the ported version.

Yes. Lots. the different underlying operating system means that lots of 
functions based on UNIX system calls don't exist. However, this is not 
often a problem for basic work.

> Are there links in Win95 like in Unix?

No, but you still use unlink() to delete files. YOu can think of it as 
all files having but a single link (as is the case for a file under UNIX 
that hasn't had further links to it created).

John Dallman, jgd@cix.co.uk. A micro-FAQ on things I keep getting asked: 
#!perl is at ftp://.../CPAN/ports/msdos/tips-tricks/hbp_403.zip, BigPerl 
for MS-DOS can be found in CPAN via http://www.perl.com, Perl for NT/Win 
95 can be found at http://www.activeware.com, with an excellent FAQ file 
at http://www.endcontsw.com/people/evangelo/Perl_for_Win32_FAQ.html and 
no, I don't have the slightest idea what's wrong with your CGI script.


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

Date: 19 Feb 1997 19:03:31 GMT
From: jason@wisteria.cs.odu.edu (Jason C Austin)
Subject: Re: why can't "system" return a long?
Message-Id: <JASON.97Feb19140331@wisteria.cs.odu.edu>

In article <5dftu6$jv5@hecate.umd.edu>, Ellen Paik <epaik@deans.umd.edu> wrote:
>Hello,
>
>Can someone clarify what I need to do in order to get a call to a 
>C program using the "system" function to return a value of type long?
>Whenever the program returns an integer larger than type int, the 
>return value gets messed up.

	You can't.  Check the wait(2) man page on most versions of
Unix, and you'll see the child status indicator is an "int" and the
exit status portion is only the first 8 bits, so you're actually
limited to 256 possible values.  The exit status is only meant to
indicate success or an error code, and it's not a good way to pass
data.  I'm surprised the C compiler didn't pitch a fit when you passed
a long to exit().

	For transferring data, you need to use an intermediate file or
some IPC method such as a pipe.  The perl manuals explain how to do
it.
--
Jason C. Austin
austin@visi.net



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

Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Jan 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.

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 V7 Issue 984
*************************************

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