[17053] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4465 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 29 00:05:28 2000

Date: Thu, 28 Sep 2000 21:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <970200307-v9-i4465@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 28 Sep 2000     Volume: 9 Number: 4465

Today's topics:
    Re: 2 Questions <dajr4@vt.edu>
    Re: a simple perl (Gwyn Judd)
    Re: ASAP: How $SCALAR = $LIST <elephant@squirrelgroup.com>
    Re: Getting FILEVERSION info using Perl <elephant@squirrelgroup.com>
    Re: global variable <elephant@squirrelgroup.com>
    Re: Help with REGEX for newbie <yosikim@lgeds.lg.co.kr>
    Re: Help with REGEX for newbie <yosikim@lgeds.lg.co.kr>
    Re: How to get length of scalar? (Keith Calvert Ivey)
    Re: HTML Email <elephant@squirrelgroup.com>
        like an inifile <jtjohnston@courrier.usherb.ca>
    Re: like an inifile (Martien Verbruggen)
    Re: Newbie question about files ebohlman@omsdev.com
    Re: parameter passing problem <ssilv@rochester.rr.com>
    Re: Perl Regex <randy_734@my-deja.com>
    Re: Perl Regex (Craig Berry)
    Re: Perl Regex (Abigail)
    Re: Perl Regex (Craig Berry)
        Read and Split Individual Text File Lines pgodkin@my-deja.com
    Re: Read and Split Individual Text File Lines <jeff@vpservices.com>
    Re: Read and Split Individual Text File Lines (Martien Verbruggen)
        Receiving HTML email messages on Compuserve v4.01 <melkaye@compuserve.com>
    Re: Receiving HTML email messages on Compuserve v4.01 <wyzelli@yahoo.com>
    Re: splitting lines with a regex <jeffp@crusoe.net>
    Re: subroutines, print to a file not happening, cgi <elephant@squirrelgroup.com>
    Re: syntax:search and replace (Mark-Jason Dominus)
        UDP socket using perl? <trisa@sby.dnet.net.id>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 28 Sep 2000 21:47:08 -0400
From: "Daniel Longest" <dajr4@vt.edu>
Subject: Re: 2 Questions
Message-Id: <8r0s75$eon$1@solaris.cc.vt.edu>

> And by C++ i think you meant, ms c++, didn't you...Well, you could use
that,
> but a _FREE_ equivelent would be DJGPP w/ the allegro library. DJGPP is
the
> way to go if you want to program in C/C++ using 32 bits.
I would think MFC and/or the Win32 SDK itself would be the way to go.

Daniel

--
--------------------------------------------------
Daniel Longest
dajr4@vt.edu

"Java isn't platform-independent; it is a platform"- Stroustrup
comp.lang.c++ http://www.parashift.com/cpp-faq-lite/
alt.comp.lang.learn.c-c++ http://www.faqs.org/faqs/C-faq/learn/
 -----------------------------------------------------------------------
 Pursuant to US Code, Title 47, Chapter 5, Subchapter II, ¢227,
 Any and all nonsolicited commercial E-mail sent to this address
 is subject to a download and archival fee in the amount of $500.00 US.
 E-Mailing denotes the acceptance of these terms
 -----------------------------------------------------------------------
"Nick Emblow, President IT Not Just Bears" <emblow@ozlinx.com.au> wrote in
message news:6pyA5.45$8G6.2041@nsw.nnrp.telstra.net...
> That would be moving backwards, not forwards.
> I suggest this learning structure:
> BASIC [QB7x or PB]   TO   ASSEMBLY[NASM98]
> OR
> C [EGGS] TO ASSEMBLY[NASM98]
> OR
> C++[DJGPP] TO ASSEMBLY[NASM98]
>
> You see, While going from QB to VB may seem like a smart move ie, you dont
> need to program your own guis any more...You unfortunately have gone from
> controlling your program[QB,PB,ASM,C/C++] to manipulating someone _elses_
> program.
> If however, you are one lazy son ova bitch, then VB is for you, but goof
> luck trying to make an _original_ looking program.
> And by C++ i think you meant, ms c++, didn't you...Well, you could use
that,
> but a _FREE_ equivelent would be DJGPP w/ the allegro library. DJGPP is
the
> way to go if you want to program in C/C++ using 32 bits.
>
> I suggest using ASM [assembly] because it provides _MAXIMUM_ control over
> your program.
> It may be harder, longer nastier and INSANE, but in the end, you'll be so
> goddam proud of your self.
>
> Just a suggestion
> Cheers
> Nick
>
>
>
>
> "Frankie" <frankie@centurytel.net> wrote in message
> news:39C5974E.AC51F612@centurytel.net...
> > My apologies for the cross-post and the broad nature of this question.
> > I just can't seem to find the info I want via traditional search
> > engines, including Deja News.  And please, no flames.  I'm not a newbie
> > and am aware I'm on thin ice with the cross and the questions.  Thanks.
> >
> > My question is what programming language would you recommend to a
> > complete beginner in programming?  I've extensive background in various
> > environments, so I'm not going to be terribly uneasy with the comp, I'm
> > just looking for a good start.
> >
> > The second, and virtually hand in hand with the first, is where to go
> > from there and in what sequence.  IOW, I'm thinking (just an example)
> > qbasic to Visual Basic to C to C++ etc?  And yes, I'm going to throw in
> > HTML, but I want to go beyond that.
> >
> > Again, my apologies if this is an inappropriate post.  Or, for that
> > matter, too broad. Any help will be greatly appreciated.  E-mails are
> > welcome (take the ** out per below) but since I'm posing the question, I
> > can check all the Groups also.  TIA
> >
> > --
> > "I do this really moronic thing that the government doesn't want me to
> > do. It is called thinking" - George Carlin
> >
> >
> > Remove * * to reply.
> >
> > -----------------------------------------------------------------------
> > Pursuant to US Code, Title 47, Chapter 5, Subchapter II, ¢227,
> > Any and all nonsolicited commercial E-mail sent to this address
> > is subject to a download and archival fee in the amount of $500.00 US.
> > E-Mailing denotes the acceptance of these terms
> > -----------------------------------------------------------------------
>
>




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

