Correct! Using these special regex variables is not advised due to the performance decrease.

When I wrote my code, I didn't look closely at the way that these lines were generated and how the @array was built.

But to generate the @array, with this DATA, here is one way....

#!/usr/bin/perl -w use strict; my @data; foreach my $line (<DATA>) { # anchor match to the end of string with $ # anchor match to the beginning of string with ^ # ignore the K and spaces at the end (includes \n) # get the numbers and commas right before the K # get this stuff in front ($before) # but ignore any leading spaces in the line # a "greedy" match will not be so "greedy" that it # won't allow the last part of the regex to match # so it is not necessary to constrain the .+ match here my ($before, $mem) = ($line =~ /^\s*(.+)\s+([\d,]+)\s*K\s*$/); $mem =~ tr/,//d; #delete commas in like 2,787,204 push @data, "$mem $before\n"; #adds the \n back in } print @data; =prints: 1788180 disp+work.exe 3380 Console 0 2787204 sqlservr.exe 1768 Console 0 1078120 jlaunch.exe 4608 0 1830376 sqlservr.exe 1812 0 488716 disp+work.exe 4772 0 17 small_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

In reply to Re^2: transfer a array to a hash by Marshall
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.