[6471] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 96 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 11 20:07:15 1997

Date: Tue, 11 Mar 97 17:00:17 -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           Tue, 11 Mar 1997     Volume: 8 Number: 96

Today's topics:
     Re: filehandles: better way to test existence of? < hansm@icgned.nl>
     HELP compiling Compiler a3 with perl5.003_93 <bpm@techapp.com>
     Re: Interpreting this reg expression has me baffled (Laurel Shimer)
     ISBN/Checkdigit calculator <mriggsby@sybex.com>
     Re: So easy they do not explain pattern match. (Laurel Shimer)
     Re: UserCreate for NT Perl <jrtietsort@micron.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 12 Mar 1997 00:11:22 GMT
From: Hans Mulder< hansm@icgned.nl>
Subject: Re: filehandles: better way to test existence of?
Message-Id: <5g4sba$5oo@news.euro.net>

"Cal..." <jewell@halcyon.com> wrote:
>Here's what I'm thinking of using to test the existence of a filehandle:

>	#!/bin/perl -w

>	open (LOGFILE, "> /dev/null") or die "open: logfile: $!\n";

>	print "open: fileno\n" if fileno(LOGFILE);

>	close LOGFILE;

>	print "closed: fileno\n" if fileno(LOGFILE);

>I've combed through the perl pods, looking for a better way, but nothing
>struck me as the way to go. I've also checked Camels 1 and 2.

>Is fileno(fH) the best way to test the existence of a filehandle?

The best way is to use defined(fileno(fH)), because 0 is a legal
value for fileno().  For example, fileno(STDIN)==0 initially.

Hope this helps,

HansM


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

Date: 11 Mar 1997 17:53:40 -0600
From: Brian P Millett <bpm@techapp.com>
Subject: HELP compiling Compiler a3 with perl5.003_93
Message-Id: <vkhgiiq92z.fsf@terraweb.com>

I've compiled and installed perl5.003_93 with at&t's sfio97 package.
All tests are OK and apache1.2b7 & mod_perl 0.94 work just fine.  BUT
the real problem is when I tried to compile the perl Compiler a3.  I
get the following:

vlad: make
gcc -c  -fPIC -I/opt/gnu/include -I/opt/sfio/include -O     -DVERSION=\"a2\"  -DXS_VERSION=\"a2\" -fpic -I/opt/gnu/lib/perl5/sun4-solaris/5.003/CORE  B.c
gcc -c  -fPIC -I/opt/gnu/include -I/opt/sfio/include -O     -DVERSION=\"a2\"  -DXS_VERSION=\"a2\" -fpic -I/opt/gnu/lib/perl5/sun4-solaris/5.003/CORE  ccop.c
gcc -c  -fPIC -I/opt/gnu/include -I/opt/sfio/include -O     -DVERSION=\"a2\"  -DXS_VERSION=\"a2\" -fpic -I/opt/gnu/lib/perl5/sun4-solaris/5.003/CORE  byterun.c
byterun.c: In function `byterun':
byterun.c:47: parse error before `fread'
byterun.c:54: parse error before `fread'
byterun.c:61: parse error before `fread'
 .
 .
 .
 .
 .
byterun.c:847: parse error before `fread'
byterun.c:854: parse error before `fread'
byterun.c:861: parse error before `fread'
*** Error code 1
make: Fatal error: Command failed for target `byterun.o'


The fread is redefined in the sfio.h, but shouldn't perl generate the
correct 'c' code from the .xs file?

Any help would/is welcome.

Thanks
-- 
Brian Millett                    
Technology Applications Inc.     "Heaven can not exist,
(314) 530-1981                          If the family is not eternal"
bpm@techapp.com                   F. Ballard Washburn


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

Date: Tue, 11 Mar 1997 15:42:03 -0700
From: autopen@quake.net (Laurel Shimer)
Subject: Re: Interpreting this reg expression has me baffled
Message-Id: <autopen-1103971542030001@l1.d22.quake.net>

Thanks to Andrew for sending this. Hope this doesn't make a duplicate post
but his response showed in my email and not in my newsreader access and I
know several in the group might shoot us (\!\!\!) were the answer not made
public! LRS

Sender: root@danger.mbnet.mb.ca
Date: Tue, 11 Mar 1997 17:15:36 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Organization: not-much
MIME-Version: 1.0
To: Laurel Shimer <autopen@quake.net>
Subject: Re: Interpreting this reg expression has me baffled

