[8456] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2073 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 11 12:07:12 1998

Date: Wed, 11 Mar 98 09:00:30 -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           Wed, 11 Mar 1998     Volume: 8 Number: 2073

Today's topics:
    Re: "newbie" problem with "reverse" <stackhou@elk.cray.com>
    Re: ? on http://www.perl.com/CPAN-local/doc/FMTEYEWTK/s <jdporter@min.net>
        ?name=A+B <arnoud@notenbomer.nl>
    Re: array question <jdporter@min.net>
    Re: c.l.p.mod and TPI (Chris Nandor)
    Re: c.l.p.mod and TPI (Kate Wrightson)
    Re: Calling Perl Scripts <Jacqui.Caren@ig.co.uk>
    Re: Checking filedate in perl (Bjorn Malmberg)
    Re: Checking filedate in perl (Vincent Fatica)
    Re: Checking filedate in perl <dean@tbone.biol.sc.edu>
        Completely Stumped <d.thomson@netcom.co.uk>
    Re: difference between 's' and 'tr' [SEEDOC] <eike.grote@theo.phy.uni-bayreuth.de>
    Re: Getting started with perl (Mike Stok)
    Re: Help: avoiding eval() on a grep() function. schwern@starmedia.net
        How to export an environment variable ? myself@technologist.com
    Re: m//x punctuation + comment oddity <dboorstein@shopcfn.com>
    Re: OpenGL (Chip Salzenberg)
    Re: Perl 4/5 <Jacqui.Caren@ig.co.uk>
        Perl equivalent for /bin/which <NOSPAM.stephane.barizien@ocegr.fr>
        PGP / $PGPPASS sentinel@spprod.se
    Re: Philisophical Response? Perl5/oop <Jacqui.Caren@ig.co.uk>
    Re: Regex & Variables (Mike Stok)
    Re: Regex & Variables <westxga@ptsc.slg.eds.com>
    Re: Speed of sort routine vs. one-by-one compare   (123 (Abigail)
    Re: Speed of sort routine vs. one-by-one compare   (123 (Ken Fox)
    Re: splice -- useful uses? (Mike Stok)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Mar 1998 10:03:14 -0600
From: Mark P Stackhouse <stackhou@elk.cray.com>
To: Quentin Fennessy <quentin@jihad.amd.com>
Subject: Re: "newbie" problem with "reverse"
Message-Id: <3506B5C2.41C6@elk.cray.com>

Quentin Fennessy wrote:
> 
> >>>>> "MPS" == Mark P Stackhouse <stackhou@elk.cray.com> writes:
> 
>     MPS> I am trying to reverse the order of data in a file.  I can
>     MPS> open a test file, write the data into an array and then
>     MPS> reverse the data into another array.  However, when I print
>     MPS> the data to STDOUT, the data appears to be off by one line.
>     MPS> Why?
> 
> From perlfunc(1), or perldoc -f reverse
> 
>     print reverse <>;
> 
> --
> Quentin Fennessy                        AMD, Austin Texas


Thanks Quentin.  It took awhile to figure out what to put in the <> but
I'm up and running now!

-- 
 Mark Stackhouse
 x64704

 *********************************************************
 *							 
 * Senior Electrical-Mechanical Technician		 
 * Homepage - http://wwwmfg.cray.com/~stackhou	 
 * E-mail - stackhou@elk.cray.com				 
 *							 
 * Off site homepage - http://www.execpc.com/~stackhou
 *
 * Home E-mail - stackhou@execpc.com				 
 *				 			 
 * "The best things in life aren't things"		 
 *							 
 *********************************************************


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

Date: Wed, 11 Mar 1998 11:39:50 -0500
From: John Porter <jdporter@min.net>
Subject: Re: ? on http://www.perl.com/CPAN-local/doc/FMTEYEWTK/sort.html --- Sorting ?
Message-Id: <3506BE56.7AD1@min.net>

Andrew M. Langmead wrote:
> 
> perl treats "split('\t', $_)" the same as "split(/\t/,$_)"
> 
> Actually, double quotes can be worse because then the variable gets
> interpolated twice. (Once in the double quotes, and then again in the
> match operator.)

Oook, you're right.


> John Porter <jdporter@min.net> writes:
> 
> >Short answer:
right;

> > you need "\t" instead of '\t'.
wrong.


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

Date: Wed, 11 Mar 1998 17:20:53 +0100
From: "Arnoud de Jong" <arnoud@notenbomer.nl>
Subject: ?name=A+B
Message-Id: <6e6dq9$c8b$1@info.service.rug.nl>

Hi

Suppose i have name with spaces included (Arnoud de Jong). Now I want to
create a link to another .pl that would look like this :
dosomething?name=Arnoud+de+Jong

How can I change the <space> to <+>?

Arnoud



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

Date: Wed, 11 Mar 1998 11:43:47 -0500
From: John Porter <jdporter@min.net>
Subject: Re: array question
Message-Id: <3506BF43.38D8@min.net>

Hunter Johnson wrote:
> 
> So $VG contains "vg00" and you then want to create @vg00, right?
> 
> $VG = "vg00";
> eval ("@" . $VG . " = (1, 2, 3);");
> eval ("print @" . $VG . ";");
> print "\n", @vg00, "\n";

Blargh, just use symbolic refs.

$VG = "vg00";
@{$VG} = ( 7,8,9 );

$" = ",";
print "VG=(@{$VG})\n";

John Porter


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

Date: Wed, 11 Mar 1998 11:02:48 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: c.l.p.mod and TPI
Message-Id: <pudge-1103981102480001@ppp-49.ts-1.kin.idt.net>

In article <889584849.326190@cabal>, ? the platypus {aka David Formosa}
<dformosa@st.nepean.uws.edu.au> wrote:

# >Sigh.  Not one person on TPI's board was listed as one of the moderators. 
# >What, you mean the provision that TPI can post "ads" makes it a
# >moderator?  That is nonsensical.
# 
# I was told on this thread that ads would be sent to TPI, thay would look
# at them and decide wether or not thay where apporprate to the newsgroup
# and then post them. In other words thay are acting just as a moderator
# would.

No, they are not.  Don't spread lies.  Even were this to be the case, this
is only one function of being a moderator.  That's like saying that the
Oval Office janitor is the President just because he flushes the toilet
for Bill.

--
Chris Nandor               pudge@pobox.com           http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])
#==                    MacPerl: Power and Ease                     ==#
#==    Publishing Date: Early 1998. http://www.ptf.com/macperl/    ==#


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

