[10654] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4246 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 18 10:07:17 1998

Date: Wed, 18 Nov 98 07:00:27 -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, 18 Nov 1998     Volume: 8 Number: 4246

Today's topics:
        /g modifier: why not 'last' out of while loop? (J.D. Laub)
    Re: 500 server error (Matthew Bafford)
        Access Database (nospam)
    Re: Access Database <perlguy@technologist.com>
        Auto Incrementing Characters-a subtle problem? (Owen Cook)
    Re: Auto Incrementing Characters-a subtle problem? <garethr@cre.canon.co.uk>
    Re: Auto Incrementing Characters-a subtle problem? <garethr@cre.canon.co.uk>
    Re: Auto Incrementing Characters-a subtle problem? <lbenfie1@nospamford.com>
    Re: Beginner Book? scott@softbase.com
    Re: CGI Problem is so far unsolvable any takers wanna t <cgormley@netcomuk.co.uk>
        Help needed: How to redirect output from STDOUT into li (Ron)
    Re: How do I make an EXE in Win 98? <Allan@due.net>
    Re: How to access a file within a perl program <harms@rupert.informatik.uni-stuttgart.de>
    Re: how to get `date` in perl for win32 (newbie) <barnett@houston.Geco-Prakla.slb.com>
    Re: Intermediate Perl questions <m.kaiser@sz-sb.de>
    Re: is embedded Perl thread-safe ? (Greg Chapman)
    Re: Learning <Allan@due.net>
    Re: MacPerl + Resource Fork (Steffen Beyer)
    Re: MacPerl + Resource Fork dturley@pobox.com
        perl & win95Dosbox <Thomas.Schachner@awd.at>
        perl 5.005_02 <prauz@sprynet.com>
    Re: Perl Array Question? Anybody... <Allan@due.net>
    Re: Perl_for_Win32_FAQ <perlguy@technologist.com>
    Re: Possible bug in "sort" (Tad McClellan)
        reverse comma operator in the camel (J.D. Laub)
    Re: Smarter Web Mailer (I.J. Garlick)
    Re: Two-Part RE question (I.J. Garlick)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Wed, 18 Nov 1998 14:23:23 GMT
From: jdl@iasi.com (J.D. Laub)
Subject: /g modifier: why not 'last' out of while loop?
Message-Id: <3652d910.0@mirage.iasi.com>

I don't understand something in the Cookbook.  From pg. 170:

[To find the Nth match in a string,]
Use the /g modifier in a while loop, keeping count of matches:

$WANT = 3;
$count = 0;
while (/(\w+)\s+fish\b/gi) {
    if (++$count == $WANT) {
        print "The third fish is a $1 one.\n";
        # Warning: don't `last' out of this loop
    }
}

Why can't a 'last' be used to bail out of the loop?

J.D. Laub (Laubster) |"I think you're very, very, very, very, very,
jdl@iasi.com         |very, very, very, very, ..." - Flying Lizards



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

Date: Wed, 18 Nov 1998 07:46:51 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: 500 server error
Message-Id: <MPG.10bc8bc11941c3d8989718@news.scescape.net>

In article <36523476.4AA6@erase.courrier.usherb.ca>, JTJ 
<jtjohnston@erase.courrier.usherb.ca> pounded in the following:
=> 	perl -w file.pl
=> 	perl -w file.cgi
=> 
=> These will run your perl debugger.
=> 

They will?

Maybe you mean:

     perl -d file.pl
     perl -d file.cgi

--Matthew


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

Date: Wed, 18 Nov 1998 20:09:29 +0800
From: "Ho Seng Yip" <hsengyip@(nospam)singnet.com.sg>
Subject: Access Database
Message-Id: <72udch$4vb$2@mawar.singnet.com.sg>

Hi,

I am wondering if Perl can actually read and write data into / from a
Microsoft Access database.

If you have any useful links to relevant resources, please let me know too.

Thanks.

Regards,
Seng Yip

- Please remove ' (nospam) ' to e-mail me. -





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

Date: Wed, 18 Nov 1998 13:09:06 GMT
From: Brent Michalski <perlguy@technologist.com>
Subject: Re: Access Database
Message-Id: <3652C6F2.97E82B8C@technologist.com>

