Home: Perl Programming Help: Regular Expressions:
get size in a variable



sajanagr
Novice

Jan 26, 2010, 11:58 PM


Views: 7076
get size in a variable

Hi
I have a simple query to get the size output of a command into a variable. This is what i have tried :
The command output is like :

Code
   68.58G


Regular expression :

Code
if ($out =~ /(\d*\.\d*\S)/){ 
$out=$1;
}


This seemed to work earlier and i hav updated perl and it now gives me output ' .p '; I don't seem to understand the issue.

Kindly help!!
Not all who wander are lost ---- /me


shawnhcorey
Enthusiast


Jan 27, 2010, 5:10 AM


Views: 7069
Re: [sajanagr] get size in a variable

Print out the contents of $out. I think you'll find it has at least two periods in it.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


sajanagr
Novice

Jan 27, 2010, 5:20 AM


Views: 7067
Re: [shawnhcorey] get size in a variable

The issue has been solved. The expression was fine, but not perfect. Checked out the output of $out and solved it. Modified the expression by -


Code
$out =~  /(\d+\.\d+G\s+)/

Not all who wander are lost ---- /me


shawnhcorey
Enthusiast


Jan 27, 2010, 5:53 AM


Views: 7062
Re: [sajanagr] get size in a variable


Code
$out =~  /(\d+\.\d+G\b);/


\b works even at the end of a string.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".