Date: 11 Mar 1998 08:14:54 -0800
From: kate@eyrie.org (Kate Wrightson)
Subject: Re: c.l.p.mod and TPI
Message-Id: <6e6d9u$ulk@eyrie.org>

In article <pudge-1103981102480001@ppp-49.ts-1.kin.idt.net>,
Chris Nandor <pudge@pobox.com> wrote:
>In article <889584849.326190@cabal>, ? the platypus {aka David Formosa}
><dformosa@st.nepean.uws.edu.au> wrote:

># I was told on this thread that ads would be sent to TPI, thay would look
># at them and decide wether or not thay where apporprate to the newsgroup
># and then post them. In other words thay are acting just as a moderator
># would.
>
>No, they are not.  Don't spread lies.  Even were this to be the case, this

Randal wrote, earlier in this thread:

>The postings to be approved by the TPI board for "commercial"
>announcements will most likely be just conference related
>(call-for-papers, final announcement) and new products available
>(one-time postings for books etc.). 

I can certainly understand David' interpretation.  It's not necessary to
call him a liar.
-- 
___________________________________________________________________________
     kate@eyrie.org          Kate Wrightson        www.eyrie.org/~kate
what flower expresses days go by and they just keep going by over and over
                  endlessly into the future days go by....


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

Date: Wed, 11 Mar 1998 13:14:51 GMT
From: Jacqui Caren <Jacqui.Caren@ig.co.uk>
Subject: Re: Calling Perl Scripts
Message-Id: <Epnosr.71E@ig.co.uk>

In article <6cq2ve$ebr$1@nnrp2.dejanews.com>,  <amerar@unsu.com> wrote:
>
>
>Hello,
>
>From within an HTML document, how do I can a Perl script when no form or
>button is involved?

news:comp.infosystems.www.authoring.cgi
news:comp.infosystems.www.servers.unix

