Re: Small question: Why can't I print "@-"?
by BrowserUk (Patriarch) on Sep 23, 2003 at 19:08 UTC
|
You can interpolate both arrays, but you have to do so at the right time
print "@-:@+"
while 'the quick brown fox jumps over the lazy dog' =~ /(\b.+?\b)(.+
+?)\b/g
0 0 3:4 3 4
4 4 9:10 9 10
10 10 15:16 15 16
16 16 19:20 19 20
20 20 25:26 25 26
26 26 30:31 30 31
31 31 34:35 34 35
35 35 39:40 39 40
print "@-:@+"
:
Both arrays are reset before a new match is attempted, so when the match fails, they contain nothing to interpolate.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.
| [reply] [d/l] |
|
print "@-:@+\n"
while 'the quick brown fox jumps over the lazy dog' =~ /(\b.+?\b)(.+
+?)\b/g
I get the following output:
@-:@+
@-:@+
@-:@+
@-:@+
@-:@+
@-:@+
@-:@+
@-:@+
whereas if I adapt it as per sauoq's suggestion below:
print "@{-}:@{+}\n"
while 'the quick brown fox jumps over the lazy dog' =~ /(\b.+?\b)(.+
+?)\b/g
I get what I want.
I use AS 5.61 on XP
dave | [reply] [d/l] [select] |
|
Yep, this a known bug in 5.6.1, but it is fixed in 5.8.0.
-- Mike
--
XML::Simpler does not require XML::Parser or a SAX parser.
It does require File::Slurp.
-- grantm, perldoc XML::Simpler
| [reply] |
|
| [reply] |
Re: Small question: Why can't I print "@-"?
by sauoq (Abbot) on Sep 23, 2003 at 19:09 UTC
|
print "@{+}";
instead.
-sauoq
"My two cents aren't worth a dime.";
| [reply] [d/l] |
|
# or
print "@{[@+]}\n";
# or
print join($"||"",@+),"\n";
:-)
---
demerphq
First they ignore you, then they laugh at you, then they fight you, then you win.
-- Gandhi
| [reply] [d/l] [select] |
|
Sure, you could use one of those. But, why would you?
Would it improve efficiency? Uh uh. Clarity? Certainly not.
I can't think of a good reason... can you?
BTW, I didn't realize this was a "bug" fixed in 5.8. I was thinking that perl didn't like to interpolate any variables that didn't start with a \w character. But, putting the name in braces will work with other (admittedly poor choices for) variable names such as @% and @!, not just ones perl knows.
-sauoq
"My two cents aren't worth a dime.";
| [reply] |
|
|
|
Re: Small question: Why can't I print "@-"?
by bart (Canon) on Sep 23, 2003 at 19:48 UTC
|
A simple solution: set $, to something not empty. Then you can just drop the quotes.
$_ = 'There is food at the bar';
/(fo+)/;
$, = "-";
$\ = "\n";
print @-;
| [reply] [d/l] |
Re: Small question: Why can't I print "@-"?
by converter (Priest) on Sep 23, 2003 at 19:33 UTC
|
If your code executes print "@-"; and the output is @-, then your perl is probaby version 5.005_03 or older. @- and @+ aren't supported until perl version 5.6, if I remember correctly.
converter
Updated: Interpolation of @- and @+ seems to be broken until version 5.008.
| [reply] [d/l] [select] |
|
No, I still see "@-", perl version = 5.6.1.
| [reply] |
|
| [reply] [d/l] [select] |