Date: Fri, 29 Sep 2000 03:06:13 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: a simple perl
Message-Id: <slrn8t81p2.5q2.tjla@thislove.dyndns.org>

I was shocked! How could Larry Rosler <lr@hpl.hp.com>
say such a terrible thing:
>[Not much of a subject!  Perl isn't all that simple.  :-]
>
>In article <8r02ud$foe$1@nnrp1.deja.com> on Thu, 28 Sep 2000 18:33:49 
>GMT, nodo70@my-deja.com <nodo70@my-deja.com> says...
>> How come the script below doesn't work if I want to set up a variable
>> DATESTAMP to the current date in environment?  Please advise.  Thanks.

>Oh, yes, what we've all been waiting for -- the answer to your question:
>
>  $ENV{DATESTAMP} = now();
>
>Look in perlvar for %ENV.

Of course that only works for spawned subshells, not I think what the OP
wanted to do, but rather to set it in the parent. I think what the OP
wants is to read perlfaq8:

perldoc -q environment

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The paperback is very interesting but I find it will never replace the
hardcover book -- it makes a very poor doorstop.
-Alfred Hitchcock


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

Date: Fri, 29 Sep 2000 12:08:43 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: ASAP: How $SCALAR = $LIST
Message-Id: <MPG.143ea4b7eb1a49879897de@localhost>

Ren Maddox wrote ..
>jason <elephant@squirrelgroup.com> writes:
>
>> amonotod wrote ..
>> >In article <39D259DC.7DE580A8@webimpact.com>,
>> >  Don Vaillancourt <donv@webimpact.com> wrote:
>> >> How to I get the number of elements in a list that is only accessible
>> >> through a reference from a scalar.
>> >>
>> >> I have the following of code:
>> >>
>> >> $properties->{columns}=[];
>> >> $columns=$properties->{columns};
>> >>
>> >>  $columns->[0]={"name" => "delete",
>> >>        "type" => $NUMBER,
>> >>        "size" => 1,
>> >>        "unique" => $FALSE,
>> >>        "primary_key" => $FALSE,
>> >>        "required" => $TRUE,
>> >>        "allow_null" => $FALSE};
>> >>
>> >> How do I find how many elements the list pointed to by
>> >> $properties->{columns} contains.
>> >
>> >You already have... $columns is a scalar value of the number of fields
>> >in $properties->{columns}, and @columns is an array (with a hash as the
>> >first field).
>> 
>> look again amonotod .. $properties->{columns} contains a reference to an 
>> empty list .. which is also what $columns contains
>> 
>> >Try :
>> >print $columns ,"\n";
>> 
>> I think you should try this .. you might see the error of your ways ;)
>
>You neglected to quote the very next thing that amonotod wrote:

I'm at a loss to understand how it's relevant ?

>> >At this point, since you had
>> >$properties->{columns}=[]; #This is empty, as in 0 fields.
>> >
>> >you should get
>> > 
>> >
>> >Yeah, nothing.
>
>(Except that you should get "0", not nothing.)

someone else who hasn't tried it (or is this some stupid joke)

  $properties->{columns}=[];
  $columns=$properties->{columns};

  $columns->[0]={"name" => "delete",
         "type" => $NUMBER,
         "size" => 1,
         "unique" => $FALSE,
         "primary_key" => $FALSE,
         "required" => $TRUE,
         "allow_null" => $FALSE};

  print $columns ,"\n";

you'll actually get something like this

  ARRAY(0x1b9f0d0)

because $columns is an array ref .. try it yourself and you might see 
the error of your ways ;)

>amonotod's point was that the OP had code that basically gave him what
>he wanted, he just needed to use it at the right time in the right
>place.

the only time that $columns will give the number of elements in 
@{$properties->{columns}} is before any elements are added to 
@{$properties->{columns}} and before $columns is initialised (and 
assuming that you force $columns into numeric context)

eg.

  $properties->{columns}=[];
  print 0 + $columns ,"\n";