http://perl.apache.org/

Jacqui
-- 
Email: Jacqui.Caren@ig.co.uk  http://www.ig.co.uk/
Fax  : +44 1483 419 419       http://www.perlclinic.com/
Phone: +44 1483 424 424       http://www.perl.co.uk/
Paul Ingram Group Ltd,140A High Street,Godalming GU7 1AB United Kingdom



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

Date: Wed, 11 Mar 1998 16:08:00 GMT
From: news@NOSPAMgb-design.com (Bjorn Malmberg)
Subject: Re: Checking filedate in perl
Message-Id: <3506b67b.13357579@news.algonet.se>

On Wed, 11 Mar 1998 13:49:33 GMT, news@NOSPAMgb-design.com (Bjorn
Malmberg) wrote:

<snip>
>I use perl for win32 (5.003) Could I make a system command (dir) and
>take the date from there perhaps? Any help on this is appreciated,
<snip>

Problem fixed !

Thanks to Vincent for great answer on my problem ! :)
____________________________________________________
Take away the word NOSPAM to make an email reply! :)


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

Date: Wed, 11 Mar 1998 15:57:49 GMT
From: vefatica@syr.edu (Vincent Fatica)
Subject: Re: Checking filedate in perl
Message-Id: <3506b013.150633920@news.ican.net>

On Wed, 11 Mar 1998 13:49:33 GMT, news@NOSPAMgb-design.com (Bjorn Malmberg)
wrote:

>OK, so I need to check a file when it was written now... if the file
>is not written that day, the perl script should write to it, but if it
>was written the same day, not write to it... that should be no
>problem, I think.. however, how could I check when the file was
>written last time in perl?

Use stat("file")  and compare the returned $mtime (field [9]) to "time". If
you're just concerned with today, you can hit 'em both with gmttime (or
localtime) and compare the $year ([5]) and $yday ([7]) fields.

 - Vince

___
   Vincent Fatica
   Syracuse University Mathematics
   vefatica@syr.edu
   http://barnyard.syr.edu/~vefatica/


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

Date: 11 Mar 1998 11:14:27 -0500
From: Dean Pentcheff <dean@tbone.biol.sc.edu>
Subject: Re: Checking filedate in perl
Message-Id: <87u395yzks.fsf@tbone.biol.sc.edu>

news@NOSPAMgb-design.com (Bjorn Malmberg) writes:
> Hi all!!
> 
> Thanks a lot for all the help on my rand prob.. the script works fine
> now!
> 
> OK, so I need to check a file when it was written now... if the file
> is not written that day, the perl script should write to it, but if it
> was written the same day, not write to it... that should be no
> problem, I think.. however, how could I check when the file was
> written last time in perl?

Have you considered reading the Perl documentation?  Several megabytes
of it came with your Perl installation.  Filetest operators are
documented in the perlfunc manual section.

> I use perl for win32 (5.003) Could I make a system command (dir) and
> take the date from there perhaps? Any help on this is appreciated,
> same as before... please CC a copy to my mailbox taking away the
> NOSPAM thing in my address! Can't look so very much on the newsgroup
> right now since inet cost so damn much here in Sweden ! :)
> 
> Thanks for any help on this ! 
> 
> Bjorn
> ____________________________________________________
> Take away the word NOSPAM to make an email reply! :)

No.  You want to use Usenet to get help, but you don't want to read
Usenet?  And you want me to edit your email address for you?  You're
kidding.  

-Dean (in a bit of a Tom C. mood this morning...)
-- 
N. Dean Pentcheff                                          <pentcheff@acm.org>
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-7068)


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

Date: Wed, 11 Mar 1998 16:46:11 -0000
From: "David" <d.thomson@netcom.co.uk>
Subject: Completely Stumped
Message-Id: <3506c084.0@news.netcom.co.uk>

Please Help,

I am brand new to all this Perl programming business although I have a
familiarity with HTML and C.
The first thing I done was to download Perl release 5.004, but am finding it
difficult to get working. To be honest, I haven't got the faintest idea of
where to start...I have a book on Perl which says about compiling with a C
compiler(which I have) but it is very vague about instructions(and when I
say vague, I mean virtually none)....so my main questions are below and I
would be grateful if anybody could help me out:

1. How do compile a script? Do I even need to?
2. How do I install the Perl 5.004 I have?
3. Do I need to be connected to my service provider to run a program?
4. Can I write scripts in something like 'Notepad' and then just save them
with the extension .pl.

Any help most graciously welcomed
Jim.




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

Date: Wed, 11 Mar 1998 16:41:48 +0100
From: Eike Grote <eike.grote@theo.phy.uni-bayreuth.de>
Subject: Re: difference between 's' and 'tr' [SEEDOC]
Message-Id: <3506B0BC.446B@theo.phy.uni-bayreuth.de>

Hi,

Carl David wrote:
> 
> If in the perl program one write tr/a/A one gets uppercase 
> translation, but if one writes:
> $a = 'a';
> $A = 'A';
> $b =~ tr/$a/$A/;
> well, to be honest, nothing happens.

See the 'perlop' manual page:

   Note that because the translation table is built at compile time,    
   neither the SEARCHLIST nor the REPLACEMENTLIST are subjected to 
   double quote interpolation. ...


Bye, Eike
-- 
=======================================================================
>>--->>    Eike Grote  <eike.grote@theo.phy.uni-bayreuth.de>    <<---<<
-----------------------------------------------------------------------
 Home Page, Address, PGP,...:  http://www.phy.uni-bayreuth.de/~btpa25/
-----------------------------------------------------------------------
 PGP fingerprint:      1F F4 AB CF 1B 5F 4B 1D 75 A1 F9 C5 7B 3F 37 06
=======================================================================


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

Date: 11 Mar 1998 16:09:55 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Getting started with perl
Message-Id: <6e6d0j$8n2@news-central.tiac.net>

In article <6e6a99$hmr$1@nnrp1.dejanews.com>,  <wsayegh@lynx.neu.edu> wrote:
>I am not a PERL professional, and I need the following help. How could I do
>the following:
>
>Store the first 140 characters of each line (line by line) in a variable, and
>the rest of the characters (141+) in another variable. If the first character
>in the variable is equal to X the do so else do that....
>
>Please get back with your help

If you're reading from a file then:

  while (<FILE>) {
    # $_ contains each record, usually a line

    # maybe ('cos in perl there's more than one way to do it)

    # use length to see if the line is long enough 
    # use substr to carve up the line, maybe into $part1 and $part2

    if ($part1 eq 'something') {
      # ...
    }
    else {
      # ...
    }
  }

should help you find perl's functions which can be used to do what yoiu
want.  In recent installations of perl

  perldoc perlfunc

will get you the documentation for perl's built in functions, and if you
want to see the (slightly marked up) docs for a particular function then

  perldoc -f length

might be helpful.

If this seems too complicated then you should probably think about getting
a book like Learning Perl by Schwartz & Christiansen to take you through
the basics of perl.  There's lots of useful information (including
frequently asked questions & their answers, book reviews) at
http://www.perl.com which will save you time and effort in the future.

Hope this helps,

Mike

  
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Wed, 11 Mar 1998 09:55:38 -0600
From: schwern@starmedia.net
Subject: Re: Help: avoiding eval() on a grep() function.
Message-Id: <6e6c36$j1i$1@nnrp1.dejanews.com>

Aren't look ahead patterns expensive?


In article <35057D95.52212F75@gpu.srv.ualberta.ca>,
  Andrew Johnson <ajohnson@gpu.srv.ualberta.ca> wrote:
>
> or, we can build with look-ahead patterns
> and avoid eval() altogether:
>
> @Array=('aaa'..'zzz');
> @patterns=qw(a q w);
> $big_pattern=join('',map{"(?=.*$_)"}@patterns);
> @matches=grep /^$big_pattern/i,@Array;
> print "@matches\n";
>
> regards
> andrew
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Wed, 11 Mar 1998 09:51:35 -0600
From: myself@technologist.com
Subject: How to export an environment variable ?
Message-Id: <6e6bs3$j05$1@nnrp1.dejanews.com>

Is it possible to export an environment variable in a perl script ?We want
to call PGP and to pass it some environment variables.
Thanks for your help.





















