[32492] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3757 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 13 09:09:23 2012

Date: Mon, 13 Aug 2012 06:09:08 -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           Mon, 13 Aug 2012     Volume: 11 Number: 3757

Today's topics:
    Re: a regex for removing a password in a source listing <ben@morrow.me.uk>
    Re: a regex for removing a password in a source listing <uri@stemsystems.com>
    Re: a regex for removing a password in a source listing <oneingray@gmail.com>
    Re: a regex for removing a password in a source listing <ben@morrow.me.uk>
    Re: a regex for removing a password in a source listing <ben@morrow.me.uk>
    Re: a regex for removing a password in a source listing <uri@stemsystems.com>
    Re: dynamic content with PDF::API2 <ben@morrow.me.uk>
    Re: How to debug a regex with (?DEFINE)? <ben@morrow.me.uk>
    Re: Man, has this newsgroup shrunk.  Why?  Where gone t <xhoster@gmail.com>
    Re: Netnews for Gen X <oneingray@gmail.com>
        Pause until external program exits with success? <tuxedo@mailinator.com>
    Re: Pause until external program exits with success? <jurgenex@hotmail.com>
    Re: Pause until external program exits with success? <tuxedo@mailinator.com>
    Re: Using variable in replacement expression <derykus@gmail.com>
    Re: Using variable in replacement expression <ben@morrow.me.uk>
        Windows: Rakudo-Star Perl6 now available as *.msi <dilbert1999@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 12 Aug 2012 13:22:04 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <cojkf9-5l51.ln1@anubis.morrow.me.uk>


Quoth tmcd@panix.com:
> 
> While it's a true statement and people should know that there's a
> difference and sometimes it matters, I used Perl for many years
> thinking that lists and arrays were the same and didn't get bit by it.
> Even just rereading that FAQ entry, I may be still a bit fuzzy.

It's very simple: a list is a value, like 3 or "hello world". An array
is a variable, like $x. Just as the variable $x can hold the value 3, so
the variable @x can hold the value (1, 2, 3).

Ben



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

Date: Sun, 12 Aug 2012 12:46:17 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <877gt4kqhy.fsf@stemsystems.com>

>>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:

  BM> Quoth tmcd@panix.com:
  >> 
  >> While it's a true statement and people should know that there's a
  >> difference and sometimes it matters, I used Perl for many years
  >> thinking that lists and arrays were the same and didn't get bit by it.
  >> Even just rereading that FAQ entry, I may be still a bit fuzzy.

  BM> It's very simple: a list is a value, like 3 or "hello world". An array
  BM> is a variable, like $x. Just as the variable $x can hold the value 3, so
  BM> the variable @x can hold the value (1, 2, 3).

i have more i teach about that. lists are on the stack, are only in
expressions and can't live beyond them. arrays are allocated from the
heap and can live between statements. you can assign lists to/from
arrays and both can be sliced.

uri


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

Date: Sun, 12 Aug 2012 23:57:57 +0700
From: Ivan Shmakov <oneingray@gmail.com>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <86393scaju.fsf@gray.siamics.net>

>>>>> Ben Morrow <ben@morrow.me.uk> writes:
>>>>> Quoth tmcd@panix.com:

 >> While it's a true statement and people should know that there's a
 >> difference and sometimes it matters, I used Perl for many years
 >> thinking that lists and arrays were the same and didn't get bit by
 >> it.  Even just rereading that FAQ entry, I may be still a bit fuzzy.

 > It's very simple: a list is a value, like 3 or "hello world". An
 > array is a variable, like $x.  Just as the variable $x can hold the
 > value 3, so the variable @x can hold the value (1, 2, 3).

	That's helpful, thanks.  Though it still doesn't seem to tell
	whether there's an array in [1, 2, 3] or not.

-- 
FSF associate member #7257	http://sf-day.org/


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

Date: Sun, 12 Aug 2012 19:15:17 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <le8lf9-t5p1.ln1@anubis.morrow.me.uk>