Laurel Shimer wrote:
> 
> To paraphrase the great one ('lo we worship before your linguist's
> throne') there are many ways to do the same thing. Still I find other
> people's code very helpful to understand.
> 
> This morning I wrote a response to a posting by Stuart w/ the subj
> "Parsing a CSV file into two Arrays'. I was able to figure out an
> alternative method of doing what he wanted done (I hope he wasn't looking
> for something more sophisticated - he won't get it from me) but in the
> meantime I used his code as an example to increase my proficiency with
> Perl. I wasn't able to successfully understand 2 techniques he was using
> and wonder if anyone else will enlighten my ignorance.
> 
> Funny how it's easier to work on someone else's problem than my own...
> 
> Okay here are the bits I don't get (despite my 'Perl Reference Guide' and
> the Camel book at my side)
> 
> > while (<NAMES>) {
> >         #chomp;
> >         push @fullnames, ($1||$+)
> >             while /\s*"(([^"\\]|\\"|\\\\)*)"\s*|\s*([^",]+)\s*/g;
> > }
> >
> 
> 1) For some reason he doesn't need to use 'chomp'. I guess that has
> something to do w/ this substitution (or what seems to be a substitution)
> that is such a bear for me to interpret. But I don't understand where the
> paragrah character would be removed.

there is no substitution happening here just matching (see next)

> 2) My use of $1 is limited to passing arguments to subroutines, or
> examining (hum - Think I've used it to examine something returned from
> something but I forget how or what I did. )
> 
> The ref guide says 'Contains the subpatterns from the corresponding sets
> of parenthesies in the last pattern successfully matched' - so I guess
> this means that when the regular expression is evulated something, which
> is a transformation of what's currently in $_,  will get shoved in here.
> 
> Do I have that vague idea right?

when pattern matching if you use capturing parentheses, the stuff matched
inside of those is later available in $1 $2 etc for each set of parentheses
you use...an example is clearer:

$text='this is a string for an example match';

$text=~/(\w+\s\w+).*?(an example)/;

now $text is unchanged, and $1 holds "this is" and $2 holds "an example"
the \s matches a whitespace character.

the parentheses can be nested so if we used;

$text=~/((\w+\s\w+).*?(an example))/;

then $1 holds "this is a string for an example"
$2 holds "this is"
$3 holds "an example"

$+ holds the highest matched parentheses group so $+ in the last example
would also hold "an example"  it is useful for if you had something
optional in the first set of brackets and so wouldn't know what number
highest matched bracket would be:

/^(\d+)*\s*(\w+)/

now, this will match a leading \d+ zero or more times, then a space 
and a word, but what about when there are zero digits before the first
word? the word (\w+) is always available in $+, which might be $1 or $2
in our example.
 
> 3) Now there is this $+ business. Ref guide says "last bracket matched by
> the last search pattern". And the two bits $1 and $+ are 'or\'d' together.
> 
> I don't quite understand what might be or'd together, or why it is or'd
> together, or how you would know what to expect when they are or'd together
> or why you would want the result to be the value in your array.
> 
not or'd together, he is || operator to push in $1 (if exists) or $+

> 4) Okay now I get to the regular expression.
> 
> while /\s*"(([^"\\]|\\"|\\\\)*)"\s*|\s*([^",]+)\s*/g;
> 
> a) while : okay so something is happening repeatedly w/ the current
> contents of $_.
> 
>     How does it know when to exit the while ?

it exits while when repeated matching fails, although in this case
it might have problems

> 
> b) /\s*

