in reply to Getting rid of (.*) from a not-quite-complex regex.
This will save the regex engine from having to match to the end of the line and then backtrack all the way back to the first column. I also changed 0-9 to \d in the character classes, and changed \d{2} to \d{1,3}, assuming you don't really want to ignore devices that are 100% full or less than 10% full.my ($ptid, $total, $used, $avail, $pct, $mp) = $element =~ m!^(/dev/\S+) # which partition $ptid \s+([\d.]+[MGK]) # total size of parition $total \s+([\d.]+[MGK]) # used space $used \s+([\d.]+[MGK]) # available space $avail \s+(\d{1,3})% # percent usage $pct \s+(.*)$!x; # mounting point $mp
BTW, your regex isn't compatible across Unix platforms:
Filesystem Type blocks use avail %use Mounted on /dev/root xfs 16718720 11050536 5668184 67 / /dev/dsk/dks1d6s0 xfs 8758624 1968528 6790096 23 /usr/darmo +k AFS afs 14400000 0 14400000 0 /afs
Anyway, I think tilly's and lemming's suggestion of using split with a limit is the best approach.
|
|---|