but that's entirely coincidental and stupid

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Fri, 29 Sep 2000 12:25:05 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Getting FILEVERSION info using Perl
Message-Id: <MPG.143ea88a4e7ef53d9897e0@localhost>

Paul Kolonay wrote ..
>I would like to get the version information for dlls from a Perl script (on
>WIN32). Is there already a module out there that already does this ? If not,
>is there a way to call the win32 api to get this info ? I would prefer that
>this solution be in the standard perl distribution and not have an active
>state Perl be a requirement.

umm .. I don't know the answer to your question (sorry) .. but I'd just 
like to let you know that the ActiveState port of Perl *IS* the 
"standard perl distribution" for Win32

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Fri, 29 Sep 2000 12:43:57 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: global variable
Message-Id: <MPG.143eacf59d8209dc9897e2@localhost>

nlymbo@my-deja.com wrote ..
>I have a global variable in my main package. I also "require" a library
>and i would like that variable to be available to the required package.
>How can i do this??
>
>eg.
>
>main:
>
>$GLOBALVAR = "something";
>
>require "alib.pl"
>
>...
>
>I want alib.pl to have access to $GLOBALVAR. Is this possible??

<style voice="Chief Wiggam">
  oh for the love of God !!
</style>

does the recent (like yesterday and today) thread entitled "accessing 
global variables in another perl module" shed any light on your problem 
?

please have a look at the recently discussed topics in a newsgroup 
before posting your question .. or use one of the many free usenet 
search tools to search for keywords in your topic before posting

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Wed, 27 Sep 2000 18:03:35 +0900
From: Yongsik Kim <yosikim@lgeds.lg.co.kr>
Subject: Re: Help with REGEX for newbie
Message-Id: <39D1B7E7.CCDE1F26@lgeds.lg.co.kr>



Shawn and Francine wrote:
> 
> Hi,
> 
> I want to use REGEX to scan a string and find a single digit followed by
> any two charecters followed by a white space and delete only that
> digit.  The snipet I have below deletes everything, digit charecters and
> white space.  I have tried several variations.  Couls someone throw me a
> bone?
> 
> Thanks in advance.
> 
> foreach $cycle (@contents)
> {
>      $cycle =~ s/[0-9]..\s//g;
       $cycle =~ s/[0-9](..\s)/$1/g;
> }


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

Date: Wed, 27 Sep 2000 18:56:39 +0900
From: Yongsik Kim <yosikim@lgeds.lg.co.kr>
Subject: Re: Help with REGEX for newbie
Message-Id: <39D1C457.814FA9BF@lgeds.lg.co.kr>



Shawn and Francine wrote:
> 
> Hi,
> 
> I want to use REGEX to scan a string and find a single digit followed by
> any two charecters followed by a white space and delete only that
> digit.  The snipet I have below deletes everything, digit charecters and
> white space.  I have tried several variations.  Couls someone throw me a
> bone?
> 
> Thanks in advance.
> 
> foreach $cycle (@contents)
> {
>      $cycle =~ s/[0-9]..\s//g;
       $cycle =~ s/[0-9](..\s)/$1/g;
> }


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

Date: Fri, 29 Sep 2000 01:44:10 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: How to get length of scalar?
Message-Id: <39d4f389.3212319@news.newsguy.com>

"Mark Carruth" <mcarruth@talk21.com> wrote:

>As I send all my emails (which are part of my LIFE Uri) using HTML, the
>programme sends all my posts in HTML. I never have people moaning about HTML
>in Email so I don't know why I should change.

You obviously need to meet a better class of correspondents.
I'm glad you're not on any of the e-mail discussion lists I
subscribe to.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Fri, 29 Sep 2000 12:30:36 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: HTML Email
Message-Id: <MPG.143ea9d53665c419897e1@localhost>

joshfeingold@my-deja.com wrote ..
>I am trying to send HTML email from a perl script, but when it is sent
>the HTML formatting is not used (rather the mark-up is in plain view).
>
>I imagine that I am doing the MIME header incorrectly but am not sure
>how.  I have looked around the discussion boards but have not found
>anyone addressing the exact text that should be printed at the header
>for it to be read as HTML by the email application (in my case Outlook).

back in my day you'd send yourself one of these fancy shmancy emails .. 
and then just telnet into the POP server to have a look at the raw email 
before Outlook (or whatever) had a chance to process it

then craft your Perl code to reproduce the same thing .. I'm afraid 
that's all the help I can bring myself to give you in sending HTML 
emails

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Thu, 28 Sep 2000 22:26:36 -0400
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: like an inifile
Message-Id: <39D3FDDC.53C9@courrier.usherb.ca>