Ho Seng Yip wrote:
> 
> Hi,
> 
> I am wondering if Perl can actually read and write data into / from a
> Microsoft Access database.
> 
> If you have any useful links to relevant resources, please let me know too.

It is quite simple on an NT box.  On a Unix box, from what I have
(read|heard), you need to buy a program to access the Access DB. :-)

Useful links, hmmmm.....

I **ALWAYS** start at http://www.perl.com  From there I'd click on the
"Database" link.  Then I'd check out the DBI interface and look at the
DBD::ODBC drivers...

Good luck!
Brent
-- 
Java? I've heard of it, it is what I drink when I am hacking Perl. -me
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$            Brent Michalski             $
$         -- Perl Evangelist --          $
$    E-Mail: perlguy@technologist.com    $
$ Resume: http://www.inlink.com/~perlguy $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$


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

Date: Wed, 18 Nov 1998 12:30:25 GMT
From: rcook@pcug.org.au (Owen Cook)
Subject: Auto Incrementing Characters-a subtle problem?
Message-Id: <36548b7b.24852467@newshost.pcug.org.au>

I found this in an FAQ

Quote
You can also get into subtle problems on those few operations in Perl that
actually do care about the difference between a string and a number, such
as the magical ++ autoincrement operator or the syscall function. 
Unquote

So I tried running this line,
for ($j="a";$j le "z";$j++){print "$j\n";}

I got 676 entries from  'a'  to 'yz' , it doesn't stop at  'z' , but when I
changed the 'le' to 'lt', 

for ($j="a";$j lt "z";$j++){print "$j\n";}

I got the expected 25 entries, 'a' to 'y'.  It stops before it hits 'z'

I would have thought that there would only be one character difference from
the two lines.  

So presumeably, this is a subtle problem? or is the expression wrong in the
first test?

-- 
Owen


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

Date: Wed, 18 Nov 1998 12:47:45 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: Auto Incrementing Characters-a subtle problem?
Message-Id: <sik90ttbf2.fsf@cre.canon.co.uk>

Owen Cook <rcook@pcug.org.au> wrote:
> I tried running this line,
> for ($j="a";$j le "z";$j++){print "$j\n";}
> 
> I got 676 entries from  'a'  to 'yz' , it doesn't stop at  'z'

What do you expect?  When $j is 'z', the expression $j le 'z' returns
true, so the loop continues.  Then after executing the auto-increment
$j++, $j is 'aa', and $j le 'z' still returns true, so the loop
continues.

You're expecting ++ to have the following property:

   ++$a always compares greater than $a

which is not true of strings in Perl.

-- 
Gareth Rees


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

Date: Wed, 18 Nov 1998 13:02:35 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: Auto Incrementing Characters-a subtle problem?
Message-Id: <siiugdtaqc.fsf@cre.canon.co.uk>

Owen Cook <rcook@pcug.org.au> wrote:
> So I tried running this line,
> for ($j="a";$j le "z";$j++){print "$j\n";}
> 
> I got 676 entries from  'a'  to 'yz' , it doesn't stop at  'z'

Of course, the way to do what you want is

   for ('a' .. 'z') { print }

-- 
Gareth Rees


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

Date: Wed, 18 Nov 1998 13:28:44 +0000
From: Lee Benfield <lbenfie1@nospamford.com>
Subject: Re: Auto Incrementing Characters-a subtle problem?
Message-Id: <3652CB8B.3DCB@nospamford.com>

Gareth Rees wrote:
> 
> Owen Cook <rcook@pcug.org.au> wrote:
> > <snippedy>
> 
> What do you expect?  When $j is 'z', the expression $j le 'z' returns
> true, so the loop continues.  Then after executing the auto-increment
> $j++, $j is 'aa', and $j le 'z' still returns true, so the loop
> continues.

A question on a similar note...

Autoincrementing a character gives a character, but autodecrementing
doesnt.

Any way to change this behaviour?  And why is it like it is, out of 
interest?

Lee.

-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Lee A Benfield, Ford Motor Co. | The above are my opinions alone.
                               | I couldn't afford better ones...


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

Date: 18 Nov 1998 13:52:14 GMT
From: scott@softbase.com
Subject: Re: Beginner Book?
Message-Id: <3652d10e.0@news.new-era.net>

David Barnes (nospamaardvark@ibm.net) wrote:
> The book you want is Perl by Example by Ellie Quigley, ISBN
> 0-13-122839-0.

