could anybody point me in the right direction when it comes to looping through the output of a system command in perl (i.e. df -k) doing a test against each line to see if it matches?
for example if i have a df -k output like this and I wanted to grab the lines that matched "sda" or "udev" in the first column
thanks Pludi, im not entirely sure i understand exactly what is going on here. but it seems to work as you expected. Specifically, i dont understand the comma separated open/variable declaration bit...... this technique is very new to me
I assumed perl would have a syntactically simple and intuitive way of performing an action such as this. i guess not
, but I find the 3 parameter form (variable, mode, "file") to be more readable. And the variable declaration is advisable here, unless you're reusing an older variable (you are using use strict;, aren't you?)
As for more intuitive, do you mean something like
print foreach `df -k`
If so, it's shorter, but much more unmaintainable.