[8985] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2603 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 14 20:07:23 1998

Date: Thu, 14 May 98 17:00:50 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 14 May 1998     Volume: 8 Number: 2603

Today's topics:
    Re: Compiling Perl (Martien Verbruggen)
    Re: Does Perl have a IDE?I don't like command line. (Ilya Zakharevich)
    Re: Does Perl have a IDE?I don't like command line. (Abigail)
    Re: Does Perl have a IDE?I don't like command line. (Michael J Gebis)
    Re: Does Perl have a IDE?I don't like command line. <ebohlman@netcom.com>
    Re: Does Perl have a IDE?I don't like command line. <ebohlman@netcom.com>
    Re: Does Perl have a IDE?I don't like command line. (Michael J Gebis)
    Re: HELP: Need Perl for Macintosh (brian d foy)
    Re: How can you break out of a 'while... ' loop in a fu (Nathan V. Patwardhan)
    Re: How can you break out of a 'while... ' loop in a fu (Ilya Zakharevich)
    Re: How can you break out of a 'while... ' loop in a fu (Ilya Zakharevich)
    Re: IPC with not nice programs (solution) <haverlan@agric.gov.ab.ca>
    Re: New Math Modules (Ilya Zakharevich)
    Re: Perl compiler: does it work (Ilya Zakharevich)
    Re: Perl Not Showing Errors <webbgw@erols.com>
    Re: perl text editor for windows95 (Steven Wayne)
    Re: perl text editor for windows95 <joneil@cks.ssd.k12.wa.us>
    Re: perl text editor for windows95 <due@murray.fordham.edu>
    Re: REGEX Question <rbskipper@wimberley-tx.com>
    Re: Tearing my hair out over Regular Expressions - help (Martien Verbruggen)
    Re: Tip: How to access a hash through a pointer (Martien Verbruggen)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 14 May 1998 23:28:41 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Compiling Perl
Message-Id: <6jfun9$l0p$2@comdyn.comdyn.com.au>

In article <01bd7f24$f411cf40$683615a5@singnet>,
	"LauRenCe WonG" <xiaoyu@singnet.com.sg> writes:
> Hello!
>  
> any good compilers to recommend for perl?  i heard there are only a few
> compilers in the market and most are still in process of modifications and
> a lot of patches.  i need a compiler to compile my scripts becoz i need to
> pass the scripts to a friend who doesnt have a perl interpreter.  

As far as I know, there is only one perl compiler (if you don't count
the perl interpreter, which also compiles, in a way) That perl
compiler is in an alpha stage, and is certainly not ready for
production use.

Normally you use perl with the interpreter, and there is really only
one of those. There are some ports, but they are all based on the same
perl.

Have a look at http://www.perl.com/

Browse around a bit. Go into the documentation section, check out the
FAQ (part 1 will answer your question, part 3 talks about the
experimental compiler). Then download perl from there, install it, and
off you go.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd.       | you come to the end; then stop.
NSW, Australia                      | 


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

Date: 14 May 1998 23:08:56 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6jfti8$j0n$1@mathserv.mps.ohio-state.edu>
Keywords: If you're happy and you know it, clunk your chains.

[A complimentary Cc of this posting was sent to Tom Christiansen 
<tchrist@mox.perl.com>],
who wrote in article <6jforg$o5i$7@csnews.cs.colorado.edu>:
> That's the whole point.  These silly things -- including emacs -- are
> best for people who don't know how to use the tools that came with
> their operating system.  And they'll never learn them either, since
> they aren't using them.  It's like emacs weenies who freak out
> when you autoreformat paragraphs in vi.  Folks who never learned the
> multiple-tool philosophy and orthogonal command set are stumped.

Note, however, that "multiple-tool philosophy and orthogonal command
set" is what "Perl philosophy" was designed to replace.  

And we are discussing Perl here, not some GNU tools (for which your
remark would be hitting the nail).

Ilya


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

Date: 14 May 1998 23:29:00 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6jfuns$eoj$2@client2.news.psi.net>

