Yes, by all means, let's take the regex first.
Using the special vars you do,

002: $processname=" $`";  # matches before string
003: $memory = $&  ;     # $& matches the string

may increase your cost-of-processing. See perlre at the "Warning" section of the "Capture Buffers" segment. As that doc now (as of 5.10 but perhaps earlier; certainly for 5.12) there's a bit of ambiguity about the cost of $` and $&:

WARNING: Once Perl sees that you need one of $&, $`, or $' anywhere in the program, it has to provide them for every pattern match. This may substantially slow your program. Perl uses the same mechanism to produ +ce $1, $2, etc, so you also pay a price for each pattern that contains capturing parentheses. (To avoid this cost while retaining the groupin +g behaviour, use the extended regular expression "(?: ... )" instead.) B +ut if you never use $&, $` or $', then patterns *without* capturing parentheses will not be penalized. So avoid $&, $', and $` if you can, but if you can't (and some algorithms really appreciate them), once you've used them once, use them at will, because you've already paid t +he price. As of 5.005, $& is not so costly as the other two.

Others, deeper into benchmarking, or perlguts, may be able to clarify, but based on the traditional warning against those special regex vars, you might chose ordinary captures:

#!/usr/bin/perl use strict; use warnings; use 5.012; # 948541 my @arr = <DATA>; for $_(@arr) { if ( $_ =~ /([a-z 0-9\+\.]+?)(\d{0,3},{0,1}\d{0,3},{0,1}\d{1,3}) K +/i ) { #1 my $processname = $1; my $memory = $2; say "$memory --- $processname"; } } #1 NB this regex allows for entries as small as 1K -- a condition # of which you might want to be aware. =head output: 1,788,180 --- disp+work.exe 3380 Console 0 2,787,204 --- sqlservr.exe 1768 Console 0 1,078,120 --- jlaunch.exe 4608 0 1,830,376 --- sqlservr.exe 1812 0 488,716 --- disp+work.exe 4772 0 17 --- proc 9412 Console 0 =cut __DATA__ disp+work.exe 3380 Console 0 1,788,180 K sqlservr.exe 1768 Console 0 2,787,204 K jlaunch.exe 4608 0 1,078,120 K sqlservr.exe 1812 0 1,830,376 K disp+work.exe 4772 0 488,716 K small_proc 9412 Console 0 17 K

Is your data sample correct, showing "Console" present in some entries and not in others?


In reply to Re: transfer a array to a hash by ww
in thread transfer a array to a hash by BlackForrest

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.