[QSD]

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Wed, 11 Mar 1998 11:04:42 -0500
From: Dan Boorstein <dboorstein@shopcfn.com>
Subject: Re: m//x punctuation + comment oddity
Message-Id: <3506B61A.D568895@shopcfn.com>

jnutting@rebisoft.com wrote:
> 
> Here's something odd.  With the following program:
> 
> $testString = "bill=evil";
> if ($testString =~
>   /\w+  # bill comment
>   =
>   \w+   # evil comment
>   /x) { print "case 1: Matched the =.\n"};
> if ($testString =~
>   /\w+  # bill comment
>   =     # comment of death
>   \w+   # evil comment
>   /x) { print "case 2: Matched the =.\n"};
> I get this output:
> 
> 1: Matched the =.
> 

looks like and old bug. it prints both instances with 5.004.
i'd recommend an upgrade for this and many other reasons.

cheers,

-- 
# dan boorstien <dboorstein@shopcfn.com>
seek DATA,0,0;print($_=<DATA>),__END__
Just another Perl hacker,


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

Date: Wed, 11 Mar 1998 16:49:40 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: OpenGL
Message-Id: <6e6fej$8rs$1@cyprus.atlantic.net>

According to Nick Ing-Simmons <nik@tiuk.ti.com>:
>Does anyone know wher I can contact author, or failing that 
>existing users of the OpenGL module?

Perhaps you could download the OpenGL module and look in the README
and the comments.
-- 
Chip Salzenberg                - a.k.a. -               <chip@pobox.com>
"I brought the atom bomb.  I think it's a good time to use it."  //MST3K
           ->  Ask me about Perl training and consulting  <-
     Like Perl?  Want to help out?  The Perl Institute: www.perl.org


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

Date: Wed, 11 Mar 1998 12:52:21 GMT
From: Jacqui Caren <Jacqui.Caren@ig.co.uk>
Subject: Re: Perl 4/5
Message-Id: <Epnnr9.6wI@ig.co.uk>

In article <34ED68D5.129E@POBoxes.com>,
Geert Roovers  <Geert.Roovers@POBoxes.com> wrote:
>Hi All!
>
>I'm making my first steps on the Perl path, and sofar, I have one major
>problem. I can only find books teaching me Perl 5, but my system manager
>has only Perl 4 installed, and won't install the newest version. And I
>think there is where some of my problems are.

Let me guess, it's a HPUX machine?
It seems that sysadmins believe that the perl4 shipped with these
machines is "supported" and so will not migrate to perl5. FWIU,
the perl4 shipped is contributory only, and *no support* is provided.

I hope someone from HP will respond to this and clarify the matter
as I have seen a lot of similar complaints by sysadmins and
end-users about perl4 being "supported" and perl5 being "unsupported".

If this is your situation
-------------------------
You first have to correct your sysadmins misapprehension about
perl4 being a supported, stable product. You then have to point him
to
	www.perlclinic.com  - support for almost anything perlish
and	www.perlsupport.com - platform specific builds and support?

for commercial support for perl5. Both services are ran by people
well known in the Perl world.

The only people I know who are sticking to perl4 are those who
require Perl on DOS boxes, or those whose applications run
slower under perl5 and are very stable - these people tend to
have a good many years of Perl under thier belt, and make
such decisions very carefully. They also provide thier own
perl4 support.

Beginners should NOT use perl4, as it lacks so many features
and development opportunities provided by perl5.

>thanx,
>
>Geert Roovers

All the best,
	Jacqui
-- 
Email: Jacqui.Caren@ig.co.uk  http://www.ig.co.uk/
Fax  : +44 1483 419 419       http://www.perlclinic.com/
Phone: +44 1483 424 424       http://www.perl.co.uk/
Paul Ingram Group Ltd,140A High Street,Godalming GU7 1AB United Kingdom



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

Date: Wed, 11 Mar 1998 16:56:28 +0100
From: "Stephane Barizien" <NOSPAM.stephane.barizien@ocegr.fr>
Subject: Perl equivalent for /bin/which
Message-Id: <6e6c2c$oh01@janus.ocegr.fr>

Maybe (probably) a newbie's question: how do I perform the equivalent of
/bin/which (or, for Korn Shell addicts, the equivalent of "whence" or
"type") in a Perl program?

