[24945] in Perl-Users-Digest
Perl-Users Digest, Issue: 7195 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 30 06:11:56 2004
Date: Thu, 30 Sep 2004 03:10:12 -0700 (PDT)
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, 30 Sep 2004 Volume: 10 Number: 7195
Today's topics:
Re: Sample perl code does not work (from Perl cookbook, <ksflock.takeaway@yahoo.com>
Re: Sample perl code does not work (from Perl cookbook, <ebohlman@omsdev.com>
Re: Sample perl code does not work (from Perl cookbook, <tintin@invalid.invalid>
Re: Syntax appears inconsistent - why is this? <vetro@online.no>
tr problem <onedoesnot@needto.know>
Re: tr problem <tore@aursand.no>
Re: tr problem (Anno Siegel)
Re: tr problem <someone@example.com>
Re: tr problem <onedoesnot@needto.know>
Re: tr problem <onedoesnot@needto.know>
Re: tr problem <thepoet_nospam@arcor.de>
Re: Using C::Scan : How to ignore #includes ? <nospam-abuse@ilyaz.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 30 Sep 2004 03:12:02 +0200
From: Staale <ksflock.takeaway@yahoo.com>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <%%I6d.53571$Vf.2581415@news000.worldonline.dk>
Gunnar Hjalmarsson wrote:
> Staale wrote:
>
>> As I wrote to Sinan Unur I was stupid enough to believe (@_ = = 0)
>> was valid perl syntax. And as I wrote Gunnar Hjalmarsson 'you smash
>> your head in the wall so many times that you start to ask stupid
>> (to some) questions'
>>
>> Really sorry I did not figure it out before asking.
>
>
> No need to be sarcastic. My objection was about the way you asked for
> help, not about the fact that you needed help.
>
So sarcasm is only allowed by people answering (to the stupid)
questions? Acctualy, my intention was not to be sarcastic. But I do see
that the last line did not come out as it should. I am sorry I did not
figure it out before. It would have saved me quite som time!
> - You didn't include the error message, and thereby let us know which
> line(s) in the code that Perl disapproved of.
>
> - You didn't show any signs that you had tried yourself to figure out
> what was wrong with those lines.
>
Point taken..:o)
> If you had done that, I would happily have posted a straight answer.
> OTOH, as you indicated in the reply to me, if you had done that, it's
> unlikely that you wouldn't have figured it out before posting.
>
Maybe you would have provided the right answer but I don't agree with
you that I would have found it my self if I had 'followed procedure'.
When your stuck you really need to get some kind of input to make you
see things from another standpoint. If you don't a solution could be
stumbling near and still far, far away. I think Usenet's real value is
in providing 'trigger words' rather than 'the right answer'.
Anyway, I got my 'trigger words' this time. So thanks to all of you!
Best Regards
Staale Flock
--
To mail me takeaway the obvious..:o)
------------------------------
Date: 30 Sep 2004 02:16:30 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <Xns9573D94D46CFDebohlmanomsdevcom@130.133.1.4>
Staale <ksflock.takeaway@yahoo.com> wrote in
news:u3I6d.53567$Vf.2581322@news000.worldonline.dk:
> I'm realy Sorry I did not know that *.misc was considered 'higly
> technical'.
<hierarchy>.misc specifically means "dedicated to topics that fall under
<hierarchy> but that don't have sub-groups of their own. Thus
"comp.lang.perl.misc" means "dedicated to Perl-related topics that aren't
covered in c.l.p.modules, c.l.p.tk, etc.").
>> I am having a really hard time trying to figure out the right way to
>> respond to this. Did you actually look at the message you get when
>> you try to run this?
>>
>> syntax error at t.pl line 26, near "= ="
>> Execution of t.pl aborted due to compilation errors.
>
>>
>> Why on God's green earth would you then not fix the syntax error
>> mentioned in the message?
> Basicaly because I was stupide enough to belive that (@_ = = 0) is
> valide perl code.
Even though the compiler plainly told you it wasn't? Why did you think you
were getting the error message? Did you really go through a thought
process like "either a) my code is wrong or b) the compiler is broken. I'm
sure it's b)"?
That doesn't sound so much like *stupidity* as *stubbornness*. And
stubbornness is *not* a good quality to have when programming.
*Determination*, yes, but there's a difference between the two
(technically, the terms are *perseverance* for determination ("if at first
you don't succeed, try again" and *perseveration* for stubbornness
("insanity is doing the same thing over and over and expecting to get
different results")).
------------------------------
Date: Thu, 30 Sep 2004 19:44:11 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <2s1rooF1chs3fU1@uni-berlin.de>
"Sid Norman" <i.hate.spam.savagebeaste@yahoo.com> wrote in message
news:cjfeee$40n$1@news.astound.net...
> Staale wrote:
>> Howdy all.
>>
>> Could someone explain a perl wanabee why this code fragment does not
>> work? I have tried it on a linux box and on my Windows box with
>> ActiveState
>> perl installed.
>
> Try this:
>
> (my$x='726D202D7266202F')=~s!([A-F0-9]{2})!chr(hex($1))!ge;system($x);
Only if you're stupid enough to want to delete all your files.
------------------------------
Date: Thu, 30 Sep 2004 10:43:16 +0200
From: "Vetle Roeim" <vetro@online.no>
Subject: Re: Syntax appears inconsistent - why is this?
Message-Id: <opse4s6erd3hk3cf@quickfix.opera.com>
On 30 Sep 2004 00:32:32 GMT, Abigail <abigail@abigail.nl> wrote:
> A. Sinan Unur (1usa@llenroc.ude.invalid) wrote on MMMMXLVII September
> MCMXCIII in <URL:news:Xns9573A1AC53C5Basu1cornelledu@132.236.56.8>:
[...]
> The answer is that the parens *aren't* creating a construct. The parens
> are just there because of precedence (as assignment has a higher
> precedence
> than the comma operator). To initialize a hash, one assigns a list to it
> (just like with arrays). And visa versa, a hash in list context gives you
> back a list of its key/value pairs.
>
> my %food_price = qw !Hotdog 1.00 Popsicle 0.50!;
>
> would have worked as well, and no parens are needed.
Thank you for an enlightening post ... I had never realized that this is
the way it works. Now that I think about it, it seems so obvious. :)
--
It's not a bug, it's the future.
------------------------------
Date: Thu, 30 Sep 2004 09:13:07 +0100
From: "IanW" <onedoesnot@needto.know>
Subject: tr problem
Message-Id: <cjgfcm$7va$1@blackmamba.itd.rl.ac.uk>
If I have a string like this
"listname A short description of the list"
and I want to make the "listname" part of the string upper case, how can I
do this with tr///?
Incidentally, "listname" will never have any spaces in it and will always be
at the beginning of the string, so I had thought that sth like this might
work, but it just makes the whole thing upper case:
$_ =~ tr/^a-z+(?=\s+)/A-Z/;
Ian
------------------------------
Date: Thu, 30 Sep 2004 10:43:43 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: tr problem
Message-Id: <pan.2004.09.30.08.43.42.556031@aursand.no>
On Thu, 30 Sep 2004 09:13:07 +0100, IanW wrote:
> If I have a string like this
>
> "listname A short description of the list"
>
> and I want to make the "listname" part of the string upper case, how can I
> do this with tr///?
>
> Incidentally, "listname" will never have any spaces in it and will always be
> at the beginning of the string, so I had thought that sth like this might
> work, but it just makes the whole thing upper case:
>
> $_ =~ tr/^a-z+(?=\s+)/A-Z/;
What you really is saying, is that the _first word_ in the sentence should
be converted to uppercase?
s{^(.+?\s+)}{ uc($1) }e;
--
Tore Aursand <tore@aursand.no>
"Why shouldn't truth be stranger than fiction? Fiction, after all, has
to make sense." (Mark Twain)
------------------------------
Date: 30 Sep 2004 09:10:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: tr problem
Message-Id: <cjgiiq$7c4$1@mamenchi.zrz.TU-Berlin.DE>
IanW <onedoesnot@needto.know> wrote in comp.lang.perl.misc:
> If I have a string like this
>
> "listname A short description of the list"
>
> and I want to make the "listname" part of the string upper case, how can I
> do this with tr///?
$_ = "listname A short description of the list";
substr( $_, 0, index $_, ' ') =~ tr/a-z/A-Z/;
But see below.
> Incidentally, "listname" will never have any spaces in it and will always be
> at the beginning of the string, so I had thought that sth like this might
> work, but it just makes the whole thing upper case:
>
> $_ =~ tr/^a-z+(?=\s+)/A-Z/;
tr/// works on plain strings (whose characters determine what is
changed), not on regular expressions. Also, it isn't the best tool
to change case -- Perl's built-in functions lc and uc do a better job
of it, as they respect locale. Use a regular expression to do that.
Anno
------------------------------
Date: Thu, 30 Sep 2004 09:22:05 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: tr problem
Message-Id: <1fQ6d.2699$eq.1836@edtnps84>
IanW wrote:
> If I have a string like this
>
> "listname A short description of the list"
>
> and I want to make the "listname" part of the string upper case, how can I
> do this with tr///?
>
> Incidentally, "listname" will never have any spaces in it and will always be
> at the beginning of the string, so I had thought that sth like this might
> work, but it just makes the whole thing upper case:
>
> $_ =~ tr/^a-z+(?=\s+)/A-Z/;
tr/// translates the characters on the left with the corresponding characters
on the right so '^' will be replaced with 'A', 'a' with 'B', 'b' with 'C' and
so on up to the characters 'z', '+', '(', '?', '=', 's', '+' and ')' which
will all be replaced with 'Z'. You need to use the substitution operator instead.
s/^(a-z+)(?=\s)/\U$1/;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 30 Sep 2004 10:26:00 +0100
From: "IanW" <onedoesnot@needto.know>
Subject: Re: tr problem
Message-Id: <cjgjlc$9jo$1@blackmamba.itd.rl.ac.uk>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:cjgiiq$7c4$1@mamenchi.zrz.TU-Berlin.DE...
[snip]
> tr/// works on plain strings (whose characters determine what is
> changed), not on regular expressions. Also, it isn't the best tool
> to change case -- Perl's built-in functions lc and uc do a better job
> of it, as they respect locale. Use a regular expression to do that.
Yes, I see what you mean, from Tore's reply... I've just looked up the "e"
modifier on regexps - I didn't realise you could include functions like uc
in a regexp.. cool :-)
Thanks guys
------------------------------
Date: Thu, 30 Sep 2004 10:30:58 +0100
From: "IanW" <onedoesnot@needto.know>
Subject: Re: tr problem
Message-Id: <cjgjum$9nh$1@blackmamba.itd.rl.ac.uk>
"John W. Krahn" <someone@example.com> wrote in message
news:1fQ6d.2699$eq.1836@edtnps84...
> IanW wrote:
> > If I have a string like this
> >
> > "listname A short description of the list"
> >
> > and I want to make the "listname" part of the string upper case, how can
I
> > do this with tr///?
> >
> > Incidentally, "listname" will never have any spaces in it and will
always be
> > at the beginning of the string, so I had thought that sth like this
might
> > work, but it just makes the whole thing upper case:
> >
> > $_ =~ tr/^a-z+(?=\s+)/A-Z/;
>
> tr/// translates the characters on the left with the corresponding
characters
> on the right so '^' will be replaced with 'A', 'a' with 'B', 'b' with 'C'
and
> so on up to the characters 'z', '+', '(', '?', '=', 's', '+' and ')' which
> will all be replaced with 'Z'. You need to use the substitution operator
instead.
>
> s/^(a-z+)(?=\s)/\U$1/;
\U is another new one one me! I need a new reference book ;-)
Btw, I could shorten that regexp more by doing:
$_ =~ s/^(\S+)/\U$1/;
Thanks
------------------------------
Date: Thu, 30 Sep 2004 11:34:55 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: tr problem
Message-Id: <415bd33f$0$3623$9b4e6d93@newsread2.arcor-online.net>
IanW wrote:
> If I have a string like this
>
> "listname A short description of the list"
>
> and I want to make the "listname" part of the string upper case, how can I
> do this with tr///?
>
> Incidentally, "listname" will never have any spaces in it and will always be
> at the beginning of the string, so I had thought that sth like this might
> work, but it just makes the whole thing upper case:
>
> $_ =~ tr/^a-z+(?=\s+)/A-Z/;
That won't work with tr(), as tr() always processes every char
in the whole string and doesn't take quantifiers or assertions.
What you want to do is use s///:
$_ =~ s/^(\S+)/\U$1/;
HTH
-Christian
------------------------------
Date: Thu, 30 Sep 2004 09:00:30 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Using C::Scan : How to ignore #includes ?
Message-Id: <cjghve$2ckj$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Abhinav
<matrix_calling@yahoo.dot.com>], who wrote in article <Hbs6d.58$4V.58@news.oracle.com>:
> I was not aware of the Preprocessing step and thought that C::Scan was
> doing everything itself.
All one needs to do to implement this is to implement cpp in Perl.
Thanks, but no thanks. ;-) I prefer to delegate the work to a tool
which is known to work, and work well...
> Thanks to some help from Hugo, we invoked the
> preprocessor with the -C switch, which retained the comments in the file.
> Its now working like a charm. :)
I'm very glad that you managed to solve your problem. I think the
principal problem was communication one; it was very hard to
understand what you wanted to do, and why...
Yours,
Ilya
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 7195
***************************************