Tom Christiansen (tchrist@mox.perl.com) wrote on MDCCXVII September
MCMXCIII in <URL: news:6jforg$o5i$7@csnews.cs.colorado.edu>:
++  [courtesy cc of this posting sent to cited author via email]
++ 
++ In comp.lang.perl.misc, 
++     murrayb@vansel.alcatel.com writes:
++ :So at what point does this IDE become redundant because you are doing
++ :work already available via the operating system?  
++ 
++ That's the whole point.  These silly things -- including emacs -- are
++ best for people who don't know how to use the tools that came with
++ their operating system.  And they'll never learn them either, since
++ they aren't using them.  It's like emacs weenies who freak out
++ when you autoreformat paragraphs in vi.  Folks who never learned the
++ multiple-tool philosophy and orthogonal command set are stumped.

My operationg system didn't come with Perl either. It came with sh,
awk, mv, sleep, etc. 

Shoul I use those instead of Perl?



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


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

Date: 14 May 1998 23:35:30 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6jfv42$p9s@mozo.cc.purdue.edu>

Tom Christiansen <tchrist@mox.perl.com> writes:
}In comp.lang.perl.misc, 
}    gebis@albrecht.ecn.purdue.edu (Michael J Gebis) writes:
}:Okay, sure, I can accept that for now.  So what is the right course of
}:action?  What's a proactive type of guy like myself supposed to do?  

}Just make the PoB Perl installation kit include a GUI popup called perl
}help or something.

This isn't a snipe, but I have to ask.

I'm having trouble why I caught such flak from you previously, and how
a GUI popup is all that different than:

[MJG wrote:]
>My previous course of action was to hope that a good IDE could bring
>the documentation home to Win users in a way they would be more likely
>to use.


-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: Thu, 14 May 1998 23:47:43 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <ebohlmanEsz0rJ.DF4@netcom.com>

Mark Maurer <mwmaurer@mtu.edu> wrote:

: I wouldn't worry about distant lose32 brethren.  If perl really catches on,
: pretty soon someone will create Visual Perl, thereby proving even Perl can be
                                  ^^^^^^^^^^^
: made useless by adding the Visual... :)

YM "Visual P++."  HTH.



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

Date: Thu, 14 May 1998 23:45:26 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <ebohlmanEsz0nq.D8n@netcom.com>

fsg@gallo.ultranet.com wrote:
: IDEs are tools that perform a certain function.  They have no inbuilt 
: intent.  Many people's needs are completely filled by IDEs.  The fact
: that this frustrates and angers and disappoints you is in no way contrary
: to that reality.

One could argue that IDEs were created to fulfill a need that no longer
exists.  They originated as DOS applications, where they served an
important function, namely getting around some of the limitations imposed
by having a single-task OS.  The benefit of an IDE was that, for example,
you didn't have to keep reloading your editor and then reloading your
source after after trying a compile, and you didn't have to write down or
print out your list of error messages and warnings (in case you couldn't
memorize them at all) before reloading your editor wiped them off the 
screen.  Those were real benefits.

But now, even Win95 lets you have multiple console windows open at the 
same time.  You can keep one (or several) editing sessions open at the 
same time you run a compilation.  You can be editing in one window and 
looking at error messages in another one.  Now, it's possible to get 
those benefits without an IDE, using ordinary command-line tools.  From 
this point of view, people look for IDEs not because IDEs are 
particularly useful, but because IDEs are what they're used to.

Now, there are some benefits to working in a familiar environment, but
there are also benefits from learning a new environment when that new
environment lets you do more than the old environment.  There's a possibly
apocryphal story about a new military officer who observed an
artillery-shooting exercise and wondered just why there was always a pause
in the action as some of the soldiers moved off to the side and stood
there.  The troops said that was the way they had always done it and they
didn't know the exact reason but if it wasn't important it wouldn't have
been part of the procedure.  The officer thought that the troops could
fire more rounds in a given time if they got rid of the pause, and as he
was still too new to have succumbed to beaurocratic inertia, he did some
research which didn't seem to come up with anything.  Finally he
encountered an elderly veteran socially, learned that he had been part of
an artillery battalion and thought to ask him about it.  The elderly
veteran said "well, in my day we'd have to go off to the side and hold the
horses so they wouldn't bolt when the cannon went boom." 



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

Date: 14 May 1998 23:40:45 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6jfvdt$pfc@mozo.cc.purdue.edu>

Tom Christiansen <tchrist@mox.perl.com> writes:

}Tell me again why these people are programming if they aren't 
}cut out for it?

A very wise person once wrote:

By casual programmer, I do not mean those cerebral priests in
their secluded cloisters dedicating their entire lives to writing the
next great operating systems, newsreaders, command shells,
distributed network admin tools, number crunching spreadsheets,
WYSIWIG editors, or flashy new programming languages. No;
instead I'm talking about that incredibly vast majority of simple
users out there who are only trying to get their jobs done, jobs
that require a mere modicum of practical programming rather than
stellar science. 

I suspect that when people say "nonprogrammer" they really mean this
definition of "casual programmer," but hadn't heard the phrase before.

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: Thu, 14 May 1998 20:02:42 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: HELP: Need Perl for Macintosh
Message-Id: <comdog-ya02408000R1405982002420001@news.panix.com>
Keywords: from just another new york perl hacker

In article <takashi-1405982351060001@195.11.251.156>, takashi@dds.nl (Baseman) posted:

>Does anyone know where I can get Perl for the Mac? If its possible the
>latest version.

see CPAN.  go to the ports directory.

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers <URL:http://www.pm.org>


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

Date: 14 May 1998 23:07:23 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <6jftfb$rdf@fridge.shore.net>

Tom Christiansen (tchrist@mox.perl.com) wrote:

: Of course they do.  Here's what I learned from.

"But I can't read your inclusion with my ("OS" name here) help
program, your highness.  It just goes to show that you're an
elitist..." -- a typical clpm malarchy spreader

--
Nathan V. Patwardhan



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

Date: 14 May 1998 23:18:27 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <6jfu43$jt6$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to John Porter
<jdporter@min.net>],
who wrote in article <MPG.fc525d55aa516db9896c8@news.min.net>:
> So, all I hear from you is whining about how perl docs are not made
> available in a useable format, or nearly-useable, such as that OS/2
> thing.
> 
> Maybe "OS/2 online book" is a starting point. Is the format
> proprietary?  Can you or someone give us a functional specification
> from which to build a better, open-sourced rip-off (gnu-ish)?
> Is anybody working on this problem, or are we doomed to hear
> whining from here on?  How easy is it for you/someone to convert
> pod to "OS/2 online book" format?  If easy, can you/someone make
> the "OS/2 online book"-formated docs available on the CPAN each
> time they're revised?  Or are we going to hear whining about this
> from here on out?

If you do not want to make a fool of yourself in public any more, try
to memorize my name, and next time do you homework before answering my
posts.  

(Unless you notice an obvious error or missssspell, which I' quite
prone to.  ;-)

Ilya


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