I can of course parse $ENV{"PATH"} myself, but there sure is a
simpler-don't-reinvent-the-wheel method out there (CPAN?)

TIA





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

Date: Wed, 11 Mar 1998 09:50:49 -0600
From: sentinel@spprod.se
Subject: PGP / $PGPPASS
Message-Id: <6e6bq8$itp$1@nnrp1.dejanews.com>

Stupid question...

I am trying to execute pgp using 'system("pgp bla-bla-bla");'. Well, the
problem is that I don't know how to setup $PGPPASS variable (within perl
script), so pgp can use it!? If i use system("setenv...") it doesn't work.
$ENV{'PGPPASS'} doesn't work either. Could someone help me, or "forward" to
some doc which contains explanation about this?

Thanks in advance.

Vanja

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Wed, 11 Mar 1998 13:12:32 GMT
From: Jacqui Caren <Jacqui.Caren@ig.co.uk>
Subject: Re: Philisophical Response? Perl5/oop
Message-Id: <Epnoox.704@ig.co.uk>

In article <6d22a5$9uh$1@brokaw.wa.com>, Elf Sternberg <elf@halcyon.com> wrote:
>In article <autopen-2202981053190001@dynamic58.pm07.mv.best.com> 
>    autopen@autopen.com (Laurel Shimer) writes:
>
>>When we talk he always says 'you are going to need to write this (new
>>code) in Perl 5'. It seems to me that since I invoke the Perl5 interpreter
>>and use functions that are new to Perl 5 (chomp, newer version of
>>subroutine calls, etc.) that I am 'writing in Perl 5'. He, of course,
>>feels that to write in Perl 5 is to write object oriented only.
>
>	You are writing in Perl 5.  The poor boy needs a small
>clue upside the head.  I write OO Perl all the time (I even write

s/clue/club/; # Typo? :-)

Jacqui
-- 
Email: Jacqui.Caren@ig.co.uk  http://www.ig.co.uk/
Fax  : +44 1483 419 419       http://www.perlclinic.com/
Phone: +44 1483 424 424       http://www.perl.co.uk/
Paul Ingram Group Ltd,140A High Street,Godalming GU7 1AB United Kingdom



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

Date: 11 Mar 1998 16:00:01 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Regex & Variables
Message-Id: <6e6ce1$8n2@news-central.tiac.net>

In article <6e6a0j$hsm$1@usenet40.supernews.com>,
Brian Morin <brian@laserlink.net> wrote:
>
>I'm having a heck of a time trying to change a variable with a regex.
>Here is the code.
>
>The input looks like this
>
>Area = "west"
>
>I'm trying to pull out ONLY whats IN the double-quotes, not the quotes
>themselves. Then I'm also trying to put that into a variable, or change the
>variable that currently holds the information.
>
>$field1 = "Area = \"west\"" # The input is actually from a file.. This is
>for testing.
>$field1 =~ /"[^"]*"/gi;     # This matches the whole double-quote, and
>information inside.
>print "$&\n";               # This prints out the string.
>
>I would like to be able to simply change the $field1 with a regex, but can't
>get it to fly.
>
>$field2 = ($field1 =~ /"[^"]*"/gi;) # Only produces 1's

The 1 means that the match worked,

  ($field2) = $field1 =~ /"([^"]*)"/;

is one way to do what you want to the data you've presented, the ()s
around the $field2 on the left of the = provide a list context to the
match, and the ()s in the match remember what matched the part of the
regex inside them.

The /ig modifier is probably unnecessary for the data presented as you're
not using characters which have case in your regex and there's only one
match, this might help show what the g does:

  DB<1> $field1 = "Area = \"west\""

  DB<2> ($field2) = $field1 =~ /"([^"]*)"/

  DB<3> print $field2
west
  DB<4> $field1 = 'Area = "West" Size = "Big"'

  DB<5> @list = $field1 =~ /"([^"]*)"/g

  DB<6> X list
@list = (
   0  'West'
   1  'Big'
)

Note that as @list is already a list it doesn't need to be enclosed in ()s

The perlre man page might be a good thing to look at for further
information.  The list of frequently asked questions has section 6 which
deals with regexes.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Wed, 11 Mar 1998 11:12:23 +0000
From: Glenn West <westxga@ptsc.slg.eds.com>
Subject: Re: Regex & Variables
Message-Id: <35067197.6579@ptsc.slg.eds.com>