Question 1:
How can I use a text file like an inifile? I thought I knew I was doing,
but :( ...   I retreive data like:

	name:numberofvotes:
	--- Snip -----
	John:5:
	Gail:3:
	Dave:3:
	--- Snip -----

Question 2:
How can I add a new line, if a person didn't exist in the file:


This is what I tried until I realised I didn't know how to write the
data back in:
----------------------------------------------------------------------
sub RegisterVote
{
	open (VOTINGDATAFILE, "$votes_database") or die "can't open
$votes_database: $!\n";
	@VoteData = <VOTINGDATAFILE>;
	close VOTINGDATAFILE;

	foreach $Message (@Data)
	{
	  @VoteData = split (/:/, $Message);
	  if ($VoteData[0] eq $in{'Vote1'}
	  {
	   $VoteData[1]++;
	  }
	}
	open(VOTES,">$votes_database") or die "can't open $votes_database:
$!\n";
	 print VOTES @VOTES;
	close VOTES;
}
----------------------------------------------------------------------

Thanks,

John


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

Date: Fri, 29 Sep 2000 03:29:48 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: like an inifile
Message-Id: <slrn8t8358.64u.mgjv@verbruggen.comdyn.com.au>

On Thu, 28 Sep 2000 22:26:36 -0400,
    jtjohnston <jtjohnston@courrier.usherb.ca> wrote:
> Question 1:

If you have two questions, you should post two separate articles. That
way the thread won't end up having a mix of two discussions.

> How can I use a text file like an inifile? I thought I knew I was doing,
> but :( ...   I retreive data like:
> 
>   name:numberofvotes:
>   --- Snip -----
>   John:5:
>   Gail:3:
>   Dave:3:
>   --- Snip -----

Euhmmm.. Where's your code? How do we tell you what's wrong if you
don't show us how you get this? For all we know, you might be reading
stuff correctly, and just printing it incorrectly.

That said, have you ever heard of CPAN? if not, you should start using
it.

http://www.cpan.org/

$ perl -MCPAN -e shell
cpan> i /ini/
[only showing relevant output, reformatted]
Module          Config::IniFiles (R/RB/RBOW/Config-IniFiles-1.6.tar.gz)
Module          IniConf         (R/RB/RBOW/IniConf-1.03.tar.gz)
Module          IniFile         (A/AV/AVATAR/IniFile-1.01.zip)

> Question 2:
> How can I add a new line, if a person didn't exist in the file:
> 
> 
> This is what I tried until I realised I didn't know how to write the
> data back in:

You don't use -w or the strict pragma, do you? You really should.

#!/usr/bin/perl -w
use strict;

> ----------------------------------------------------------------------
> sub RegisterVote
> {
>   open (VOTINGDATAFILE, "$votes_database") or die "can't open
> $votes_database: $!\n";

You check for errors. Good. ou are also using quotes where it isn't
necessary.

>   @VoteData = <VOTINGDATAFILE>;

here you read all lines in @VoteData

>   close VOTINGDATAFILE;
> 
>   foreach $Message (@Data)

here you loop for each element of @Data

>   {
>     @VoteData = split (/:/, $Message);

And here you overwrite @VoteData

It's a good thing nothing in this loop will ever get executed, unless
you have a global variable @Data, or another one in scope.

>     if ($VoteData[0] eq $in{'Vote1'}
>     {
>      $VoteData[1]++;
>     }
>   }

You don't specify what your input lines look like. I will assume that
they are shaped like:

name:34

with no extra fields. 

>   open(VOTES,">$votes_database") or die "can't open $votes_database:
> $!\n";
>    print VOTES @VOTES;
>   close VOTES;
> }
> ----------------------------------------------------------------------

If I read this correctly, you are reading in some records from a file,
and you want to increment one of the fields in each of these records,
but only if the start of the line, up to the first separator (:) is
equal to a certain string. I'd probably write that as

#!/usr/local/bin/perl -w
use strict;

my $votes_database = '/tmp/db.v';

sub register_vote
{
    my $match = shift;
    local(*DBF);

    open(DBF, $votes_database) or
        die "Cannot open $votes_database for read: $!";
    my @lines = <DBF>;
    close DBF;

    for (@lines)
    {
        next unless /^\Q$match:\E(\d+)/;
        $_ = join(':', $match, $1+1) . "\n";
    }

    open(DBF, ">$votes_database") or 
        die "Cannot open $votes_database for write: $!";
    print DBF @lines;
    close DBF;
}

register_vote('banana');

Note that this doesn't do anything if the parameter doesn't exist in
the file.

The things I'd like you to pay attention to are the fact that all
variables are lexically scoped to the sub, except for $vote_database,
and that I have also localised the DBF filehandle so that I run a
lower risk of interfering with another possibly open filehandle with
the same name. I've also avoided splitting any of this stuff. If my
assumption that there are only two fields per record is wrong, you
probably want to use split again. The check for a match might in that
case be better made into a substring check for speed, not for
readability.

If that vote file got very large, I would not slurp it all in in
memory, but instead I'd use a temporary file. Also see perl FAQ 5,
question

# perldoc perlfaq5
[snip]
    How do I change one line in a file/delete a line in a
    file/insert a line in the middle of a file/append to the
     beginning of a file?
[snip]

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd.   | you come to the end; then stop.
NSW, Australia                  | 


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

Date: 29 Sep 2000 03:26:56 GMT
From: ebohlman@omsdev.com
Subject: Re: Newbie question about files
Message-Id: <8r1260$1hcn$1@news.enteract.com>

Larry Rosler <lr@hpl.hp.com> wrote:
> Might it not help to un-Unixify Perl further by adding yet another 
> capability to 'delete EXPR':

>   Note that the EXPR can be arbitrarily complicated as long as the final
>   operation is a hash element, array element, hash slice, or array slice
>   lookup:

> So add that if the EXPR evaluates to a string, the string is taken to be 
> the name of a file, and the operation is synonymous with unlink().  

I'd rather add "This isn't what you want to use if you're trying to delete
a file; C<unlink> is what you need in that case." at the beginning of the
entry for delete() in perlfunc.



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

Date: Fri, 29 Sep 2000 01:30:59 GMT
From: "orassilv" <ssilv@rochester.rr.com>
Subject: Re: parameter passing problem
Message-Id: <nhSA5.45736$%h6.7552865@typhoon.nyroc.rr.com>

Jason,

Works great - thanks!

orassilv


"jason" <elephant@squirrelgroup.com> wrote in message
news:MPG.143ae0dec9c6725b9897cc@localhost...
> orassilv wrote ..
> >Environment:
> >nt4.0,
> >perl is in my path,
> >running from a msdos command line.
> >
> >Have a file called test.pl with the following:
> >   print "Hello world \n";
> >   print "@ARGV \n";
> >   print "First arg: $ARGV[0] \n";
> >   print "Second arg: $ARGV[1] \n";
> >
> >When I call it with test.pl p1 p2 from the command line I get:
> >Hello world
> >
> >First arg:
> >Second arg:
> >
> >When I call it with perl test.pl p1 p2 from the command line I get:
> >Hello world
> > p1 p2
> >First arg: p1
> >Second arg: p2
> >
> >Why do I need to explicity call test.pl using "perl test.pl p1 p2" in
order
> >to get my parameters passed correctly into test.pl?
>
> because your .pl file association is setup incorrectly .. I don't know
> which version of perl you're using .. but the latest 5.6 release makes
> the correct association .. so - three choices
>
> 1) keep doing the "perl program.pl parameters" thing
>
> 2) install the latest perl from ActiveState
>
> 3) adjust the association yourself .. from Explorer go to View > Options
> > File Types tab .. then in the "Registered file types" window scroll
> down to the "Perl File" entry .. highlight it - click Edit .. highlight
> the "Open" entry in the Actions window - click Edit and change the
> command line to
>
>   drive:\path\to\perl\bin\Perl.exe "%1" %*
>
> note the double quoted %1 (that's the filename of the perl program -
> double quotes to allow spaces in the filename) .. then the %* which is
> any number of parameters
>
> QED
>
> --
>   jason -- elephant@squirrelgroup.com --




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

Date: Fri, 29 Sep 2000 02:20:25 GMT
From: Randy <randy_734@my-deja.com>
Subject: Re: Perl Regex
Message-Id: <39d3fb66.50256359@207.126.101.100>


>Thanks for your help, but I think I got it worked out, I bought a book
>on regex :), For anyone who cares it is:
>$_ =~ s/([0-9]*) ([0-9]*) ([0-9]*)/\\$1\\$2\\$3\\/;
>
Buying the book was probably a good idea.  You've come up with a
solution that will work.  Of course, so will the very nice Regex that
Larry put together for you, far more efficiently.



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