Quoth Ivan Shmakov <oneingray@gmail.com>:
> >>>>> Ben Morrow <ben@morrow.me.uk> writes:
> >>>>> Quoth tmcd@panix.com:
> 
>  >> While it's a true statement and people should know that there's a
>  >> difference and sometimes it matters, I used Perl for many years
>  >> thinking that lists and arrays were the same and didn't get bit by
>  >> it.  Even just rereading that FAQ entry, I may be still a bit fuzzy.
> 
>  > It's very simple: a list is a value, like 3 or "hello world". An
>  > array is a variable, like $x.  Just as the variable $x can hold the
>  > value 3, so the variable @x can hold the value (1, 2, 3).
> 
> 	That's helpful, thanks.  Though it still doesn't seem to tell
> 	whether there's an array in [1, 2, 3] or not.

That is the confusing case, yes :). An expression like

    my $x = [1, 2, 3];

is equivalent to something like

    sub build_array {
        my @array = @_;
        return \@array;
    }

    my $x = build_array(1, 2, 3);

so there is an array there, it just hasn't got a name and is only
accessible through the reference.

Ben



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

Date: Sun, 12 Aug 2012 19:22:18 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <qr8lf9-t5p1.ln1@anubis.morrow.me.uk>


Quoth Uri Guttman <uri@stemsystems.com>:
> >>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:
> 
>   BM> Quoth tmcd@panix.com:
>   >> 
>   >> While it's a true statement and people should know that there's a
>   >> difference and sometimes it matters, I used Perl for many years
>   >> thinking that lists and arrays were the same and didn't get bit by it.
>   >> Even just rereading that FAQ entry, I may be still a bit fuzzy.
> 
>   BM> It's very simple: a list is a value, like 3 or "hello world". An array
>   BM> is a variable, like $x. Just as the variable $x can hold the value 3, so
>   BM> the variable @x can hold the value (1, 2, 3).
> 
> i have more i teach about that. lists are on the stack, are only in
> expressions and can't live beyond them. arrays are allocated from the
> heap and can live between statements. 

That's just the variable/value distinction. In a statement like

    $x + 4;

both the 4 and the result of the addition are temporaries on the stack,
and will evaporate at the end of the statement.

> you can assign lists to/from arrays and both can be sliced.

Slicing a list is different from slicing an array, in that a list slice
consumes the list and the values sliced away are no longer accesible. In
this respect it's more like a variant of 'grep' than like an array
slice.

Ben



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

Date: Mon, 13 Aug 2012 02:02:18 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: a regex for removing a password in a source listing
Message-Id: <87393rl47p.fsf@stemsystems.com>

>>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:

  BM> Quoth Uri Guttman <uri@stemsystems.com>:

  BM> It's very simple: a list is a value, like 3 or "hello world". An array
  BM> is a variable, like $x. Just as the variable $x can hold the value 3, so
  BM> the variable @x can hold the value (1, 2, 3).
  >> 
  >> i have more i teach about that. lists are on the stack, are only in
  >> expressions and can't live beyond them. arrays are allocated from the
  >> heap and can live between statements. 

  BM> That's just the variable/value distinction. In a statement like

  BM>     $x + 4;

  BM> both the 4 and the result of the addition are temporaries on the stack,
  BM> and will evaporate at the end of the statement.

sure but it explains it better those confused about values vs
vars. showing the lifetime and where the live give a better picture. i
didn't say you were wrong but i add more when i teach that issue.

  >> you can assign lists to/from arrays and both can be sliced.

  BM> Slicing a list is different from slicing an array, in that a list slice
  BM> consumes the list and the values sliced away are no longer accesible. In
  BM> this respect it's more like a variant of 'grep' than like an array
  BM> slice.

i disagree. you can reorder sliced elements and even duplicate
them. grep can do neither as it can only return a subset list in the
same original order.

slicing is the same effective op on both lists and arrays. i dunno the
actual op tree.

uri


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

Date: Sun, 12 Aug 2012 19:02:04 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: dynamic content with PDF::API2
Message-Id: <sl7lf9-t5p1.ln1@anubis.morrow.me.uk>