***NO***!!!!

This book is HORRIBLE. I gave it a "total loss" review on my
Cyber Reviews web site. It is *BAD*.

Scott

PS: for the review, see http://www.skwc.com/essent/cyberreviews.html
Look for the Windows 95 Book FAQ.


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

Date: Wed, 18 Nov 1998 13:18:59 -0000
From: "Clinton Gormley" <cgormley@netcomuk.co.uk>
Subject: Re: CGI Problem is so far unsolvable any takers wanna try to solve...
Message-Id: <72uhfc$r57$1@taliesin.netcom.net.uk>

Forget the solution!  I haven't been able to figure out what it is you want
to do.  Try to break it down a bit - like into sentences.

Clint




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

Date: Wed, 18 Nov 1998 15:09:49 +0200
From: macron.nospam@casema.net (Ron)
Subject: Help needed: How to redirect output from STDOUT into list?
Message-Id: <macron.nospam-1811981509500001@5dyn18.utr.casema.net>

Hi all,

On my site I use a set of scripts. I need to use the output of a couple of
the subroutines of those in a new script. But the output is 'print'-ed to
STDOUT (and that I
need).

Would I be able to redirect the output of a subroutine (that prints to
STDOUT) into a list?

Thanks for all tips!

Ron

-- 
macron(a)casema.net (change (a) to @ when replying; vervang (a) door @ bij
antwoorden)


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

Date: Wed, 18 Nov 1998 08:12:37 -0500
From: "AmD" <Allan@due.net>
Subject: Re: How do I make an EXE in Win 98?
Message-Id: <72ugra$94r$1@camel15.mindspring.com>


Geoffrey Cleaves wrote in message <3652554E.EAC95807@bigfoot.com>...
>Can somebody please lead me in the right direction, please.  I am
>(fairly) new to Perl, so I kindly ask for a little detail and maybe an
>example or two.  I'm not looking to compile my scripts to hide them from
>anybody, I just want to make it easier to run them and I'm just curious
>to know if it is possible.  Thanks for any help.
>

WWW.perl2exe.com


HTH

AmD




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

Date: 18 Nov 1998 12:16:52 GMT
From: Christian Harms <harms@rupert.informatik.uni-stuttgart.de>
Subject: Re: How to access a file within a perl program
Message-Id: <72udrk$oc9$6@inf2.informatik.uni-stuttgart.de>

Murali Kanaga <mkanaga@hotmail.com> wrote:
> 
> Greetings!
> 
> I am new to Perl. I have to write a perl program which will search through
> the /etc/group file. When I type a user name (jdoe), the script will go
> through
> /etc/group file & find out which group jode is in.
> 
> In order to do this, how can I read the file /etc/group from my perl script.
> 
> I would really apprecitae any idea or input on this.
> 
> Thank you,
> murali


foreach $i (grep(/$user/,`cat /etc/group`))
{
   ($i,$u)=split(/::/,$i);
   print "$i\n";               
}


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

Date: Wed, 18 Nov 1998 08:25:40 -0600
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
To: Bill Hogsett <bhogsett@apk.net>
Subject: Re: how to get `date` in perl for win32 (newbie)
Message-Id: <3652D8E4.74879F97@houston.Geco-Prakla.slb.com>

[courtesy cc to cited author]
Bill Hogsett wrote:
> 
> I have a question about strftime formatting.  I want to format the date as
> "Month Day, Year" with days 1 through 9 shown as single digits.  Is there a
> way to do it strftime?
> 
> Here is a test program:
> 
> # Uses Posix module!
> use POSIX qw(strftime);
> $testdate = 841851694;
> $day = strftime "%B %d, %Y", localtime($testdate);
> print "$day\n";
> 
> $day =~ s/0(\d,)/$1/;
> print "$day\n";
> 
> This prints:
> 
> September 04, 1996
> September 4, 1996
> 
> I can't see any additional formatting that works with strftime.  For example:
> 
> $today = strftime "%B %-d, %Y", localtime($testdate);
> 
> does not surpress the leading zero in the day.
> 
> Any suggestions?
1.  Do it yourself, via localtime.
2.  man strftime
	%e replaces leading 0 with leading <space>