Date: Fri, 29 Sep 2000 02:21:52 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Perl Regex
Message-Id: <st7v60g459r033@corp.supernews.com>

vlad_the_impaler24@my-deja.com wrote:
: Thanks for your help, but I think I got it worked out, I bought a book
: on regex :), For anyone who cares it is:
: $_ =~ s/([0-9]*) ([0-9]*) ([0-9]*)/\\$1\\$2\\$3\\/;

A few comments:

* Though it's perfectly okay, doing '$_ =~' explicitly is rather non-
  Perlish.  $_ is the default operand of matches and substitutions.
* The regex pattern \d is equivalent to [0-9], and often easier to
  understand in a complex regex.
* Your pattern matches too much; because you use the * quantifier,
  zero digits is a perfectly acceptable match.  So, for example,
  '  1' will become '\\\1'.
* As a general rule, solving an 'n equivalent patterns' problem like
  this with a hand-copied sequence of matches and substitutions is
  a bad idea.  It multiplies opportunities for mistyping, and makes
  maintenance harder when you decide your data suddenly includes
  four-number sequences.  (Obviously, ignore this advice if for
  some reason three-number sequences are exactly what you want, and
  e.g. '1 2 3 4 5' should definitely become '\1\2\3\4 5'.)

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Quidquid latine dictum sit, altum viditur."
   |


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

Date: 29 Sep 2000 02:44:29 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Perl Regex
Message-Id: <slrn8t80dt.k0e.abigail@alexandra.foad.org>