Quoth ccc31807 <cartercc@gmail.com>:
> I've been using PDF::API2 for years without a problem of any kind, but
> now have a new requirement -- text wrapping. Here's an example:
> 
> #from a hashref from a database, name could be NULL
> my $name = $hashref->{$key}{name};
> my $sentence = '';
> $sentence = "Hello, my name is $name." if $name;
> 
> #in PDF code
> $text->text("Greetings. $sentence Here is some information.");
> 
> This works if $name is NULL, because $sentence takes up no space and the
> end result contains two spaces after the greeting, which isn't a big
> deal.
> 
> However, there's a big difference between 'Ed' and 'Barack Hussein
> Obama.' The longer names cause the line to run off the right margin.
> 
> Is it possible to wrap text in PDF::API2? I've looked and can't see how.
> 
> I could write my own wrapping routine, but would rather not.

PDF::API2::Simple has a simple-minded text-wrapping feature, or you
could use Text::Flow::Wrap to wrap the text before writing it to the
PDF.

Doing text wrapping properly is Hard. If you care about the quality of
your output you ought to be using a proper typesetting program like TeX.
(Modern versions of TeX, LuaTeX and ConTeXt in particular, are much less
gnarly than they used to be, especially when it comes to using ordinary
fonts.) You could also consider generating something you can feed
through InDesign or <spit> Word.

Ben



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

Date: Sun, 12 Aug 2012 18:33:41 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to debug a regex with (?DEFINE)?
Message-Id: <l06lf9-mto1.ln1@anubis.morrow.me.uk>


Quoth Peng Yu <pengyu.ut@gmail.com>:
> 
> I'm trying to extract the nested namespace in the following code. But
> the code can only extract the inner namespace. It is very hard for me
> to see what is wrong. Does anybody know some tricks how to debug a
> regex like the following? Thanks!

The best way to debug something like this is to run it under 'use re
"debug"'. The output is rather verbose and a little arcane, so it takes
a bit of patience to pick through it, but it tells you *exactly* what
the regex engine is doing and where it fails.

In this case the important bit (reformatted slightly) is

  29 <e B {> <%n  }%n}%n>    | 62:  OPEN5 'namespace_body'(64)
  29 <e B {> <%n  }%n}%n>    | 64:  BRANCH(72)
  29 <e B {> <%n  }%n}%n>    | 65:    STAR(67)
                                      SPACE can match 3 times out of 
                                           2147483647...
  32 <e B {%n  > <}%n}%n>    | 67:      GOSUB4[-26](70)
  32 <e B {%n  > <}%n}%n>    | 41:        OPEN4 'namespace'(43)
  32 <e B {%n  > <}%n}%n>    | 43:        GOSUB3[-12](46)
  32 <e B {%n  > <}%n}%n>    | 31:          OPEN3 'namespace_keyword'(33)
  32 <e B {%n  > <}%n}%n>    | 33:          BOUND(34)
                                            failed...