use POSIX;
$testdate = 841851694;
$day = strftime "%B %e, %Y", localtime($testdate);
print "$day\n";

Generates:
September  4, 1996

$day =~ s/\s+/ /g;

will cut all spaces down to one space.


HTH.

Cheers,
Dave

-- 
Dave Barnett	Software Support Engineer	(281) 596-1434


Women like silent men, they think they're listening.


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

Date: Wed, 18 Nov 1998 14:45:04 +0100
From: "Markus Kaiser" <m.kaiser@sz-sb.de>
Subject: Re: Intermediate Perl questions
Message-Id: <72uj1b$c44$1@hades.rz.uni-sb.de>

| > I missed the first post. Surely 'substr( $_, -1, 1 )' returns the last
| > character in the string, so I assume you then delete that character,
| > or am I completely wrong???

|
| Hey, Markus, if you want to go backwards through the string, use chop.
| If you want to go forward, use split //.


indeed the code looks somewhat like

while( substr($_, -1, 1) eq "\x11" )
{
    $_ = substr( $_, 0, length($_) -1 );
}

So, the idea of using chop() sounds good.
How would you use it (keep the EXPR in while() statement and cut off the
trailing char w/ chop() or chop() first, examine the resulting char and put
it back (at the end) if it's not "\x11" ?

Thanks a lot for your help.
Markus

--
Markus Kaiser (m.kaiser@sz-sb.de)

Malstatter Strasse 4, 66117 Saarbruecken, Germany
Phone +49 681 92630-0, Facsimile +49 681 92630-15





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

Date: 18 Nov 1998 14:56:03 GMT
From: glc@well.com (Greg Chapman)
Subject: Re: is embedded Perl thread-safe ?
Message-Id: <3654ddc6.12818907@netnews.worldnet.att.net>

>From what I've seen, Perl's thread support is limited to managing threads
created by Perl.  If you want to access a single embedded Perl interpreter from
multiple threads, I think you have to manage the access from your C++ program
(using critical sections or mutexes or whatever) so that only one thread at a
time calls into Perl.  

On Mon, 16 Nov 1998 14:24:20 +0000, Peter McLaughlin
<Peter.McLaughlin@gssec.bt.co.uk> wrote:

>Hello.  
>
>I notice that Perl has some language support for multi-threading.
>I'm interested in embedding Perl into a multi-threaded C/C++ server.
>Is this possible ?  Is the interpreter thread-safe ?  I'd like
>to call a Perl subroutine with a character string input parameter
>and somehow get a character string output back in a thread-safe
>manner (there would be many threads in the program calling the
>same, or different, chunks of embedded Perl at the same time). 
>
>Unfortunately, I have no Perl experience so it'd be good
>to find out if this is even possible before I go down this route.
>
>Thanks,
>Peter...



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

Date: Wed, 18 Nov 1998 08:18:19 -0500
From: "AmD" <Allan@due.net>
Subject: Re: Learning
Message-Id: <72uh5s$9jv$1@camel15.mindspring.com>


Ross Milton wrote in message <72sthj$hfs$1@oak.prod.itd.earthlink.net>...
>I am interested in Learning Perl. Where should I start. Are there any good
>tutorials on the web?
>
>Thank You

Get thee to:
http://reference.perl.com/query.cgi?tutorials
All shall be revealed.

AmD




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

Date: 18 Nov 1998 12:19:23 GMT
From: sb@engelschall.com (Steffen Beyer)
Subject: Re: MacPerl + Resource Fork
Message-Id: <72ue0b$sq9$1@en1.engelschall.com>

eva m. klopper <eva_spiral@hotmail.com> wrote:

> I have a weird task to do here. A client has sent us a file that appears
> to contain a Mac resource fork that has been transformed into a data
> fork.

> What I've been trying to do is use MacPerl to open the data fork, slurp
> in the data (OK so far), then open the resource fork of a new file and
> write it out as a single block of data.

> Stuck here...

> Does anyone know if this is even possible? Already tried ResEdit and
> Resourcerer without much luck.

Did you already ask your client *how* the heck they succeeded doing this
conversion in the first place?

Maybe you can use the same method in order to reverse the change.

HTH.

Yours,
-- 
    Steffen Beyer <sb@engelschall.com>
    Free Perl and C Software for Download:
    http://www.engelschall.com/u/sb/download/
    New: Build'n'Play 2.1.0 (all-purpose Unix batch installation tool)


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

Date: Wed, 18 Nov 1998 13:56:17 GMT
From: dturley@pobox.com
Subject: Re: MacPerl + Resource Fork
Message-Id: <72ujlo$55$1@nnrp1.dejanews.com>

In article <3652ACB7.3D17EBC1@hotmail.com>,
  "eva m. klopper" <eva_spiral@hotmail.com> wrote:

> What I've been trying to do is use MacPerl to open the data fork, slurp
> in the data (OK so far), then open the resource fork of a new file and
> write it out as a single block of data.
>

Try the MacPerl mailing list archive:
  Search Results  (9401 items searched in 19.84 seconds)
  181 items found containing resource and fork

http://www.binary.net/dturley/macperl/search.html

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 18 Nov 1998 13:14:43 +0100
From: Thomas Schachner <Thomas.Schachner@awd.at>
Subject: perl & win95Dosbox
Message-Id: <3652BA33.AA788239@awd.at>

Hi out there!
The following problem:
System Win95 ver 950c.
An dos application which needs the user in an enviroment variable, after
Netlogon.
Therefore i worked out this script:

use Win32;

my $name;
$name=Win32::LoginName();
system(qq[set user = $name]);

When i run this script i get the error : Invalid operation;

Also when i only run this argument:

system(qq[set user=test]);

I'll get this error, but when i type into the commandline of the dosbox
" set user=test" it works.

No i have tried to make a workaround with a batch file, but i do not
know how i can assign the
output from the script a variable in the batch enviroment!
Maybe there is some Dos user around which can help me.
Or some more expirienced perl programmer which has a workaround.


Any ideas, will be welcome!!



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

Date: Wed, 18 Nov 1998 12:21:08 +0000
From: Balazs Rauznitz <prauz@sprynet.com>
Subject: perl 5.005_02
Message-Id: <3652BBB4.3405C9BE@sprynet.com>

Hi,

I've just compiled and installed  Perl 5.005_02 on my linux box. My
qusetion is where can I find some docs on what's new in Perl 5.005. I
know there are the Changes files in the distribution, but I don't think
they are docs. Also why is there not a Changes5.005 which would list the
deltas from 5.004 to 5.005 ?

Thanks,

Balazs


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

Date: Wed, 18 Nov 1998 08:02:21 -0500
From: "AmD" <Allan@due.net>
Subject: Re: Perl Array Question? Anybody...
Message-Id: <72ug7u$7va$1@camel15.mindspring.com>


shazad@my-dejanews.com wrote in message <72tir2$5k0$1@nnrp1.dejanews.com>...
>Hi perl people....
>
>Well, I am trying to compare two files which arrive randomly.  Both file
have
>the name harry common, but object and rules are different.(example below:)
>
>Subject: harry object  # File1
>
>Subject: harry rules   # File2
>
>WHen I run my perl script, I need to store:
>@myarray=("harry","object");
>
>After, the second file comes, I need to APPEND rules into @myarray, when it
>matches harry as the common field.
>
>But each time the second file parses...it overwrites
>@myarray=("harry","object");
>with
>@myarray=("harry","rules");
>
>How can I APPEND the second file "rules", so that
>@myarray=("harry","object","rule");

>I have tries pop(@mtarray,$a), unshift(@mtarray,$a)...but nothing seems to
>work!!  Anybody!!!

>IN SIMPLE ENGLISH!! How can I restore the context of @myarray each time I
run
>my script.


Well, I am not completely clear on what the actual problem is, but an answer
to part of that question might be push.

@myarray=("harry","object");

push(@myarray,"rules");  # @myarray = ("harry","object","rules");

Except that "rules" is not a file in any sense I can think of so that can't
be all of it.  Since you know pop, you must be aware of push so I doubt this
is really the answer you need either.  Is the problem that you don't know
the order in which the information will arrive, but it the array needs to be
in that order?  I think you need to be a bit more explicit, or maybe someone
else will have deeper insight into your problem.

HTH

AmD




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

Date: Wed, 18 Nov 1998 13:30:10 GMT
From: Brent Michalski <perlguy@technologist.com>
Subject: Re: Perl_for_Win32_FAQ
Message-Id: <3652CBE2.71280391@technologist.com>

Tom Phoenix wrote:
> 
> On Tue, 17 Nov 1998, Brent Michalski wrote:
> 
> > >     http://www.perl.com/CPAN-local/doc/FAQs/nt/perlwin32faq.html
> 
> > This link is returning:
> >
> > <ERROR MESSSAGE>
> > File Not Found
> 
> Not for me, when I use either of two different browsers. I'm not sure why
> you should be seeing that, but I'd guess that it's a problem with a
> server, a browser, a proxy, or something like that. But maybe you'll have
> better luck with this:
> 
>     http://www.cpan.org/doc/FAQs/nt/perlwin32faq.html
> 
> "This web page best viewed with telnet-80." Hope this helps!
> 
> --
> Tom Phoenix       Perl Training and Hacking       Esperanto
> Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/

It finally worked for me too!  Once I shut of "Style Sheets" everything
was fine...

Brent
-- 
Java? I've heard of it, it is what I drink when I am hacking Perl. -me
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$            Brent Michalski             $
$         -- Perl Evangelist --          $
$    E-Mail: perlguy@technologist.com    $
$ Resume: http://www.inlink.com/~perlguy $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$


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

Date: Wed, 18 Nov 1998 07:01:23 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Possible bug in "sort"
Message-Id: <3fgu27.cta.ln@flash.net>

huntersean@hotmail.com wrote:
: I have recently discovered what I think may be a bug in the way perl parses
: calls to "sort".  When using the form "sort SUBNAME LIST", I can happily use
: a literal or a scalar for a subname, but I can't use a member of a hash to
: specify the subname. perl -v gives me "This is perl, version 5.004_04 built
: for i386-linux".

: The following code will demonstrate:


: #print sort $hash{order} @array;


   As another followup pointed out, it sounds like it is a feature
   rather than a bug.  ;-)

   Anyway, to get the job done, you could use the 'sort BLOCK' form,
   then use a symbolic reference in the block:


      print join ' ', sort {&{$hash{order}}} @array;


   Rather homely though...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 18 Nov 1998 14:41:35 GMT