Craig Berry (cberry@cinenet.net) wrote on MMDLXXXVI September MCMXCIII in
<URL:news:st7v60g459r033@corp.supernews.com>:
,, vlad_the_impaler24@my-deja.com wrote:
,, : Thanks for your help, but I think I got it worked out, I bought a book
,, : on regex :), For anyone who cares it is:
,, : $_ =~ s/([0-9]*) ([0-9]*) ([0-9]*)/\\$1\\$2\\$3\\/;
,, 
,, A few comments:
,, 
,, * Though it's perfectly okay, doing '$_ =~' explicitly is rather non-
,,   Perlish.  $_ is the default operand of matches and substitutions.
,, * The regex pattern \d is equivalent to [0-9], and often easier to
,,   understand in a complex regex.

What \d matches is locale dependent. While for most (all?) locales based
on ASCII and the various ISO-8859 standards, \d will match [0-9], this
becomes quite different with Unicode.

    use utf8;
    use strict;

    my $count = 0;

    for my $c (0 .. 2 ** 16 - 1) {
        $count ++ if chr ($c) =~ /^\d$/;
    }

    print "Unicode has $count characters matching \\d.\n";
    __END__


With Perl 5.6.0 this will emit a bunch of warnings, and then print:
    Unicode has 188 characters matching \d.

In Perl 5.7.0, the warnings are fixed, and with the updated Unicode
tables, we get:
    Unicode has 198 characters matching \d.

Note that no locale is set.

,, * Your pattern matches too much; because you use the * quantifier,
,,   zero digits is a perfectly acceptable match.  So, for example,
,,   '  1' will become '\\\1'.
,, * As a general rule, solving an 'n equivalent patterns' problem like
,,   this with a hand-copied sequence of matches and substitutions is
,,   a bad idea.  It multiplies opportunities for mistyping, and makes
,,   maintenance harder when you decide your data suddenly includes
,,   four-number sequences.  (Obviously, ignore this advice if for
,,   some reason three-number sequences are exactly what you want, and
,,   e.g. '1 2 3 4 5' should definitely become '\1\2\3\4 5'.)


OTOH, if you later decide the middle sequence should have only even 
digits, the hand copied sequence is much easier to change. ;-)



Abigail
-- 
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
#    Two mosquitoes
#    crawling in an oak. A goldfish
#    swimming. A dove.


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

Date: Fri, 29 Sep 2000 03:33:12 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Perl Regex
Message-Id: <st83bohh2i1rc5@corp.supernews.com>

Abigail (abigail@foad.org) wrote:
: ,, * The regex pattern \d is equivalent to [0-9], and often easier to
: ,,   understand in a complex regex.
: 
: What \d matches is locale dependent. While for most (all?) locales based
: on ASCII and the various ISO-8859 standards, \d will match [0-9], this
: becomes quite different with Unicode.

Dear god.  There goes the last thing I thought I could count on.  <shakes
head sadly>

[snip]
: OTOH, if you later decide the middle sequence should have only even 
: digits, the hand copied sequence is much easier to change. ;-)

Yeah, but a real perler would be happier capturing the new pattern
algorithmically, anyway. :)

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Quidquid latine dictum sit, altum viditur."
   |


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

Date: Fri, 29 Sep 2000 02:40:03 GMT
From: pgodkin@my-deja.com
Subject: Read and Split Individual Text File Lines
Message-Id: <8r0ve2$759$1@nnrp1.deja.com>

This should be easy. All I want to do is step through the first 4 lines
of a text file, split each line and get the second field value. I don't
want to use a while statement as the file is large.

How do you step through a text file? Thank-you.

open(DATA, "$input_dir/$filename") or die "Could not open $filename:
$!";
#  while (<DATA>)
#   {
      next;
      readline $_;
      print "$_\n";
      ($field1, $field2) = split /=/, $_;

      if ($field1 = "#SPATIAL_EXPORT_SID")
      {
        $export_sid = $field2;
        print "export sid = $export_sid\n" if $debug;
      }
#   }
   close DATA or die "Couldn't close the DATAFILE: $!";


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 28 Sep 2000 20:08:43 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Read and Split Individual Text File Lines
Message-Id: <39D407BB.E4B79487@vpservices.com>

pgodkin@my-deja.com wrote:
> 
> This should be easy. All I want to do is step through the first 4 lines
> of a text file, split each line and get the second field value. 

> I don't
> want to use a while statement as the file is large.

Perhaps that sentence makes sense to you, it doesn't make sense to me. 
Using a while steps through the file a line at a time and is exactly
what is called for when the file is large.

> How do you step through a text file? Thank-you.

With a while loop, almost like you have done below.

> open(DATA, "$input_dir/$filename") or die "Could not open $filename:
> $!";

The word DATA has a special meaning in Perl when capitalized like that,
choose something else.

> #  while (<DATA>)
> #   {

Uncomment those lines.

>      next;

???? This says, never do anything, just keep reading lines but hop to
the next line as soon as you've read it.  Remove this.

>       readline $_;

I have no idea what that is suppossed to do.

>       print "$_\n";
>       ($field1, $field2) = split /=/, $_;

That is fine, though you don't need to explicitly mention the $_.

>       if ($field1 = "#SPATIAL_EXPORT_SID")

You want the operator "eq", not "=".

>       {
>         $export_sid = $field2;
>         print "export sid = $export_sid\n" if $debug;
>       }
> #   }
>    close DATA or die "Couldn't close the DATAFILE: $!";