Brian Morin wrote:
> 
> I'm having a heck of a time trying to change a variable with a regex.
> Here is the code.
> 
> The input looks like this
> 
> Area = "west"
> 
> I'm trying to pull out ONLY whats IN the double-quotes, not the quotes
> themselves. Then I'm also trying to put that into a variable, or change the
> variable that currently holds the information.
> 
> $field1 = "Area = \"west\"" # The input is actually from a file.. This is
> for testing.
> $field1 =~ /"[^"]*"/gi;     # This matches the whole double-quote, and
> information inside.

$field1 =~ /"([^"]*)"/gi;

> print "$&\n";               # This prints out the string.

print "$1\n";

> 
> I would like to be able to simply change the $field1 with a regex, but can't
> get it to fly.
> 
> $field2 = ($field1 =~ /"[^"]*"/gi;) # Only produces 1's
>


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

Date: 11 Mar 1998 16:03:02 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Speed of sort routine vs. one-by-one compare   (123)
Message-Id: <6e6cjm$g45$1@client2.news.psi.net>

Uri Guttman (uri@sysarch.com) wrote on 1653 September 1993 in
<URL: news:x7sooptxic.fsf@sysarch.com>:
++ 
++ read the problem. a single record inserted into a single file on
++ disk. no ram caches, buffers etc. show me how to process all the records
++ without doing the same I/O. my solution at least lowers the number of
++ record compares. which can add up to signifigant cpu if the compare is
++ long or complex and the file is large. I/O is usually not cpu intensive
++ and is a CONSTANT for the purposes of analysis. only when you must
++ design algorithms where your dataset must be in memory do you need to
++ deal with it as in tape merge/sort operations.

N records is a constant? Please....



Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: 11 Mar 1998 16:00:41 GMT
From: kfox@pt0204.pto.ford.com (Ken Fox)
Subject: Re: Speed of sort routine vs. one-by-one compare   (123)
Message-Id: <6e6cf9$2jk12@eccws1.dearborn.ford.com>

abigail@fnx.com (Abigail) writes:
> Ken Fox (kfox@pt0204.pto.ford.com) wrote:
> ++ However, Abigail assumes a naive insertion.  If the insertions are
> ++ cached in memory ...
> 
> No, that has nothing to do with a naive insertion. It is my impression
> that the new records are coming one by one and need to be processed when
> arrived.

I must have missed the original posting.  If the records have to be
processed (and written back to disk) immediately, then the original
poster is screwed.  I hope he doesn't have to insert very many
records... ;)

About the only thing that can be done is to adopt a more sophisticated
file format that (usually) doesn't require moving data to insert a record.

- Ken

-- 
Ken Fox (kfox@ford.com)                  | My opinions or statements do
                                         | not represent those of, nor are
Ford Motor Company, Powertrain           | endorsed by, Ford Motor Company.
Analytical Powertrain Methods Department |
Software Development Section             | "Is this some sort of trick
                                         |  question or what?" -- Calvin


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

Date: 11 Mar 1998 16:26:53 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: splice -- useful uses?
Message-Id: <6e6e0d$8n2@news-central.tiac.net>

In article <6e6aeo$17m$1@aurwww.aur.alcatel.com>,
John Klassa <klassa@aur.alcatel.com> wrote:
>I've been programming in perl (or is that "programming perl"? :-)) for a
>few years now.  In that time, I have never once used splice...  Either my
>code is more convoluted than it would be, were I to use splice, or splice
>just isn't that useful in the application domain in which I operate.
>
>Either way, what do people use splice for?  I know what it does and how to
>use it, but I don't really have a handle on cool places it might show up.
>I don't know of any handy perl idioms that make use of it, for example.

A couple of uses might be:

If you're consuming multiple elements from an array at once e.g.

  while (@list > 3) {
    my ($one, $two, $three) = splice @list, 0, 3;

    ...
  }

If you're maintaining an ordered list and want to put something in the
middle or remove something from then splice can be useful - this is one
way of using perl's dynamic arrays similar to the way a linked list might
be used in C to achieve the same effect. 

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

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

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