[23962] in Perl-Users-Digest
Perl-Users Digest, Issue: 6163 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 19 06:10:33 2004
Date: Thu, 19 Feb 2004 03:10:10 -0800 (PST)
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, 19 Feb 2004 Volume: 10 Number: 6163
Today's topics:
perl fundamentals <yamini_rajan@nospam.com>
Re: perl fundamentals <uri@stemsystems.com>
Re: perl fundamentals <usenet@c0s.org>
Re: perl fundamentals <jurgenex@hotmail.com>
Re: perl fundamentals <spamtrap@dot-app.org>
Re: perl fundamentals <xaonon@hotpop.com>
perl <prabals_r@yahoo.com>
Re: perl <nobull@mail.com>
regex newbie <gregfcarlson@hotmail.com>
Re: regex newbie <usenet@c0s.org>
Re: regex newbie <dcspam@ntlworld.com>
Re: regex newbie <nobull@mail.com>
Re: regex newbie <nobull@mail.com>
regex <yamini_rajan@nospam.com>
Replacing a text in multiple files with regular express (Angel)
Re: Unexplained output for PERL print statement (Xavier)
Re: Unexplained output for PERL print statement (Xavier)
Re: Unexplained output for PERL print statement <sbryce@scottbryce.com>
Re: Why is Perl losing ground? <sbpoleySpicedHamTrap@xs4all.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 19 Feb 2004 00:53:39 -0600
From: "yamini" <yamini_rajan@nospam.com>
Subject: perl fundamentals
Message-Id: <c9e548a119f9331a4880c40698afebdc@localhost.talkaboutprogramming.com>
hi,
Is there any particular difference in using singlequoted strings in place of double quuoted strings
thank u
------------------------------
Date: Thu, 19 Feb 2004 06:48:31 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perl fundamentals
Message-Id: <x7vfm3pnsx.fsf@mail.sysarch.com>
>>>>> "y" == yamini <yamini_rajan@nospam.com> writes:
y> Is there any particular difference in using singlequoted strings in
y> place of double quuoted strings
in practical coding ways, there is little difference. in conveying
accurate semantic informantion to someone reading your code, it makes a
world of difference. double quotes tells the reader to look inside this
string for interpolated variables and escaped chars like \n. single
quoted strings tell the reader that this is a plain string and only \\
or \' are special (assuming ' is the delimiter).
so do you want to be nice to the reader of your code or do you feel
indifferent about them? that understanding is a hallmark of a good coder
in any language. this can be summarized in these rules:
code is for people, not computers.
code is for other people, not yourself.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 18 Feb 2004 22:51:05 -0800
From: gabe anzelini <usenet@c0s.org>
Subject: Re: perl fundamentals
Message-Id: <86llmzwoiu.fsf@tyler.c0s.org>
"yamini" <yamini_rajan@nospam.com> writes:
> hi,
> Is there any particular difference in using singlequoted strings in place of double quuoted strings
> thank u
$foo='bar';
print "$foo bar"; #prints foo bar
print '$foo bar'; #prints $foo bar
------------------------------
Date: Thu, 19 Feb 2004 06:55:50 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: perl fundamentals
Message-Id: <W5ZYb.24797$5W3.8435@nwrddc02.gnilink.net>
yamini wrote:
> Is there any particular difference in using singlequoted strings in
> place of double quuoted strings
Yes, there is. Double quotes strings are being interpolated, single quoted
strings are not.
For further details please see the section "Quote and Quote-like Operators"
in "perldoc perlop".
jue
------------------------------
Date: Thu, 19 Feb 2004 01:57:53 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: perl fundamentals
Message-Id: <s8idnfQktfnuw6ndRVn-tA@adelphia.com>
yamini wrote:
> Is there any particular difference in using singlequoted strings in place
> of double quuoted strings thank u
Yes, there is a very significant difference.
I had written a brief, one-sentence description of the difference. But
really, such a brief description doesn't do the subject justice. You need
to read the Perl docs to get the full picture:
perldoc perlop - The "Quote and Quote-like Operators" section.
perldoc -q quoting - For more about when *not* to quote things.
sherm--
------------------------------
Date: 19 Feb 2004 07:12:55 GMT
From: Xaonon <xaonon@hotpop.com>
Subject: Re: perl fundamentals
Message-Id: <slrnc38ocl.bdd.xaonon@xaonon.local>
Ned i bach <86llmzwoiu.fsf@tyler.c0s.org>, gabe anzelini <usenet@c0s.org>
teithant i thiw hin:
> "yamini" <yamini_rajan@nospam.com> writes:
>
> > hi,
> > Is there any particular difference in using singlequoted strings in
> > place of double quuoted strings
> > thank u
>
> $foo='bar';
>
> print "$foo bar"; #prints foo bar
ITYM "bar bar".
--
Xaonon, EAC Chief of Mad Scientists and informal BAAWA, aa #1821, Kibo #: 1
http://xaonon.dyndns.org/ Guaranteed content-free since 1999. No refunds.
"Remember, kids! Don't try to stop Russians from picking mushrooms! Or
they'll nuke you!" -- James "Kibo" Parry, in alt.religion.kibology
------------------------------
Date: Thu, 19 Feb 2004 02:20:21 -0600
From: "prabs" <prabals_r@yahoo.com>
Subject: perl
Message-Id: <7cfe0023a87b6b1e3ded817951da5cfc@localhost.talkaboutprogramming.com>
how to get a http request header in perl?
------------------------------
Date: 19 Feb 2004 08:52:20 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: perl
Message-Id: <u9n07ffo3f.fsf@wcl-l.bham.ac.uk>
"prabs" <prabals_r@yahoo.com> writes:
> Subject: perl
Please put the subject of your post in the Subject of your post.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 19 Feb 2004 06:17:32 GMT
From: "Greg Carlson" <gregfcarlson@hotmail.com>
Subject: regex newbie
Message-Id: <0yYYb.218502$U%5.1326349@attbi_s03>
I've looked through a number of books and faq's and such and haven't been
able to solve my regex conundrum. I need to find the first match before
another match. For example, with the string 'abcdefgabcdefgfooabcdefg', I
need to match 'foo' and the 'a' previous to but nearest 'foo' (not the one
at the beginning of the string). Also, there's an unknown number of
characters between the 'a' and the 'foo'. Any help would be greatly
appreciated.
Greg Carlson
------------------------------
Date: 18 Feb 2004 22:30:08 -0800
From: gabe anzelini <usenet@c0s.org>
Subject: Re: regex newbie
Message-Id: <86ad3fintb.fsf@tyler.c0s.org>
"Greg Carlson" <gregfcarlson@hotmail.com> writes:
> I've looked through a number of books and faq's and such and haven't been
> able to solve my regex conundrum. I need to find the first match before
> another match. For example, with the string 'abcdefgabcdefgfooabcdefg', I
> need to match 'foo' and the 'a' previous to but nearest 'foo' (not the one
> at the beginning of the string). Also, there's an unknown number of
> characters between the 'a' and the 'foo'. Any help would be greatly
> appreciated.
>
> Greg Carlson
i dont think you can do this with a single regex (i could be wrong)
what i would do is split on foo and then do a .*a to get the last a
i think that would do it... maybe not
-----
gabe
------------------------------
Date: Thu, 19 Feb 2004 06:32:01 -0000
From: "Dave Cardwell" <dcspam@ntlworld.com>
Subject: Re: regex newbie
Message-Id: <SLYYb.3492$AQ4.1071225@newsfep2-win.server.ntli.net>
"Greg Carlson" <gregfcarlson@hotmail.com> wrote:
> I've looked through a number of books and faq's and such and haven't been
> able to solve my regex conundrum. I need to find the first match before
> another match. For example, with the string 'abcdefgabcdefgfooabcdefg', I
> need to match 'foo' and the 'a' previous to but nearest 'foo' (not the one
> at the beginning of the string). Also, there's an unknown number of
> characters between the 'a' and the 'foo'. Any help would be greatly
> appreciated.
>
> Greg Carlson
>
>
Normally a regular expression tries to gobble up as much as it can, in this
case it will try to match the 'a' furthest away from 'foo'.
To get round this, you can do:
/a[^a]*foo/
which will match an 'a', any number of anything-but-a, then foo.
Alternatively you can do:
/a.*?foo/
Here the ? makes the regexp 'not greedy'. That is, it will try to match
across the minimum amount of characters (hence the closest 'a' to 'foo').
Either would work, though I'd wager the second was using the best coding
practice.
Regards,
--
Dave Cardwell.
http://dave.blubbernet.com
------------------------------
Date: 19 Feb 2004 09:00:28 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: regex newbie
Message-Id: <u9d68bfnpv.fsf@wcl-l.bham.ac.uk>
"Dave Cardwell" <dcspam@ntlworld.com> writes:
> "Greg Carlson" <gregfcarlson@hotmail.com> wrote:
> > I need to match 'foo' and the 'a' previous to but nearest 'foo'
> > (not the one at the beginning of the string). Also, there's an
> > unknown number of characters between the 'a' and the 'foo'.
> /a[^a]*foo/
> which will match an 'a', any number of anything-but-a, then foo.
That's the normal solution assuming 'a' really is single character.
> Alternatively you can do:
> /a.*?foo/
> Here the ? makes the regexp 'not greedy'. That is, it will try to match
> across the minimum amount of characters (hence the closest 'a' to 'foo').
Bzzzt! Non-geedy does not trump first-match.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 19 Feb 2004 08:58:45 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: regex newbie
Message-Id: <u98yizfncg.fsf@wcl-l.bham.ac.uk>
"Greg Carlson" <gregfcarlson@hotmail.com> writes:
> Subject: regex newbie
Please put the subject of your post in the Subject of your post. If
in doubt try this simple test. Imagine you could have been bothered
to have done a search before you posted. Next imagine you found a
thread with your subject line. Would you have been able to recognise
it as the same subject?
> I've looked through a number of books and faq's and such and haven't been
> able to solve my regex conundrum. I need to find the first match before
> another match. For example, with the string 'abcdefgabcdefgfooabcdefg', I
> need to match 'foo' and the 'a' previous to but nearest 'foo' (not the one
> at the beginning of the string). Also, there's an unknown number of
> characters between the 'a' and the 'foo'. Any help would be greatly
> appreciated.
If 'a' really is a single character then see other response.
Otherwise I'd usually use...
/(.*)(a.*foo)/
Note this actually matches both everything before the desired target
and the desired target. Note also this finds the last 'a' before the
_last_ 'foo'.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 19 Feb 2004 02:10:20 -0600
From: "yamini" <yamini_rajan@nospam.com>
Subject: regex
Message-Id: <cf9af96f1bee5d59196418fb69ad41b7@localhost.talkaboutprogramming.com>
hi,
$tag="({NP_PP}|{NP_B})";
$_="{NP_PP} kinase{/NP_PP} citron {NP_B}tyrosine{/NP_B}";
will $tag match both the specified patterns?
regards
yamini
------------------------------
Date: 19 Feb 2004 00:49:55 -0800
From: anichin@vip.bg (Angel)
Subject: Replacing a text in multiple files with regular expressions
Message-Id: <8732d910.0402190049.3933532a@posting.google.com>
I would like to make an image clickable, in other words
to replace all occurrences of:
<img src="pic.gif" width="199" height="31" alt="" border="0">
with
<a href="http://somewhere.com"><img src="pic.gif" width="199"
height="31" alt="" border="0"></a>
I would like to search and replace on many files located in
different subfolders of one main folder.
I know it should be possible using regular expressions but
all my attempts failed. Can anyone help me ?
Thanks.
------------------------------
Date: 18 Feb 2004 21:36:58 -0800
From: spamaway03@yahoo.com (Xavier)
Subject: Re: Unexplained output for PERL print statement
Message-Id: <491d2c0d.0402182136.3699115c@posting.google.com>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message news:<33DYb.20670$5W3.12423@nwrddc02.gnilink.net>...
> Xavier wrote:
> > I have the following code in my perl script to generate some HTML:
> >
> > printf "\<img src=\"Dir1/%s/%s\"\>\n", $dirname, $filename;
>
> Maybe a stupid question, but why are you using printf() to begin with?
> There is nothing in your desired output that would require you to use
> printf() instead of the much simpler print().
i have tried all variants of the print statement and just using printf
in the example.
------------------------------
Date: 18 Feb 2004 22:03:35 -0800
From: spamaway03@yahoo.com (Xavier)
Subject: Re: Unexplained output for PERL print statement
Message-Id: <491d2c0d.0402182203.c65fcfd@posting.google.com>
glenn...u are right, i am reading filenames from a dos file and
chopping. ur suggestion helped solve the problem. could u explain why
just a chop wasn't sufficient? i guess i'm not too familiar with the
dos representation of a newline.
thanks
x.
> Matthew Braid <mb@uq.net.au.invalid> wrote:
> > Xavier wrote:
> > > I have the following code in my perl script to generate some HTML:
> > > printf "\<img src=\"Dir1/%s/%s\"\>\n", $dirname, $filename;
> > >
> > > looks like
> > >
> > > ">mg src="Dir1/dirname/filename
> >
> > What's in $filename? Is there maybe a weird character at the end?
> > Maybe there's a carriage return there without a line-feed?
>
> Perhaps you're reading a DOS text file, and chomp-ing?
>
> Can reproduce with:
> $dirname='dir'
> $filename="file\r"
> printf "\<img src=\"Dir1/%s/%s\"\>\n", $dirname, $filename;
> # ==> ">mg src="Dir1/dir/file
>
> You might want to trim whitespace off the end of $filename:
> $filename =~ s/\s+$//;
------------------------------
Date: Thu, 19 Feb 2004 00:30:02 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Unexplained output for PERL print statement
Message-Id: <1038pfo2r6itd40@corp.supernews.com>
Xavier wrote:
> glenn...u are right, i am reading filenames from a dos file and
> chopping. ur suggestion helped solve the problem. could u explain why
> just a chop wasn't sufficient? i guess i'm not too familiar with the
> dos representation of a newline.
Because a DOS file uses a CR/LF pair to as a newline character. Chop
removed the Line Feed and left the Carriage Return in place. Chomp would
have removed both the Carriage Return and the Line Feed.
Chop removes the last character in a string. Chomp removes all trailing
newline characters.
------------------------------
Date: Thu, 19 Feb 2004 07:50:02 +0100
From: Stephen Poley <sbpoleySpicedHamTrap@xs4all.nl>
Subject: Re: Why is Perl losing ground?
Message-Id: <53n830hq1fjbh48fe7qp8m9tpjnf9cf6q0@4ax.com>
On Tue, 17 Feb 2004 23:27:07 +0000 (UTC), Ben Morrow
<usenet@morrow.me.uk> wrote:
>I have an irresitable urge to insert this quote here, from
>linux/Documentation/CodingStyle. True, it's about C, but Perl has a lot
>of C heritage:
>
>| C is a Spartan language, and so should your naming be. Unlike Modula-2
>| and Pascal programmers, C programmers do not use cute names like
>| ThisVariableIsATemporaryCounter. A C programmer would call that
>| variable "tmp", which is much easier to write, and not the least more
>| difficult to understand.
I have an irresistable urge to point out that that is not a useful
variable name, given that all variables are temporary. The permanent
stuff is in files and databases after all. If you want a meaningless
name, you might as well use t. If you want it to have some small
mnemonic value, call it count.
>Yup, arguing from authority is the last recourse of the ignorant...
Actually, I thought the last recourse of the ignorant was abuse...
--
Stephen Poley
------------------------------
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 6163
***************************************