That's all fine.  Although you haven't done anything with the values
you've captured except to print them when debugging.

If I understood what your intention is, you want to only read the first
four lines, and then stop reading the rest of the file.  If that's the
case, then you need to count the lines and use "last" to break out of
the while loop when the count reaches four.  So before the while loop
put "my $count = 0;".  Inside the while loop, just before the final
curly brace, put these lines:

    $count++;             # increment the count
    last if $count == 4;  # stop reading after the 4th line

HTH,

-- 
Jeff


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

Date: Fri, 29 Sep 2000 03:50:48 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Read and Split Individual Text File Lines
Message-Id: <slrn8t84cl.64u.mgjv@verbruggen.comdyn.com.au>

On Thu, 28 Sep 2000 20:08:43 -0700,
	Jeff Zucker <jeff@vpservices.com> wrote:
> 
> If I understood what your intention is, you want to only read the first
> four lines, and then stop reading the rest of the file.  If that's the
> case, then you need to count the lines and use "last" to break out of
> the while loop when the count reaches four.  So before the while loop
> put "my $count = 0;".  Inside the while loop, just before the final
> curly brace, put these lines:
> 
>     $count++;             # increment the count
>     last if $count == 4;  # stop reading after the 4th line

Or you can use the Perl builtin variable $. (or $NR or
$INPUT_LINE_NUMBER if you use English).

$ perldoc perlvar

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 42.6% of statistics is made up on the
Commercial Dynamics Pty. Ltd.   | spot.
NSW, Australia                  | 


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

Date: Fri, 29 Sep 2000 01:30:05 -0000
From: Mel Kaye <melkaye@compuserve.com>
Subject: Receiving HTML email messages on Compuserve v4.01
Message-Id: <st7s4t62he2eac@corp.supernews.com>

When I receive emails in HTML, I get a display that says the file cannot 
be opened.

What utility am I missing?

Thanks,

Mel Kaye

--
Posted via CNET Help.com
http://www.help.com/


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

Date: Fri, 29 Sep 2000 11:08:20 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Receiving HTML email messages on Compuserve v4.01
Message-Id: <6mSA5.1470$ea3.4131@vic.nntp.telstra.net>

"Mel Kaye" <melkaye@compuserve.com> wrote in message
news:st7s4t62he2eac@corp.supernews.com...
> When I receive emails in HTML, I get a display that says the file
cannot
> be opened.
>
> What utility am I missing?
>

You need to install Perl 5.6 available from www.activestate.com

Then check CPAN for the appropriate module.


--
Wyzelli
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




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

Date: Thu, 28 Sep 2000 23:52:07 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: splitting lines with a regex
Message-Id: <Pine.GSO.4.21.0009282256300.5957-100000@crusoe.crusoe.net>

>Really and truly? Have you tested your code? Usually
>a good practice to test code before posting. I always
>do and, even after exhaustive testing, sometimes my
>code is still buggy. Have you tested your code?

"If this does not produce the proper output, oops on me."

"I mis-wrote.  The program, to the best of my knowledge, places a properly
formatted string into $newstr."

Yes, I tested my code, but with a rather special set of data that ended up
not showing the error in my code.  I present a corrected version.  This
even allows for paragraphs to be broken up.

#!/usr/bin/perl

print formatString(60, << 'END');
Jeff Pinyan believes that, in order
for people to understand Perl, they
need to put forth the effort to
discover things on their own.  He's
not saying he won't help them, but
he's also not saying he will serve
them what they wish on a platter.

Rather, he will give them pointers
and hints and suggestions, and even
tell them what resources he
recommends they look at for further
information.  He doesn't have the
time nor personal resources to
explain every nuance of Perl to
every person who asks him a question.
END

sub formatString {
  my ($len, $string) = @_;
  my $format = '^' . ('<' x --$len) . "~~\n";
  my @wrapped;

  for (split /\n{2,}/, $string) {
    local $^A;
    formline($format, $_);
    push @wrapped, $^A;
  }

  return join "\n", @wrapped;
}

__END__

Yes, you will notice I made significant changes to the code -- this is
because, like I said, the data I used for my (single) test proved to be a
unique case.  And, although I cannot remember the poster's original
intent, I understand there may be some desire for paragraph handling.
This has been taken care of.  There are still more features to be added,
like dealing with a block of indented text.

>Oh. I get it. Post gibberish code and have the reader
>spends hours, perhaps days, trying to figure it out,
>if this can be done, figuring it out this is.

There was an error on my part in posting insufficient and erroneous
code.  If I was asked, though, I gladly would have explained what the
"mysterious" format line I created is doing.

>> I'm introducing the topic of formats, which are an INTEGRAL part of a
>> language that was orginally developed for practical extraction and
>> REPORTING of data.  Formats offer very nicely styled reportation of data.
>
>I read no introduction. I read a few personal insults
>followed by a lot of techno-geekster gibberish. Why
>are you so motivated to initiate your articles with
>personal insults? Personality problem? Sociopath?