[snip some attempts to claw back spaces from the \s*; using (?>) or \s*+
might be a good idea...]

                                      failed...
  29 <e B {> <%n  }%n}%n>    | 72:  BRANCH(76)
  29 <e B {> <%n  }%n}%n>    | 73:    GOSUB6[+5](76)
  29 <e B {> <%n  }%n}%n>    | 78:      OPEN6 'block'(80)
  29 <e B {> <%n  }%n}%n>    | 80:      EXACT <{>(82)
                                        failed...
                                    BRANCH failed...
                                 failed...

Here it's matched as far as 'namespace B {' and it's trying to match
(?&namespace_body), but that requires either a sub-namespace or a
(?<block>) (with explicit braces) so it doesn't match. You need to add
an empty case here:

>         (?<namespace_body>
>             (?:
>               \s*
>               (?&namespace)
>               \s*
>             )
>             |
>             (?&block)

            | \s*

>         )

though I suspect that you actually want to allow whitespace around
blocks, so what you want is

    (?<namespace_body>
        \s*
        (?: (?&namespace)
        |   (?&block)
        |   # empty
        )
        \s*
    )

or perhaps

    (?<namespace>
        (?&namespace_keyword) \s+ (?&namespace_token) \s*
        \{ \s* (?: (?&namespace_body) \s* )* \}
    )

    (?<namespace_body>
        (?&namespace) | (?&block)
    )

to allow multiple blocks-or-namespaces within one namespace.

>         (?<block>
>             \{
>                 (?: (?&block) | . )*?
>             \}

You want to be careful about using .*? to mean 'match anything
until...'. This will correctly match good input, but it is too
permissive; for instance, this

    namespace A { { { } }

will match, despite not having balanced braces. You want

    (?: (?&block) | [^\{] )*

to prevent that, and if you also want to forbid namespaces within blocks
you need

    (?: (?&block)
    |   (?! (?&namespace_keyword) | \{ ) .
    )*

Ben



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

Date: Thu, 09 Aug 2012 19:48:41 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Man, has this newsgroup shrunk.  Why?  Where gone to?
Message-Id: <5025a625$0$20997$ed362ca5@nr5-q3a.newsreader.com>

On 08/08/2012 05:48 AM, Shmuel (Seymour J.) Metz wrote:
> In <5021f274$0$20999$ed362ca5@nr5-q3a.newsreader.com>, on 08/07/2012
>     at 08:55 PM, Xho Jingleheimerschmidt <xhoster@gmail.com> said:
>
>> And Google's ever-increasing crappification of their interface
>> surely doesn't help.  It is hard to tell what is less usable,
>> their search interface or their posting interface.  It is amazing
>> how an otherwise good company can so systematically screw up this
>> one area with such consistency, intensity, and vigor.
>
> Perhaps you need to reexamine your assumption that they are otherwise
> good.
>

I reexamine it on a regular basis.

It's a cron job.

Xho


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

Date: Sun, 12 Aug 2012 23:19:57 +0700
From: Ivan Shmakov <oneingray@gmail.com>
Subject: Re: Netnews for Gen X
Message-Id: <86ehncccb6.fsf@gray.siamics.net>

>>>>> Shmuel (Seymour J ) Metz writes:
>>>>> In <86a9y4i655.fsf_-_@gray.siamics.net>, Ivan Shmakov said:

 >> In this scheme, and taking INN as an example, newsfeeds(5), and its
 >> reciprocal incoming.conf(5), serve two purposes: they remedy the
 >> fact that Netnews currently lack autodiscovery (contrary to the P2P
 >> networks mentioned above), and they code (in a crude, but working,
 >> fashion) the "trust" relationship between the peers.

 > There's more than trust involved in current news routing; there's
 > also the ability, e. g., for specific servers to carry only specific
 > groups,

	First of all, newsgroups doesn't matter that much.  They're just
	tags, which are immutable once the message is posted, and, quite
	often than not, are incomplete or misleading.  (And this thread
	is a good example of that.)  Would I run my own NNTP "server",
	I'd make it "track" a number of selected individuals, and all
	the threads they've been participating in, whatever are the
	newsgroups.

	Unfortunately, NNTP doesn't make this task all that easy.

 > and to announce what they carry.

	AIUI, NNTP only provides for a way to know if a newsgroup is
	created on the "server", not whether it's actually carried
	(i. e., subscribed to on one or more of the peers) or not.

 >> With a sound use of digital signatures (and implementing the
 >> relevant WoT, or re-using the OpenPGP one), we can lay the control
 >> over what's trustworthy and what's not straight to the hands of the
 >> user.

 > I don't see how.

	Isn't it trivial to make a whitelist of public keys of all the
	people one wants to receive mail from?  It's much less an issue
	than providing a way for a stranger (or one who has lost his or
	her private key) to communicate, while still stopping abuse.

 >> Let's first assume that "autodiscovery" is in place.  Now, Alice
 >> chooses a "relay" (there may be both free of charge and paid ones),
 >> and her agent puts (into the distributed hash table, or DHT) a
 >> (digitally-signed) "pointer" record that all her mail should be
 >> delivered to that relay.

 > How do you authenticate a message from a stranger?

	If the stranger's public key isn't reachable via my own WoT, and
	if it wasn't used to sign any "public" messages I may find, then
	I have no way to authenticate it.

 > With SMTP there's an unforgeable source IP address that I can filter
 > on.

	Not quite, at least since the time various Webmails became
	widespread.  For privacy concerns, they're quite likely to
	"hide" the IP of the HTTP client used to submit the message.

	Also, the IP in question may be autoconfigured, or "leased" via
	DHCPv6 or DHCP, or it may be an IPv4 address of the NAT'ting
	router, just as well.  Thus, only the network prefix could be
	obtained (more or less) reliably from the message's headers.

	Tor could be used to anonymize IP, too, but its default is to
	block traffic to TCP port 25.  (Which doesn't quite help if
	there was a "transit Webmail" at TCP port 80 or 443, though.)

 >> It makes sense for the Bob's letter to mention a few of his previous
 >> messages (sent to Alice) in the header.

 > Not if there are no previous messages.

	Obviously.

 >> Both GNUnet and Freenet (IIRC) implement an HTTP interface, so that
 >> an ordinary Web browser can be used to connect to the network.

 > Exactly what I want to avoid.

	HTTP is a quite decent file transfer protocol, and "speaking" it
	isn't a problem.  (Not anymore, and arguably much less, than
	speaking FTP, for instance.)  My guess is that one can access
	these networks with, say, GNU Wget or aria2, too.

 >> And what exactly it's for?

 > The audit trail in e-mail is intended for diagnostic purposes,

	Yes, but as I've said before, any complex routing doesn't make
	much sense for e-mail anymore, and there isn't much "diagnostic"
	that could be obtained in the "two MTA's" case other than that
	already recorded in the logs of those MTA's.

	Don't we already have some complex routing running on the
	network level?  Why repeat it a few levels higher?

 > but in practice it is used for spam filtering as well.

	Essentially, that means that instead of relying on almost
	unforgeable TCP/IP "peer" (address, port) pair, one decides to
	rely on the Received: headers, as added by the "third party"
	(= transit MTA's.)

 >> I don't see why one may need to care /how/ the letter has reached
 >> its destination if it's a valid and wanted one.

 > There's no automated way to tell that a message is a validated and
 > wanted one, so you have to rely on heuristics.  Deep filtering is one
 > useful heuristic.

	We can design a system for /reliable/ (something that the
	present e-mail doesn't quite offer) delivery between
	pairwise-trusted peers.  It's up to the user then to decide
	whose messages he wants to be delivered to him or her.

 >> only a partial solution.

 > Partial solutions are all we have.

	Ultimately, yes.

 > In addition to the difficulty of developing a new infrastructure that
 > retains the functionality of the existing infrastructure, there's
 > also the problem of transition.

	Yes, at least to some extent.

	Though it was my understanding that opting for social networking
	sites, GenX has pretty much forsaken e-mail.  (My guess is that
	they didn't notice that part of the functionality has vanished
	meanwhile.)

-- 
FSF associate member #7257	http://sf-day.org/


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

Date: Sat, 11 Aug 2012 07:18:40 +0200
From: Tuxedo <tuxedo@mailinator.com>
Subject: Pause until external program exits with success?
Message-Id: <k04pvh$ttn$1@news.albasani.net>

In running an external process I would like to continue (or terminate) a 
script depending on the output of the external process.

For example, if the process is to scale a very large image with 
ImageMagick's convert, how can the script be made to continue after the 
completion of the external system process, e.g. once ImageMagick's Fatal 
Error exit code has returned 0:

system "convert -quality 80 -resize 500x600 giant.jpg small.jpg";

more stuff....

What are good ways to proceed with more stuff if/when the system command 
has completed?

Tuxedo


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

Date: Fri, 10 Aug 2012 23:45:10 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Pause until external program exits with success?
Message-Id: <gfvb28tfpml7tu9jgq5e08osgbsdgs0cfb@4ax.com>

Tuxedo <tuxedo@mailinator.com> wrote:
>In running an external process I would like to continue (or terminate) a 
>script depending on the output of the external process.
>
>For example, if the process is to scale a very large image with 
>ImageMagick's convert, how can the script be made to continue after the 
>completion of the external system process, e.g. once ImageMagick's Fatal 
>Error exit code has returned 0:
>
>system "convert -quality 80 -resize 500x600 giant.jpg small.jpg";

'perldoc -f system' describes two different ways for how to check the
return value of an external process. Did you try those? Did neither
work?

>more stuff....
>
>What are good ways to proceed with more stuff if/when the system command 
>has completed?

What you are asking for is system()'s standard behaviour. What behaviour
are you observing instead?

jue


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

Date: Sat, 11 Aug 2012 22:51:56 +0200
From: Tuxedo <tuxedo@mailinator.com>
Subject: Re: Pause until external program exits with success?
Message-Id: <k06gle$kf$1@news.albasani.net>

Jürgen Exner wrote:

[...]

> 'perldoc -f system' describes two different ways for how to check the
> return value of an external process. Did you try those? Did neither
> work?

No I didn't, thanks for the pointer.

> >What are good ways to proceed with more stuff if/when the system command
> >has completed?
> 
> What you are asking for is system()'s standard behaviour. What behaviour
> are you observing instead?

Not knowing what to look for I did not test anything yet. I will look into 
'system' and also System::Command. I'm not sure which may be a better way.

Thanks for the tips!
Tuxedo



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

Date: Sat, 11 Aug 2012 00:25:11 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Using variable in replacement expression
Message-Id: <6c8f272a-c02c-4025-9231-c9f41af15222@googlegroups.com>

On Wednesday, August 8, 2012 3:42:15 PM UTC-7, Tim McDaniel wrote:
> In article <141389db-09e3-43de-89c5-e8cb9ce8abeb@googlegroups.com>,
> 
> RobV  <rob@sypron.nl> wrote:
> 
> >I'm trying to do a global replace with a varying replacement string
> 
> >which includes a counter to count the replacements.
> 
> >The idea is this (replacing all "xy" strings):
> 
> >   Source: "ab xy cd xy ef xy gh"
> 
> >   Result: "ab Mark1 cd Mark2 ef Mark3 gh"
> 
> >
> 
> >I read through perlre and the best I can come up with is below. Yet
> 
> >it doesn't do what I wanted, the replacement is identical every time:
> 
> >
> 
> >$cnt = 1;
> 
> >$replace = '"Mark$cnt"';
> 
> >$s = "ab xy cd xy ef xy gh";
> 
> >
> 
> >while ($s =~ s/xy/$replace/gee) { 
> 
> >	  $cnt++;
> 
> >}
> 
> >print $s;
> 
> 
> 
> As a side note: even in a simple test program, it's best to keep the
> 
> discipline of
> 
>     use warnings;
> 
>     use strict;
> 
> and "my"ing all variables.
> 
> 
> 
> >Result is: "ab Mark1 cd Mark1 ef Mark1 gh"
> 
> >
> 
> >My understanding of the /ee modifier is that it forces the right-hand
> 
> >side to be evaluated every time, but somewhere in my understanding
> 
> >something seems to be missing.
> 
> 
> 
> Print $cnt after the loop.  You'll see that it's 2.  That means that
> 
> the loop iterated only once.
> 
> 
> 
> The problem is the "g" modifier.  It replaces ALL occurrences the
> 
> first time it runs.
> 
> 
> 
> "g" in general is a good idea, to prevent an infinite loop if the RHS
> 
> happened to contain the LHS (that is, if $replace contained "xy").
> 
> 
> 
> This works for me in 5.14.2:
> 
> 
> 
>     my $s = "ab xy cd xy ef xy gh\n";
> 
>     my $cnt = 0;
> 
>     $s =~ s/xy/++$cnt, "Mark$cnt"/ge;
> 
>     print $s;
> 
> 
> 
> and therefore
> 
> 
> 
>     my $s = "ab xy cd xy ef xy gh\n";
> 
>     my $cnt = 0;
> 
>     my $replace = '++$cnt, "Mark$cnt"';
> 
>     $s =~ s/xy/$replace/gee;
> 
>     print $s;
> 
> 

A variant sans comma operator:

$cnt = 1;
$replace = '"Mark" . $cnt++';
$s =~ s/xy/$replace/gee;

-- 
Charles DeRykus


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

Date: Sun, 12 Aug 2012 19:08:59 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Using variable in replacement expression
Message-Id: <r28lf9-t5p1.ln1@anubis.morrow.me.uk>


Quoth RobV <rob@sypron.nl>:
> I'm trying to do a global replace with a varying replacement string
> which includes a counter to count the replacements. 
> The idea is this (replacing all "xy" strings):
>    Source: "ab xy cd xy ef xy gh"
>    Result: "ab Mark1 cd Mark2 ef Mark3 gh"
> 
> I read through perlre and the best I can come up with is below. Yet it
> doesn't do what I wanted, the replacement is identical every time:
> 
> $cnt = 1;
> $replace = '"Mark$cnt"';
> $s = "ab xy cd xy ef xy gh";
> 
> while ($s =~ s/xy/$replace/gee) { 

Don't do that. /ee does a string eval, which should be avoided unless
absolutely necessary. Just use ordinary /e:

    $s =~ s/xy/"Mark" . $cnt++/;

Even in cases where you do decide you need the string eval, I would
write it as

    $s =~ s/xy/$c++; eval $replace/ge;

so the 'eval' is extremely obvious. A simple extra /e is much too easy
to miss.

Ben



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

Date: Mon, 13 Aug 2012 05:24:43 -0700 (PDT)
From: Dilbert <dilbert1999@gmail.com>
Subject: Windows: Rakudo-Star Perl6 now available as *.msi
Message-Id: <5071df31-1c82-4e11-a90d-4ebbb636fae2@f2g2000vbm.googlegroups.com>

Hello everybody,

I am a Windows user and I always wanted to run Rakudo-Star Perl 6, but
I couldn't get the installation / compile from source to run on my
Windows 7 box (32 bits). I grew more and more frustrated.

Then I came across a posting "Windows .msi available for Rakudo Star
2012.07" by pmichaud on http://rakudo.org/2012/07/30/windows-msi-available-=
for-rakudo-star-2012-07/
and I installed the Rakudo *.msi file (which is a really simple one-
click installation process) and it worked perfectly.

I thought that Windows people on comp.lang.perl.misc are interested to
know that they too can now run Rakudo-Star Perl 6.

>> Windows .msi available for Rakudo Star 2012.07
>> Posted on 2012.07.30 by pmichaud
>>
>> I'm pleased to announce that starting with the
>> current Rakudo Star release (2012.07), we will
>> now be providing Windows .msi distributions with
>> precompiled binaries for Rakudo Star. The .msi
>> distribution is available in the same location as
>> other Rakudo Star releases, at
>> https://github.com/rakudo/star/downloads/ .
>>
>> On this site, on IRC, and at YAPC::NA 2012 I heard
>> many people comment that Windows users really
>> wanted a binary install option. We=92ve occasionally
>> done .msi and .exe installers for Rakudo Star
>> releases in the past, but didn't have any dedicated
>> tools or sufficient environments to be able to
>> produce them consistently each month. So, this month
>> I dedicated some time to create scripts and tools
>> that can automate much of the process of building .msi
>> distributions from the Rakudo Star release tarballs.
>> Over the next couple of weeks I will be documenting
>> the process so that others can hopefully follow it
>> as well. With the new tools in place I think we=92ll be
>> able to consistently provide Rakudo .msi distributions
>> within a few days (if not hours) of each monthly
>> tarball release.
>>
>> (At this time I can=92t guarantee that .msi files will
>> always be published at the same time as the standard
>> tarballs, because some monthly release managers may
>> not have access to a suitable Widnows environments for
>> building the .msi. Bear with us while we work out the
>> full release details. :-) )
>>
>> This is still a newish process for us, so if you
>> encounter any problems with the .msi distribution, let
>> us know on IRC #perl6, file a bug ticket, or send a
>> note to perl6-users@perl.org or perl6-compiler@perl.org.
>>
>> Enjoy!


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3757
***************************************


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