Date: 14 May 1998 23:21:19 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <6jfu9f$k99$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Tom Christiansen 
<tchrist@mox.perl.com>],
who wrote in article <6jfo3g$o5i$4@csnews.cs.colorado.edu>:
> :Existence proof:  People _do_ learn from the online docs.
> 
> Of course they do.  Here's what I learned from.
> 
> --tom
> 
> .rn '' }`
> ''' $Header: perl.man.1,v 1.0 87/12/18 16:18:16 root Exp $

Me too.  Note that Chip was answering my statement that perl4 doc was
excellent (even when accessed with *nixish tools), but perl5 doc is
not.

Ilya


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

Date: Thu, 14 May 1998 14:56:46 -0600
From: Gordon Haverland <haverlan@agric.gov.ab.ca>
Subject: Re: IPC with not nice programs (solution)
Message-Id: <355B5A8E.6D0C@agric.gov.ab.ca>

Gordon Haverland wrote:
[ a bunch of IPC related drivel ]
  Oh goody, I get to answer my own note.

Two Days of using CPAN Search and Wait, and using
Infoseek and Altavista search engines turned up
nothing on how to get IPC to work with a program
which is "bc" like, but uses buffered IO.  And even
another day at DejaNews looking through the *perl*
groups was almost fruit-less.  Lots of people
seem to ask the question of how to get this IPC
to work with things superficially like bc, but answers
are sure hard to come by.

So here goes my try at an explanation.

I have a GIS program which can convert coordinates from
latitude-longitude to UTM (universal transverse mercator?).
Anyway, you start the program at the terminal, it
displays an obligatory header, and then prompts you for
input with
> 
At which point you type in the coordinates and it responds
with the UTM coordinates.  Almost like giving bc the problem
of adding "1+1" to get "2".

[ IPC::Open2 and Comm.pl never seemed to be able to work.
Comm.pl would get input into and out of the program, but
it never seemed to discard what was already read.  So the
second time you wanted to read input, you had to read everything
from the begining.  (This is on Solaris 2.5.1/UltraSparc.)
IPC::Open2 always attached the process to a pseudo-terminal
which was already in use by another program.  I have no
idea why. ]

So here goes my program.
#!/path/to/your/perl

use Expect;
use IO::File;  # I don't know if this is needed, but what the heck.

$ll2u = Expect->spawn('m.ll2u', 'spheroid=wgs84');
$ll2u->expect(undef,"> ") || die "Timed out wating for m.ll2u\n";
$ll2u->clear_accum();

#Hopefully Expect is now read for care and feeding of m.ll2u

for($i = 0; $i < 385090; $i++ ) {
    # Told you I had a lot of coordinates to convert :-)

    $line = <STDIN>;  # Get a line of input
    ...               # Massage into format to feed m.ll2u
    print $ll2u "$dms\n";
    ($match, $error, $string, $before, $after) =
        $ll2u->expect( $timeout, "\n" );
    die "Timed out\n" if $error;

    # $string contains the newline we matched.
    # $before contains the string we fed into m.ll2u (with prompt)
    # and $after contains the coordinates we want
    ...  # More processing of data
}

Hopefully the above will be of use to someone.

Thanks to the writer of the Expect.pm package.

Gordon Haverland
haverlan @ agric.gov.ab.ca


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

Date: 14 May 1998 23:15:20 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: New Math Modules
Message-Id: <6jftu8$jlm$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Ala Qumsieh 
<aqumsieh@matrox.com>],
who wrote in article <355B521F.F2E90D9D@matrox.com>:
> Hi all,
> 
> I have developped a couple of modules that allow symbolic manipulation
> of mathematical expressions. As long as you adhere to the convention I
> use, the functions will work as you expect (and might save you some time
> and effort in the process).
> Some limitations apply, of course. For example, you can use only 1
> variable and you have to be careful with using brackets. Currently, they
> can't handle functions like sin, cos .. etc , but I will be working
> toward that.
> The modules allow simplifying a long expression, as well as integration
> and differentiation.

I do not think anyone will be able to deduce what you did from this
description.  I also hope that you investigated Math::Pari before
doing your work.

Ilya


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

Date: 14 May 1998 23:24:59 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl compiler: does it work
Message-Id: <6jfugb$kgo$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Tom Phoenix 
<rootbeer@teleport.com>],
who wrote in article <Pine.GSO.3.96.980514154736.17330R-100000@user2.teleport.com>:
> Are you aware that Perl code which has been compiled can also be
> de-compiled? :-)

I had a glance through the output of perlcc for _64 (which would not
run with threads enabled, so I cannot check it - my only _64 is
threaded) and I would say that this is not very likely.  And the
original poster would not care...

Ilya


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

Date: Thu, 14 May 1998 07:46:23 -0500
From: Garth Webb <webbgw@erols.com>
Subject: Re: Perl Not Showing Errors
Message-Id: <355AE798.88E999C9@erols.com>

To answer Tom C., I know that error recovery is difficult and I agree
that seeing a flood of error messages after the first couple is
useless.  However, regardless of what compiler theory and construction
courses we've taken, you must agree that Perl or any
compiler/interpreter must at least report where the *first* error
occurred.  If you read my message you'll see I say that I don't get
*any* error messages besides the "XXXX had compilation errors" message.
In your terms, Perl isn't even telling me where the flood starts.
    Tom P. and Ilya, I am using Perl 5.00404 and running 'perl -c' on
one module of my program.  Ilya you mentioned the possibility of $@
being overwritten.  Since 'perl -c' only runs code within 'BEGIN' and
'use' blocks I'll try commenting out any such blocks and see if that
makes a difference.  Thank you both for your help, and let me know if
you can think of any other possible reasons why I would be getting this
terse output.

Garth Webb



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

Date: Thu, 14 May 1998 23:10:31 GMT
From: steven@amber.co.uk (Steven Wayne)
Subject: Re: perl text editor for windows95
Message-Id: <355d7943.5910959@news.demon.co.uk>

Diane Strahl <jimndi@sgi.net> wrote:

>Can someone recommend a good, easy-to-use text editor to use for writing
>perl programs on windows95? I used bbedit on a friend's mac, which is
>the sort of thing I'm looking for. I've looked at vim and emacs, but
>they seem more complicated than what I want. Are they worth spending the
>time to learn? What are the advantages of these? Anything out there with
>pull-down menus rather than having to memorize all the commands which
>need to be typed in? Right now I'm using the basic windows95 text
>editors - notepad and wordpad. It'd be nice to use something that at
>least had syntax coloring.

Give emacs another try, and use the cperl module for the colours. Learn the
control key codes, it's faster than clicking on pull down menus, even on
things that have menus.

Steven.

-- 
We pray for one last landing, on the globe that gave us birth,
To rest our eyes on fleecy skies, and the cool green hills of Earth.
                                                  -- R.A. Heinlein
http://www.ambercomputing.demon.co.uk/


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

Date: Thu, 14 May 1998 16:10:26 -0700
From: Jerome O'Neil <joneil@cks.ssd.k12.wa.us>
To: jimndi@sgi.net
Subject: Re: perl text editor for windows95
Message-Id: <355B79E2.7C021314@cks.ssd.k12.wa.us>

ED for Windows.  http://www.getsoft.com

Does everything you want from a text editor, in just about any language you
might choose to write.

Jerome

Diane Strahl wrote:

> Can someone recommend a good, easy-to-use text editor to use for writing
> perl programs on windows95? I used bbedit on a friend's mac, which is
> the sort of thing I'm looking for. I've looked at vim and emacs, but
> they seem more complicated than what I want. Are they worth spending the
> time to learn? What are the advantages of these? Anything out there with
> pull-down menus rather than having to memorize all the commands which
> need to be typed in? Right now I'm using the basic windows95 text
> editors - notepad and wordpad. It'd be nice to use something that at
> least had syntax coloring.
>
> Thanks!
>
> Diane





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

Date: 14 May 1998 23:58:41 GMT
From: "Allan M. Due" <due@murray.fordham.edu>
Subject: Re: perl text editor for windows95
Message-Id: <6jg0fh$908$0@206.165.146.143>

    If you are willing to spare a few dollars I really like UltraEdit
www.ultraedit.com.  It has all the bells and whistles, including colored
text, plus it allows you to run Perl from within the editor and then capture
the output to either a new file or a listbox.  I find it much easier to edit
my scripts this way as I don't have to keep opening and closing files or
move back and forth between windows.  UE also lets you run your default
browser from within the editor so you can check how your CGI scripts are
working all from within the same environment.  You can even add a run Perl
button to your UE task bar so you just click the button and check the
output.  Either the listbox or new file option lets you scroll through the
output from Perl very easily.
    TextPad (essential free) http://www.textpad.com/ offers many of the same
options plus a point and click library of Perl code.  I use both of them
often.
    HTH


Allan M. Due
Due@discovernet.net
Admin@WhiteCrow.net

The beginning of wisdom is the definitions of terms.
- Socrates




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

Date: Thu, 14 May 1998 18:34:23 -0500
From: Robert Boyd Skipper <rbskipper@wimberley-tx.com>
Subject: Re: REGEX Question
Message-Id: <355B7F7E.AAEED059@wimberley-tx.com>

Your regex doesn't ask what you want to ask.  (\S*){1,3} asks for any number
(perhaps none) of non-space characters, and between one and three such
matches.  This is satisfied by "(T)(w)(i)ce."  To get three words, you need
to include word breaks in your parens: (\S+\s+){1,3} would do it, or
(\w+\s+){1,3}.

Skipper

Kevin Miles wrote:

> Try this:
>
> if (/\s*(\S*)\s*(\d+\.\d+)\s*(.*?)\d/)
>
> Gary Chambers wrote:
>
> > #!/usr/bin/perl -w
> >
> > while (<>)
> > {
> >     if (/\s*(\S*)\s*(\d+\.\d+)\s*(\S*){1,3}/)
> >     {
> >        $login = $1; $totalpmt = $2; $frequency = $3;
> >        print "$login\t$totalpmt\t$frequency\n";
> >     }
> > }
> >
> > Why am I only extracting "Twice" in the "Twice a year" field?  Should
> > I not be getting all three of the words with {1,3} in the regexp?  Any
> > help is *GREATLY* appreciated...





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

Date: 14 May 1998 23:24:32 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Tearing my hair out over Regular Expressions - help!
Message-Id: <6jfufg$l0p$1@comdyn.comdyn.com.au>


Please read the following information on how to choose a good subject
line:

http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

In article <3559f6e5.4095422@news.cableinet.co.uk>,
	ljs@cableinet.co.uk (Luke Steele) writes:

> The problem is this:  I have a file containing a number of lines, each
> of which consists of a field name (in uppercase) followed by some text
> (the 'value' of that particular line) followed by a newline.  The
> contents of the file is placed in a scalar.  I wish to be able to
> place the text following the field name in each line into a specific
> scalar variable determined by the field name.

Is there any reason why you have to read in the whole file in a
scalar,  which you then have to process, instead of reading in each
line, and processing them one by one? Or even reading the file in in a
list, and processing that. It's a lot easier.

while (<DATA>)
{
    chomp;
    my($name, $value) = split(/:\s*/);

    $value =~ s/\s+$//;

    print "|$name| - |$value|\n";
}

__DATA__
CONTACT:  Luke Steele  
ADDRESS: asdf  

I'll leave error checking up to you, and storage of the variables.
BTW: Have you considered using a hash to store this stuff? It is
probably a lot more efficient, and certainly a lot easier to
understand, manage and maintain.

Since you asked about how to do this with a regexp if the whole thing
is stored in a variable:

> I've written a regular expression to acheive this but it goes haywire
> every time it encounters a line which has a field name but is
> otherwise empty (i.e. an empty entry).  Below is an example of the
> regular expression I've come up with (I've substituted underscores for
> spaces in the variable values):
> 
> "CONTACT:  Luke Steele  \nADDRESS: asdf  \n" =~
> /^CONTACT:\s*(.*)\s*\n/gmi;
> $&==CONTACT:_______Luke Steele___
> $1==Luke Steele___

That is because the \s* part of the regexp matches the \n

Try something like (notice that you don't need the m modifier, and in
my case, the i modifier isn't needed either:

my $stuff;

{
    local($/) = undef;
    $stuff = <DATA>;
}

# Don't worry about trying to get rid of spaces here
while ($stuff =~ /(\w+):(.*)\n/g)
{
    my $name = $1;
    my $value = $2;

	# Now get rid of the spaces
    $value =~ s/^\s+//;
    $value =~ s/\s+$//;
    
    print "|$name| - |$value|\n";
}

__DATA__  
CONTACT:  Luke Steele
EMPTY:   
ADDRESS: asdf

It doesn't matter wether there are any spaces behind EMPTY: or not.

I still maintain that splitting your lines up in a list, and
processing that list one line at a time is a lot easier.

There are some simple examples in the perlre man pages about this sort
of thing:

# perldoc perlre

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | 
Commercial Dynamics Pty. Ltd.       | What's another word for Thesaurus?
NSW, Australia                      | 


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

Date: 14 May 1998 23:38:31 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Tip: How to access a hash through a pointer
Message-Id: <6jfv9n$l0p$3@comdyn.comdyn.com.au>

In article <6jegon$ia8$1@nnrp1.dejanews.com>,
	greene@gucc.org writes:
> I'm not exactly a newbie to perl (I've been using it for over 18 months), but
> have often wondered what the proper form is for de-referencing pointers to a
> hash. After a bit of trial-and-error, I've found that the following code
> works, and is accepted even with 'use strict' turned on.

You use the word 'pointer' but I suspect that you are really talking
about references?

I don't think there is a proper way of dereferencing them, and since
perl does all kinds of magic things to figure out what is in all that,
you can do it in several ways.

The perlref man page sums them up, in a rather clear way, I must say,
with notes about advantages and disadvantages, and caveats.

# perldoc perlref
     That's it for creating references.  By now you're probably
     dying to know how to use references to get back to your
     long-lost data.  There are several basic methods.

etc..

No matter which style you choose, I think it's just important that you
stick with it, just to keep your code readable :)

Martien

PS. You say: 'I feel that this is not well explained in either the
on-line docs ...'. Personally I don't see what is wrong with the
explanation in perlref, especially if one also reads perldsc. Maybe
you can submit a patch to the documentation that is more clear?
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | That's not a lie, it's a terminological
Commercial Dynamics Pty. Ltd.       | inexactitude.
NSW, Australia                      | 


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

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

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