Why do you wait until the middle of your articles to insult me?  I had to
read a few paragraphs of text before I was labelled a techno-geekster and
charged with spewing gibberish.  And I did not insult you.  This is the
text I wrote:

  I think that Godzilla should put an
  end to her incredibly obtuse, and
  often off-topic, metaphors and such.
  Clouding an explanation with useless
  rhetoric is not helpful, especially
  to new users to the newsgroup.

If you will not admit that you pepper your postings with highly repetitive
and often obtuse comments, then you are in denial, as far as I am
concerned.  For someone who seems awfully bent on giving readers the code
they want that works how they want it, you do a great deal of beating
around the bush.

And as for being a sociopath (read: psychopath, as per Merriam-Webster), I
am not in a state of mental illness, nor is every person who makes less
than favorable comments about another person a psychopath.

>Yeah, and programmers should test their
>code before proclaiming it a masterpiece.

That is an unbased snide remark -- I did not ever state my code was
bug-free, nor that it was better than yours, nor that it was a
masterpiece.  I simply stated that formats are "another way to do it".

>My presumption is you either don't know how 
>to write programs or couldn't be bothered
>with helping someone by offering a program
>which is a stand alone, as a courtesy. You
>know, like anyone who doesn't have a command
>line screen, is a blithering idiot. Why bother
>with such idiots, huh?

My experience with many people learning Perl is that, when given a
standalone program, they have problems incorporating the specific parts of
the program they need into THEIR creation.  I will use this analogy, which
I think is perfectly suitable:  if you want a carburetor and tailpipe for
an invention of yours, you wouldn't want to have to get an entire car and
determine what parts of it you needed -- you would like to get
specifically the pieces you requested.

I gave the poster another method of solving his problem (and now, in this
posting, I have corrected errors that you pointed out, and suggested even
more improvements).  He asked for means to split a string, and I gave him
a specific method -- I expect him to have the intelligence to take the
code fragment and use it as he needs.

You'll notice a trend in function documentation for practically every
programming language:

  function(ARGLIST)
  explanation
  sample usage

Here's an excerpt from perlfunc.pod:

  localtime EXPR
  [...]
  In scalar context, returns the ctime(3) value:
    $now_string = localtime;  # e.g., "Thu Oct 13 04:54:34 1994"

Well, if you run THAT sample program, you'd better make sure you specify
perl at the command line, since there's no #! line -- even worse,
$now_string is never used.  The Perl documentation offers sample usages,
and expects the reader to extrapolate the usage into a functional program.

Here's an excerpt from the getc() documentation for C:

     #include <stdio.h>
     int getc(FILE *stream);

Apart from an explanation of getc() -- which is a macro, not a function --
that's all there is.  The C documentation is more space-efficient than to
produce a full-blown program for every function and macro and directive it
offers.

Here's the __doc__ string for the string.split() function in Python:

  split(str [,sep [,maxsplit]]) -> list of strings
  splitfields(str [,sep [,maxsplit]]) -> list of strings

  Return a list of the words in the string s, using sep as the
  delimiter string.  If maxsplit is nonzero, splits into at most
  maxsplit words If sep is not specified, any whitespace string
  is a separator.  Maxsplit defaults to 0.

It offers a template for usage, and an explanation.  Again, no program.

This trend is followed because (personal mantra of mine)

  Programming is About Finding Patterns

To be a good programmer, you have to recognize patterns -- specifically in
the language you're using -- but in algorithms in general.  You should be
able to apply the knowledge that localtime() in scalar context returns a
string that holds the date in a readable format, and that, to display this
string, you need to use the print() function.  If you need a program to
demonstrate that, you need to spend more time learning the language.

>Teenager right?

Yes.  I'll soon be 19.  

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/






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

Date: Fri, 29 Sep 2000 12:20:45 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: subroutines, print to a file not happening, cgi
Message-Id: <MPG.143ea789140ce2959897df@localhost>

tjmurphy9677@my-deja.com wrote ..
>strange problem. i'm trying to write data to a file from a perl cgi
>script (apache web server on NT) and its not writing anything to the
>file that orginates from a subroutine.

your code works for me v5.6 build 616 on WinNT

what version of Perl are you using ?

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Fri, 29 Sep 2000 02:41:27 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: syntax:search and replace
Message-Id: <39d40156.5195$1c4@news.op.net>
Keywords: Galapagos, grebe, tachistoscope, trauma


In article <8r0g7l$s1t$1@nnrp1.deja.com>,  <sujh@my-deja.com> wrote:
>I need to search "production/xml" and replace it
>with "xmlbuild/production/xml". 
> $targetline =~ s/production//xml/xmlbuild//production//xml/;

  $targetline =~ s{production/xml}{xmlbuild/production/xml};



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

Date: Thu, 28 Sep 2000 08:43:43 +0700
From: Djoko Tri <trisa@sby.dnet.net.id>
Subject: UDP socket using perl?
Message-Id: <39D2A24F.DF57090E@sby.dnet.net.id>

do anyone now how to create socket connection for UDP protocol using
perl?
or maybe some simple client/server script example of it in perl?
help....

thanx

Djoko



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

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

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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.

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 V9 Issue 4465
**************************************


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