Re: REGEXP removing - il- - -b-f and - il- - - - f



I will answer and ask all questions in one email! k.

> $!";
> 5> my @fa =();
> 6> my @ha =();
> 7> my $i =0;
> 8> foreach (<V4>) {

> Is there any good reason to slurp the entire file into memory?

What would you suggest? I want to read the entire file via a filehandle.
I have plenty of system memory, therefore why not?



> You are using the match in a boolean context so the /g option makes no
sense.
> 15> #$fa[$i++] = +(split)[5,6,7] if (m/f01(\d+)/gi );

If I do not use the /g modifier then it will not slurp the entire file or
all instances of F01, I tried it without /g and it did not work.


>The value of $#fa is not the number of elements in the array, for that you
>want to use the array in scalar context:

>print "Now printing array count \t", scalar @fa, "\n";

>Or:

>print "Now printing array count \t" . @fa . "\n";


In my Learning Perl 2nd edition and Programming Perl 3rd edition, no where
does it say use
scaler @fa to get the element count, rather it says use $#fa. Is there
something I am unaware of or was $# deprecated recently?

Why is scaler @fa better/more correct than $#fa?

I have been told that my @a = ( ); is more correct than my @a, but now I am
confused b/c others are telling me otherwise??? Personally, I like my @a =
( );
because it lets me know explicitly that this array is now initialized to 0
elements, plus its faster at compile time...KUDOS to John Kran!

>From Jupiter :

> > You do realize that the characters 'F', '0' and '1' are included in the
> character class \w which split() is removing? :-)

yeah I realized that typo too late :), I meant \s not \w but then plain
old my @tmp = split; is even better :)

But I thought spit by default separates on whitespace? And F, 0 and 1 are
indeed apart of char classes \w and \d?

Finally no one has answered my question what does (split)[-1] mean?


thank you!
derek


Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams





"John W. Krahn"
<krahnj@xxxxxxxxx
> To
Perl Beginners <beginners@xxxxxxxx>
04/27/2005 05:24 cc
PM
Subject
Re: REGEXP removing - il- - -b-f
and - il- - - - f










DBSMITH@xxxxxxxxxxxxxx wrote:
> yes I agree I was a little ambiguous... I was in a hurry. sorry. Anyway
> here is my updated code. and here is a sample output:
> My goal is to get all F01 which I am but I am having issues capturing all
> of these values into my array. When I run the I get the data I want to
see
> which is just the F01 column, but when I comment out line 14 and
uncomment
> line 15 and uncomment line 21 I see no data in the array???
> In the end I want the F01 column and the % column.

You only want the two columns, that looks simple enough:

while ( <V4> ) {
my ( $percent, $f01 ) = /(\d+%).*?(f01\d+)/i or next;
print "$percent $f01\n";
}


> 1 2005/01/20 15:39 17 2% -il-o-b- - - - - sg F01000
> 2 2005/01/20 15:53 14 1% -il-o-b----- sg F01001
> 3 2005/01/18 09:53 2 0% -il-o-b----- sg F01002
> 4 2005/02/04 16:41 196 100% -il-o-b----f sg F01003
> 5 2005/02/05 21:13 305 100% -il-o-b----f sg F01004
> 6 2005/02/28 22:47 180 100% -il-o-b----- sg F01005
> 13 2005/02/08 16:07 112 100% -il-o-b----f sg F01006
> 14 2005/02/09 21:56 122 100% -il-o-b----f sg F01007
> 15 2005/02/11 10:51 147 100% -il-o-b----f sg F01008
> 16 2005/02/13 11:35 193 100% -il-o-b----f sg F01009
> 17 2005/02/14 23:46 79 100% -il-o-b- - - -f sg F01010
>

<SNIP>
John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
<http://learn.perl.org/> <http://learn.perl.org/first-response>




.



Relevant Pages

  • Re: reading a file
    ... if you don't want to slurp all the lines into an array (to save memory). ... The way to avoid slurping the file is to use while rather than foreach: ...
    (perl.beginners)
  • Re: Fast string operations
    ... Looping: I thought looping over arrays in managed code was "slow" ... array handling and such. ... The problem with TrimHelper is that it always returns a new string instance. ... The customer perceives this as a memory leak. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: High Memory Consumption of Classes and Arrays
    ... Only the array itself has overhead. ... memory as a reference type. ... > least consume 40 bytes of memory. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Fast linked list
    ... > amounts of memory rather than huge chunks of it. ... random insertions into a vector/dynamic array are not as slow ... to cause a cache miss. ... some hard numbers on speed differences between lists and arrays. ...
    (microsoft.public.vc.mfc)
  • Re: Fast linked list
    ... > amounts of memory rather than huge chunks of it. ... random insertions into a vector/dynamic array are not as slow ... to cause a cache miss. ... some hard numbers on speed differences between lists and arrays. ...
    (microsoft.public.vc.language)