hasimir44 has asked for the wisdom of the Perl Monks concerning the following question:
This little snippet works fine to grab a (compressed) file name and it's time stamp, but I'm sure that the regexp part could be written better. Also, does it have to be in an "if" statement?
The Output looks like this:chomp($ll[0] = `ls -lto $path/*B1006* |head -n 1`); chomp($ll[1] = `ls -lto $path/*B1106-* |head -n 1`); chomp($ll[2] = `ls -lto $path/*B11062* |head -n 1`); $next = 0; foreach (@ll) { if (m#([A-Z][a-z][a-z]\s[0-9][0-9]\s[0-9][0-9]:[0-9][0-9])\s(/.+\. +Z)#) { $stamp[$next] = $1; $name[$next] = $2; } print "\$name[\$next]: $name[$next]\n"; print "\$stamp[\$next]: $stamp[$next]\n"; $next++; }
I am the young grasshopper. In one hour, I will be off work and practicing my drunken style :) Cheers.$name[$next]: /<path>/B1006-cnvexp.20060605.200841.Z $stamp[$next]: Jun 05 20:08 $name[$next]: /<path>/B1106-cnvexp.20060605.2008.Z $stamp[$next]: Jun 05 20:09 $name[$next]: /<path>/B11062-cnvexp.20060605.2008.Z $stamp[$next]: Jun 05 20:09
2006-06-06 Retitled by planetscape, as per Monastery guidelines ( keep:0 edit:11 reap:0 )
Original title: 'Tips for elegence'
Back to
Seekers of Perl Wisdom