From: jdl@iasi.com (J.D. Laub)
Subject: reverse comma operator in the camel
Message-Id: <3652dd54.0@mirage.iasi.com>

On page 48 of the camel:

# A "reverse comma operator".
return (pop(@foo),pop(@foo))[0];

On page 93, when discussing the comma operator, the book states that "in a 
scalar context it evaluates its left argument, throws that value away, then 
evaluates its right argument and returns that value."  Given that, I would 
think a reverse comma operator would evaluate its RIGHT argument, then 
evaluate and return its LEFT argument.  So, I'll plug in some values into the 
example.  Stripping off the 'return' because I'm not in a subroutine or eval 
leaves me with:

    #!/usr/local/bin/perl -w
    my @foo = (101, 303);
    my $a = (pop @foo, pop @foo)[0];
    print "a=$a.\n";

This prints 303, the RIGHT argument in the list, which is the same as the 
comma operator.  Can someone explain what Larry, Tom, & Randall are trying to 
convey with their "reverse comma operator" example?

J.D. Laub (Laubster) |"I think you're very, very, very, very, very,
jdl@iasi.com         |very, very, very, very, ..." - Flying Lizards



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

Date: Wed, 18 Nov 1998 09:36:21 GMT
From: ijg@csc.liv.ac.uk (I.J. Garlick)
Subject: Re: Smarter Web Mailer
Message-Id: <F2M2oL.5yr@csc.liv.ac.uk>