as above: \s is whitespace
> 
> so is 's' being escaped? Why? Or does this mean something else? Is this an
> 's' like a substitution? Or something else? (All my substitutions so far
> use match (=~) and I'm not even sure where to look to figure out what sort
> of 's' this means.
> 
> I have the vague idea that this is eliminating all the double quotes
> (something that had to be done in the problem - there were multiple double
> quotes that needed to be cleaned out. I used =~ s/"//g to do that bit.
> 

i sent him the following to grab the each quoted bit and push
into separate arrays:

open(NAMES, "names.txt") or die "Can't open names.txt: $! \n";
while (<NAMES>) {
   
   /\s*"([^"]+?)",\s*"([^"]+?)"/;
   push @firstname,$1;
   push @lastname,$2;
   
}

what his purposes in using all the backslashes was unlcear to me, and 
not apparent from his example file---he can add them back if they were
in fact necessary.

regards,
andrew In article <autopen-1103971030180001@l82.d22.quake.net>,
autopen@quake.net (Laurel Shimer) wrote:

> To paraphrase the great one ('lo we worship before your linguist's
> throne') there are many ways to do the same thing. Still I find other
> people's code very helpful to understand.
> 
> This morning I wrote a response to a posting by Stuart w/ the subj
> "Parsing a CSV file into two Arrays'. I was able to figure out an
> alternative method of doing what he wanted done (I hope he wasn't looking
> for something more sophisticated - he won't get it from me) but in the
> meantime I used his code as an example to increase my proficiency with
> Perl. I wasn't able to successfully understand 2 techniques he was using
> and wonder if anyone else will enlighten my ignorance.
> 
> Funny how it's easier to work on someone else's problem than my own...
> 
> Okay here are the bits I don't get (despite my 'Perl Reference Guide' and
> the Camel book at my side)
> 
> > while (<NAMES>) {
> >         #chomp;
> >         push @fullnames, ($1||$+)
> >             while /\s*"(([^"\\]|\\"|\\\\)*)"\s*|\s*([^",]+)\s*/g;
> > }
> > 
> 
> 1) For some reason he doesn't need to use 'chomp'. I guess that has
> something to do w/ this substitution (or what seems to be a substitution)
> that is such a bear for me to interpret. But I don't understand where the
> paragrah character would be removed.
> 
> 2) My use of $1 is limited to passing arguments to subroutines, or
> examining (hum - Think I've used it to examine something returned from
> something but I forget how or what I did. )
> 
> The ref guide says 'Contains the subpatterns from the corresponding sets
> of parenthesies in the last pattern successfully matched' - so I guess
> this means that when the regular expression is evulated something, which
> is a transformation of what's currently in $_,  will get shoved in here.
> 
> Do I have that vague idea right?
> 
> 3) Now there is this $+ business. Ref guide says "last bracket matched by
> the last search pattern". And the two bits $1 and $+ are 'or\'d' together.
> 
> I don't quite understand what might be or'd together, or why it is or'd
> together, or how you would know what to expect when they are or'd together
> or why you would want the result to be the value in your array.
> 
> ?????
> 
> 4) Okay now I get to the regular expression. 
> 
> while /\s*"(([^"\\]|\\"|\\\\)*)"\s*|\s*([^",]+)\s*/g;
> 
> a) while : okay so something is happening repeatedly w/ the current
> contents of $_. 
> 
>     How does it know when to exit the while ?
> 
> b) /\s*
> 
> so is 's' being escaped? Why? Or does this mean something else? Is this an
> 's' like a substitution? Or something else? (All my substitutions so far
> use match (=~) and I'm not even sure where to look to figure out what sort
> of 's' this means.
> 
> I have the vague idea that this is eliminating all the double quotes
> (something that had to be done in the problem - there were multiple double
> quotes that needed to be cleaned out. I used =~ s/"//g to do that bit.
> 
> But this seems to do something more. At least I think so.
> 
> And somehow he is eliminating the paragraph return.
> 
> When I tried to use this expression without the while bit I failed
> miserably so somehow the 2 parts are intertwined.
> 
> Laurel
> 
> 
> -------- Original Post --------
> In article <3324F2BC.6535@quake.net>, Stuart McClure
<smcclure@quake.net> wrote:
> 
> > Can any of you gurus help out?
> > 
> > I want to read a line at a time from a text file and then strip the
> > field (from within double quotes) as a comma as the field delimiter and
> > push the first field into array1 and the second field into array2.
> > 
> > I can strip each field from the text file (or CSV) and push into a
> > single array, but don't know how to distinguish between the first field
> > and the second (to put into the second array).
> > 
> > Here's a sample CSV file:
> > "Tom","Cruise"
> > "Nicole","Kidman"
> > 
> > And a sample of the push code to an array.
> > 
> > open(NAMES, "names.txt") or die "Can't open names.txt: $! \n";
> > while (<NAMES>) {
> >         #chomp;
> >         push @fullnames, ($1||$+)
> >             while /\s*"(([^"\\]|\\"|\\\\)*)"\s*|\s*([^",]+)\s*/g;
> > }
> > 
> > Thanks in advance for any help.
> > 
> > -- 
> > Stuart McClure
> 
> -- 
>         The Reader's Corner: Mystery, Romance, Fantasy 
>          http://www.autopen.com/index.shtml 
>      Subscribe to our free StoryBytes publication
>  New: Fashion Challenges for the Time Traveling Heroine    
http://www.autopen.com/romance.well.dressed.shtml

-- 
        The Reader's Corner: Mystery, Romance, Fantasy 
         http://www.autopen.com/index.shtml 
     Subscribe to our free StoryBytes publication
 New: Fashion Challenges for the Time Traveling Heroine     http://www.autopen.com/romance.well.dressed.shtml


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

Date: Tue, 11 Mar 1997 16:48:27 -0800
From: Matt Riggsby <mriggsby@sybex.com>
Subject: ISBN/Checkdigit calculator
Message-Id: <3325FD5B.7546@sybex.com>

I need a perl script that will calculate the final digit of an ISBN and
would prefer not to reinvent the wheel if at all possible.  For those of
you unfamiliar with the process, a book's ISBN is an eleven digit
number, the first ten of which identify the publisher and sequence in
publishing.  A check-digit is calculated by calculating a sum with the
first ten digits (10 * the first digit + 9 * the second and so on), then
dividing the sum by 11 and taking the remainder (the digit is "X" if the
remainder is 10).  Has anyone written a perl routine for this?  I
browsed through CPAN, but nothing definitively relevant popped up at
me.


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

Date: Tue, 11 Mar 1997 15:54:17 -0700
From: autopen@quake.net (Laurel Shimer)
Subject: Re: So easy they do not explain pattern match.
Message-Id: <autopen-1103971554170001@l1.d22.quake.net>

The general answer to this question is 'regular expressions'. They are
also explained in the Llama book. I think they are a kinda Unix'y
construct, if I understand it right, and I probably don't, Unix has it's
own regular expressions and it seems to me that they work sort of
differently from Perl. No doubt someone will correct me on this. 

I haven't quite figured out where Unix uses regular expressions. My Unix
book says they are used by 'a number of UNIX utilities such as sed'. I
recently tried to play around w/ the regular expressions and my limited
understanding of sed and didn't get very far. I know how to do like one
thing in sed - though it comes in handy for that one thing.

And I know just what you mean about not being born into Unix. Now I know
how all those COBOL programmers felt when my fresh-faced-CS-degree
generation came on the scene in the late 70's. (Course I seee that the
contract market for COBOL programmers is doing quite well. Guess we would
have done well not to look down our pointy little noses...)

Laurel

In article <adelton.858068768@aisa.fi.muni.cz>, adelton@fi.muni.cz (Honza
Pazdziora) wrote:

> soccer@microserve.net (Geoffrey Hebert) writes:
> 
> > Searching for an easy answer.  It must be easy, because the book did
> > not explain what was meant.
> > 
> > Perhaps if I were born into UNIX I would obviously know what is meant
> > below.  
> > 
> > What do these mean -
> > s/^/< /
> > $var=~s/\^/\n/          
> 
> I hope you meant
> 
> s/^/< /;
> $var=~s/\^/\n/;
> 
> The first one replaces beginning of the string by two letter string "< ".
> The second one, with ^ escaped, replaces the first letter ^ in the
> string with the new-line character.
> 
> My Camel book mentions this (page 62).
> 
> Hope this helps.
> 
> --
> ------------------------------------------------------------------------
>  Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
>                    I can take or leave it if I please
> ------------------------------------------------------------------------

-- 
        The Reader's Corner: Mystery, Romance, Fantasy 
         http://www.autopen.com/index.shtml 
     Subscribe to our free StoryBytes publication
 New: Fashion Challenges for the Time Traveling Heroine     http://www.autopen.com/romance.well.dressed.shtml


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

Date: 11 Mar 1997 22:25:52 GMT
From: "JR Tietsort" <jrtietsort@micron.com>
Subject: Re: UserCreate for NT Perl
Message-Id: <01bc2e6b$4fe1fcc0$9b6ac989@jrtietsort>

Here is a working piece of code that suggests the current
domain.  It took me awhile to get this module to work.  I had
to do some tinkering with having it in the current directory,
and making sure that my registry key was pointing to the
correct area.

Win32::NetAdmin::UserCreate('',$uid,'',1644487,1,'','',66049,'')


Daniel Hinkle <dhinkle@cisco.com> wrote in article
<01bc2c33$ce3e60c0$55cd44ab@rambo>...
> Has anyone got the Win32::NetAdmin::UserCreate function to work?  I tried
> it on a NT 4.0 server and could not get it to work.  It looks pretty
simple
> so I can't see what I could be doing wrong.  I'm thinking maybe it just
> doesn't work.
> 
> Daniel
> 


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

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

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