In article <365215B2.625E@courrier.usherb.ca>,
JTJ <jtjohnston@courrier.usherb.ca> writes:
> I am playing with a Web-Based E-mailer. How do I extract a web address
> in a block of text and replace it with a link:
> 
> -------- Sample message ---------
> here is the link:
> http://somewhere.com
> ---------------------------------
> 
> ---------- What I want ----------
> here is the link:
> <A HREF="http://somewhere.com">http://somewhere.com</A>
> ---------------------------------
> 
> I would use a substitution string:
> 
> $message =~ s/???/???/g;
> 
> Something like??
> 
> 	$message =~ s/http:\/\/\s*(\w+|$)/????/go;
> 

I am having a similar prob. I got this far

	s!(^|[^=])(\s*)(http://.*?)(\s+|/\W\s+)!$2<A HREF=$3>$3</A>$4!gs;

Which seems to work for simple standard URL's
eg.

	http://www.xxxxx.ddddd/hdskdj.html
	http://www.xxxxx.ddddd/hdskdj/

and even

	(http://www.xxxxx.ddddd/hdskdj/)

but not

	(http://www.xxxxx.ddddd/hdskdj/).

:-( which is what I am aiming at.

One word of warning, you wont ever get all of them as the regex (I saw one of
the gurus solutions to this once and it ran for several lines ;-} ) to catch
every single one is very complex. I don't want perfection just a fair stab at
the common ones will do.

BTW the [^=] bit is so I don't find A HREF=http:// ...etc. HTML ones, for
what I am using it for I only want them in plain text context, bit like
when people post URL' to this group.

Some one with a lot more regex knowledge will now proceed to disect this
and point out a million and one places I got it wrong, but hey that's why
I did it. Perhaps I will get a shorter more efficient regex out of it, I
doubt it, but you never know.

If you are really interested then get Friedl's (sp?) book 'Mastering 
Regular Expressions'.

However I suspect your just trying to improve that Web based email client
you where crowing about earlier :-) :-)

> Thanks in advance.
> 
> JTJ

-- 
--
Ian J. Garlick
<ijg@csc.liv.ac.uk>
<postmaster@merseymail.com>

Churchill's Commentary on Man:
        Man will occasionally stumble over the truth, but most of the
time he will pick himself up and continue on.



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

Date: Wed, 18 Nov 1998 09:52:10 GMT
From: ijg@csc.liv.ac.uk (I.J. Garlick)
To: sara starre <nospam.gear4u@hotmail.com>
Subject: Re: Two-Part RE question
Message-Id: <F2M3Ey.6sx@csc.liv.ac.uk>

[Posted and mailed]

In article <365244A5.33609DA8@hotmail.com>,
sara starre <nospam.gear4u@hotmail.com> writes:
> OK, this is a two-part question. The first part is only for the perl
> newsgroup hoseheads who flame everyone who asks a question. Here is your
> part, put your might brain to work on it and post your solution to
> alt.whocares:
> 
>                   interpret this special RE I designed expecially for
> you: $x =~ [4q];
> 
> Now, for the 90% of you out there who are here to help the less-gifted
> (like me) here is my question:
> 
> I wish to extract a string between two different characters from a
> larger
> string. For example, I want to extract everything between "[" and "]",
> such as extract man from cat[man]dog.
> 
> Now, I brute (in my case brute-ette?) forced a solution:
> #!/usr/bin/perl -w
> #
> # Created by sara starre, 11/98
> #
> # ---------------------------------------------------------------------
> #
>   $x = 'cat[man]dog';
>   $i1=index($x,"\[");
>   $i2=index($x,"\]");
>   $y =substr($x,$i1+1,$i2-$i1-1);
>   print "input: $x\noutput: $y\n";
> 
> ]$ perl x.pl
> input: cat[man]dog
> output: man
> 
> Isn't there an easier way to accomplish this?

use a rgex like this

   ($y = $x) =~ s|^\w*\[(\w*)\]\w*$|$1|;

God knows if you think this is more elegant but it is one line :-)

A word of warning, it'll only work for the situation you described
'cat[man]dog' and any other all alpha character string with [] around part
of it. You put any other punctuation in it and it will fail.

> 
> I looked in the perl FAQ- a search on "extract" only produced substr,
> which is what I'm already using.
> 
> I read my Tom C book- I think this is a little advanced for that text.
> 

You are joking arn't you? your not? Ah well takes all kinds.

TBH I suspect this is to simple for Tom's book, I haven't read it yet,
nowhere stocks it in Liverpool :-( but from what I have heard it's supposed
to be for the more advanced perl probs. (We are talking about the Cookbook
here?).

> This isn't a homework assignment, no school would have me after my
> performance on my first two masters'!
> 
> I made this test case that works, but I want something pretty and
> elegante'! OK your turn...
> 
> HUG,
> S
> 

-- 
--
Ian J. Garlick
<ijg@csc.liv.ac.uk>
<postmaster@merseymail.com>

Churchill's Commentary on Man:
        Man will occasionally stumble over the truth, but most of the
time he will pick himself up and continue on.



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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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